[libc-commits] [libc] [libc][stdfix] Add round functions for fixed point types. (PR #81994)
Guillaume Chatelet via libc-commits
libc-commits at lists.llvm.org
Fri Feb 16 07:39:24 PST 2024
================
@@ -19,6 +21,36 @@
namespace LIBC_NAMESPACE::fixed_point {
+// Bit-wise operations are not available for fixed point types yet.
+template <typename T>
+LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_fixed_point_v<T>, T>
+bit_and(T x, T y) {
+ using BitType = typename FXRep<T>::StorageType;
+ static_assert(sizeof(BitType) * CHAR_BIT == sizeof(T) * CHAR_BIT);
+ BitType x_bit = cpp::bit_cast<BitType>(x);
+ BitType y_bit = cpp::bit_cast<BitType>(y);
+ return cpp::bit_cast<T, BitType>(x_bit & y_bit);
+}
+
+template <typename T>
+LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_fixed_point_v<T>, T>
+bit_or(T x, T y) {
+ using BitType = typename FXRep<T>::StorageType;
+ static_assert(sizeof(BitType) * CHAR_BIT == FXRep<T>::TOTAL_LEN);
+ BitType x_bit = cpp::bit_cast<BitType>(x);
+ BitType y_bit = cpp::bit_cast<BitType>(y);
+ return cpp::bit_cast<T, BitType>(x_bit | y_bit);
----------------
gchatelet wrote:
same here
https://github.com/llvm/llvm-project/pull/81994
More information about the libc-commits
mailing list