1// RUN: %clang_builtins %s %librt -o %t && %run %t
2// REQUIRES: librt_has_muldi3
3
4#include "int_lib.h"
5#include <stdio.h>
6
7COMPILER_RT_ABI di_int __muldi3(di_int a, di_int b);
8
9int test__muldi3(di_int a, di_int b, di_int expected)
10{
11 di_int x = __muldi3(a, b);
12 if (x != expected)
13 printf(format: "error in __muldi3: %lld * %lld = %lld, expected %lld\n",
14 a, b, x, expected);
15 return x != expected;
16}
17
18char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
19
20int main()
21{
22 if (test__muldi3(a: 0, b: 0, expected: 0))
23 return 1;
24 if (test__muldi3(a: 0, b: 1, expected: 0))
25 return 1;
26 if (test__muldi3(a: 1, b: 0, expected: 0))
27 return 1;
28 if (test__muldi3(a: 0, b: 10, expected: 0))
29 return 1;
30 if (test__muldi3(a: 10, b: 0, expected: 0))
31 return 1;
32 if (test__muldi3(a: 0, b: 81985529216486895LL, expected: 0))
33 return 1;
34 if (test__muldi3(a: 81985529216486895LL, b: 0, expected: 0))
35 return 1;
36
37 if (test__muldi3(a: 0, b: -1, expected: 0))
38 return 1;
39 if (test__muldi3(a: -1, b: 0, expected: 0))
40 return 1;
41 if (test__muldi3(a: 0, b: -10, expected: 0))
42 return 1;
43 if (test__muldi3(a: -10, b: 0, expected: 0))
44 return 1;
45 if (test__muldi3(a: 0, b: -81985529216486895LL, expected: 0))
46 return 1;
47 if (test__muldi3(a: -81985529216486895LL, b: 0, expected: 0))
48 return 1;
49
50 if (test__muldi3(a: 1, b: 1, expected: 1))
51 return 1;
52 if (test__muldi3(a: 1, b: 10, expected: 10))
53 return 1;
54 if (test__muldi3(a: 10, b: 1, expected: 10))
55 return 1;
56 if (test__muldi3(a: 1, b: 81985529216486895LL, expected: 81985529216486895LL))
57 return 1;
58 if (test__muldi3(a: 81985529216486895LL, b: 1, expected: 81985529216486895LL))
59 return 1;
60
61 if (test__muldi3(a: 1, b: -1, expected: -1))
62 return 1;
63 if (test__muldi3(a: 1, b: -10, expected: -10))
64 return 1;
65 if (test__muldi3(a: -10, b: 1, expected: -10))
66 return 1;
67 if (test__muldi3(a: 1, b: -81985529216486895LL, expected: -81985529216486895LL))
68 return 1;
69 if (test__muldi3(a: -81985529216486895LL, b: 1, expected: -81985529216486895LL))
70 return 1;
71
72 if (test__muldi3(a: 3037000499LL, b: 3037000499LL, expected: 9223372030926249001LL))
73 return 1;
74 if (test__muldi3(a: -3037000499LL, b: 3037000499LL, expected: -9223372030926249001LL))
75 return 1;
76 if (test__muldi3(a: 3037000499LL, b: -3037000499LL, expected: -9223372030926249001LL))
77 return 1;
78 if (test__muldi3(a: -3037000499LL, b: -3037000499LL, expected: 9223372030926249001LL))
79 return 1;
80
81 if (test__muldi3(a: 4398046511103LL, b: 2097152LL, expected: 9223372036852678656LL))
82 return 1;
83 if (test__muldi3(a: -4398046511103LL, b: 2097152LL, expected: -9223372036852678656LL))
84 return 1;
85 if (test__muldi3(a: 4398046511103LL, b: -2097152LL, expected: -9223372036852678656LL))
86 return 1;
87 if (test__muldi3(a: -4398046511103LL, b: -2097152LL, expected: 9223372036852678656LL))
88 return 1;
89
90 if (test__muldi3(a: 2097152LL, b: 4398046511103LL, expected: 9223372036852678656LL))
91 return 1;
92 if (test__muldi3(a: -2097152LL, b: 4398046511103LL, expected: -9223372036852678656LL))
93 return 1;
94 if (test__muldi3(a: 2097152LL, b: -4398046511103LL, expected: -9223372036852678656LL))
95 return 1;
96 if (test__muldi3(a: -2097152LL, b: -4398046511103LL, expected: 9223372036852678656LL))
97 return 1;
98
99 return 0;
100}
101

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