[PATCH 0/3] math: Avoid per-constant literal loads in the CORE-MATH routines on aarch64

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Wed Sep 16 19:38:46 GMT 2026



On 16/09/26 13:57, Adhemerval Zanella wrote:
> It was reported that the CORE-MATH routines generate poor code on aarch64,
> where GCC folds each element of the static coefficient tables into a separate
> floating-point literal.  GCC 13, 14 and 15 place those literals in a
> mergeable section that cannot use section anchors, so every coefficient
> costs an ADRP/LDR pair instead of one address computation and LDP loads.
> 
> GCC 16 fixes this for 8-byte constants (PR target/121240), but not for
> older compilers.
> 
> The AArch64 vector routines already avoid the problem by reading their
> data through an asm barrier that hides the table address.  This series
> moves that macro to a sysdeps header, math-ptr-barrier.h, and uses it on
> the constant-indexed tables of the CORE-MATH float and double routines.
> 
> On aarch64 with GCC 15 this removes about 85% of the literal loads in the
> 34 files and 4 to 9% of the instructions; with GCC 16 the code is within a
> few instructions of the current one.
> 
> Benchtests on Neoverse-N1 with GCC 15 show a 1.3% geomean improvement for
> the float routines, with acosf, asinf and lgammaf around 5 to 7% faster,
> and no change for the double ones.
> 
> Checked on aarch64-linux-gnu with GCC 15 and 16 and on x86_64-linux-gnu.
After checking with Wilco, the issues is not aarch64 specific and the barrier
seems beneficial to other architectures as well. 

* x86_64-v3 (Ryzen 5900 / Zen3) with gcc 17.0

function  geomean
acosf      +0.52%
acoshf     -0.36%
asinf      -4.05%
atan2f     -2.24%
atanhf     -0.25%
coshf      -0.37%
lgammaf    +1.08%
tgammaf    -1.25%
log10f     +2.10%
sinhf      -0.23%
asinhf     -0.19%
atan2pif   -1.95%
atanf      -0.38%
atanpif    +0.58%
cbrtf      +3.12%
erfcf      -1.14%
erff       -0.63%
exp10m1f   -0.66%
exp2m1f    -2.71%
expm1f     -0.11%
log10p1f   -4.17%
log2p1f    -1.30%
tanf       +0.51%
tanpif     -4.42%

summary: 4 improvements, 2 regressions beyond 5%, geomean -0.79% (lower is better)

* POWER10 with gcc 16.1.1

function  geomean
acosf      -1.19%
acoshf     +0.49%
asinf      -1.09%
atan2f     -0.66%
atanhf     -0.52%
coshf      +0.08%
lgammaf    -1.58%
tgammaf    -1.39%
log10f     +1.34%
sinhf      -0.08%
asinhf     +0.09%
atan2pif   -1.32%
atanf      -1.73%
atanpif    -3.40%
cbrtf      -0.95%
erfcf      -1.06%
erff       -0.17%
exp10m1f   +1.46%
exp2m1f    +1.20%
expm1f     +3.23%
log10p1f   -0.26%
log2p1f    +1.75%
tanf       -1.09%
tanpif     +0.22% 

summary: 1 improvements, 0 regressions beyond 5%, geomean -0.29% (lower is better)

I will try to check on other ABI, I think cfarm might have some other I can try.


More information about the Libc-alpha mailing list