[PATCH 6/8] math: Sync log2 with Arm Optimized Routines
Adhemerval Zanella
adhemerval.zanella@linaro.org
Thu Feb 26 20:01:52 GMT 2026
Sync with commit 712aa21 for log2.c and 189dfef for log2_data.c No
functional change.
Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu.
---
sysdeps/ieee754/dbl-64/e_log2.c | 14 ++++++++++----
sysdeps/ieee754/dbl-64/math_config.h | 3 +--
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/sysdeps/ieee754/dbl-64/e_log2.c b/sysdeps/ieee754/dbl-64/e_log2.c
index 872cebddd8..3f9a846ff2 100644
--- a/sysdeps/ieee754/dbl-64/e_log2.c
+++ b/sysdeps/ieee754/dbl-64/e_log2.c
@@ -50,8 +50,10 @@ __log2 (double x)
ix = asuint64 (x);
top = top16 (x);
-#define LO asuint64 (1.0 - 0x1.5b51p-5)
-#define HI asuint64 (1.0 + 0x1.6ab2p-5)
+#if LOG2_POLY1_ORDER == 11
+# define LO asuint64 (1.0 - 0x1.5b51p-5)
+# define HI asuint64 (1.0 + 0x1.6ab2p-5)
+#endif
if (__glibc_unlikely (ix - LO < HI - LO))
{
/* Handle close to 1.0 inputs separately. */
@@ -71,6 +73,7 @@ __log2 (double x)
#endif
r2 = r * r; /* rounding error: 0x1p-62. */
r4 = r2 * r2;
+#if LOG2_POLY1_ORDER == 11
/* Worst-case error is less than 0.54 ULP (0.55 ULP without fma). */
p = r2 * (B[0] + r * B[1]);
y = hi + p;
@@ -78,6 +81,7 @@ __log2 (double x)
lo += r4 * (B[2] + r * B[3] + r2 * (B[4] + r * B[5])
+ r4 * (B[6] + r * B[7] + r2 * (B[8] + r * B[9])));
y += lo;
+#endif
return y;
}
if (__glibc_unlikely (top - 0x0010 >= 0x7ff0 - 0x0010))
@@ -110,9 +114,9 @@ __log2 (double x)
/* r ~= z/c - 1, |r| < 1/(2*N). */
#ifdef __FP_FAST_FMA
/* rounding error: 0x1p-55/N. */
- r = __builtin_fma (z, invc, -1.0);
+ r = fma (z, invc, -1.0);
t1 = r * InvLn2hi;
- t2 = r * InvLn2lo + __builtin_fma (r, InvLn2hi, -t1);
+ t2 = r * InvLn2lo + fma (r, InvLn2hi, -t1);
#else
double rhi, rlo;
/* rounding error: 0x1p-55/N + 0x1p-65. */
@@ -132,10 +136,12 @@ __log2 (double x)
/* Evaluation is optimized assuming superscalar pipelined execution. */
r2 = r * r; /* rounding error: 0x1p-54/N^2. */
r4 = r2 * r2;
+#if LOG2_POLY_ORDER == 7
/* Worst-case error if |y| > 0x1p-4: 0.547 ULP (0.550 ULP without fma).
~ 0.5 + 2/N/ln2 + abs-poly-error*0x1p56 ULP (+ 0.003 ULP without fma). */
p = A[0] + r * A[1] + r2 * (A[2] + r * A[3]) + r4 * (A[4] + r * A[5]);
y = lo + r2 * p + hi;
+#endif
return y;
}
#ifndef __log2
diff --git a/sysdeps/ieee754/dbl-64/math_config.h b/sysdeps/ieee754/dbl-64/math_config.h
index ea92cf313a..a3506d77eb 100644
--- a/sysdeps/ieee754/dbl-64/math_config.h
+++ b/sysdeps/ieee754/dbl-64/math_config.h
@@ -287,12 +287,11 @@ extern const struct log2_data
double invln2lo;
double poly[LOG2_POLY_ORDER - 1];
double poly1[LOG2_POLY1_ORDER - 1];
- /* See e_log2_data.c for details. */
struct {double invc, logc;} tab[1 << LOG2_TABLE_BITS];
#ifndef __FP_FAST_FMA
struct {double chi, clo;} tab2[1 << LOG2_TABLE_BITS];
#endif
-} __log2_data attribute_hidden;
+} __log2_data __attribute__ ((__aligned__ (16))) attribute_hidden;
#define POW_LOG_TABLE_BITS 7
#define POW_LOG_POLY_ORDER 8
--
2.43.0
More information about the Libc-alpha
mailing list