Skip to content

Commit 159f70d

Browse files
committed
Add extendhfdf2_test.c
1 parent 0c6c4d9 commit 159f70d

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

Diff for: compiler-rt/test/builtins/Unit/extendhfdf2_test.c

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// RUN: %clang_builtins %s %librt -o %t && %run %t
2+
// REQUIRES: librt_has_extendhfdf2
3+
4+
#include <stdio.h>
5+
6+
#include "fp_test.h"
7+
8+
double __extendhfdf2(TYPE_FP16 a);
9+
10+
int test__extendhfdf2(TYPE_FP16 a, uint64_t expected)
11+
{
12+
double x = __extendhfdf2(a);
13+
int ret = compareResultD(x, expected);
14+
15+
if (ret){
16+
printf("error in test__extendhfdf2(%#.4x) = %f, "
17+
"expected %f\n", toRep16(a), x, fromRep64(expected));
18+
}
19+
return ret;
20+
}
21+
22+
char assumption_1[sizeof(TYPE_FP16) * CHAR_BIT == 16] = {0};
23+
24+
int main()
25+
{
26+
// qNaN
27+
if (test__extendhfdf2(makeQNaN16(),
28+
UINT64_C(0x7ff8000000000000)))
29+
return 1;
30+
// NaN
31+
if (test__extendhfdf2(fromRep16(0x7f80),
32+
UINT64_C(0x7ffe000000000000)))
33+
return 1;
34+
// inf
35+
if (test__extendhfdf2(makeInf16(),
36+
UINT64_C(0x7ff0000000000000)))
37+
return 1;
38+
// -inf
39+
if (test__extendhfdf2(makeNegativeInf16(),
40+
UINT64_C(0xfff0000000000000)))
41+
return 1;
42+
// zero
43+
if (test__extendhfdf2(fromRep16(0x0),
44+
UINT64_C(0x0)))
45+
return 1;
46+
// -zero
47+
if (test__extendhfdf2(fromRep16(0x8000),
48+
UINT64_C(0x8000000000000000)))
49+
return 1;
50+
if (test__extendhfdf2(fromRep16(0x4248),
51+
UINT64_C(0x4009200000000000)))
52+
return 1;
53+
if (test__extendhfdf2(fromRep16(0xc248),
54+
UINT64_C(0xc009200000000000)))
55+
return 1;
56+
if (test__extendhfdf2(fromRep16(0x6e62),
57+
UINT64_C(0x40b9880000000000)))
58+
return 1;
59+
if (test__extendhfdf2(fromRep16(0x3c00),
60+
UINT64_C(0x3ff0000000000000)))
61+
return 1;
62+
if (test__extendhfdf2(fromRep16(0x0400),
63+
UINT64_C(0x3f10000000000000)))
64+
return 1;
65+
// denormal
66+
if (test__extendhfdf2(fromRep16(0x0010),
67+
UINT64_C(0x3eb0000000000000)))
68+
return 1;
69+
if (test__extendhfdf2(fromRep16(0x0001),
70+
UINT64_C(0x3e70000000000000)))
71+
return 1;
72+
if (test__extendhfdf2(fromRep16(0x8001),
73+
UINT64_C(0xbe70000000000000)))
74+
return 1;
75+
if (test__extendhfdf2(fromRep16(0x0001),
76+
UINT64_C(0x3e70000000000000)))
77+
return 1;
78+
// max (precise)
79+
if (test__extendhfdf2(fromRep16(0x7bff),
80+
UINT64_C(0x40effc0000000000)))
81+
return 1;
82+
// max (rounded)
83+
if (test__extendhfdf2(fromRep16(0x7bff),
84+
UINT64_C(0x40effc0000000000)))
85+
return 1;
86+
return 0;
87+
}

0 commit comments

Comments
 (0)