[libc-commits] [libc] [libc][math] Implement nearest integer functions using builtins when available (PR #98376)

via libc-commits libc-commits at lists.llvm.org
Wed Jul 10 13:28:12 PDT 2024


================
@@ -75,15 +75,17 @@ LIBC_INLINE T ceil(T x) {
   }
 
   uint32_t trim_size = FPBits<T>::FRACTION_LEN - exponent;
-  StorageType trunc_mantissa =
-      static_cast<StorageType>((bits.get_mantissa() >> trim_size) << trim_size);
-  bits.set_mantissa(trunc_mantissa);
-  T trunc_value = bits.get_val();
+  StorageType x_u = bits.uintval();
+  StorageType trunc_u =
+      static_cast<StorageType>((x_u >> trim_size) << trim_size);
 
   // If x is already an integer, return it.
-  if (trunc_value == x)
+  if (trunc_u == x_u)
     return x;
 
+  bits.set_uintval(trunc_u);
+  T trunc_value = bits.get_val();
+
----------------
overmighty wrote:

Not sure if this should be in the same PR as the builtin stuff really. It's also a performance optimization.

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


More information about the libc-commits mailing list