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