[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / fixunsdfti_test.c
blobe867d4f9d6182d405f09862942e40f3464d2c6be
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixunsdfti
3 // REQUIRES: int128
4 //===-- fixunsdfti_test.c - Test __fixunsdfti -----------------------------===//
5 //
6 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7 // See https://llvm.org/LICENSE.txt for license information.
8 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //
10 //===----------------------------------------------------------------------===//
12 // This file tests __fixunsdfti for the compiler_rt library.
14 //===----------------------------------------------------------------------===//
16 #include "int_lib.h"
17 #include <stdio.h>
19 // Returns: convert a to a unsigned long long, rounding toward zero.
20 // Negative values all become zero.
22 // Assumption: double is a IEEE 64 bit floating point type
23 // tu_int is a 64 bit integral type
24 // value in double is representable in tu_int or is negative
25 // (no range checking performed)
27 // seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
29 #ifdef CRT_HAS_128BIT
31 COMPILER_RT_ABI tu_int __fixunsdfti(double a);
33 int test__fixunsdfti(double a, tu_int expected)
35 tu_int x = __fixunsdfti(a);
36 if (x != expected)
38 utwords xt;
39 xt.all = x;
40 utwords expectedt;
41 expectedt.all = expected;
42 printf("error in __fixunsdfti(%A) = 0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
43 a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
45 return x != expected;
48 char assumption_1[sizeof(tu_int) == 2*sizeof(du_int)] = {0};
49 char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};
50 char assumption_3[sizeof(double)*CHAR_BIT == 64] = {0};
52 #endif
54 int main()
56 #ifdef CRT_HAS_128BIT
57 if (test__fixunsdfti(0.0, 0))
58 return 1;
60 if (test__fixunsdfti(0.5, 0))
61 return 1;
62 if (test__fixunsdfti(0.99, 0))
63 return 1;
64 if (test__fixunsdfti(1.0, 1))
65 return 1;
66 if (test__fixunsdfti(1.5, 1))
67 return 1;
68 if (test__fixunsdfti(1.99, 1))
69 return 1;
70 if (test__fixunsdfti(2.0, 2))
71 return 1;
72 if (test__fixunsdfti(2.01, 2))
73 return 1;
74 if (test__fixunsdfti(-0.5, 0))
75 return 1;
76 if (test__fixunsdfti(-0.99, 0))
77 return 1;
78 #if !TARGET_LIBGCC
79 if (test__fixunsdfti(-1.0, 0)) // libgcc ignores "returns 0 for negative input" spec
80 return 1;
81 if (test__fixunsdfti(-1.5, 0))
82 return 1;
83 if (test__fixunsdfti(-1.99, 0))
84 return 1;
85 if (test__fixunsdfti(-2.0, 0))
86 return 1;
87 if (test__fixunsdfti(-2.01, 0))
88 return 1;
89 #endif
91 if (test__fixunsdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL))
92 return 1;
93 if (test__fixunsdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL))
94 return 1;
96 #if !TARGET_LIBGCC
97 if (test__fixunsdfti(-0x1.FFFFFEp+62, 0))
98 return 1;
99 if (test__fixunsdfti(-0x1.FFFFFCp+62, 0))
100 return 1;
101 #endif
103 if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800ULL))
104 return 1;
105 if (test__fixunsdfti(0x1.0000000000000p+63, 0x8000000000000000ULL))
106 return 1;
107 if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00ULL))
108 return 1;
109 if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800ULL))
110 return 1;
112 if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+127, make_ti(0xFFFFFFFFFFFFF800ULL, 0)))
113 return 1;
114 if (test__fixunsdfti(0x1.0000000000000p+127, make_ti(0x8000000000000000ULL, 0)))
115 return 1;
116 if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+126, make_ti(0x7FFFFFFFFFFFFC00ULL, 0)))
117 return 1;
118 if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp+126, make_ti(0x7FFFFFFFFFFFF800ULL, 0)))
119 return 1;
120 if (test__fixunsdfti(0x1.0000000000000p+128, make_ti(0xFFFFFFFFFFFFFFFFULL,
121 0xFFFFFFFFFFFFFFFFULL)))
122 return 1;
124 #if !TARGET_LIBGCC
125 if (test__fixunsdfti(-0x1.FFFFFFFFFFFFFp+62, 0))
126 return 1;
127 if (test__fixunsdfti(-0x1.FFFFFFFFFFFFEp+62, 0))
128 return 1;
129 #endif
131 #endif
132 return 0;