xref: /llvm-project/libc/src/__support/FPUtil/generic/README.md (revision 5ff3ff33ff930e4ec49da7910612d8a41eb068cb)
1This directory contains machine independent implementations of floating point
2operations. The implementations are nested in the namespace
3`LIBC_NAMESPACE::fputil::generic`. This is to facilitate calling these generic
4implementations from machine dependent implementations. Consider the example of
5the fuse-multiply-add operation (FMA). The C standard library requires three
6different flavors, `fma` which operates double precision numbers, `fmaf` which
7operates on single precision numbers, and `fmal` which operates on `long double`
8numbers. On aarch64, there are hardware instructions which implement the single
9and double precision flavors but not the `long double` flavor. For such targets,
10we want to be able to call the generic `long double` implementation from the
11`long double` flavor. By putting the generic implementations in a separate
12nested namespace, we will be to call them as follows:
13
14```
15namespace LIBC_NAMESPACE_DECL {
16namespace fputil {
17
18long double fmal(long double x, long double y, long double z) {
19  return generic::fmal(x, y, z);
20}
21
22} // namespace fputil
23} // namespace LIBC_NAMESPACE_DECL
24```
25
26Note that actual code might not be as straightforward as above (for example,
27we might want to prevent implicit type promotions by using some template
28facilities). But, the general idea is very similar.
29