summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test/builtins/Unit
diff options
context:
space:
mode:
Diffstat (limited to 'compiler-rt/test/builtins/Unit')
-rw-r--r--compiler-rt/test/builtins/Unit/extendhfsf2_test.c113
-rw-r--r--compiler-rt/test/builtins/Unit/fp_test.h43
-rw-r--r--compiler-rt/test/builtins/Unit/truncdfhf2_test.c111
-rw-r--r--compiler-rt/test/builtins/Unit/truncsfhf2_test.c111
4 files changed, 378 insertions, 0 deletions
diff --git a/compiler-rt/test/builtins/Unit/extendhfsf2_test.c b/compiler-rt/test/builtins/Unit/extendhfsf2_test.c
new file mode 100644
index 00000000000..5dd994cae1c
--- /dev/null
+++ b/compiler-rt/test/builtins/Unit/extendhfsf2_test.c
@@ -0,0 +1,113 @@
+//===--------------- extendhfsf2_test.c - Test __extendhfsf2 --------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file tests __extendhfsf2 for the compiler_rt library.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdio.h>
+
+#include "fp_test.h"
+
+float __extendhfsf2(uint16_t a);
+
+int test__extendhfsf2(uint16_t a, float expected)
+{
+ float x = __extendhfsf2(a);
+ int ret = compareResultH(x, expected);
+
+ if (ret){
+ printf("error in test__extendhfsf2(%#.4x) = %f, "
+ "expected %f\n", a, x, expected);
+ }
+ return ret;
+}
+
+char assumption_1[sizeof(__fp16) * CHAR_BIT == 16] = {0};
+
+int main()
+{
+ // qNaN
+ if (test__extendhfsf2(UINT16_C(0x7e00),
+ makeQNaN32()))
+ return 1;
+ // NaN
+ if (test__extendhfsf2(UINT16_C(0x7e00),
+ makeNaN32(UINT32_C(0x8000))))
+ return 1;
+ // inf
+ if (test__extendhfsf2(UINT16_C(0x7c00),
+ makeInf32()))
+ return 1;
+ if (test__extendhfsf2(UINT16_C(0xfc00),
+ -makeInf32()))
+ return 1;
+ // zero
+ if (test__extendhfsf2(UINT16_C(0x0),
+ 0.0f))
+ return 1;
+ if (test__extendhfsf2(UINT16_C(0x8000),
+ -0.0f))
+ return 1;
+
+ if (test__extendhfsf2(UINT16_C(0x4248),
+ 3.1415926535f))
+ return 1;
+ if (test__extendhfsf2(UINT16_C(0xc248),
+ -3.1415926535f))
+ return 1;
+ if (test__extendhfsf2(UINT16_C(0x7c00),
+ 0x1.987124876876324p+100f))
+ return 1;
+ if (test__extendhfsf2(UINT16_C(0x6e62),
+ 0x1.988p+12f))
+ return 1;
+ if (test__extendhfsf2(UINT16_C(0x3c00),
+ 0x1.0p+0f))
+ return 1;
+ if (test__extendhfsf2(UINT16_C(0x0400),
+ 0x1.0p-14f))
+ return 1;
+ // denormal
+ if (test__extendhfsf2(UINT16_C(0x0010),
+ 0x1.0p-20f))
+ return 1;
+ if (test__extendhfsf2(UINT16_C(0x0001),
+ 0x1.0p-24f))
+ return 1;
+ if (test__extendhfsf2(UINT16_C(0x8001),
+ -0x1.0p-24f))
+ return 1;
+ if (test__extendhfsf2(UINT16_C(0x0001),
+ 0x1.5p-25f))
+ return 1;
+ // and back to zero
+ if (test__extendhfsf2(UINT16_C(0x0000),
+ 0x1.0p-25f))
+ return 1;
+ if (test__extendhfsf2(UINT16_C(0x8000),
+ -0x1.0p-25f))
+ return 1;
+ // max (precise)
+ if (test__extendhfsf2(UINT16_C(0x7bff),
+ 65504.0f))
+ return 1;
+ // max (rounded)
+ if (test__extendhfsf2(UINT16_C(0x7bff),
+ 65504.0f))
+ return 1;
+ // max (to +inf)
+ if (test__extendhfsf2(UINT16_C(0x7c00),
+ makeInf32()))
+ return 1;
+ if (test__extendhfsf2(UINT16_C(0xfc00),
+ -makeInf32()))
+ return 1;
+ return 0;
+}
diff --git a/compiler-rt/test/builtins/Unit/fp_test.h b/compiler-rt/test/builtins/Unit/fp_test.h
index da58ca989cd..95740b68c9c 100644
--- a/compiler-rt/test/builtins/Unit/fp_test.h
+++ b/compiler-rt/test/builtins/Unit/fp_test.h
@@ -19,6 +19,11 @@ enum EXPECTED_RESULT {
LESS_0, LESS_EQUAL_0, EQUAL_0, GREATER_0, GREATER_EQUAL_0, NEQUAL_0
};
+static inline uint16_t fromRep16(uint16_t x)
+{
+ return x;
+}
+
static inline float fromRep32(uint32_t x)
{
float ret;
@@ -41,6 +46,11 @@ static inline long double fromRep128(uint64_t hi, uint64_t lo)
return ret;
}
+static inline uint16_t toRep16(uint16_t x)
+{
+ return x;
+}
+
static inline uint32_t toRep32(float x)
{
uint32_t ret;
@@ -62,6 +72,24 @@ static inline __uint128_t toRep128(long double x)
return ret;
}
+static inline int compareResultH(uint16_t result,
+ uint16_t expected)
+{
+ uint16_t rep = toRep16(result);
+
+ if (rep == expected){
+ return 0;
+ }
+ // test other posible NaN representation(signal NaN)
+ else if (expected == 0x7e00U){
+ if ((rep & 0x7c00U) == 0x7c00U &&
+ (rep & 0x3ffU) > 0){
+ return 0;
+ }
+ }
+ return 1;
+}
+
static inline int compareResultF(float result,
uint32_t expected)
{
@@ -177,6 +205,11 @@ static inline char *expectedStr(enum EXPECTED_RESULT expected)
return "";
}
+static inline uint16_t makeQNaN16()
+{
+ return fromRep16(0x7e00U);
+}
+
static inline float makeQNaN32()
{
return fromRep32(0x7fc00000U);
@@ -192,6 +225,11 @@ static inline long double makeQNaN128()
return fromRep128(0x7fff800000000000UL, 0x0UL);
}
+static inline uint16_t makeNaN16(uint16_t rand)
+{
+ return fromRep16(0x7c00U | (rand & 0x7fffU));
+}
+
static inline float makeNaN32(uint32_t rand)
{
return fromRep32(0x7f800000U | (rand & 0x7fffffU));
@@ -207,6 +245,11 @@ static inline long double makeNaN128(uint64_t rand)
return fromRep128(0x7fff000000000000UL | (rand & 0xffffffffffffUL), 0x0UL);
}
+static inline uint16_t makeInf16()
+{
+ return fromRep16(0x7c00U);
+}
+
static inline float makeInf32()
{
return fromRep32(0x7f800000U);
diff --git a/compiler-rt/test/builtins/Unit/truncdfhf2_test.c b/compiler-rt/test/builtins/Unit/truncdfhf2_test.c
new file mode 100644
index 00000000000..98c5c9dac2e
--- /dev/null
+++ b/compiler-rt/test/builtins/Unit/truncdfhf2_test.c
@@ -0,0 +1,111 @@
+//===--------------- truncdfhf2_test.c - Test __truncdfhf2 ----------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file tests __truncdfhf2 for the compiler_rt library.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdio.h>
+
+#include "fp_test.h"
+
+uint16_t __truncdfhf2(double a);
+
+int test__truncdfhf2(double a, uint16_t expected)
+{
+ uint16_t x = __truncdfhf2(a);
+ int ret = compareResultH(x, expected);
+
+ if (ret){
+ printf("error in test__truncdfhf2(%f) = %#.4x, "
+ "expected %#.4x\n", a, x, fromRep16(expected));
+ }
+ return ret;
+}
+
+char assumption_1[sizeof(__fp16) * CHAR_BIT == 16] = {0};
+
+int main()
+{
+ // qNaN
+ if (test__truncdfhf2(makeQNaN64(),
+ UINT16_C(0x7e00)))
+ return 1;
+ // NaN
+ if (test__truncdfhf2(makeNaN64(UINT64_C(0x8000)),
+ UINT16_C(0x7e00)))
+ return 1;
+ // inf
+ if (test__truncdfhf2(makeInf64(),
+ UINT16_C(0x7c00)))
+ return 1;
+ if (test__truncdfhf2(-makeInf64(),
+ UINT16_C(0xfc00)))
+ return 1;
+ // zero
+ if (test__truncdfhf2(0.0, UINT16_C(0x0)))
+ return 1;
+ if (test__truncdfhf2(-0.0, UINT16_C(0x8000)))
+ return 1;
+
+ if (test__truncdfhf2(3.1415926535,
+ UINT16_C(0x4248)))
+ return 1;
+ if (test__truncdfhf2(-3.1415926535,
+ UINT16_C(0xc248)))
+ return 1;
+ if (test__truncdfhf2(0x1.987124876876324p+1000,
+ UINT16_C(0x7c00)))
+ return 1;
+ if (test__truncdfhf2(0x1.987124876876324p+12,
+ UINT16_C(0x6e62)))
+ return 1;
+ if (test__truncdfhf2(0x1.0p+0,
+ UINT16_C(0x3c00)))
+ return 1;
+ if (test__truncdfhf2(0x1.0p-14,
+ UINT16_C(0x0400)))
+ return 1;
+ // denormal
+ if (test__truncdfhf2(0x1.0p-20,
+ UINT16_C(0x0010)))
+ return 1;
+ if (test__truncdfhf2(0x1.0p-24,
+ UINT16_C(0x0001)))
+ return 1;
+ if (test__truncdfhf2(-0x1.0p-24,
+ UINT16_C(0x8001)))
+ return 1;
+ if (test__truncdfhf2(0x1.5p-25,
+ UINT16_C(0x0001)))
+ return 1;
+ // and back to zero
+ if (test__truncdfhf2(0x1.0p-25,
+ UINT16_C(0x0000)))
+ return 1;
+ if (test__truncdfhf2(-0x1.0p-25,
+ UINT16_C(0x8000)))
+ return 1;
+ // max (precise)
+ if (test__truncdfhf2(65504.0,
+ UINT16_C(0x7bff)))
+ return 1;
+ // max (rounded)
+ if (test__truncdfhf2(65519.0,
+ UINT16_C(0x7bff)))
+ return 1;
+ // max (to +inf)
+ if (test__truncdfhf2(65520.0,
+ UINT16_C(0x7c00)))
+ return 1;
+ if (test__truncdfhf2(-65520.0,
+ UINT16_C(0xfc00)))
+ return 1;
+ return 0;
+}
diff --git a/compiler-rt/test/builtins/Unit/truncsfhf2_test.c b/compiler-rt/test/builtins/Unit/truncsfhf2_test.c
new file mode 100644
index 00000000000..2024605d010
--- /dev/null
+++ b/compiler-rt/test/builtins/Unit/truncsfhf2_test.c
@@ -0,0 +1,111 @@
+//===--------------- truncsfhf2_test.c - Test __truncsfhf2 ----------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file tests __truncsfhf2 for the compiler_rt library.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdio.h>
+
+#include "fp_test.h"
+
+uint16_t __truncsfhf2(float a);
+
+int test__truncsfhf2(float a, uint16_t expected)
+{
+ uint16_t x = __truncsfhf2(a);
+ int ret = compareResultH(x, expected);
+
+ if (ret){
+ printf("error in test__truncsfhf2(%f) = %#.4x, "
+ "expected %#.4x\n", a, x, fromRep16(expected));
+ }
+ return ret;
+}
+
+char assumption_1[sizeof(__fp16) * CHAR_BIT == 16] = {0};
+
+int main()
+{
+ // qNaN
+ if (test__truncsfhf2(makeQNaN32(),
+ UINT16_C(0x7e00)))
+ return 1;
+ // NaN
+ if (test__truncsfhf2(makeNaN32(UINT32_C(0x8000)),
+ UINT16_C(0x7e00)))
+ return 1;
+ // inf
+ if (test__truncsfhf2(makeInf32(),
+ UINT16_C(0x7c00)))
+ return 1;
+ if (test__truncsfhf2(-makeInf32(),
+ UINT16_C(0xfc00)))
+ return 1;
+ // zero
+ if (test__truncsfhf2(0.0f, UINT16_C(0x0)))
+ return 1;
+ if (test__truncsfhf2(-0.0f, UINT16_C(0x8000)))
+ return 1;
+
+ if (test__truncsfhf2(3.1415926535f,
+ UINT16_C(0x4248)))
+ return 1;
+ if (test__truncsfhf2(-3.1415926535f,
+ UINT16_C(0xc248)))
+ return 1;
+ if (test__truncsfhf2(0x1.987124876876324p+100f,
+ UINT16_C(0x7c00)))
+ return 1;
+ if (test__truncsfhf2(0x1.987124876876324p+12f,
+ UINT16_C(0x6e62)))
+ return 1;
+ if (test__truncsfhf2(0x1.0p+0f,
+ UINT16_C(0x3c00)))
+ return 1;
+ if (test__truncsfhf2(0x1.0p-14f,
+ UINT16_C(0x0400)))
+ return 1;
+ // denormal
+ if (test__truncsfhf2(0x1.0p-20f,
+ UINT16_C(0x0010)))
+ return 1;
+ if (test__truncsfhf2(0x1.0p-24f,
+ UINT16_C(0x0001)))
+ return 1;
+ if (test__truncsfhf2(-0x1.0p-24f,
+ UINT16_C(0x8001)))
+ return 1;
+ if (test__truncsfhf2(0x1.5p-25f,
+ UINT16_C(0x0001)))
+ return 1;
+ // and back to zero
+ if (test__truncsfhf2(0x1.0p-25f,
+ UINT16_C(0x0000)))
+ return 1;
+ if (test__truncsfhf2(-0x1.0p-25f,
+ UINT16_C(0x8000)))
+ return 1;
+ // max (precise)
+ if (test__truncsfhf2(65504.0f,
+ UINT16_C(0x7bff)))
+ return 1;
+ // max (rounded)
+ if (test__truncsfhf2(65519.0f,
+ UINT16_C(0x7bff)))
+ return 1;
+ // max (to +inf)
+ if (test__truncsfhf2(65520.0f,
+ UINT16_C(0x7c00)))
+ return 1;
+ if (test__truncsfhf2(-65520.0f,
+ UINT16_C(0xfc00)))
+ return 1;
+ return 0;
+}
OpenPOWER on IntegriCloud