1*7c3d14c8STreehugger Robot //===-- multi3_test.c - Test __multi3 -------------------------------------===//
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 __multi3 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 #ifdef CRT_HAS_128BIT
18*7c3d14c8STreehugger Robot
19*7c3d14c8STreehugger Robot COMPILER_RT_ABI ti_int __multi3(ti_int a, ti_int b);
20*7c3d14c8STreehugger Robot
test__multi3(ti_int a,ti_int b,ti_int expected)21*7c3d14c8STreehugger Robot int test__multi3(ti_int a, ti_int b, ti_int expected)
22*7c3d14c8STreehugger Robot {
23*7c3d14c8STreehugger Robot ti_int x = __multi3(a, b);
24*7c3d14c8STreehugger Robot if (x != expected)
25*7c3d14c8STreehugger Robot {
26*7c3d14c8STreehugger Robot twords at;
27*7c3d14c8STreehugger Robot at.all = a;
28*7c3d14c8STreehugger Robot twords bt;
29*7c3d14c8STreehugger Robot bt.all = b;
30*7c3d14c8STreehugger Robot twords xt;
31*7c3d14c8STreehugger Robot xt.all = x;
32*7c3d14c8STreehugger Robot twords expectedt;
33*7c3d14c8STreehugger Robot expectedt.all = expected;
34*7c3d14c8STreehugger Robot printf("error in __multi3: 0x%.16llX%.16llX * 0x%.16llX%.16llX = "
35*7c3d14c8STreehugger Robot "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
36*7c3d14c8STreehugger Robot at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low,
37*7c3d14c8STreehugger Robot expectedt.s.high, expectedt.s.low);
38*7c3d14c8STreehugger Robot }
39*7c3d14c8STreehugger Robot return x != expected;
40*7c3d14c8STreehugger Robot }
41*7c3d14c8STreehugger Robot
42*7c3d14c8STreehugger Robot char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
43*7c3d14c8STreehugger Robot
44*7c3d14c8STreehugger Robot #endif
45*7c3d14c8STreehugger Robot
main()46*7c3d14c8STreehugger Robot int main()
47*7c3d14c8STreehugger Robot {
48*7c3d14c8STreehugger Robot #ifdef CRT_HAS_128BIT
49*7c3d14c8STreehugger Robot if (test__multi3(0, 0, 0))
50*7c3d14c8STreehugger Robot return 1;
51*7c3d14c8STreehugger Robot if (test__multi3(0, 1, 0))
52*7c3d14c8STreehugger Robot return 1;
53*7c3d14c8STreehugger Robot if (test__multi3(1, 0, 0))
54*7c3d14c8STreehugger Robot return 1;
55*7c3d14c8STreehugger Robot if (test__multi3(0, 10, 0))
56*7c3d14c8STreehugger Robot return 1;
57*7c3d14c8STreehugger Robot if (test__multi3(10, 0, 0))
58*7c3d14c8STreehugger Robot return 1;
59*7c3d14c8STreehugger Robot if (test__multi3(0, 81985529216486895LL, 0))
60*7c3d14c8STreehugger Robot return 1;
61*7c3d14c8STreehugger Robot if (test__multi3(81985529216486895LL, 0, 0))
62*7c3d14c8STreehugger Robot return 1;
63*7c3d14c8STreehugger Robot
64*7c3d14c8STreehugger Robot if (test__multi3(0, -1, 0))
65*7c3d14c8STreehugger Robot return 1;
66*7c3d14c8STreehugger Robot if (test__multi3(-1, 0, 0))
67*7c3d14c8STreehugger Robot return 1;
68*7c3d14c8STreehugger Robot if (test__multi3(0, -10, 0))
69*7c3d14c8STreehugger Robot return 1;
70*7c3d14c8STreehugger Robot if (test__multi3(-10, 0, 0))
71*7c3d14c8STreehugger Robot return 1;
72*7c3d14c8STreehugger Robot if (test__multi3(0, -81985529216486895LL, 0))
73*7c3d14c8STreehugger Robot return 1;
74*7c3d14c8STreehugger Robot if (test__multi3(-81985529216486895LL, 0, 0))
75*7c3d14c8STreehugger Robot return 1;
76*7c3d14c8STreehugger Robot
77*7c3d14c8STreehugger Robot if (test__multi3(1, 1, 1))
78*7c3d14c8STreehugger Robot return 1;
79*7c3d14c8STreehugger Robot if (test__multi3(1, 10, 10))
80*7c3d14c8STreehugger Robot return 1;
81*7c3d14c8STreehugger Robot if (test__multi3(10, 1, 10))
82*7c3d14c8STreehugger Robot return 1;
83*7c3d14c8STreehugger Robot if (test__multi3(1, 81985529216486895LL, 81985529216486895LL))
84*7c3d14c8STreehugger Robot return 1;
85*7c3d14c8STreehugger Robot if (test__multi3(81985529216486895LL, 1, 81985529216486895LL))
86*7c3d14c8STreehugger Robot return 1;
87*7c3d14c8STreehugger Robot
88*7c3d14c8STreehugger Robot if (test__multi3(1, -1, -1))
89*7c3d14c8STreehugger Robot return 1;
90*7c3d14c8STreehugger Robot if (test__multi3(1, -10, -10))
91*7c3d14c8STreehugger Robot return 1;
92*7c3d14c8STreehugger Robot if (test__multi3(-10, 1, -10))
93*7c3d14c8STreehugger Robot return 1;
94*7c3d14c8STreehugger Robot if (test__multi3(1, -81985529216486895LL, -81985529216486895LL))
95*7c3d14c8STreehugger Robot return 1;
96*7c3d14c8STreehugger Robot if (test__multi3(-81985529216486895LL, 1, -81985529216486895LL))
97*7c3d14c8STreehugger Robot return 1;
98*7c3d14c8STreehugger Robot
99*7c3d14c8STreehugger Robot if (test__multi3(3037000499LL, 3037000499LL, 9223372030926249001LL))
100*7c3d14c8STreehugger Robot return 1;
101*7c3d14c8STreehugger Robot if (test__multi3(-3037000499LL, 3037000499LL, -9223372030926249001LL))
102*7c3d14c8STreehugger Robot return 1;
103*7c3d14c8STreehugger Robot if (test__multi3(3037000499LL, -3037000499LL, -9223372030926249001LL))
104*7c3d14c8STreehugger Robot return 1;
105*7c3d14c8STreehugger Robot if (test__multi3(-3037000499LL, -3037000499LL, 9223372030926249001LL))
106*7c3d14c8STreehugger Robot return 1;
107*7c3d14c8STreehugger Robot
108*7c3d14c8STreehugger Robot if (test__multi3(4398046511103LL, 2097152LL, 9223372036852678656LL))
109*7c3d14c8STreehugger Robot return 1;
110*7c3d14c8STreehugger Robot if (test__multi3(-4398046511103LL, 2097152LL, -9223372036852678656LL))
111*7c3d14c8STreehugger Robot return 1;
112*7c3d14c8STreehugger Robot if (test__multi3(4398046511103LL, -2097152LL, -9223372036852678656LL))
113*7c3d14c8STreehugger Robot return 1;
114*7c3d14c8STreehugger Robot if (test__multi3(-4398046511103LL, -2097152LL, 9223372036852678656LL))
115*7c3d14c8STreehugger Robot return 1;
116*7c3d14c8STreehugger Robot
117*7c3d14c8STreehugger Robot if (test__multi3(2097152LL, 4398046511103LL, 9223372036852678656LL))
118*7c3d14c8STreehugger Robot return 1;
119*7c3d14c8STreehugger Robot if (test__multi3(-2097152LL, 4398046511103LL, -9223372036852678656LL))
120*7c3d14c8STreehugger Robot return 1;
121*7c3d14c8STreehugger Robot if (test__multi3(2097152LL, -4398046511103LL, -9223372036852678656LL))
122*7c3d14c8STreehugger Robot return 1;
123*7c3d14c8STreehugger Robot if (test__multi3(-2097152LL, -4398046511103LL, 9223372036852678656LL))
124*7c3d14c8STreehugger Robot return 1;
125*7c3d14c8STreehugger Robot
126*7c3d14c8STreehugger Robot if (test__multi3(make_ti(0x00000000000000B5LL, 0x04F333F9DE5BE000LL),
127*7c3d14c8STreehugger Robot make_ti(0x0000000000000000LL, 0x00B504F333F9DE5BLL),
128*7c3d14c8STreehugger Robot make_ti(0x7FFFFFFFFFFFF328LL, 0xDF915DA296E8A000LL)))
129*7c3d14c8STreehugger Robot return 1;
130*7c3d14c8STreehugger Robot #else
131*7c3d14c8STreehugger Robot printf("skipped\n");
132*7c3d14c8STreehugger Robot #endif
133*7c3d14c8STreehugger Robot return 0;
134*7c3d14c8STreehugger Robot }
135