[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / extendhfsf2_test.c
blobd47a5892fa917b44c05e7ceba129e8aa0071eeb2
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_extendhfsf2
3 //===--------------- extendhfsf2_test.c - Test __extendhfsf2 --------------===//
4 //
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //
9 //===----------------------------------------------------------------------===//
11 // This file tests __extendhfsf2 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
15 #include <stdio.h>
17 #include "fp_test.h"
19 float __extendhfsf2(uint16_t a);
21 int test__extendhfsf2(uint16_t a, float expected)
23 float x = __extendhfsf2(a);
24 int ret = compareResultH(x, expected);
26 if (ret){
27 printf("error in test__extendhfsf2(%#.4x) = %f, "
28 "expected %f\n", a, x, expected);
30 return ret;
33 char assumption_1[sizeof(__fp16) * CHAR_BIT == 16] = {0};
35 int main()
37 // qNaN
38 if (test__extendhfsf2(UINT16_C(0x7e00),
39 makeQNaN32()))
40 return 1;
41 // NaN
42 if (test__extendhfsf2(UINT16_C(0x7e00),
43 makeNaN32(UINT32_C(0x8000))))
44 return 1;
45 // inf
46 if (test__extendhfsf2(UINT16_C(0x7c00),
47 makeInf32()))
48 return 1;
49 if (test__extendhfsf2(UINT16_C(0xfc00),
50 -makeInf32()))
51 return 1;
52 // zero
53 if (test__extendhfsf2(UINT16_C(0x0),
54 0.0f))
55 return 1;
56 if (test__extendhfsf2(UINT16_C(0x8000),
57 -0.0f))
58 return 1;
60 if (test__extendhfsf2(UINT16_C(0x4248),
61 3.1415926535f))
62 return 1;
63 if (test__extendhfsf2(UINT16_C(0xc248),
64 -3.1415926535f))
65 return 1;
66 if (test__extendhfsf2(UINT16_C(0x7c00),
67 0x1.987124876876324p+100f))
68 return 1;
69 if (test__extendhfsf2(UINT16_C(0x6e62),
70 0x1.988p+12f))
71 return 1;
72 if (test__extendhfsf2(UINT16_C(0x3c00),
73 0x1.0p+0f))
74 return 1;
75 if (test__extendhfsf2(UINT16_C(0x0400),
76 0x1.0p-14f))
77 return 1;
78 // denormal
79 if (test__extendhfsf2(UINT16_C(0x0010),
80 0x1.0p-20f))
81 return 1;
82 if (test__extendhfsf2(UINT16_C(0x0001),
83 0x1.0p-24f))
84 return 1;
85 if (test__extendhfsf2(UINT16_C(0x8001),
86 -0x1.0p-24f))
87 return 1;
88 if (test__extendhfsf2(UINT16_C(0x0001),
89 0x1.5p-25f))
90 return 1;
91 // and back to zero
92 if (test__extendhfsf2(UINT16_C(0x0000),
93 0x1.0p-25f))
94 return 1;
95 if (test__extendhfsf2(UINT16_C(0x8000),
96 -0x1.0p-25f))
97 return 1;
98 // max (precise)
99 if (test__extendhfsf2(UINT16_C(0x7bff),
100 65504.0f))
101 return 1;
102 // max (rounded)
103 if (test__extendhfsf2(UINT16_C(0x7bff),
104 65504.0f))
105 return 1;
106 // max (to +inf)
107 if (test__extendhfsf2(UINT16_C(0x7c00),
108 makeInf32()))
109 return 1;
110 if (test__extendhfsf2(UINT16_C(0xfc00),
111 -makeInf32()))
112 return 1;
113 return 0;