Files
clang-p2996/libc/utils/FPUtil/generic/README.md
Siva Chandra 95934c3a37 [libc] Add hardware implementations of fma and fmaf for x86_64 and aarch64.
The current generic implementation of the fmaf function has been moved
to the FPUtil directory. This allows one use the fma operation from
implementations of other math functions like the trignometric functions
without depending on/requiring the fma/fmaf/fmal function targets. If
this pattern ends being convenient, we will switch all generic math
implementations to this pattern.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D100811
2021-04-21 04:31:27 +00:00

1.3 KiB

This directory contains machine independent implementations of floating point operations. The implementations are nested in the namespace __llvm_libc::fputil::generic. This is to facilitate calling these generic implementations from machine dependent implementations. Consider the example of the fuse-multiply-add operation (FMA). The C standard library requires three different flavors, fma which operates double precsion numbers, fmaf which operates on single precision numbers, and fmal which operates on lond double numbers. On Aarch64, there are hardware instructions which implement the single and double precision flavors but not the long double flavor. For such targets, we want to be able to call the generic long double implementation from the long double flavor. By putting the generic implementations in a separate nested namespace, we will be to call them as follows:

namespace __llvm_libc {
namespace fputil {

long double fmal(long double x, long double y, long double z) {
  return generic::fmal(x, y, z);
}

} // namespace fputil
} // namespace __llvm_libc

Note that actual code might not be as straightforward as above (for example, we might want to prevent implicit type promotions by using some template facilities). But, the general idea is very similar.