[libcxx-commits] [PATCH] D138629: [libc++][math.h] Add double overloads
Louis Dionne via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Nov 24 09:42:30 PST 2022
ldionne added subscribers: Izaron, bcain, fhahn, aaron.ballman.
ldionne added a comment.
Pinging some Clang folks to get a better understanding of how Clang builtins work (feel free to suggest other people, I'm shooting randomly based on a quick `git blame`): @fhahn @Izaron @aaron.ballman
@bcain also for freestanding questions
I have a few questions:
1. Which math functions does Clang define as builtin? Does it define all the overloads, or only the `double` one that's usually coming from the C library?
2. What do these builtins do, exactly? I assume they try to do something clever and then fall back to a library-provided implementation (and they assume there's a suitable C-linkage definition somewhere)?
3. Why are builtins that are not reserved identifiers (e.g. `cos`, `sin`) disabled in freestanding mode? I'm asking generally, I know `cmath` is not part of Freestanding per se.
4. More generally speaking, what's the purpose of `-fno-builtins`?
Sorry, this is kind of open-ended, but I feel like this is important to understand here.
Also, on a related but tangential note, @philnik and I were trying to wrap our heads around what's the purpose of compiler builtin headers. It looks like the order of includes in Clang (and GCC) is: C++ library headers > compiler builtin headers > C library headers. This is true on both Linux and Darwin, so it's not accidental, it's really by design. Now, some headers exist only in the builtin headers (e.g. `<stdbool.h>`), some only in the C library headers (e.g. `<stdio.h>`), and some in both (e.g. `<stdint.h>`). Can anyone shed light on the logic behind this?
Is any of this documented anywhere?
================
Comment at: libcxx/include/math.h:541
+template <class = int>
+_LIBCPP_HIDE_FROM_ABI double acos(double __x) _NOEXCEPT {
+ return __builtin_acos(__x);
----------------
Q: Is there any reason we are not using `_LIBCPP_PREFERRED_OVERLOAD`?
Answer: GCC does not support it.
Fair enough.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138629/new/
https://reviews.llvm.org/D138629
More information about the libcxx-commits
mailing list