xref: /aosp_15_r20/external/compiler-rt/test/builtins/Unit/floatunsitf_test.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot //===--------------- floatunsitf_test.c - Test __floatunsitf --------------===//
2*7c3d14c8STreehugger Robot //
3*7c3d14c8STreehugger Robot //                     The LLVM Compiler Infrastructure
4*7c3d14c8STreehugger Robot //
5*7c3d14c8STreehugger Robot // This file is dual licensed under the MIT and the University of Illinois Open
6*7c3d14c8STreehugger Robot // Source Licenses. See LICENSE.TXT for details.
7*7c3d14c8STreehugger Robot //
8*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
9*7c3d14c8STreehugger Robot //
10*7c3d14c8STreehugger Robot // This file tests __floatunsitf for the compiler_rt library.
11*7c3d14c8STreehugger Robot //
12*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
13*7c3d14c8STreehugger Robot 
14*7c3d14c8STreehugger Robot #include "int_lib.h"
15*7c3d14c8STreehugger Robot #include <stdio.h>
16*7c3d14c8STreehugger Robot 
17*7c3d14c8STreehugger Robot #if __LDBL_MANT_DIG__ == 113
18*7c3d14c8STreehugger Robot 
19*7c3d14c8STreehugger Robot #include "fp_test.h"
20*7c3d14c8STreehugger Robot 
21*7c3d14c8STreehugger Robot COMPILER_RT_ABI long double __floatunsitf(unsigned int a);
22*7c3d14c8STreehugger Robot 
test__floatunsitf(unsigned int a,uint64_t expectedHi,uint64_t expectedLo)23*7c3d14c8STreehugger Robot int test__floatunsitf(unsigned int a, uint64_t expectedHi, uint64_t expectedLo)
24*7c3d14c8STreehugger Robot {
25*7c3d14c8STreehugger Robot     long double x = __floatunsitf(a);
26*7c3d14c8STreehugger Robot     int ret = compareResultLD(x, expectedHi, expectedLo);
27*7c3d14c8STreehugger Robot 
28*7c3d14c8STreehugger Robot     if (ret){
29*7c3d14c8STreehugger Robot         printf("error in test__floatunsitf(%u) = %.20Lf, "
30*7c3d14c8STreehugger Robot                "expected %.20Lf\n", a, x, fromRep128(expectedHi, expectedLo));
31*7c3d14c8STreehugger Robot     }
32*7c3d14c8STreehugger Robot     return ret;
33*7c3d14c8STreehugger Robot }
34*7c3d14c8STreehugger Robot 
35*7c3d14c8STreehugger Robot char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
36*7c3d14c8STreehugger Robot 
37*7c3d14c8STreehugger Robot #endif
38*7c3d14c8STreehugger Robot 
main()39*7c3d14c8STreehugger Robot int main()
40*7c3d14c8STreehugger Robot {
41*7c3d14c8STreehugger Robot #if __LDBL_MANT_DIG__ == 113
42*7c3d14c8STreehugger Robot     if (test__floatunsitf(0x7fffffff, UINT64_C(0x401dfffffffc0000), UINT64_C(0x0)))
43*7c3d14c8STreehugger Robot         return 1;
44*7c3d14c8STreehugger Robot     if (test__floatunsitf(0, UINT64_C(0x0), UINT64_C(0x0)))
45*7c3d14c8STreehugger Robot         return 1;
46*7c3d14c8STreehugger Robot     if (test__floatunsitf(0xffffffff, UINT64_C(0x401efffffffe0000), UINT64_C(0x0)))
47*7c3d14c8STreehugger Robot         return 1;
48*7c3d14c8STreehugger Robot     if (test__floatunsitf(0x12345678, UINT64_C(0x401b234567800000), UINT64_C(0x0)))
49*7c3d14c8STreehugger Robot         return 1;
50*7c3d14c8STreehugger Robot 
51*7c3d14c8STreehugger Robot #else
52*7c3d14c8STreehugger Robot     printf("skipped\n");
53*7c3d14c8STreehugger Robot 
54*7c3d14c8STreehugger Robot #endif
55*7c3d14c8STreehugger Robot     return 0;
56*7c3d14c8STreehugger Robot }
57