1// RUN: %clang_builtins %s %librt -o %t && %run %t
2// REQUIRES: librt_has_mulvsi3
3
4#include "int_lib.h"
5#include <stdio.h>
6
7// Returns: a * b
8
9// Effects: aborts if a * b overflows
10
11COMPILER_RT_ABI si_int __mulvsi3(si_int a, si_int b);
12
13int test__mulvsi3(si_int a, si_int b, si_int expected)
14{
15 si_int x = __mulvsi3(a, b);
16 if (x != expected)
17 printf("error in __mulvsi3: %d * %d = %d, expected %d\n",
18 a, b, x, expected);
19 return x != expected;
20}
21
22int main()
23{
24 if (test__mulvsi3(0, 0, 0))
25 return 1;
26 if (test__mulvsi3(0, 1, 0))
27 return 1;
28 if (test__mulvsi3(1, 0, 0))
29 return 1;
30 if (test__mulvsi3(0, 10, 0))
31 return 1;
32 if (test__mulvsi3(10, 0, 0))
33 return 1;
34 if (test__mulvsi3(0, 0x1234567, 0))
35 return 1;
36 if (test__mulvsi3(0x1234567, 0, 0))
37 return 1;
38
39 if (test__mulvsi3(0, -1, 0))
40 return 1;
41 if (test__mulvsi3(-1, 0, 0))
42 return 1;
43 if (test__mulvsi3(0, -10, 0))
44 return 1;
45 if (test__mulvsi3(-10, 0, 0))
46 return 1;
47 if (test__mulvsi3(0, -0x1234567, 0))
48 return 1;
49 if (test__mulvsi3(-0x1234567, 0, 0))
50 return 1;
51
52 if (test__mulvsi3(1, 1, 1))
53 return 1;
54 if (test__mulvsi3(1, 10, 10))
55 return 1;
56 if (test__mulvsi3(10, 1, 10))
57 return 1;
58 if (test__mulvsi3(1, 0x1234567, 0x1234567))
59 return 1;
60 if (test__mulvsi3(0x1234567, 1, 0x1234567))
61 return 1;
62
63 if (test__mulvsi3(1, -1, -1))
64 return 1;
65 if (test__mulvsi3(1, -10, -10))
66 return 1;
67 if (test__mulvsi3(-10, 1, -10))
68 return 1;
69 if (test__mulvsi3(1, -0x1234567, -0x1234567))
70 return 1;
71 if (test__mulvsi3(-0x1234567, 1, -0x1234567))
72 return 1;
73
74// if (test__mulvsi3(0x7FFFFFFF, -2, 0x80000001)) // abort
75// return 1;
76// if (test__mulvsi3(-2, 0x7FFFFFFF, 0x80000001)) // abort
77// return 1;
78 if (test__mulvsi3(0x7FFFFFFF, -1, 0x80000001))
79 return 1;
80 if (test__mulvsi3(-1, 0x7FFFFFFF, 0x80000001))
81 return 1;
82 if (test__mulvsi3(0x7FFFFFFF, 0, 0))
83 return 1;
84 if (test__mulvsi3(0, 0x7FFFFFFF, 0))
85 return 1;
86 if (test__mulvsi3(0x7FFFFFFF, 1, 0x7FFFFFFF))
87 return 1;
88 if (test__mulvsi3(1, 0x7FFFFFFF, 0x7FFFFFFF))
89 return 1;
90// if (test__mulvsi3(0x7FFFFFFF, 2, 0x80000001)) // abort
91// return 1;
92// if (test__mulvsi3(2, 0x7FFFFFFF, 0x80000001)) // abort
93// return 1;
94
95// if (test__mulvsi3(0x80000000, -2, 0x80000000)) // abort
96// return 1;
97// if (test__mulvsi3(-2, 0x80000000, 0x80000000)) // abort
98// return 1;
99// if (test__mulvsi3(0x80000000, -1, 0x80000000)) // abort
100// return 1;
101// if (test__mulvsi3(-1, 0x80000000, 0x80000000)) // abort
102// return 1;
103 if (test__mulvsi3(0x80000000, 0, 0))
104 return 1;
105 if (test__mulvsi3(0, 0x80000000, 0))
106 return 1;
107 if (test__mulvsi3(0x80000000, 1, 0x80000000))
108 return 1;
109 if (test__mulvsi3(1, 0x80000000, 0x80000000))
110 return 1;
111// if (test__mulvsi3(0x80000000, 2, 0x80000000)) // abort
112// return 1;
113// if (test__mulvsi3(2, 0x80000000, 0x80000000)) // abort
114// return 1;
115
116// if (test__mulvsi3(0x80000001, -2, 0x80000001)) // abort
117// return 1;
118// if (test__mulvsi3(-2, 0x80000001, 0x80000001)) // abort
119// return 1;
120 if (test__mulvsi3(0x80000001, -1, 0x7FFFFFFF))
121 return 1;
122 if (test__mulvsi3(-1, 0x80000001, 0x7FFFFFFF))
123 return 1;
124 if (test__mulvsi3(0x80000001, 0, 0))
125 return 1;
126 if (test__mulvsi3(0, 0x80000001, 0))
127 return 1;
128 if (test__mulvsi3(0x80000001, 1, 0x80000001))
129 return 1;
130 if (test__mulvsi3(1, 0x80000001, 0x80000001))
131 return 1;
132// if (test__mulvsi3(0x80000001, 2, 0x80000000)) // abort
133// return 1;
134// if (test__mulvsi3(2, 0x80000001, 0x80000000)) // abort
135// return 1;
136
137 return 0;
138}
139