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
9extern COMPILER_RT_ABI su_int __udivmodsi4(su_int a, su_int b, su_int* rem);
10
11int 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: &rem);
16 if (result != expected_result) {
17 printf(format: "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(format: "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
31int main()
32{
33 if (test__udivmodsi4(a: 0, b: 1, expected_result: 0, expected_rem: 0))
34 return 1;
35
36 if (test__udivmodsi4(a: 2, b: 1, expected_result: 2, expected_rem: 0))
37 return 1;
38
39 if (test__udivmodsi4(a: 19, b: 5, expected_result: 3, expected_rem: 4))
40 return 1;
41
42 if (test__udivmodsi4(a: 0x80000000, b: 8, expected_result: 0x10000000, expected_rem: 0))
43 return 1;
44
45 if (test__udivmodsi4(a: 0x80000003, b: 8, expected_result: 0x10000000, expected_rem: 3))
46 return 1;
47
48 return 0;
49}
50

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