[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / fixxfdi_test.c
blobaed3579eb1c978a8da0743e153ca7f9fd740aa94
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_fixxfdi
3 //===-- fixxfdi_test.c - Test __fixxfdi -----------------------------------===//
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 __fixxfdi for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
15 #include "int_lib.h"
16 #include <stdio.h>
19 #if HAS_80_BIT_LONG_DOUBLE
20 // Returns: convert a to a signed long long, rounding toward zero.
22 // Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
23 // su_int is a 32 bit integral type
24 // value in long double is representable in di_int (no range checking performed)
26 // gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
27 // 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
29 COMPILER_RT_ABI di_int __fixxfdi(long double a);
31 int test__fixxfdi(long double a, di_int expected)
33 di_int x = __fixxfdi(a);
34 if (x != expected)
35 printf("error in __fixxfdi(%LA) = %llX, expected %llX\n",
36 a, x, expected);
37 return x != expected;
40 char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
41 char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};
42 char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
43 #endif
45 int main()
47 #if HAS_80_BIT_LONG_DOUBLE
48 if (test__fixxfdi(0.0, 0))
49 return 1;
51 if (test__fixxfdi(0.5, 0))
52 return 1;
53 if (test__fixxfdi(0.99, 0))
54 return 1;
55 if (test__fixxfdi(1.0, 1))
56 return 1;
57 if (test__fixxfdi(1.5, 1))
58 return 1;
59 if (test__fixxfdi(1.99, 1))
60 return 1;
61 if (test__fixxfdi(2.0, 2))
62 return 1;
63 if (test__fixxfdi(2.01, 2))
64 return 1;
65 if (test__fixxfdi(-0.5, 0))
66 return 1;
67 if (test__fixxfdi(-0.99, 0))
68 return 1;
69 if (test__fixxfdi(-1.0, -1))
70 return 1;
71 if (test__fixxfdi(-1.5, -1))
72 return 1;
73 if (test__fixxfdi(-1.99, -1))
74 return 1;
75 if (test__fixxfdi(-2.0, -2))
76 return 1;
77 if (test__fixxfdi(-2.01, -2))
78 return 1;
80 if (test__fixxfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL))
81 return 1;
82 if (test__fixxfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL))
83 return 1;
85 if (test__fixxfdi(-0x1.FFFFFEp+62, 0x8000008000000000LL))
86 return 1;
87 if (test__fixxfdi(-0x1.FFFFFCp+62, 0x8000010000000000LL))
88 return 1;
90 if (test__fixxfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL))
91 return 1;
92 if (test__fixxfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL))
93 return 1;
95 if (test__fixxfdi(-0x1.FFFFFFFFFFFFFp+62, 0x8000000000000400LL))
96 return 1;
97 if (test__fixxfdi(-0x1.FFFFFFFFFFFFEp+62, 0x8000000000000800LL))
98 return 1;
100 if (test__fixxfdi(0x1.FFFFFFFFFFFFFFFCp+62L, 0x7FFFFFFFFFFFFFFFLL))
101 return 1;
102 if (test__fixxfdi(0x1.FFFFFFFFFFFFFFF8p+62L, 0x7FFFFFFFFFFFFFFELL))
103 return 1;
105 if (test__fixxfdi(-0x1.0000000000000000p+63L, 0x8000000000000000LL))
106 return 1;
107 if (test__fixxfdi(-0x1.FFFFFFFFFFFFFFFCp+62L, 0x8000000000000001LL))
108 return 1;
109 if (test__fixxfdi(-0x1.FFFFFFFFFFFFFFF8p+62L, 0x8000000000000002LL))
110 return 1;
112 #else
113 printf("skipped\n");
114 #endif
115 return 0;