Message ID | 20250213193737.3784065-4-adhemerval.zanella@linaro.org |
---|---|
State | New |
Headers | show |
Series | Optimize CORE-MATH internal tables | expand |
Am Donnerstag, 13. Februar 2025, 20:35:45 Mitteleuropäische Normalzeit schrieb Adhemerval Zanella: > 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 | 1 + > sysdeps/ieee754/flt-32/e_acosf.c | 19 ++--------- > sysdeps/ieee754/flt-32/e_asinf.c | 19 ++--------- > sysdeps/ieee754/flt-32/s_asincosf_data.c | 43 ++++++++++++++++++++++++ > sysdeps/ieee754/flt-32/s_asincosf_data.h | 35 +++++++++++++++++++ > 5 files changed, 85 insertions(+), 32 deletions(-) > create mode 100644 sysdeps/ieee754/flt-32/s_asincosf_data.c > create mode 100644 sysdeps/ieee754/flt-32/s_asincosf_data.h > > diff --git a/math/Makefile b/math/Makefile > index 43e0e365eb..6dab60095b 100644 > --- a/math/Makefile > +++ b/math/Makefile > @@ -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 \ ok > diff --git a/sysdeps/ieee754/flt-32/e_acosf.c b/sysdeps/ieee754/flt-32/e_acosf.c > index a5a4de4fc2..820e929864 100644 > --- a/sysdeps/ieee754/flt-32/e_acosf.c > +++ b/sysdeps/ieee754/flt-32/e_acosf.c > @@ -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; > } ok > diff --git a/sysdeps/ieee754/flt-32/e_asinf.c b/sysdeps/ieee754/flt-32/e_asinf.c > index 944bf6f5ce..c6972d2122 100644 > --- a/sysdeps/ieee754/flt-32/e_asinf.c > +++ b/sysdeps/ieee754/flt-32/e_asinf.c > @@ -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 ok > @@ -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; ok > diff --git a/sysdeps/ieee754/flt-32/s_asincosf_data.c b/sysdeps/ieee754/flt-32/s_asincosf_data.c > new file mode 100644 > index 0000000000..0399ecc975 > --- /dev/null > +++ b/sysdeps/ieee754/flt-32/s_asincosf_data.c > @@ -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 > + }; > + ok > +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 > + }; ok > diff --git a/sysdeps/ieee754/flt-32/s_asincosf_data.h b/sysdeps/ieee754/flt-32/s_asincosf_data.h > new file mode 100644 > index 0000000000..c3f9ed5a27 > --- /dev/null > +++ b/sysdeps/ieee754/flt-32/s_asincosf_data.h > @@ -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 > ok
diff --git a/math/Makefile b/math/Makefile index 43e0e365eb..6dab60095b 100644 --- a/math/Makefile +++ b/math/Makefile @@ -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 \ diff --git a/sysdeps/ieee754/flt-32/e_acosf.c b/sysdeps/ieee754/flt-32/e_acosf.c index a5a4de4fc2..820e929864 100644 --- a/sysdeps/ieee754/flt-32/e_acosf.c +++ b/sysdeps/ieee754/flt-32/e_acosf.c @@ -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; } diff --git a/sysdeps/ieee754/flt-32/e_asinf.c b/sysdeps/ieee754/flt-32/e_asinf.c index 944bf6f5ce..c6972d2122 100644 --- a/sysdeps/ieee754/flt-32/e_asinf.c +++ b/sysdeps/ieee754/flt-32/e_asinf.c @@ -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 index 0000000000..0399ecc975 --- /dev/null +++ b/sysdeps/ieee754/flt-32/s_asincosf_data.c @@ -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 index 0000000000..c3f9ed5a27 --- /dev/null +++ b/sysdeps/ieee754/flt-32/s_asincosf_data.h @@ -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