[libc-commits] [libc] 71ffc1f - [libc] Initialize rand for fma tests (#88055)

via libc-commits libc-commits at lists.llvm.org
Tue Apr 9 09:07:40 PDT 2024


Author: Joseph Huber
Date: 2024-04-09T11:07:36-05:00
New Revision: 71ffc1f0ea1c64d475d9248ea7c68dfec16ee1ab

URL: https://github.com/llvm/llvm-project/commit/71ffc1f0ea1c64d475d9248ea7c68dfec16ee1ab
DIFF: https://github.com/llvm/llvm-project/commit/71ffc1f0ea1c64d475d9248ea7c68dfec16ee1ab.diff

LOG: [libc] Initialize rand for fma tests (#88055)

Summary:
The GPU build will have some random garbage here since we do not support
initializers for the underlying implementation. Manually set the seed to
1.

Added: 
    

Modified: 
    libc/test/src/math/CMakeLists.txt
    libc/test/src/math/FmaTest.h

Removed: 
    


################################################################################
diff  --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 274018e59da5ac..55119868bdaa19 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -1271,6 +1271,7 @@ add_fp_unittest(
   DEPENDS
     libc.src.math.fmaf
     libc.src.stdlib.rand
+    libc.src.stdlib.srand
     libc.src.__support.FPUtil.fp_bits
   FLAGS
     FMA_OPT__ONLY
@@ -1286,6 +1287,7 @@ add_fp_unittest(
   DEPENDS
     libc.src.math.fma
     libc.src.stdlib.rand
+    libc.src.stdlib.srand
     libc.src.__support.FPUtil.fp_bits
 )
 

diff  --git a/libc/test/src/math/FmaTest.h b/libc/test/src/math/FmaTest.h
index a3b1c9bb8f9b8f..76bd221fcb1f2f 100644
--- a/libc/test/src/math/FmaTest.h
+++ b/libc/test/src/math/FmaTest.h
@@ -11,6 +11,7 @@
 
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/stdlib/rand.h"
+#include "src/stdlib/srand.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 #include "utils/MPFRWrapper/MPFRUtils.h"
@@ -76,6 +77,7 @@ class FmaTestTemplate : public LIBC_NAMESPACE::testing::Test {
   void test_subnormal_range(Func func) {
     constexpr StorageType COUNT = 100'001;
     constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
+    LIBC_NAMESPACE::srand(1);
     for (StorageType v = MIN_SUBNORMAL, w = MAX_SUBNORMAL;
          v <= MAX_SUBNORMAL && w >= MIN_SUBNORMAL; v += STEP, w -= STEP) {
       T x = FPBits(get_random_bit_pattern()).get_val(), y = FPBits(v).get_val(),
@@ -89,6 +91,7 @@ class FmaTestTemplate : public LIBC_NAMESPACE::testing::Test {
   void test_normal_range(Func func) {
     constexpr StorageType COUNT = 100'001;
     constexpr StorageType STEP = (MAX_NORMAL - MIN_NORMAL) / COUNT;
+    LIBC_NAMESPACE::srand(1);
     for (StorageType v = MIN_NORMAL, w = MAX_NORMAL;
          v <= MAX_NORMAL && w >= MIN_NORMAL; v += STEP, w -= STEP) {
       T x = FPBits(v).get_val(), y = FPBits(w).get_val(),


        


More information about the libc-commits mailing list