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 | |
8 | COMPILER_RT_ABI si_int __mulsi3(si_int a, si_int b); |
9 | |
10 | int 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("error in __mulsi3: %d * %d = %d, expected %d\n" , |
15 | a, b, x, expected); |
16 | return x != expected; |
17 | } |
18 | |
19 | int main() |
20 | { |
21 | if (test__mulsi3(0, 0, 0)) |
22 | return 1; |
23 | if (test__mulsi3(0, 1, 0)) |
24 | return 1; |
25 | if (test__mulsi3(1, 0, 0)) |
26 | return 1; |
27 | if (test__mulsi3(0, 10, 0)) |
28 | return 1; |
29 | if (test__mulsi3(10, 0, 0)) |
30 | return 1; |
31 | if (test__mulsi3(0, INT_MAX, 0)) |
32 | return 1; |
33 | if (test__mulsi3(INT_MAX, 0, 0)) |
34 | return 1; |
35 | |
36 | if (test__mulsi3(0, -1, 0)) |
37 | return 1; |
38 | if (test__mulsi3(-1, 0, 0)) |
39 | return 1; |
40 | if (test__mulsi3(0, -10, 0)) |
41 | return 1; |
42 | if (test__mulsi3(-10, 0, 0)) |
43 | return 1; |
44 | if (test__mulsi3(0, INT_MIN, 0)) |
45 | return 1; |
46 | if (test__mulsi3(INT_MIN, 0, 0)) |
47 | return 1; |
48 | |
49 | if (test__mulsi3(1, 1, 1)) |
50 | return 1; |
51 | if (test__mulsi3(1, 10, 10)) |
52 | return 1; |
53 | if (test__mulsi3(10, 1, 10)) |
54 | return 1; |
55 | if (test__mulsi3(1, INT_MAX, INT_MAX)) |
56 | return 1; |
57 | if (test__mulsi3(INT_MAX, 1, INT_MAX)) |
58 | return 1; |
59 | |
60 | if (test__mulsi3(1, -1, -1)) |
61 | return 1; |
62 | if (test__mulsi3(1, -10, -10)) |
63 | return 1; |
64 | if (test__mulsi3(-10, 1, -10)) |
65 | return 1; |
66 | if (test__mulsi3(1, INT_MIN, INT_MIN)) |
67 | return 1; |
68 | if (test__mulsi3(INT_MIN, 1, INT_MIN)) |
69 | return 1; |
70 | |
71 | if (test__mulsi3(46340, 46340, 2147395600)) |
72 | return 1; |
73 | if (test__mulsi3(-46340, 46340, -2147395600)) |
74 | return 1; |
75 | if (test__mulsi3(46340, -46340, -2147395600)) |
76 | return 1; |
77 | if (test__mulsi3(-46340, -46340, 2147395600)) |
78 | return 1; |
79 | |
80 | if (test__mulsi3(4194303, 8192, 34359730176)) |
81 | return 1; |
82 | if (test__mulsi3(-4194303, 8192, -34359730176)) |
83 | return 1; |
84 | if (test__mulsi3(4194303, -8192, -34359730176)) |
85 | return 1; |
86 | if (test__mulsi3(-4194303, -8192, 34359730176)) |
87 | return 1; |
88 | |
89 | if (test__mulsi3(8192, 4194303, 34359730176)) |
90 | return 1; |
91 | if (test__mulsi3(-8192, 4194303, -34359730176)) |
92 | return 1; |
93 | if (test__mulsi3(8192, -4194303, -34359730176)) |
94 | return 1; |
95 | if (test__mulsi3(-8192, -4194303, 34359730176)) |
96 | return 1; |
97 | |
98 | return 0; |
99 | } |
100 | |