[libc-commits] [libc] b0cd3ab - [libc] Remove as_double usage as constant initializations in sincosf implementation.

Tue Ly via libc-commits libc-commits at lists.llvm.org
Tue Jan 18 20:49:27 PST 2022


Author: Tue Ly
Date: 2022-01-18T23:48:48-05:00
New Revision: b0cd3abf032e01e6a8f742952e8427ad2e350a5b

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

LOG: [libc] Remove as_double usage as constant initializations in sincosf implementation.

Use hexadecimal floats with C++17 instead of as_double as floating point constant initializations.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D117628

Added: 
    

Modified: 
    libc/src/math/generic/CMakeLists.txt
    libc/src/math/generic/math_utils.cpp
    libc/src/math/generic/sincosf_data.cpp
    libc/src/math/generic/sincosf_utils.h

Removed: 
    


################################################################################
diff  --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 0f639f772ef05..d3380e73bc173 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -44,6 +44,8 @@ add_object_library(
     libc.include.errno
     libc.include.math
     libc.src.errno.__errno_location
+  COMPILE_OPTIONS
+    -Wno-c++17-extensions
 )
 
 add_object_library(
@@ -54,6 +56,8 @@ add_object_library(
     sincosf_data.cpp
   DEPENDS
     .math_utils
+  COMPILE_OPTIONS
+    -Wno-c++17-extensions
 )
 
 add_entrypoint_object(

diff  --git a/libc/src/math/generic/math_utils.cpp b/libc/src/math/generic/math_utils.cpp
index 42a912bac7697..309632953fe32 100644
--- a/libc/src/math/generic/math_utils.cpp
+++ b/libc/src/math/generic/math_utils.cpp
@@ -10,18 +10,12 @@
 
 namespace __llvm_libc {
 
-const float XFlowValues<float>::overflow_value =
-    as_float(0x70000000); // 0x1p97f
-const float XFlowValues<float>::underflow_value =
-    as_float(0x10000000); // 0x1p97f
-const float XFlowValues<float>::may_underflow_value =
-    as_float(0x1a200000); // 0x1.4p-75f
+constexpr float XFlowValues<float>::overflow_value = 0x1p97f;
+constexpr float XFlowValues<float>::underflow_value = 0x1p-95f;
+constexpr float XFlowValues<float>::may_underflow_value = 0x1.4p-75f;
 
-const double XFlowValues<double>::overflow_value =
-    as_double(0x7000000000000000); // 0x1p769
-const double XFlowValues<double>::underflow_value =
-    as_double(0x1000000000000000); // 0x1p-767
-const double XFlowValues<double>::may_underflow_value =
-    as_double(0x1e58000000000000); // 0x1.8p-538
+constexpr double XFlowValues<double>::overflow_value = 0x1p769;
+constexpr double XFlowValues<double>::underflow_value = 0x1p-767;
+constexpr double XFlowValues<double>::may_underflow_value = 0x1.8p-538;
 
 } // namespace __llvm_libc

diff  --git a/libc/src/math/generic/sincosf_data.cpp b/libc/src/math/generic/sincosf_data.cpp
index d86bae702d51d..7e5641c054190 100644
--- a/libc/src/math/generic/sincosf_data.cpp
+++ b/libc/src/math/generic/sincosf_data.cpp
@@ -15,34 +15,34 @@ namespace __llvm_libc {
 
 // The constants and polynomials for sine and cosine.  The 2nd entry
 // computes -cos (x) rather than cos (x) to get negation for free.
-const sincos_t __SINCOSF_TABLE[2] = {
+constexpr sincos_t __SINCOSF_TABLE[2] = {
     {{1.0, -1.0, -1.0, 1.0},
-     as_double(0x41645f306dc9c883),
-     as_double(0x3ff921fb54442d18),
-     as_double(0x3ff0000000000000),
-     as_double(0xbfdffffffd0c621c),
-     as_double(0x3fa55553e1068f19),
-     as_double(0xbf56c087e89a359d),
-     as_double(0x3ef99343027bf8c3),
-     as_double(0xbfc555545995a603),
-     as_double(0x3f81107605230bc4),
-     as_double(0xbf2994eb3774cf24)},
+     0x1.45f306dc9c883p+23,
+     0x1.921fb54442d18p+0,
+     0x1p+0,
+     -0x1.ffffffd0c621cp-2,
+     0x1.55553e1068f19p-5,
+     -0x1.6c087e89a359dp-10,
+     0x1.99343027bf8c3p-16,
+     -0x1.555545995a603p-3,
+     0x1.1107605230bc4p-7,
+     -0x1.994eb3774cf24p-13},
     {{1.0, -1.0, -1.0, 1.0},
-     as_double(0x41645f306dc9c883),
-     as_double(0x3ff921fb54442d18),
-     as_double(0xbff0000000000000),
-     as_double(0x3fdffffffd0c621c),
-     as_double(0xbfa55553e1068f19),
-     as_double(0x3f56c087e89a359d),
-     as_double(0xbef99343027bf8c3),
-     as_double(0xbfc555545995a603),
-     as_double(0x3f81107605230bc4),
-     as_double(0xbf2994eb3774cf24)},
+     0x1.45f306dc9c883p+23,
+     0x1.921fb54442d18p+0,
+     -0x1p+0,
+     0x1.ffffffd0c621cp-2,
+     -0x1.55553e1068f19p-5,
+     0x1.6c087e89a359dp-10,
+     -0x1.99343027bf8c3p-16,
+     -0x1.555545995a603p-3,
+     0x1.1107605230bc4p-7,
+     -0x1.994eb3774cf24p-13},
 };
 
 // Table with 4/PI to 192 bit precision.  To avoid unaligned accesses
 // only 8 new bits are added per entry, making the table 4 times larger.
-const uint32_t __INV_PIO4[24] = {
+constexpr uint32_t __INV_PIO4[24] = {
     0xa2,       0xa2f9,     0xa2f983,   0xa2f9836e, 0xf9836e4e, 0x836e4e44,
     0x6e4e4415, 0x4e441529, 0x441529fc, 0x1529fc27, 0x29fc2757, 0xfc2757d1,
     0x2757d1f5, 0x57d1f534, 0xd1f534dd, 0xf534ddc0, 0x34ddc0db, 0xddc0db62,

diff  --git a/libc/src/math/generic/sincosf_utils.h b/libc/src/math/generic/sincosf_utils.h
index 3bbb4acc5a6d3..58e6a12c73811 100644
--- a/libc/src/math/generic/sincosf_utils.h
+++ b/libc/src/math/generic/sincosf_utils.h
@@ -16,9 +16,9 @@
 namespace __llvm_libc {
 
 // 2PI * 2^-64.
-static const double pi63 = as_double(0x3c1921fb54442d18);
+static constexpr double pi63 = 0x1.921fb54442d18p-62;
 // PI / 4.
-static const double pio4 = as_double(0x3fe921fb54442d18);
+static constexpr double pio4 = 0x1.921fb54442d18p-1;
 
 // The constants and polynomials for sine and cosine.
 typedef struct {


        


More information about the libc-commits mailing list