xref: /minix3/sys/external/bsd/compiler_rt/dist/test/Unit/muldi3_test.c (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc //===-- muldi3_test.c - Test __muldi3 -------------------------------------===//
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 __muldi3 for the compiler_rt library.
11*4684ddb6SLionel Sambuc //
12*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
13*4684ddb6SLionel Sambuc 
14*4684ddb6SLionel Sambuc #include "int_lib.h"
15*4684ddb6SLionel Sambuc #include <stdio.h>
16*4684ddb6SLionel Sambuc 
17*4684ddb6SLionel Sambuc di_int __muldi3(di_int a, di_int b);
18*4684ddb6SLionel Sambuc 
test__muldi3(di_int a,di_int b,di_int expected)19*4684ddb6SLionel Sambuc int test__muldi3(di_int a, di_int b, di_int expected)
20*4684ddb6SLionel Sambuc {
21*4684ddb6SLionel Sambuc     di_int x = __muldi3(a, b);
22*4684ddb6SLionel Sambuc     if (x != expected)
23*4684ddb6SLionel Sambuc         printf("error in __muldi3: %lld * %lld = %lld, expected %lld\n",
24*4684ddb6SLionel Sambuc                a, b, __muldi3(a, b), expected);
25*4684ddb6SLionel Sambuc     return x != expected;
26*4684ddb6SLionel Sambuc }
27*4684ddb6SLionel Sambuc 
28*4684ddb6SLionel Sambuc char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
29*4684ddb6SLionel Sambuc 
main()30*4684ddb6SLionel Sambuc int main()
31*4684ddb6SLionel Sambuc {
32*4684ddb6SLionel Sambuc     if (test__muldi3(0, 0, 0))
33*4684ddb6SLionel Sambuc         return 1;
34*4684ddb6SLionel Sambuc     if (test__muldi3(0, 1, 0))
35*4684ddb6SLionel Sambuc         return 1;
36*4684ddb6SLionel Sambuc     if (test__muldi3(1, 0, 0))
37*4684ddb6SLionel Sambuc         return 1;
38*4684ddb6SLionel Sambuc     if (test__muldi3(0, 10, 0))
39*4684ddb6SLionel Sambuc         return 1;
40*4684ddb6SLionel Sambuc     if (test__muldi3(10, 0, 0))
41*4684ddb6SLionel Sambuc         return 1;
42*4684ddb6SLionel Sambuc     if (test__muldi3(0, 81985529216486895LL, 0))
43*4684ddb6SLionel Sambuc         return 1;
44*4684ddb6SLionel Sambuc     if (test__muldi3(81985529216486895LL, 0, 0))
45*4684ddb6SLionel Sambuc         return 1;
46*4684ddb6SLionel Sambuc 
47*4684ddb6SLionel Sambuc     if (test__muldi3(0, -1, 0))
48*4684ddb6SLionel Sambuc         return 1;
49*4684ddb6SLionel Sambuc     if (test__muldi3(-1, 0, 0))
50*4684ddb6SLionel Sambuc         return 1;
51*4684ddb6SLionel Sambuc     if (test__muldi3(0, -10, 0))
52*4684ddb6SLionel Sambuc         return 1;
53*4684ddb6SLionel Sambuc     if (test__muldi3(-10, 0, 0))
54*4684ddb6SLionel Sambuc         return 1;
55*4684ddb6SLionel Sambuc     if (test__muldi3(0, -81985529216486895LL, 0))
56*4684ddb6SLionel Sambuc         return 1;
57*4684ddb6SLionel Sambuc     if (test__muldi3(-81985529216486895LL, 0, 0))
58*4684ddb6SLionel Sambuc         return 1;
59*4684ddb6SLionel Sambuc 
60*4684ddb6SLionel Sambuc     if (test__muldi3(1, 1, 1))
61*4684ddb6SLionel Sambuc         return 1;
62*4684ddb6SLionel Sambuc     if (test__muldi3(1, 10, 10))
63*4684ddb6SLionel Sambuc         return 1;
64*4684ddb6SLionel Sambuc     if (test__muldi3(10, 1, 10))
65*4684ddb6SLionel Sambuc         return 1;
66*4684ddb6SLionel Sambuc     if (test__muldi3(1, 81985529216486895LL, 81985529216486895LL))
67*4684ddb6SLionel Sambuc         return 1;
68*4684ddb6SLionel Sambuc     if (test__muldi3(81985529216486895LL, 1, 81985529216486895LL))
69*4684ddb6SLionel Sambuc         return 1;
70*4684ddb6SLionel Sambuc 
71*4684ddb6SLionel Sambuc     if (test__muldi3(1, -1, -1))
72*4684ddb6SLionel Sambuc         return 1;
73*4684ddb6SLionel Sambuc     if (test__muldi3(1, -10, -10))
74*4684ddb6SLionel Sambuc         return 1;
75*4684ddb6SLionel Sambuc     if (test__muldi3(-10, 1, -10))
76*4684ddb6SLionel Sambuc         return 1;
77*4684ddb6SLionel Sambuc     if (test__muldi3(1, -81985529216486895LL, -81985529216486895LL))
78*4684ddb6SLionel Sambuc         return 1;
79*4684ddb6SLionel Sambuc     if (test__muldi3(-81985529216486895LL, 1, -81985529216486895LL))
80*4684ddb6SLionel Sambuc         return 1;
81*4684ddb6SLionel Sambuc 
82*4684ddb6SLionel Sambuc     if (test__muldi3(3037000499LL, 3037000499LL, 9223372030926249001LL))
83*4684ddb6SLionel Sambuc         return 1;
84*4684ddb6SLionel Sambuc     if (test__muldi3(-3037000499LL, 3037000499LL, -9223372030926249001LL))
85*4684ddb6SLionel Sambuc         return 1;
86*4684ddb6SLionel Sambuc     if (test__muldi3(3037000499LL, -3037000499LL, -9223372030926249001LL))
87*4684ddb6SLionel Sambuc         return 1;
88*4684ddb6SLionel Sambuc     if (test__muldi3(-3037000499LL, -3037000499LL, 9223372030926249001LL))
89*4684ddb6SLionel Sambuc         return 1;
90*4684ddb6SLionel Sambuc 
91*4684ddb6SLionel Sambuc     if (test__muldi3(4398046511103LL, 2097152LL, 9223372036852678656LL))
92*4684ddb6SLionel Sambuc         return 1;
93*4684ddb6SLionel Sambuc     if (test__muldi3(-4398046511103LL, 2097152LL, -9223372036852678656LL))
94*4684ddb6SLionel Sambuc         return 1;
95*4684ddb6SLionel Sambuc     if (test__muldi3(4398046511103LL, -2097152LL, -9223372036852678656LL))
96*4684ddb6SLionel Sambuc         return 1;
97*4684ddb6SLionel Sambuc     if (test__muldi3(-4398046511103LL, -2097152LL, 9223372036852678656LL))
98*4684ddb6SLionel Sambuc         return 1;
99*4684ddb6SLionel Sambuc 
100*4684ddb6SLionel Sambuc     if (test__muldi3(2097152LL, 4398046511103LL, 9223372036852678656LL))
101*4684ddb6SLionel Sambuc         return 1;
102*4684ddb6SLionel Sambuc     if (test__muldi3(-2097152LL, 4398046511103LL, -9223372036852678656LL))
103*4684ddb6SLionel Sambuc         return 1;
104*4684ddb6SLionel Sambuc     if (test__muldi3(2097152LL, -4398046511103LL, -9223372036852678656LL))
105*4684ddb6SLionel Sambuc         return 1;
106*4684ddb6SLionel Sambuc     if (test__muldi3(-2097152LL, -4398046511103LL, 9223372036852678656LL))
107*4684ddb6SLionel Sambuc         return 1;
108*4684ddb6SLionel Sambuc 
109*4684ddb6SLionel Sambuc     return 0;
110*4684ddb6SLionel Sambuc }
111