[libc-commits] [libc] [libc][stdfix] Implement `countlsfx` functions (PR #114318)

via libc-commits libc-commits at lists.llvm.org
Sat Nov 2 18:35:27 PDT 2024


================
@@ -66,6 +67,23 @@ template <typename T> struct FXBits {
     }
   }
 
+  // Clause 6.2.6.3 of ISO/IEC TR 18037 defines the value bits of a fixed-point
+  // type to include the integral and fraction bits but not padding nor sign
+  // bits.
+  //
+  // This function returns the value bits, right-aligned, as an unsigned integer
+  // type which is at least large enough to hold them all.
+  //
+  // Note the integral and fraction bits are contiguous. The rightmost bits in
+  // the returned value are the fraciton bits, then immediately left of those
+  // are the integral bits.
+  //
+  // Any left-padding in the return value is guaranteed to be zero.
+  LIBC_INLINE constexpr StorageType get_value_bits() {
+    constexpr StorageType VALUE_MASK = INTEGRAL_MASK | FRACTION_MASK;
----------------
lntue wrote:

we should refactor this to be available for the whole `FXBits` class, and include the sign mask.

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


More information about the libc-commits mailing list