1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
2 | // REQUIRES: librt_has_divmodsi4 |
3 | |
4 | #include "int_lib.h" |
5 | #include <stdio.h> |
6 | |
7 | // Returns: a / b |
8 | |
9 | extern COMPILER_RT_ABI si_int __divmodsi4(si_int a, si_int b, si_int* rem); |
10 | |
11 | |
12 | int test__divmodsi4(si_int a, si_int b, |
13 | si_int expected_result, si_int expected_rem) |
14 | { |
15 | si_int rem; |
16 | si_int result = __divmodsi4(a, b, rem: &rem); |
17 | if (result != expected_result) { |
18 | printf(format: "error in __divmodsi4: %d / %d = %d, expected %d\n" , |
19 | a, b, result, expected_result); |
20 | return 1; |
21 | } |
22 | if (rem != expected_rem) { |
23 | printf(format: "error in __divmodsi4: %d mod %d = %d, expected %d\n" , |
24 | a, b, rem, expected_rem); |
25 | return 1; |
26 | } |
27 | |
28 | return 0; |
29 | } |
30 | |
31 | |
32 | int main() |
33 | { |
34 | if (test__divmodsi4(a: 0, b: 1, expected_result: 0, expected_rem: 0)) |
35 | return 1; |
36 | if (test__divmodsi4(a: 0, b: -1, expected_result: 0, expected_rem: 0)) |
37 | return 1; |
38 | |
39 | if (test__divmodsi4(a: 2, b: 1, expected_result: 2, expected_rem: 0)) |
40 | return 1; |
41 | if (test__divmodsi4(a: 2, b: -1, expected_result: -2, expected_rem: 0)) |
42 | return 1; |
43 | if (test__divmodsi4(a: -2, b: 1, expected_result: -2, expected_rem: 0)) |
44 | return 1; |
45 | if (test__divmodsi4(a: -2, b: -1, expected_result: 2, expected_rem: 0)) |
46 | return 1; |
47 | |
48 | if (test__divmodsi4(a: 7, b: 5, expected_result: 1, expected_rem: 2)) |
49 | return 1; |
50 | if (test__divmodsi4(a: -7, b: 5, expected_result: -1, expected_rem: -2)) |
51 | return 1; |
52 | if (test__divmodsi4(a: 19, b: 5, expected_result: 3, expected_rem: 4)) |
53 | return 1; |
54 | if (test__divmodsi4(a: 19, b: -5, expected_result: -3, expected_rem: 4)) |
55 | return 1; |
56 | |
57 | if (test__divmodsi4(a: 0x80000000, b: 8, expected_result: 0xf0000000, expected_rem: 0)) |
58 | return 1; |
59 | if (test__divmodsi4(a: 0x80000007, b: 8, expected_result: 0xf0000001, expected_rem: -1)) |
60 | return 1; |
61 | |
62 | return 0; |
63 | } |
64 | |