[compiler-rt] [llvm] Add extendhfxf2 into compiler rt (PR #111099)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 23 23:41:46 PDT 2024


================
@@ -0,0 +1,67 @@
+// RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: librt_has_extendhfxf2
+
+#include <limits.h>
+#include <math.h> // for isnan, isinf
+#include <stdio.h>
+
+#if __LDBL_MANT_DIG__ >= 64 && defined(COMPILER_RT_HAS_FLOAT16)
+long double __extendhfxf2(_Float16 f);
+
+int test_extendhfxf2(_Float16 a, long double expected) {
+  long double x = __extendhfxf2(a);
+  __uint16_t *b = (void *)&a;
+  int ret = !(x == expected || (isnan(x) && isnan(expected)) ||
+              (isinf(x) && isinf(expected) && x == expected));
+  if (ret) {
+    printf("error in test__extendhfxf2(%#.4x) = %.20Lf, "
+           "expected %.20Lf\n",
+           *b, x, expected);
+  }
+  return ret;
+}
+
+char assumption_1[sizeof(_Float16) * CHAR_BIT == 16] = {0};
+
+#endif
+
+int main() {
----------------
lntue wrote:

will it be clearer if we just put everything in a single `ifdef ... else ... endif` like:
```
#ifdef __LDBL_MANT_DIG__ >= 64 && defined(COMPILER_RT_HAS_FLOAT16)
...
int main() {
...
}
#else
int main() {
  printf("skipped");
  return 0;
}
#endif
```
WDYT?

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


More information about the llvm-commits mailing list