summaryrefslogtreecommitdiff
path: root/test/builtins/Unit/fp_test.h
diff options
context:
space:
mode:
Diffstat (limited to 'test/builtins/Unit/fp_test.h')
-rw-r--r--test/builtins/Unit/fp_test.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/builtins/Unit/fp_test.h b/test/builtins/Unit/fp_test.h
index da58ca989cda..1f0e7be6d6a4 100644
--- a/test/builtins/Unit/fp_test.h
+++ b/test/builtins/Unit/fp_test.h
@@ -14,11 +14,17 @@
#include <stdlib.h>
#include <limits.h>
#include <string.h>
+#include <stdint.h>
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;
@@ -33,6 +39,7 @@ static inline double fromRep64(uint64_t x)
return ret;
}
+#if __LDBL_MANT_DIG__ == 113
static inline long double fromRep128(uint64_t hi, uint64_t lo)
{
__uint128_t x = ((__uint128_t)hi << 64) + lo;
@@ -40,6 +47,12 @@ static inline long double fromRep128(uint64_t hi, uint64_t lo)
memcpy(&ret, &x, 16);
return ret;
}
+#endif
+
+static inline uint16_t toRep16(uint16_t x)
+{
+ return x;
+}
static inline uint32_t toRep32(float x)
{
@@ -55,12 +68,32 @@ static inline uint64_t toRep64(double x)
return ret;
}
+#if __LDBL_MANT_DIG__ == 113
static inline __uint128_t toRep128(long double x)
{
__uint128_t ret;
memcpy(&ret, &x, 16);
return ret;
}
+#endif
+
+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)
@@ -98,6 +131,7 @@ static inline int compareResultD(double result,
return 1;
}
+#if __LDBL_MANT_DIG__ == 113
// return 0 if equal
// use two 64-bit integers intead of one 128-bit integer
// because 128-bit integer constant can't be assigned directly
@@ -121,6 +155,7 @@ static inline int compareResultLD(long double result,
}
return 1;
}
+#endif
static inline int compareResultCMP(int result,
enum EXPECTED_RESULT expected)
@@ -177,6 +212,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);
@@ -187,10 +227,17 @@ static inline double makeQNaN64()
return fromRep64(0x7ff8000000000000UL);
}
+#if __LDBL_MANT_DIG__ == 113
static inline long double makeQNaN128()
{
return fromRep128(0x7fff800000000000UL, 0x0UL);
}
+#endif
+
+static inline uint16_t makeNaN16(uint16_t rand)
+{
+ return fromRep16(0x7c00U | (rand & 0x7fffU));
+}
static inline float makeNaN32(uint32_t rand)
{
@@ -202,10 +249,17 @@ static inline double makeNaN64(uint64_t rand)
return fromRep64(0x7ff0000000000000UL | (rand & 0xfffffffffffffUL));
}
+#if __LDBL_MANT_DIG__ == 113
static inline long double makeNaN128(uint64_t rand)
{
return fromRep128(0x7fff000000000000UL | (rand & 0xffffffffffffUL), 0x0UL);
}
+#endif
+
+static inline uint16_t makeInf16()
+{
+ return fromRep16(0x7c00U);
+}
static inline float makeInf32()
{
@@ -217,7 +271,9 @@ static inline double makeInf64()
return fromRep64(0x7ff0000000000000UL);
}
+#if __LDBL_MANT_DIG__ == 113
static inline long double makeInf128()
{
return fromRep128(0x7fff000000000000UL, 0x0UL);
}
+#endif