[libc-commits] [libc] [libc] Proof of concept of aliasing long double math functions. (PR #132627)
via libc-commits
libc-commits at lists.llvm.org
Mon Mar 24 13:49:44 PDT 2025
================
@@ -37,21 +37,47 @@
#define LLVM_LIBC_ATTR(name) EXPAND_THEN_SECOND(LLVM_LIBC_FUNCTION_ATTR_##name)
-// MacOS needs to be excluded because it does not support aliasing.
-#if defined(LIBC_COPT_PUBLIC_PACKAGING) && (!defined(__APPLE__))
-#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) \
+// MacOS needs to be excluded because it does not support [[gnu::aliasing]].
+#ifndef __APPLE__
+
+#if defined(LIBC_COPT_PUBLIC_PACKAGING)
+#define LLVM_LIBC_FUNCTION(type, name, arglist) \
LLVM_LIBC_ATTR(name) \
LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name) \
- __##name##_impl__ __asm__(#name); \
+ __##name##_impl__ asm(#name); \
decltype(LIBC_NAMESPACE::name) name [[gnu::alias(#name)]]; \
type __##name##_impl__ arglist
-#else
-#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist) type name arglist
-#endif
-// This extra layer of macro allows `name` to be a macro to rename a function.
+#define LLVM_LIBC_ALIASING_FUNCTION(name, func) \
+ namespace LIBC_NAMESPACE_DECL { \
----------------
lntue wrote:
it's because when adding aliases for `copysignl`, we will need to include `copysignl.h` header. So to keep them in just one `#if ... #endif` block for ease of use, it's cleaner to add the namespace to the macro than having 1 line macro in the namespace all the time, like:
```
#if ...
#include "copysignl.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_ALIASING_FUNCTION(copysignl, copysignf128);
}
#endif
```
vs
```
#if ...
#include "copysignl.h"
LLVM_LIBC_ALIASING_FUNCTION(copysignl, copysignf128);
#endif
https://github.com/llvm/llvm-project/pull/132627
More information about the libc-commits
mailing list