[libc-commits] [libc] [libc][math] Implement nearest integer functions using builtins when available (PR #98376)

via libc-commits libc-commits at lists.llvm.org
Wed Jul 10 13:28:12 PDT 2024


================
@@ -9,9 +9,17 @@
 #include "src/math/ceilf16.h"
 #include "src/__support/FPUtil/NearestIntegerOperations.h"
 #include "src/__support/common.h"
+#include "src/__support/macros/properties/architectures.h"
 
 namespace LIBC_NAMESPACE {
 
-LLVM_LIBC_FUNCTION(float16, ceilf16, (float16 x)) { return fputil::ceil(x); }
+LLVM_LIBC_FUNCTION(float16, ceilf16, (float16 x)) {
+#if defined(__LIBC_USE_BUILTIN_CEIL_FLOOR_TRUNC) &&                            \
+    defined(LIBC_TARGET_ARCH_IS_AARCH64)
----------------
overmighty wrote:

Probably would be faster than the generic implementation on x86-64 with AVX-512 FP16, but I don't have a CPU that supports it. It could also be interesting to try on a Zen 2 or later CPU, because F16C instructions have lower latencies on those: https://uops.info/table.html?search=vcvtph2ps%20(xmm%2C%20xmm)&cb_lat=on&cb_tp=on&cb_uops=on&cb_ports=on&cb_ADLP=on&cb_ADLE=on&cb_ZENp=on&cb_ZEN2=on&cb_measurements=on&cb_doc=on&cb_others=on. 

https://github.com/llvm/llvm-project/pull/98376


More information about the libc-commits mailing list