[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / fixxfti_test.c
blobff7186aa322c069e8821fc6d88a9508870bd9577
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixxfti
3 // REQUIRES: x86-target-arch
5 //===-- fixxfti_test.c - Test __fixxfti -----------------------------------===//
6 //
7 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8 // See https://llvm.org/LICENSE.txt for license information.
9 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11 //===----------------------------------------------------------------------===//
13 // This file tests __fixxfti for the compiler_rt library.
15 //===----------------------------------------------------------------------===//
17 #include "int_lib.h"
18 #include <stdio.h>
20 #if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
22 // Returns: convert a to a signed long long, rounding toward zero.
24 // Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
25 // su_int is a 32 bit integral type
26 // value in long double is representable in ti_int (no range checking performed)
28 // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
29 // 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
31 COMPILER_RT_ABI ti_int __fixxfti(long double a);
33 int test__fixxfti(long double a, ti_int expected)
35 ti_int x = __fixxfti(a);
36 if (x != expected)
38 utwords xt;
39 xt.all = x;
40 utwords expectedt;
41 expectedt.all = expected;
42 printf("error in __fixxfti(%LA) = 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 COMPILE_TIME_ASSERT(sizeof(ti_int) == 2*sizeof(di_int));
49 COMPILE_TIME_ASSERT(sizeof(su_int)*CHAR_BIT == 32);
50 COMPILE_TIME_ASSERT(sizeof(long double)*CHAR_BIT == 128);
52 #endif
54 int main()
56 #if defined(CRT_HAS_128BIT) && HAS_80_BIT_LONG_DOUBLE
57 if (test__fixxfti(0.0, 0))
58 return 1;
60 if (test__fixxfti(0.5, 0))
61 return 1;
62 if (test__fixxfti(0.99, 0))
63 return 1;
64 if (test__fixxfti(1.0, 1))
65 return 1;
66 if (test__fixxfti(1.5, 1))
67 return 1;
68 if (test__fixxfti(1.99, 1))
69 return 1;
70 if (test__fixxfti(2.0, 2))
71 return 1;
72 if (test__fixxfti(2.01, 2))
73 return 1;
74 if (test__fixxfti(-0.5, 0))
75 return 1;
76 if (test__fixxfti(-0.99, 0))
77 return 1;
78 if (test__fixxfti(-1.0, -1))
79 return 1;
80 if (test__fixxfti(-1.5, -1))
81 return 1;
82 if (test__fixxfti(-1.99, -1))
83 return 1;
84 if (test__fixxfti(-2.0, -2))
85 return 1;
86 if (test__fixxfti(-2.01, -2))
87 return 1;
89 if (test__fixxfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL))
90 return 1;
91 if (test__fixxfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL))
92 return 1;
94 if (test__fixxfti(-0x1.FFFFFEp+62, make_ti(0xFFFFFFFFFFFFFFFFLL,
95 0x8000008000000000LL)))
96 return 1;
97 if (test__fixxfti(-0x1.FFFFFCp+62, make_ti(0xFFFFFFFFFFFFFFFFLL,
98 0x8000010000000000LL)))
99 return 1;
101 if (test__fixxfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL))
102 return 1;
103 if (test__fixxfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL))
104 return 1;
106 if (test__fixxfti(-0x1.FFFFFFFFFFFFFp+62, make_ti(0xFFFFFFFFFFFFFFFFLL,
107 0x8000000000000400LL)))
108 return 1;
109 if (test__fixxfti(-0x1.FFFFFFFFFFFFEp+62, make_ti(0xFFFFFFFFFFFFFFFFLL,
110 0x8000000000000800LL)))
111 return 1;
113 if (test__fixxfti(0x1.FFFFFFFFFFFFFFFCp+62L, 0x7FFFFFFFFFFFFFFFLL))
114 return 1;
115 if (test__fixxfti(0x1.FFFFFFFFFFFFFFF8p+62L, 0x7FFFFFFFFFFFFFFELL))
116 return 1;
118 if (test__fixxfti(-0x1.0000000000000000p+63L, make_ti(0xFFFFFFFFFFFFFFFFLL,
119 0x8000000000000000LL)))
120 return 1;
121 if (test__fixxfti(-0x1.FFFFFFFFFFFFFFFCp+62L, make_ti(0xFFFFFFFFFFFFFFFFLL,
122 0x8000000000000001LL)))
123 return 1;
124 if (test__fixxfti(-0x1.FFFFFFFFFFFFFFF8p+62L, make_ti(0xFFFFFFFFFFFFFFFFLL,
125 0x8000000000000002LL)))
126 return 1;
128 if (test__fixxfti(0x1.FFFFFFFFFFFFFFFEp+126L, make_ti(0x7FFFFFFFFFFFFFFFLL,
129 0x8000000000000000LL)))
130 return 1;
131 if (test__fixxfti(0x1.FFFFFFFFFFFFFFFCp+126L, make_ti(0x7FFFFFFFFFFFFFFFLL,
132 0x0000000000000000LL)))
134 return 1;
136 if (test__fixxfti(-0x1.0000000000000000p+127L, make_ti(0x8000000000000000LL,
137 0x0000000000000000LL)))
138 return 1;
139 if (test__fixxfti(-0x1.FFFFFFFFFFFFFFFEp+126L, make_ti(0x8000000000000000LL,
140 0x8000000000000000LL)))
141 return 1;
142 if (test__fixxfti(-0x1.FFFFFFFFFFFFFFFCp+126L, make_ti(0x8000000000000001LL,
143 0x0000000000000000LL)))
144 return 1;
145 #else
146 printf("skipped\n");
147 #endif
148 return 0;