xref: /llvm-project/compiler-rt/test/builtins/Unit/udivmodsi4_test.c (revision 70f9cfc857f14ce7ae4057aea7b3568e6aa41d38)
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_udivmodsi4
3 
4 #include "int_lib.h"
5 #include <stdio.h>
6 
7 // Returns: a / b
8 
9 extern COMPILER_RT_ABI su_int __udivmodsi4(su_int a, su_int b, su_int* rem);
10 
test__udivmodsi4(su_int a,su_int b,su_int expected_result,su_int expected_rem)11 int test__udivmodsi4(su_int a, su_int b,
12 						su_int expected_result, su_int expected_rem)
13 {
14 	su_int rem;
15     su_int result = __udivmodsi4(a, b, &rem);
16     if (result != expected_result) {
17         printf("error in __udivmodsi4: %u / %u = %u, expected %u\n",
18                a, b, result, expected_result);
19 		return 1;
20 	}
21     if (rem != expected_rem) {
22         printf("error in __udivmodsi4: %u mod %u = %u, expected %u\n",
23                a, b, rem, expected_rem);
24 		return 1;
25 	}
26 
27     return 0;
28 }
29 
30 
main()31 int main()
32 {
33     if (test__udivmodsi4(0, 1, 0, 0))
34         return 1;
35 
36     if (test__udivmodsi4(2, 1, 2, 0))
37         return 1;
38 
39 	if (test__udivmodsi4(19, 5, 3, 4))
40         return 1;
41 
42 	if (test__udivmodsi4(0x80000000, 8, 0x10000000, 0))
43         return 1;
44 
45  	if (test__udivmodsi4(0x80000003, 8, 0x10000000, 3))
46         return 1;
47 
48 	return 0;
49 }
50