]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
math: Consolidate acosf and asinf internal tables
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 13 Feb 2025 19:35:45 +0000 (16:35 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 17 Feb 2025 13:09:09 +0000 (10:09 -0300)
The libm size improvement built with gcc-14, "--enable-stack-protector=strong
--enable-bind-now=yes --enable-fortify-source=2":

Before:

 582292     844      12  583148   8e5ec aarch64-linux-gnu/math/libm.so
 975133    1076      12  976221   ee55d x86_64-linux-gnu/math/libm.so
1203586    5608     368 1209562  1274da powerpc64le-linux-gnu/math/libm.so

After:

 581972     844      12  582828   8e4ac aarch64-linux-gnu/math/libm.so
 974941    1076      12  976029   ee49d x86_64-linux-gnu/math/libm.so
1203394    5608     368 1209370  12741a powerpc64le-linux-gnu/math/libm.so
Reviewed-by: Andreas K. Huettel <dilfridge@gentoo.org>
math/Makefile
sysdeps/ieee754/flt-32/e_acosf.c
sysdeps/ieee754/flt-32/e_asinf.c
sysdeps/ieee754/flt-32/s_asincosf_data.c [new file with mode: 0644]
sysdeps/ieee754/flt-32/s_asincosf_data.h [new file with mode: 0644]

index 43e0e365eb4b154250faaa00d129b4aed7ab1290..6dab60095b32af51d261fb7054278ba594522dc7 100644 (file)
@@ -368,6 +368,7 @@ type-float-routines := \
   e_powf_log2_data \
   e_sincoshf_data \
   math_errf \
+  s_asincosf_data \
   s_asincoshf_data \
   s_asincospif_data \
   s_sincosf_data \
index a5a4de4fc2d9e1088b5ee6fb0f53b20bf6c113e1..820e9298646152d06e49ac7cc06ca92aa9f3a880 100644 (file)
@@ -30,6 +30,7 @@ SOFTWARE.
 #include <libm-alias-finite.h>
 #include <math-barriers.h>
 #include "math_config.h"
+#include "s_asincosf_data.h"
 
 static __attribute__ ((noinline)) float
 as_special (float x)
@@ -110,33 +111,19 @@ __ieee754_acosf (float x)
   /* accurate path  */
   if (ax < (0x7eu << 24))
     {
-      static const double c[] =
-       {
-         0x1.555555555529cp-3,  0x1.333333337e0ddp-4, 0x1.6db6db3b4465ep-5,
-         0x1.f1c72e13ac306p-6,  0x1.6e89cebe06bc4p-6, 0x1.1c6dcf5289094p-6,
-         0x1.c6dbbcc7c6315p-7,  0x1.8f8dc2615e996p-7, 0x1.a5833b7bf15e8p-8,
-         0x1.43f44ace1665cp-6, -0x1.0fb17df881c73p-6, 0x1.07520c026b2d6p-5
-       };
       if (t == 0x328885a3u)
        return 0x1.921fb6p+0f + 0x1p-25;
       if (t == 0x39826222u)
        return 0x1.920f6ap+0f + 0x1p-25;
       double x2 = xs * xs;
-      r = (pi2 - xs) - (xs * x2) * poly12 (x2, c);
+      r = (pi2 - xs) - (xs * x2) * poly12 (x2, C0);
     }
   else
     {
-      static const double c[] =
-       {
-         0x1.6a09e667f3bcbp+0,   0x1.e2b7dddff2db9p-4,  0x1.b27247ab42dbcp-6,
-         0x1.02995cc4e0744p-7,   0x1.5ffb0276ec8eap-9,  0x1.033885a928decp-10,
-         0x1.911f2be23f8c7p-12,  0x1.4c3c55d2437fdp-13, 0x1.af477e1d7b461p-15,
-         0x1.abd6bdff67dcbp-15, -0x1.1717e86d0fa28p-16, 0x1.6ff526de46023p-16
-       };
       double bx = fabs (xs);
       double z = 1.0 - bx;
       double s = copysign (sqrt (z), xs);
-      r = o[t >> 31] + s * poly12 (z, c);
+      r = o[t >> 31] + s * poly12 (z, C1);
     }
   return r;
 }
index 944bf6f5ce0b4138fb2f7d2c479ac46fff3ea7e4..c6972d212226cb7bc218b28474875bbbf86f269e 100644 (file)
@@ -28,6 +28,7 @@ SOFTWARE.
 #include <errno.h>
 #include <libm-alias-finite.h>
 #include "math_config.h"
+#include "s_asincosf_data.h"
 
 static __attribute__ ((noinline)) float
 as_special (float x)
@@ -95,16 +96,9 @@ __ieee754_asinf (float x)
     }
   if (ax < (0x7eu << 24))
     {
-      static const double c[] =
-       {
-         0x1.555555555529cp-3,  0x1.333333337e0ddp-4, 0x1.6db6db3b4465ep-5,
-         0x1.f1c72e13ac306p-6,  0x1.6e89cebe06bc4p-6, 0x1.1c6dcf5289094p-6,
-         0x1.c6dbbcc7c6315p-7,  0x1.8f8dc2615e996p-7, 0x1.a5833b7bf15e8p-8,
-         0x1.43f44ace1665cp-6, -0x1.0fb17df881c73p-6, 0x1.07520c026b2d6p-5
-       };
       double z = xs;
       double z2 = z * z;
-      double c0 = poly12 (z2, c);
+      double c0 = poly12 (z2, C0);
       r = z + (z * z2) * c0;
     }
   else
@@ -116,14 +110,7 @@ __ieee754_asinf (float x)
       double bx = fabs (xs);
       double z = 1.0 - bx;
       double s = sqrt (z);
-      static const double c[] =
-       {
-         0x1.6a09e667f3bcbp+0,   0x1.e2b7dddff2db9p-4,  0x1.b27247ab42dbcp-6,
-         0x1.02995cc4e0744p-7,   0x1.5ffb0276ec8eap-9,  0x1.033885a928decp-10,
-         0x1.911f2be23f8c7p-12,  0x1.4c3c55d2437fdp-13, 0x1.af477e1d7b461p-15,
-         0x1.abd6bdff67dcbp-15, -0x1.1717e86d0fa28p-16, 0x1.6ff526de46023p-16
-       };
-      r = pi2 - s * poly12 (z, c);
+      r = pi2 - s * poly12 (z, C1);
       r = copysign (r, xs);
     }
   return r;
diff --git a/sysdeps/ieee754/flt-32/s_asincosf_data.c b/sysdeps/ieee754/flt-32/s_asincosf_data.c
new file mode 100644 (file)
index 0000000..0399ecc
--- /dev/null
@@ -0,0 +1,43 @@
+/* Common data for asinf/acosf implementations.
+
+Copyright (c) 2023-2024 Alexei Sibidanov.
+
+The original version of this file was copied from the CORE-MATH
+project (file src/binary32/asin/asinf.c, revision bc385c2).
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+#include "s_asincosf_data.h"
+
+const double __asincosf_c0[] =
+  {
+    0x1.555555555529cp-3,  0x1.333333337e0ddp-4, 0x1.6db6db3b4465ep-5,
+    0x1.f1c72e13ac306p-6,  0x1.6e89cebe06bc4p-6, 0x1.1c6dcf5289094p-6,
+    0x1.c6dbbcc7c6315p-7,  0x1.8f8dc2615e996p-7, 0x1.a5833b7bf15e8p-8,
+    0x1.43f44ace1665cp-6, -0x1.0fb17df881c73p-6, 0x1.07520c026b2d6p-5
+  };
+
+const double __asincosf_c1[] =
+  {
+    0x1.6a09e667f3bcbp+0,   0x1.e2b7dddff2db9p-4,  0x1.b27247ab42dbcp-6,
+    0x1.02995cc4e0744p-7,   0x1.5ffb0276ec8eap-9,  0x1.033885a928decp-10,
+    0x1.911f2be23f8c7p-12,  0x1.4c3c55d2437fdp-13, 0x1.af477e1d7b461p-15,
+    0x1.abd6bdff67dcbp-15, -0x1.1717e86d0fa28p-16, 0x1.6ff526de46023p-16
+  };
diff --git a/sysdeps/ieee754/flt-32/s_asincosf_data.h b/sysdeps/ieee754/flt-32/s_asincosf_data.h
new file mode 100644 (file)
index 0000000..c3f9ed5
--- /dev/null
@@ -0,0 +1,35 @@
+/* Common data for asinf/acosf implementations.
+
+Copyright (c) 2023-2024 Alexei Sibidanov.
+
+The original version of this file was copied from the CORE-MATH
+project (file src/binary32/asin/asinf.c, revision bc385c2).
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+#ifndef _S_ASINCOSF_DATA_H
+#define _S_ASINCOSF_DATA_H
+
+extern const double __asincosf_c0[] attribute_hidden;
+#define C0 __asincosf_c0
+extern const double __asincosf_c1[] attribute_hidden;
+#define C1 __asincosf_c1
+
+#endif