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

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