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