[libc-commits] [libc] [libc] add FXBits class (PR #82065)

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Sat Feb 17 00:09:40 PST 2024


================
@@ -19,6 +21,74 @@
 
 namespace LIBC_NAMESPACE::fixed_point {
 
+template <typename T> struct FXBits {
+private:
+  using fx_rep = FXRep<T>;
+  using StorageType = typename fx_rep::StorageType;
+
+  StorageType value;
+
+  static_assert(fx_rep::FRACTION_LEN > 0);
+
+  static constexpr size_t FRACTION_OFFSET = 0; // Just for completeness
+  static constexpr size_t INTEGRAL_OFFSET = fx_rep::FRACTION_LEN;
+  static constexpr size_t SIGN_OFFSET =
+      fx_rep::SIGN_LEN == 0
+          ? 0
+          : ((sizeof(StorageType) * CHAR_BIT) - fx_rep::SIGN_LEN);
+
+  static constexpr StorageType FRACTION_MASK =
+      (StorageType(1) << fx_rep::FRACTION_LEN) - 1;
----------------
gchatelet wrote:

We should use libc/src/__support/math_extras.h functions for mask creation.
`mask_trailing_ones`, `mask_trailing_zeroes`, etc...

https://github.com/llvm/llvm-project/pull/82065


More information about the libc-commits mailing list