1// RUN: %clang_builtins %s %librt -o %t && %run %t
2// REQUIRES: librt_has_extendhfsf2
3
4#include <stdio.h>
5
6#include "fp_test.h"
7
8float __extendhfsf2(TYPE_FP16 a);
9
10int test__extendhfsf2(TYPE_FP16 a, uint32_t expected)
11{
12 float x = __extendhfsf2(a);
13 int ret = compareResultF(result: x, expected);
14
15 if (ret){
16 printf(format: "error in test__extendhfsf2(%#.4x) = %f, "
17 "expected %f\n", toRep16(x: a), x, fromRep32(x: expected));
18 }
19 return ret;
20}
21
22char assumption_1[sizeof(TYPE_FP16) * CHAR_BIT == 16] = {0};
23
24int main()
25{
26 // qNaN
27 if (test__extendhfsf2(a: fromRep16(x: 0x7e00),
28 UINT32_C(0x7fc00000)))
29 return 1;
30 // NaN
31 if (test__extendhfsf2(a: fromRep16(x: 0x7f80),
32 UINT32_C(0x7ff00000)))
33 return 1;
34 // inf
35 if (test__extendhfsf2(a: fromRep16(x: 0x7c00),
36 UINT32_C(0x7f800000)))
37 return 1;
38 // -inf
39 if (test__extendhfsf2(a: fromRep16(x: 0xfc00),
40 UINT32_C(0xff800000)))
41 return 1;
42 // zero
43 if (test__extendhfsf2(a: fromRep16(x: 0x0),
44 UINT32_C(0x00000000)))
45 return 1;
46 // -zero
47 if (test__extendhfsf2(a: fromRep16(x: 0x8000),
48 UINT32_C(0x80000000)))
49 return 1;
50 if (test__extendhfsf2(a: fromRep16(x: 0x4248),
51 UINT32_C(0x40490000)))
52 return 1;
53 if (test__extendhfsf2(a: fromRep16(x: 0xc248),
54 UINT32_C(0xc0490000)))
55 return 1;
56 if (test__extendhfsf2(a: fromRep16(x: 0x6e62),
57 UINT32_C(0x45cc4000)))
58 return 1;
59 if (test__extendhfsf2(a: fromRep16(x: 0x3c00),
60 UINT32_C(0x3f800000)))
61 return 1;
62 if (test__extendhfsf2(a: fromRep16(x: 0x0400),
63 UINT32_C(0x38800000)))
64 return 1;
65 // denormal
66 if (test__extendhfsf2(a: fromRep16(x: 0x0010),
67 UINT32_C(0x35800000)))
68 return 1;
69 if (test__extendhfsf2(a: fromRep16(x: 0x0001),
70 UINT32_C(0x33800000)))
71 return 1;
72 if (test__extendhfsf2(a: fromRep16(x: 0x8001),
73 UINT32_C(0xb3800000)))
74 return 1;
75 if (test__extendhfsf2(a: fromRep16(x: 0x0001),
76 UINT32_C(0x33800000)))
77 return 1;
78 // max (precise)
79 if (test__extendhfsf2(a: fromRep16(x: 0x7bff),
80 UINT32_C(0x477fe000)))
81 return 1;
82 // max (rounded)
83 if (test__extendhfsf2(a: fromRep16(x: 0x7bff),
84 UINT32_C(0x477fe000)))
85 return 1;
86 return 0;
87}
88

source code of compiler-rt/test/builtins/Unit/extendhfsf2_test.c