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 udivmodsi4_test.c |
9 | |
10 | extern du_int __aeabi_uidivmod(su_int a, su_int b); |
11 | |
12 | int test__aeabi_uidivmod(su_int a, su_int b, |
13 | su_int expected_result, su_int expected_rem) |
14 | { |
15 | du_int ret = __aeabi_uidivmod(a, b); |
16 | su_int rem = ret >> 32; |
17 | si_int result = ret & 0xFFFFFFFF; |
18 | |
19 | if (result != expected_result) { |
20 | printf("error in __aeabi_uidivmod: %u / %u = %u, expected %u\n" , |
21 | a, b, result, expected_result); |
22 | return 1; |
23 | } |
24 | if (rem != expected_rem) { |
25 | printf("error in __aeabi_uidivmod: %u mod %u = %u, expected %u\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_uidivmod(0, 1, 0, 0)) |
39 | return 1; |
40 | |
41 | if (test__aeabi_uidivmod(2, 1, 2, 0)) |
42 | return 1; |
43 | |
44 | if (test__aeabi_uidivmod(19, 5, 3, 4)) |
45 | return 1; |
46 | |
47 | if (test__aeabi_uidivmod(0x80000000, 8, 0x10000000, 0)) |
48 | return 1; |
49 | |
50 | if (test__aeabi_uidivmod(0x80000003, 8, 0x10000000, 3)) |
51 | return 1; |
52 | #else |
53 | printf(format: "skipped\n" ); |
54 | #endif |
55 | |
56 | return 0; |
57 | } |
58 | |