Implement double precision FMA (Fused Multiply-Add) for targets without
FMA instructions using __uint128_t to store the intermediate results.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libc/test/src/math/fma_no_fma_test.cpp | ||
---|---|---|
10 ↗ | (On Diff #425395) | You should be able to include generic/FMA.h directly and avoid this? |
libc/test/src/math/fma_no_fma_test.cpp | ||
---|---|---|
10 ↗ | (On Diff #425395) | The main point was to test that __llvm_libc::fma implementation works correctly without LIBC_TARGET_HAS_FMA. Unfortunately src.math.fma is an object target built with just 1 config (FMA flag on our machine) so I choose to inlining its implementation here, which is simply calling __llvm_libc::fputil::fma, regardless of FMA flags. If we include generic/FMA.h directly, we wouldn't know/test directly if the fma implementation in generic/FMA.h is called or __llvm_libc::fputil::fma works correctly without FMA flag, unless we run it on non-FMA machines. I guess we could instrument the build system to do these, but I'm not sure if it could be cleaner, especially when the behaviors of such functions with or without FMA diverge. |
libc/test/src/math/fma_no_fma_test.cpp | ||
---|---|---|
10 ↗ | (On Diff #425395) | I think this config problem is now widespread enough that we don't want to set precedents like this. I agree that the plumbing from fputil/FMA.h to generic of specific implementations will not be tested if you directly use generic/FMA.h. But, I think testing your integer implementation should be of primary concern for this patch. We will solve the config problem separately. |
Rely on https://reviews.llvm.org/D125174 and https://reviews.llvm.org/D123615
for testing with and without FMA flags.
libc/test/src/math/fma_no_fma_test.cpp | ||
---|---|---|
10 ↗ | (On Diff #425395) | With https://reviews.llvm.org/D125174 and https://reviews.llvm.org/D123615 , tests with and without fma flags are going to be generated automatically by the build system. |
overall, LGTM with a couple nits. Also, if you're going to add a clz header to FPUtil then please add a TODO for me to change str_to_float.h over to using it, or alternately change it yourself.
libc/src/__support/FPUtil/generic/FMA.h | ||
---|---|---|
156 | nit: can you add something explaining why this number is 10? | |
186 | nit: it should either be the sticky bits remain or the sticky bit remains |
Nit: The changes to sqrt*.cpp and str_to_float.h are not related - please land them separately as "Obvious".
Refactor the changes in sqrt, str_to_float, and Hypot to https://reviews.llvm.org/rG2a746ebf1a4e
nit: can you add something explaining why this number is 10?