This is an archive of the discontinued LLVM Phabricator instance.

[libc][math] Update range reduction step for log2f and improve its performance.
ClosedPublic

Authored by lntue on Apr 6 2023, 7:40 PM.

Details

Summary

Simplify the range reduction steps by choosing the reduction constants
carefully so that the reduced arguments v = r*m_x - 1 and v^2 are exact in double
precision, even without FMA instructions, and -2^-8 <= v < 2^-7.

Diff Detail

Event Timeline

lntue created this revision.Apr 6 2023, 7:40 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 6 2023, 7:40 PM
lntue requested review of this revision.Apr 6 2023, 7:40 PM
zimmermann6 requested changes to this revision.Apr 7 2023, 12:08 AM

I get an error at compilation:

/localdisk/zimmerma/llvm-project/libc/src/math/generic/log2f.cpp:149:48: error: use of undeclared identifier 'R'
                           static_cast<double>(R[index]), -1.0); // Exact
                                               ^
This revision now requires changes to proceed.Apr 7 2023, 12:08 AM
lntue added a comment.Apr 7 2023, 4:24 AM

I get an error at compilation:

/localdisk/zimmerma/llvm-project/libc/src/math/generic/log2f.cpp:149:48: error: use of undeclared identifier 'R'
                           static_cast<double>(R[index]), -1.0); // Exact
                                               ^

Can you try to apply https://reviews.llvm.org/D147676 and https://reviews.llvm.org/D147755 before this patch to see if it works?

lntue updated this revision to Diff 512192.Apr 10 2023, 10:12 AM

Sync to HEAD.

zimmermann6 accepted this revision.Apr 10 2023, 10:59 PM

all test are ok now. Reciprocal throughput:

GNU libc version: 2.36
GNU libc release: stable
[####################] 100 %
Ntrial = 20 ; Min = 9.649 + 0.454 clc/call; Median-Min = 0.288 clc/call; Max = 11.526 clc/call;
[####################] 100 %
Ntrial = 20 ; Min = 7.224 + 0.310 clc/call; Median-Min = 0.320 clc/call; Max = 8.306 clc/call;
[####################] 100 %
Ntrial = 20 ; Min = 10.579 + 0.162 clc/call; Median-Min = 0.024 clc/call; Max = 11.528 clc/call;

Latency:

GNU libc version: 2.36
GNU libc release: stable
[####################] 100 %
Ntrial = 20 ; Min = 42.395 + 0.340 clc/call; Median-Min = 0.322 clc/call; Max = 42.983 clc/call;
[####################] 100 %
Ntrial = 20 ; Min = 38.033 + 0.434 clc/call; Median-Min = 0.304 clc/call; Max = 39.897 clc/call;
[####################] 100 %
Ntrial = 20 ; Min = 41.699 + 0.343 clc/call; Median-Min = 0.327 clc/call; Max = 42.248 clc/call;
This revision is now accepted and ready to land.Apr 10 2023, 10:59 PM