1 //===--------------------------- fp_test.h - ------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines shared functions for the test.
11 //===----------------------------------------------------------------------===//
18 enum EXPECTED_RESULT
{
19 LESS_0
, LESS_EQUAL_0
, EQUAL_0
, GREATER_0
, GREATER_EQUAL_0
, NEQUAL_0
22 static inline uint16_t fromRep16(uint16_t x
)
27 static inline float fromRep32(uint32_t x
)
34 static inline double fromRep64(uint64_t x
)
41 #if __LDBL_MANT_DIG__ == 113
42 static inline long double fromRep128(uint64_t hi
, uint64_t lo
)
44 __uint128_t x
= ((__uint128_t
)hi
<< 64) + lo
;
51 static inline uint16_t toRep16(uint16_t x
)
56 static inline uint32_t toRep32(float x
)
63 static inline uint64_t toRep64(double x
)
70 #if __LDBL_MANT_DIG__ == 113
71 static inline __uint128_t
toRep128(long double x
)
79 static inline int compareResultH(uint16_t result
,
82 uint16_t rep
= toRep16(result
);
87 // test other possible NaN representation(signal NaN)
88 else if (expected
== 0x7e00U
){
89 if ((rep
& 0x7c00U
) == 0x7c00U
&&
97 static inline int compareResultF(float result
,
100 uint32_t rep
= toRep32(result
);
102 if (rep
== expected
){
105 // test other possible NaN representation(signal NaN)
106 else if (expected
== 0x7fc00000U
){
107 if ((rep
& 0x7f800000U
) == 0x7f800000U
&&
108 (rep
& 0x7fffffU
) > 0){
115 static inline int compareResultD(double result
,
118 uint64_t rep
= toRep64(result
);
120 if (rep
== expected
){
123 // test other possible NaN representation(signal NaN)
124 else if (expected
== 0x7ff8000000000000UL
){
125 if ((rep
& 0x7ff0000000000000UL
) == 0x7ff0000000000000UL
&&
126 (rep
& 0xfffffffffffffUL
) > 0){
133 #if __LDBL_MANT_DIG__ == 113
135 // use two 64-bit integers intead of one 128-bit integer
136 // because 128-bit integer constant can't be assigned directly
137 static inline int compareResultLD(long double result
,
141 __uint128_t rep
= toRep128(result
);
142 uint64_t hi
= rep
>> 64;
145 if (hi
== expectedHi
&& lo
== expectedLo
){
148 // test other possible NaN representation(signal NaN)
149 else if (expectedHi
== 0x7fff800000000000UL
&& expectedLo
== 0x0UL
){
150 if ((hi
& 0x7fff000000000000UL
) == 0x7fff000000000000UL
&&
151 ((hi
& 0xffffffffffffUL
) > 0 || lo
> 0)){
159 static inline int compareResultCMP(int result
,
160 enum EXPECTED_RESULT expected
)
179 case GREATER_EQUAL_0
:
193 static inline char *expectedStr(enum EXPECTED_RESULT expected
)
204 case GREATER_EQUAL_0
:
214 static inline uint16_t makeQNaN16()
216 return fromRep16(0x7e00U
);
219 static inline float makeQNaN32()
221 return fromRep32(0x7fc00000U
);
224 static inline double makeQNaN64()
226 return fromRep64(0x7ff8000000000000UL
);
229 #if __LDBL_MANT_DIG__ == 113
230 static inline long double makeQNaN128()
232 return fromRep128(0x7fff800000000000UL
, 0x0UL
);
236 static inline uint16_t makeNaN16(uint16_t rand
)
238 return fromRep16(0x7c00U
| (rand
& 0x7fffU
));
241 static inline float makeNaN32(uint32_t rand
)
243 return fromRep32(0x7f800000U
| (rand
& 0x7fffffU
));
246 static inline double makeNaN64(uint64_t rand
)
248 return fromRep64(0x7ff0000000000000UL
| (rand
& 0xfffffffffffffUL
));
251 #if __LDBL_MANT_DIG__ == 113
252 static inline long double makeNaN128(uint64_t rand
)
254 return fromRep128(0x7fff000000000000UL
| (rand
& 0xffffffffffffUL
), 0x0UL
);
258 static inline uint16_t makeInf16()
260 return fromRep16(0x7c00U
);
263 static inline float makeInf32()
265 return fromRep32(0x7f800000U
);
268 static inline double makeInf64()
270 return fromRep64(0x7ff0000000000000UL
);
273 #if __LDBL_MANT_DIG__ == 113
274 static inline long double makeInf128()
276 return fromRep128(0x7fff000000000000UL
, 0x0UL
);