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