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

source code of compiler-rt/test/builtins/Unit/multi3_test.c