| 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 | // __aeabi_uidivmod actually returns a struct { quotient; remainder; } |
| 17 | // using value_in_regs calling convention. Due to the ABI rules, struct |
| 18 | // fields come in the same order regardless of endianness. However since |
| 19 | // the result is received here as a 64-bit integer, in which endianness |
| 20 | // does matter, the position of each component (quotient and remainder) |
| 21 | // varies depending on endianness. |
| 22 | # if _YUGA_BIG_ENDIAN |
| 23 | su_int rem = ret & 0xFFFFFFFF; |
| 24 | si_int result = ret >> 32; |
| 25 | # else |
| 26 | su_int rem = ret >> 32; |
| 27 | si_int result = ret & 0xFFFFFFFF; |
| 28 | # endif |
| 29 | |
| 30 | if (result != expected_result) { |
| 31 | printf("error in __aeabi_uidivmod: %u / %u = %u, expected %u\n" , |
| 32 | a, b, result, expected_result); |
| 33 | return 1; |
| 34 | } |
| 35 | if (rem != expected_rem) { |
| 36 | printf("error in __aeabi_uidivmod: %u mod %u = %u, expected %u\n" , |
| 37 | a, b, rem, expected_rem); |
| 38 | return 1; |
| 39 | } |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | #endif |
| 44 | |
| 45 | |
| 46 | int main() |
| 47 | { |
| 48 | #if __arm__ |
| 49 | if (test__aeabi_uidivmod(0, 1, 0, 0)) |
| 50 | return 1; |
| 51 | |
| 52 | if (test__aeabi_uidivmod(2, 1, 2, 0)) |
| 53 | return 1; |
| 54 | |
| 55 | if (test__aeabi_uidivmod(19, 5, 3, 4)) |
| 56 | return 1; |
| 57 | |
| 58 | if (test__aeabi_uidivmod(0x80000000, 8, 0x10000000, 0)) |
| 59 | return 1; |
| 60 | |
| 61 | if (test__aeabi_uidivmod(0x80000003, 8, 0x10000000, 3)) |
| 62 | return 1; |
| 63 | #else |
| 64 | printf(format: "skipped\n" ); |
| 65 | #endif |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |