1// RUN: %clang_builtins %s %librt -o %t && %run %t
2// REQUIRES: librt_has_udivsi3
3
4#include "int_lib.h"
5#include <stdio.h>
6
7// Returns: a / b
8
9COMPILER_RT_ABI su_int __udivsi3(su_int a, su_int b);
10
11int test__udivsi3(su_int a, su_int b, su_int expected_q)
12{
13 su_int q = __udivsi3(a, b);
14 if (q != expected_q)
15 printf(format: "error in __udivsi3: %X / %X = %X, expected %X\n",
16 a, b, q, expected_q);
17 return q != expected_q;
18}
19
20su_int tests[][4] =
21{
22{0x00000000, 0x00000001, 0x00000000},
23{0x00000000, 0x00000002, 0x00000000},
24{0x00000000, 0x00000003, 0x00000000},
25{0x00000000, 0x00000010, 0x00000000},
26{0x00000000, 0x078644FA, 0x00000000},
27{0x00000000, 0x0747AE14, 0x00000000},
28{0x00000000, 0x7FFFFFFF, 0x00000000},
29{0x00000000, 0x80000000, 0x00000000},
30{0x00000000, 0xFFFFFFFD, 0x00000000},
31{0x00000000, 0xFFFFFFFE, 0x00000000},
32{0x00000000, 0xFFFFFFFF, 0x00000000},
33{0x00000001, 0x00000001, 0x00000001},
34{0x00000001, 0x00000002, 0x00000000},
35{0x00000001, 0x00000003, 0x00000000},
36{0x00000001, 0x00000010, 0x00000000},
37{0x00000001, 0x078644FA, 0x00000000},
38{0x00000001, 0x0747AE14, 0x00000000},
39{0x00000001, 0x7FFFFFFF, 0x00000000},
40{0x00000001, 0x80000000, 0x00000000},
41{0x00000001, 0xFFFFFFFD, 0x00000000},
42{0x00000001, 0xFFFFFFFE, 0x00000000},
43{0x00000001, 0xFFFFFFFF, 0x00000000},
44{0x00000002, 0x00000001, 0x00000002},
45{0x00000002, 0x00000002, 0x00000001},
46{0x00000002, 0x00000003, 0x00000000},
47{0x00000002, 0x00000010, 0x00000000},
48{0x00000002, 0x078644FA, 0x00000000},
49{0x00000002, 0x0747AE14, 0x00000000},
50{0x00000002, 0x7FFFFFFF, 0x00000000},
51{0x00000002, 0x80000000, 0x00000000},
52{0x00000002, 0xFFFFFFFD, 0x00000000},
53{0x00000002, 0xFFFFFFFE, 0x00000000},
54{0x00000002, 0xFFFFFFFF, 0x00000000},
55{0x00000003, 0x00000001, 0x00000003},
56{0x00000003, 0x00000002, 0x00000001},
57{0x00000003, 0x00000003, 0x00000001},
58{0x00000003, 0x00000010, 0x00000000},
59{0x00000003, 0x078644FA, 0x00000000},
60{0x00000003, 0x0747AE14, 0x00000000},
61{0x00000003, 0x7FFFFFFF, 0x00000000},
62{0x00000003, 0x80000000, 0x00000000},
63{0x00000003, 0xFFFFFFFD, 0x00000000},
64{0x00000003, 0xFFFFFFFE, 0x00000000},
65{0x00000003, 0xFFFFFFFF, 0x00000000},
66{0x00000010, 0x00000001, 0x00000010},
67{0x00000010, 0x00000002, 0x00000008},
68{0x00000010, 0x00000003, 0x00000005},
69{0x00000010, 0x00000010, 0x00000001},
70{0x00000010, 0x078644FA, 0x00000000},
71{0x00000010, 0x0747AE14, 0x00000000},
72{0x00000010, 0x7FFFFFFF, 0x00000000},
73{0x00000010, 0x80000000, 0x00000000},
74{0x00000010, 0xFFFFFFFD, 0x00000000},
75{0x00000010, 0xFFFFFFFE, 0x00000000},
76{0x00000010, 0xFFFFFFFF, 0x00000000},
77{0x078644FA, 0x00000001, 0x078644FA},
78{0x078644FA, 0x00000002, 0x03C3227D},
79{0x078644FA, 0x00000003, 0x028216FE},
80{0x078644FA, 0x00000010, 0x0078644F},
81{0x078644FA, 0x078644FA, 0x00000001},
82{0x078644FA, 0x0747AE14, 0x00000001},
83{0x078644FA, 0x7FFFFFFF, 0x00000000},
84{0x078644FA, 0x80000000, 0x00000000},
85{0x078644FA, 0xFFFFFFFD, 0x00000000},
86{0x078644FA, 0xFFFFFFFE, 0x00000000},
87{0x078644FA, 0xFFFFFFFF, 0x00000000},
88{0x0747AE14, 0x00000001, 0x0747AE14},
89{0x0747AE14, 0x00000002, 0x03A3D70A},
90{0x0747AE14, 0x00000003, 0x026D3A06},
91{0x0747AE14, 0x00000010, 0x00747AE1},
92{0x0747AE14, 0x078644FA, 0x00000000},
93{0x0747AE14, 0x0747AE14, 0x00000001},
94{0x0747AE14, 0x7FFFFFFF, 0x00000000},
95{0x0747AE14, 0x80000000, 0x00000000},
96{0x0747AE14, 0xFFFFFFFD, 0x00000000},
97{0x0747AE14, 0xFFFFFFFE, 0x00000000},
98{0x0747AE14, 0xFFFFFFFF, 0x00000000},
99{0x7FFFFFFF, 0x00000001, 0x7FFFFFFF},
100{0x7FFFFFFF, 0x00000002, 0x3FFFFFFF},
101{0x7FFFFFFF, 0x00000003, 0x2AAAAAAA},
102{0x7FFFFFFF, 0x00000010, 0x07FFFFFF},
103{0x7FFFFFFF, 0x078644FA, 0x00000011},
104{0x7FFFFFFF, 0x0747AE14, 0x00000011},
105{0x7FFFFFFF, 0x7FFFFFFF, 0x00000001},
106{0x7FFFFFFF, 0x80000000, 0x00000000},
107{0x7FFFFFFF, 0xFFFFFFFD, 0x00000000},
108{0x7FFFFFFF, 0xFFFFFFFE, 0x00000000},
109{0x7FFFFFFF, 0xFFFFFFFF, 0x00000000},
110{0x80000000, 0x00000001, 0x80000000},
111{0x80000000, 0x00000002, 0x40000000},
112{0x80000000, 0x00000003, 0x2AAAAAAA},
113{0x80000000, 0x00000010, 0x08000000},
114{0x80000000, 0x078644FA, 0x00000011},
115{0x80000000, 0x0747AE14, 0x00000011},
116{0x80000000, 0x7FFFFFFF, 0x00000001},
117{0x80000000, 0x80000000, 0x00000001},
118{0x80000000, 0xFFFFFFFD, 0x00000000},
119{0x80000000, 0xFFFFFFFE, 0x00000000},
120{0x80000000, 0xFFFFFFFF, 0x00000000},
121{0xFFFFFFFD, 0x00000001, 0xFFFFFFFD},
122{0xFFFFFFFD, 0x00000002, 0x7FFFFFFE},
123{0xFFFFFFFD, 0x00000003, 0x55555554},
124{0xFFFFFFFD, 0x00000010, 0x0FFFFFFF},
125{0xFFFFFFFD, 0x078644FA, 0x00000022},
126{0xFFFFFFFD, 0x0747AE14, 0x00000023},
127{0xFFFFFFFD, 0x7FFFFFFF, 0x00000001},
128{0xFFFFFFFD, 0x80000000, 0x00000001},
129{0xFFFFFFFD, 0xFFFFFFFD, 0x00000001},
130{0xFFFFFFFD, 0xFFFFFFFE, 0x00000000},
131{0xFFFFFFFD, 0xFFFFFFFF, 0x00000000},
132{0xFFFFFFFE, 0x00000001, 0xFFFFFFFE},
133{0xFFFFFFFE, 0x00000002, 0x7FFFFFFF},
134{0xFFFFFFFE, 0x00000003, 0x55555554},
135{0xFFFFFFFE, 0x00000010, 0x0FFFFFFF},
136{0xFFFFFFFE, 0x078644FA, 0x00000022},
137{0xFFFFFFFE, 0x0747AE14, 0x00000023},
138{0xFFFFFFFE, 0x7FFFFFFF, 0x00000002},
139{0xFFFFFFFE, 0x80000000, 0x00000001},
140{0xFFFFFFFE, 0xFFFFFFFD, 0x00000001},
141{0xFFFFFFFE, 0xFFFFFFFE, 0x00000001},
142{0xFFFFFFFE, 0xFFFFFFFF, 0x00000000},
143{0xFFFFFFFF, 0x00000001, 0xFFFFFFFF},
144{0xFFFFFFFF, 0x00000002, 0x7FFFFFFF},
145{0xFFFFFFFF, 0x00000003, 0x55555555},
146{0xFFFFFFFF, 0x00000010, 0x0FFFFFFF},
147{0xFFFFFFFF, 0x078644FA, 0x00000022},
148{0xFFFFFFFF, 0x0747AE14, 0x00000023},
149{0xFFFFFFFF, 0x7FFFFFFF, 0x00000002},
150{0xFFFFFFFF, 0x80000000, 0x00000001},
151{0xFFFFFFFF, 0xFFFFFFFD, 0x00000001},
152{0xFFFFFFFF, 0xFFFFFFFE, 0x00000001},
153{0xFFFFFFFF, 0xFFFFFFFF, 0x00000001}
154};
155
156int main()
157{
158 const unsigned N = sizeof(tests) / sizeof(tests[0]);
159 unsigned i;
160 for (i = 0; i < N; ++i)
161 if (test__udivsi3(a: tests[i][0], b: tests[i][1], expected_q: tests[i][2]))
162 return 1;
163
164 return 0;
165}
166

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