xref: /minix3/sys/external/bsd/compiler_rt/dist/test/Unit/multi3_test.c (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc //===-- multi3_test.c - Test __multi3 -------------------------------------===//
2*4684ddb6SLionel Sambuc //
3*4684ddb6SLionel Sambuc //                     The LLVM Compiler Infrastructure
4*4684ddb6SLionel Sambuc //
5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*4684ddb6SLionel Sambuc //
8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
9*4684ddb6SLionel Sambuc //
10*4684ddb6SLionel Sambuc // This file tests __multi3 for the compiler_rt library.
11*4684ddb6SLionel Sambuc //
12*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
13*4684ddb6SLionel Sambuc 
14*4684ddb6SLionel Sambuc #if __x86_64
15*4684ddb6SLionel Sambuc 
16*4684ddb6SLionel Sambuc #include "int_lib.h"
17*4684ddb6SLionel Sambuc #include <stdio.h>
18*4684ddb6SLionel Sambuc 
19*4684ddb6SLionel Sambuc ti_int __multi3(ti_int a, ti_int b);
20*4684ddb6SLionel Sambuc 
test__multi3(ti_int a,ti_int b,ti_int expected)21*4684ddb6SLionel Sambuc int test__multi3(ti_int a, ti_int b, ti_int expected)
22*4684ddb6SLionel Sambuc {
23*4684ddb6SLionel Sambuc     ti_int x = __multi3(a, b);
24*4684ddb6SLionel Sambuc     if (x != expected)
25*4684ddb6SLionel Sambuc     {
26*4684ddb6SLionel Sambuc         twords at;
27*4684ddb6SLionel Sambuc         at.all = a;
28*4684ddb6SLionel Sambuc         twords bt;
29*4684ddb6SLionel Sambuc         bt.all = b;
30*4684ddb6SLionel Sambuc         twords xt;
31*4684ddb6SLionel Sambuc         xt.all = x;
32*4684ddb6SLionel Sambuc         twords expectedt;
33*4684ddb6SLionel Sambuc         expectedt.all = expected;
34*4684ddb6SLionel Sambuc         printf("error in __multi3: 0x%.16llX%.16llX * 0x%.16llX%.16llX = "
35*4684ddb6SLionel Sambuc                "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
36*4684ddb6SLionel Sambuc                at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low,
37*4684ddb6SLionel Sambuc                expectedt.s.high, expectedt.s.low);
38*4684ddb6SLionel Sambuc     }
39*4684ddb6SLionel Sambuc     return x != expected;
40*4684ddb6SLionel Sambuc }
41*4684ddb6SLionel Sambuc 
42*4684ddb6SLionel Sambuc char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
43*4684ddb6SLionel Sambuc 
44*4684ddb6SLionel Sambuc #endif
45*4684ddb6SLionel Sambuc 
main()46*4684ddb6SLionel Sambuc int main()
47*4684ddb6SLionel Sambuc {
48*4684ddb6SLionel Sambuc #if __x86_64
49*4684ddb6SLionel Sambuc     if (test__multi3(0, 0, 0))
50*4684ddb6SLionel Sambuc         return 1;
51*4684ddb6SLionel Sambuc     if (test__multi3(0, 1, 0))
52*4684ddb6SLionel Sambuc         return 1;
53*4684ddb6SLionel Sambuc     if (test__multi3(1, 0, 0))
54*4684ddb6SLionel Sambuc         return 1;
55*4684ddb6SLionel Sambuc     if (test__multi3(0, 10, 0))
56*4684ddb6SLionel Sambuc         return 1;
57*4684ddb6SLionel Sambuc     if (test__multi3(10, 0, 0))
58*4684ddb6SLionel Sambuc         return 1;
59*4684ddb6SLionel Sambuc     if (test__multi3(0, 81985529216486895LL, 0))
60*4684ddb6SLionel Sambuc         return 1;
61*4684ddb6SLionel Sambuc     if (test__multi3(81985529216486895LL, 0, 0))
62*4684ddb6SLionel Sambuc         return 1;
63*4684ddb6SLionel Sambuc 
64*4684ddb6SLionel Sambuc     if (test__multi3(0, -1, 0))
65*4684ddb6SLionel Sambuc         return 1;
66*4684ddb6SLionel Sambuc     if (test__multi3(-1, 0, 0))
67*4684ddb6SLionel Sambuc         return 1;
68*4684ddb6SLionel Sambuc     if (test__multi3(0, -10, 0))
69*4684ddb6SLionel Sambuc         return 1;
70*4684ddb6SLionel Sambuc     if (test__multi3(-10, 0, 0))
71*4684ddb6SLionel Sambuc         return 1;
72*4684ddb6SLionel Sambuc     if (test__multi3(0, -81985529216486895LL, 0))
73*4684ddb6SLionel Sambuc         return 1;
74*4684ddb6SLionel Sambuc     if (test__multi3(-81985529216486895LL, 0, 0))
75*4684ddb6SLionel Sambuc         return 1;
76*4684ddb6SLionel Sambuc 
77*4684ddb6SLionel Sambuc     if (test__multi3(1, 1, 1))
78*4684ddb6SLionel Sambuc         return 1;
79*4684ddb6SLionel Sambuc     if (test__multi3(1, 10, 10))
80*4684ddb6SLionel Sambuc         return 1;
81*4684ddb6SLionel Sambuc     if (test__multi3(10, 1, 10))
82*4684ddb6SLionel Sambuc         return 1;
83*4684ddb6SLionel Sambuc     if (test__multi3(1, 81985529216486895LL, 81985529216486895LL))
84*4684ddb6SLionel Sambuc         return 1;
85*4684ddb6SLionel Sambuc     if (test__multi3(81985529216486895LL, 1, 81985529216486895LL))
86*4684ddb6SLionel Sambuc         return 1;
87*4684ddb6SLionel Sambuc 
88*4684ddb6SLionel Sambuc     if (test__multi3(1, -1, -1))
89*4684ddb6SLionel Sambuc         return 1;
90*4684ddb6SLionel Sambuc     if (test__multi3(1, -10, -10))
91*4684ddb6SLionel Sambuc         return 1;
92*4684ddb6SLionel Sambuc     if (test__multi3(-10, 1, -10))
93*4684ddb6SLionel Sambuc         return 1;
94*4684ddb6SLionel Sambuc     if (test__multi3(1, -81985529216486895LL, -81985529216486895LL))
95*4684ddb6SLionel Sambuc         return 1;
96*4684ddb6SLionel Sambuc     if (test__multi3(-81985529216486895LL, 1, -81985529216486895LL))
97*4684ddb6SLionel Sambuc         return 1;
98*4684ddb6SLionel Sambuc 
99*4684ddb6SLionel Sambuc     if (test__multi3(3037000499LL, 3037000499LL, 9223372030926249001LL))
100*4684ddb6SLionel Sambuc         return 1;
101*4684ddb6SLionel Sambuc     if (test__multi3(-3037000499LL, 3037000499LL, -9223372030926249001LL))
102*4684ddb6SLionel Sambuc         return 1;
103*4684ddb6SLionel Sambuc     if (test__multi3(3037000499LL, -3037000499LL, -9223372030926249001LL))
104*4684ddb6SLionel Sambuc         return 1;
105*4684ddb6SLionel Sambuc     if (test__multi3(-3037000499LL, -3037000499LL, 9223372030926249001LL))
106*4684ddb6SLionel Sambuc         return 1;
107*4684ddb6SLionel Sambuc 
108*4684ddb6SLionel Sambuc     if (test__multi3(4398046511103LL, 2097152LL, 9223372036852678656LL))
109*4684ddb6SLionel Sambuc         return 1;
110*4684ddb6SLionel Sambuc     if (test__multi3(-4398046511103LL, 2097152LL, -9223372036852678656LL))
111*4684ddb6SLionel Sambuc         return 1;
112*4684ddb6SLionel Sambuc     if (test__multi3(4398046511103LL, -2097152LL, -9223372036852678656LL))
113*4684ddb6SLionel Sambuc         return 1;
114*4684ddb6SLionel Sambuc     if (test__multi3(-4398046511103LL, -2097152LL, 9223372036852678656LL))
115*4684ddb6SLionel Sambuc         return 1;
116*4684ddb6SLionel Sambuc 
117*4684ddb6SLionel Sambuc     if (test__multi3(2097152LL, 4398046511103LL, 9223372036852678656LL))
118*4684ddb6SLionel Sambuc         return 1;
119*4684ddb6SLionel Sambuc     if (test__multi3(-2097152LL, 4398046511103LL, -9223372036852678656LL))
120*4684ddb6SLionel Sambuc         return 1;
121*4684ddb6SLionel Sambuc     if (test__multi3(2097152LL, -4398046511103LL, -9223372036852678656LL))
122*4684ddb6SLionel Sambuc         return 1;
123*4684ddb6SLionel Sambuc     if (test__multi3(-2097152LL, -4398046511103LL, 9223372036852678656LL))
124*4684ddb6SLionel Sambuc         return 1;
125*4684ddb6SLionel Sambuc 
126*4684ddb6SLionel Sambuc     if (test__multi3(make_ti(0x00000000000000B5LL, 0x04F333F9DE5BE000LL),
127*4684ddb6SLionel Sambuc                      make_ti(0x0000000000000000LL, 0x00B504F333F9DE5BLL),
128*4684ddb6SLionel Sambuc                      make_ti(0x7FFFFFFFFFFFF328LL, 0xDF915DA296E8A000LL)))
129*4684ddb6SLionel Sambuc         return 1;
130*4684ddb6SLionel Sambuc #else
131*4684ddb6SLionel Sambuc     printf("skipped\n");
132*4684ddb6SLionel Sambuc #endif
133*4684ddb6SLionel Sambuc     return 0;
134*4684ddb6SLionel Sambuc }
135