[libc-commits] [libc] [libc] DRAFT: Add Generic and NVPTX Sin Benchmark (PR #99795)

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Sat Jul 27 20:09:20 PDT 2024


================
@@ -113,27 +114,20 @@ class Benchmark {
 // We want our random values to be approximately
 // |real value| <= 2^(max_exponent) * (1 + (random 52 bits) * 2^-52) <
 // 2^(max_exponent + 1)
-// The largest integer that can be stored in a double is 2^53
-static constexpr int MAX_EXPONENT = 52;
-
-static double get_rand_double() {
-  using FPBits = LIBC_NAMESPACE::fputil::FPBits<double>;
-  uint64_t bits = LIBC_NAMESPACE::rand();
-  double scale = 0.5 + MAX_EXPONENT / 2048.0;
+template <typename T> static T get_rand_input() {
+  using FPBits = LIBC_NAMESPACE::fputil::FPBits<T>;
+
+  // Required to correctly instantiate FPBits for floats and doubles.
+  using RandType = typename cpp::conditional_t<(cpp::is_same_v<T, double>),
+                                               uint64_t, uint32_t>;
+  RandType bits = LIBC_NAMESPACE::rand();
----------------
jhuber6 wrote:

I wonder if that means we need to call `rand` twice to get an actual 64-bit value... @lntue might have some better insight here. Maybe we just need a better reentrant random function.

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


More information about the libc-commits mailing list