[libc-commits] [libc] 9f69d3d - [libc][NFC][Obvious] Convert the MPFR operations enum to an enum class.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Tue May 26 22:40:55 PDT 2020


Author: Siva Chandra Reddy
Date: 2020-05-26T22:26:41-07:00
New Revision: 9f69d3d0bc65ff50b1dc3ab0a6a08ddc32b190a6

URL: https://github.com/llvm/llvm-project/commit/9f69d3d0bc65ff50b1dc3ab0a6a08ddc32b190a6
DIFF: https://github.com/llvm/llvm-project/commit/9f69d3d0bc65ff50b1dc3ab0a6a08ddc32b190a6.diff

LOG: [libc][NFC][Obvious] Convert the MPFR operations enum to an enum class.

This was suggested in https://reviews.llvm.org/D79149.

Added: 
    

Modified: 
    libc/test/src/math/cosf_test.cpp
    libc/test/src/math/exp2f_test.cpp
    libc/test/src/math/expf_test.cpp
    libc/test/src/math/fabs_test.cpp
    libc/test/src/math/fabsf_test.cpp
    libc/test/src/math/sincosf_test.cpp
    libc/test/src/math/sinf_test.cpp
    libc/utils/MPFRWrapper/MPFRUtils.cpp
    libc/utils/MPFRWrapper/MPFRUtils.h

Removed: 
    


################################################################################
diff  --git a/libc/test/src/math/cosf_test.cpp b/libc/test/src/math/cosf_test.cpp
index f9fc9c2e2d0d..1f9dffd87c10 100644
--- a/libc/test/src/math/cosf_test.cpp
+++ b/libc/test/src/math/cosf_test.cpp
@@ -80,7 +80,7 @@ TEST(CosfTest, InFloatRange) {
     float x = valueFromBits(v);
     if (isnan(x) || isinf(x))
       continue;
-    ASSERT_MPFR_MATCH(mpfr::OP_Cos, x, __llvm_libc::cosf(x), tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Cos, x, __llvm_libc::cosf(x), tolerance);
   }
 }
 
@@ -88,12 +88,12 @@ TEST(CosfTest, InFloatRange) {
 TEST(CosfTest, SmallValues) {
   float x = valueFromBits(0x17800000U);
   float result = __llvm_libc::cosf(x);
-  EXPECT_MPFR_MATCH(mpfr::OP_Cos, x, result, tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, result, tolerance);
   EXPECT_EQ(BitPatterns::one, valueAsBits(result));
 
   x = valueFromBits(0x0040000U);
   result = __llvm_libc::cosf(x);
-  EXPECT_MPFR_MATCH(mpfr::OP_Cos, x, result, tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, result, tolerance);
   EXPECT_EQ(BitPatterns::one, valueAsBits(result));
 }
 
@@ -102,6 +102,6 @@ TEST(CosfTest, SmallValues) {
 TEST(CosfTest, SDCOMP_26094) {
   for (uint32_t v : sdcomp26094Values) {
     float x = valueFromBits(v);
-    ASSERT_MPFR_MATCH(mpfr::OP_Cos, x, __llvm_libc::cosf(x), tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Cos, x, __llvm_libc::cosf(x), tolerance);
   }
 }

diff  --git a/libc/test/src/math/exp2f_test.cpp b/libc/test/src/math/exp2f_test.cpp
index dbb7046e28bd..c900ec669544 100644
--- a/libc/test/src/math/exp2f_test.cpp
+++ b/libc/test/src/math/exp2f_test.cpp
@@ -92,27 +92,27 @@ TEST(ExpfTest, Borderline) {
 
   llvmlibc_errno = 0;
   x = valueFromBits(0x42fa0001U);
-  EXPECT_MPFR_MATCH(mpfr::OP_Exp2, x, __llvm_libc::exp2f(x), tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), tolerance);
   EXPECT_EQ(llvmlibc_errno, 0);
 
   x = valueFromBits(0x42ffffffU);
-  EXPECT_MPFR_MATCH(mpfr::OP_Exp2, x, __llvm_libc::exp2f(x), tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), tolerance);
   EXPECT_EQ(llvmlibc_errno, 0);
 
   x = valueFromBits(0xc2fa0001U);
-  EXPECT_MPFR_MATCH(mpfr::OP_Exp2, x, __llvm_libc::exp2f(x), tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), tolerance);
   EXPECT_EQ(llvmlibc_errno, 0);
 
   x = valueFromBits(0xc2fc0000U);
-  EXPECT_MPFR_MATCH(mpfr::OP_Exp2, x, __llvm_libc::exp2f(x), tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), tolerance);
   EXPECT_EQ(llvmlibc_errno, 0);
 
   x = valueFromBits(0xc2fc0001U);
-  EXPECT_MPFR_MATCH(mpfr::OP_Exp2, x, __llvm_libc::exp2f(x), tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), tolerance);
   EXPECT_EQ(llvmlibc_errno, 0);
 
   x = valueFromBits(0xc3150000U);
-  EXPECT_MPFR_MATCH(mpfr::OP_Exp2, x, __llvm_libc::exp2f(x), tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), tolerance);
   EXPECT_EQ(llvmlibc_errno, 0);
 }
 
@@ -124,12 +124,12 @@ TEST(ExpfTest, Underflow) {
 
   llvmlibc_errno = 0;
   float x = valueFromBits(0xc3158000U);
-  EXPECT_MPFR_MATCH(mpfr::OP_Exp2, x, __llvm_libc::exp2f(x), tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), tolerance);
   EXPECT_EQ(llvmlibc_errno, ERANGE);
 
   llvmlibc_errno = 0;
   x = valueFromBits(0xc3165432U);
-  EXPECT_MPFR_MATCH(mpfr::OP_Exp2, x, __llvm_libc::exp2f(x), tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x), tolerance);
   EXPECT_EQ(llvmlibc_errno, ERANGE);
 }
 
@@ -149,6 +149,7 @@ TEST(exp2fTest, InFloatRange) {
     // wider precision.
     if (isnan(result) || isinf(result) || llvmlibc_errno != 0)
       continue;
-    ASSERT_MPFR_MATCH(mpfr::OP_Exp2, x, __llvm_libc::exp2f(x), tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Exp2, x, __llvm_libc::exp2f(x),
+                      tolerance);
   }
 }

diff  --git a/libc/test/src/math/expf_test.cpp b/libc/test/src/math/expf_test.cpp
index aa50bd71974b..c99058dbf6e5 100644
--- a/libc/test/src/math/expf_test.cpp
+++ b/libc/test/src/math/expf_test.cpp
@@ -109,19 +109,19 @@ TEST(ExpfTest, Borderline) {
 
   llvmlibc_errno = 0;
   x = valueFromBits(0x42affff8U);
-  ASSERT_MPFR_MATCH(mpfr::OP_Exp, x, __llvm_libc::expf(x), tolerance);
+  ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), tolerance);
   EXPECT_EQ(llvmlibc_errno, 0);
 
   x = valueFromBits(0x42b00008U);
-  ASSERT_MPFR_MATCH(mpfr::OP_Exp, x, __llvm_libc::expf(x), tolerance);
+  ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), tolerance);
   EXPECT_EQ(llvmlibc_errno, 0);
 
   x = valueFromBits(0xc2affff8U);
-  ASSERT_MPFR_MATCH(mpfr::OP_Exp, x, __llvm_libc::expf(x), tolerance);
+  ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), tolerance);
   EXPECT_EQ(llvmlibc_errno, 0);
 
   x = valueFromBits(0xc2b00008U);
-  ASSERT_MPFR_MATCH(mpfr::OP_Exp, x, __llvm_libc::expf(x), tolerance);
+  ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), tolerance);
   EXPECT_EQ(llvmlibc_errno, 0);
 }
 
@@ -141,6 +141,6 @@ TEST(ExpfTest, InFloatRange) {
     // wider precision.
     if (isnan(result) || isinf(result) || llvmlibc_errno != 0)
       continue;
-    ASSERT_MPFR_MATCH(mpfr::OP_Exp, x, __llvm_libc::expf(x), tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Exp, x, __llvm_libc::expf(x), tolerance);
   }
 }

diff  --git a/libc/test/src/math/fabs_test.cpp b/libc/test/src/math/fabs_test.cpp
index a4c934b07f5a..a9ce9e764298 100644
--- a/libc/test/src/math/fabs_test.cpp
+++ b/libc/test/src/math/fabs_test.cpp
@@ -59,6 +59,6 @@ TEST(FabsTest, InDoubleRange) {
     double x = valueFromBits(v);
     if (isnan(x) || isinf(x))
       continue;
-    ASSERT_MPFR_MATCH(mpfr::OP_Abs, x, __llvm_libc::fabs(x), tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Abs, x, __llvm_libc::fabs(x), tolerance);
   }
 }

diff  --git a/libc/test/src/math/fabsf_test.cpp b/libc/test/src/math/fabsf_test.cpp
index 40e61e6091b6..4231a251bf13 100644
--- a/libc/test/src/math/fabsf_test.cpp
+++ b/libc/test/src/math/fabsf_test.cpp
@@ -61,6 +61,7 @@ TEST(FabsfTest, InFloatRange) {
     double x = valueFromBits(v);
     if (isnan(x) || isinf(x))
       continue;
-    ASSERT_MPFR_MATCH(mpfr::OP_Abs, x, __llvm_libc::fabsf(x), tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Abs, x, __llvm_libc::fabsf(x),
+                      tolerance);
   }
 }

diff  --git a/libc/test/src/math/sincosf_test.cpp b/libc/test/src/math/sincosf_test.cpp
index 9a87e2c9e58c..66b247aeb0af 100644
--- a/libc/test/src/math/sincosf_test.cpp
+++ b/libc/test/src/math/sincosf_test.cpp
@@ -95,8 +95,8 @@ TEST(SinCosfTest, InFloatRange) {
 
     float sin, cos;
     __llvm_libc::sincosf(x, &sin, &cos);
-    ASSERT_MPFR_MATCH(mpfr::OP_Cos, x, cos, tolerance);
-    ASSERT_MPFR_MATCH(mpfr::OP_Sin, x, sin, tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Cos, x, cos, tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Sin, x, sin, tolerance);
   }
 }
 
@@ -106,16 +106,16 @@ TEST(SinCosfTest, SmallValues) {
   float x = valueFromBits(bits);
   float result_cos, result_sin;
   __llvm_libc::sincosf(x, &result_sin, &result_cos);
-  EXPECT_MPFR_MATCH(mpfr::OP_Cos, x, result_cos, tolerance);
-  EXPECT_MPFR_MATCH(mpfr::OP_Sin, x, result_sin, tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, result_cos, tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, result_sin, tolerance);
   EXPECT_EQ(BitPatterns::one, valueAsBits(result_cos));
   EXPECT_EQ(bits, valueAsBits(result_sin));
 
   bits = 0x00400000;
   x = valueFromBits(bits);
   __llvm_libc::sincosf(x, &result_sin, &result_cos);
-  EXPECT_MPFR_MATCH(mpfr::OP_Cos, x, result_cos, tolerance);
-  EXPECT_MPFR_MATCH(mpfr::OP_Sin, x, result_sin, tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, result_cos, tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, result_sin, tolerance);
   EXPECT_EQ(BitPatterns::one, valueAsBits(result_cos));
   EXPECT_EQ(bits, valueAsBits(result_sin));
 }
@@ -127,7 +127,7 @@ TEST(SinCosfTest, SDCOMP_26094) {
     float x = valueFromBits(v);
     float sin, cos;
     __llvm_libc::sincosf(x, &sin, &cos);
-    EXPECT_MPFR_MATCH(mpfr::OP_Cos, x, cos, tolerance);
-    EXPECT_MPFR_MATCH(mpfr::OP_Sin, x, sin, tolerance);
+    EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, cos, tolerance);
+    EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, sin, tolerance);
   }
 }

diff  --git a/libc/test/src/math/sinf_test.cpp b/libc/test/src/math/sinf_test.cpp
index e0821c621dcc..437281ada43a 100644
--- a/libc/test/src/math/sinf_test.cpp
+++ b/libc/test/src/math/sinf_test.cpp
@@ -80,13 +80,13 @@ TEST(SinfTest, InFloatRange) {
     float x = valueFromBits(v);
     if (isnan(x) || isinf(x))
       continue;
-    ASSERT_MPFR_MATCH(mpfr::OP_Sin, x, __llvm_libc::sinf(x), tolerance);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Sin, x, __llvm_libc::sinf(x), tolerance);
   }
 }
 
 TEST(SinfTest, SpecificBitPatterns) {
   float x = valueFromBits(0xc70d39a1);
-  EXPECT_MPFR_MATCH(mpfr::OP_Sin, x, __llvm_libc::sinf(x), tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, __llvm_libc::sinf(x), tolerance);
 }
 
 // For small values, sin(x) is x.
@@ -94,13 +94,13 @@ TEST(SinfTest, SmallValues) {
   uint32_t bits = 0x17800000;
   float x = valueFromBits(bits);
   float result = __llvm_libc::sinf(x);
-  EXPECT_MPFR_MATCH(mpfr::OP_Sin, x, result, tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, result, tolerance);
   EXPECT_EQ(bits, valueAsBits(result));
 
   bits = 0x00400000;
   x = valueFromBits(bits);
   result = __llvm_libc::sinf(x);
-  EXPECT_MPFR_MATCH(mpfr::OP_Sin, x, result, tolerance);
+  EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, result, tolerance);
   EXPECT_EQ(bits, valueAsBits(result));
 }
 
@@ -109,6 +109,6 @@ TEST(SinfTest, SmallValues) {
 TEST(SinfTest, SDCOMP_26094) {
   for (uint32_t v : sdcomp26094Values) {
     float x = valueFromBits(v);
-    EXPECT_MPFR_MATCH(mpfr::OP_Sin, x, __llvm_libc::sinf(x), tolerance);
+    EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, __llvm_libc::sinf(x), tolerance);
   }
 }

diff  --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index 74c2f760f034..51c8c3759292 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -86,21 +86,21 @@ class MPFRNumber {
     mpfr_init2(value, mpfrPrecision);
     MPFRNumber mpfrInput(rawValue);
     switch (op) {
-    case OP_Abs:
+    case Operation::Abs:
       mpfr_abs(value, mpfrInput.value, MPFR_RNDN);
       break;
-    case OP_Cos:
+    case Operation::Cos:
       mpfr_cos(value, mpfrInput.value, MPFR_RNDN);
       break;
-    case OP_Sin:
-      mpfr_sin(value, mpfrInput.value, MPFR_RNDN);
-      break;
-    case OP_Exp:
+    case Operation::Exp:
       mpfr_exp(value, mpfrInput.value, MPFR_RNDN);
       break;
-    case OP_Exp2:
+    case Operation::Exp2:
       mpfr_exp2(value, mpfrInput.value, MPFR_RNDN);
       break;
+    case Operation::Sin:
+      mpfr_sin(value, mpfrInput.value, MPFR_RNDN);
+      break;
     }
   }
 

diff  --git a/libc/utils/MPFRWrapper/MPFRUtils.h b/libc/utils/MPFRWrapper/MPFRUtils.h
index f6660f2fa78e..e39ed91281a9 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.h
+++ b/libc/utils/MPFRWrapper/MPFRUtils.h
@@ -39,7 +39,7 @@ struct Tolerance {
   uint32_t bits;
 };
 
-enum Operation { OP_Abs, OP_Cos, OP_Sin, OP_Exp, OP_Exp2 };
+enum class Operation : int { Abs, Cos, Exp, Exp2, Sin };
 
 namespace internal {
 


        


More information about the libc-commits mailing list