[libc-commits] [PATCH] D115082: [libc][NFC] refactor math implementations
Guillaume Chatelet via Phabricator via libc-commits
libc-commits at lists.llvm.org
Fri Dec 3 15:15:11 PST 2021
gchatelet added inline comments.
================
Comment at: libc/src/math/sqrt.cpp:9-24
+#include "src/__support/architectures.h"
+
+#if defined(LLVM_LIBC_ARCH_AARCH64)
+#include "aarch64/sqrt.cpp"
+#elif defined(LLVM_LIBC_ARCH_X86)
+#include "x86_64/sqrt.cpp"
+#else
----------------
@lntue I'm not entirely sure that the redirection to subfolder makes sense. The inlined version would look like this
```
#include "sqrt.h"
#include "src/__support/architectures.h"
#include "src/__support/FPUtil/Sqrt.h"
#include "src/__support/common.h"
namespace __llvm_libc {
LLVM_LIBC_FUNCTION(double, sqrt, (double x)) {
#if defined(LLVM_LIBC_ARCH_AARCH64)
double y;
__asm__ __volatile__("fsqrt %d0, %d1\n\t" : "=w"(y) : "w"(x));
return y;
#elif defined(LLVM_LIBC_ARCH_X86)
double result;
__asm__ __volatile__("sqrtsd %x1, %x0" : "=x"(result) : "x"(x));
return result;
#else
return fputil::sqrt(x);
#endif
}
} // namespace __llvm_libc
```
I find it more readable and it's less files overal. Let me know what you think
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115082/new/
https://reviews.llvm.org/D115082
More information about the libc-commits
mailing list