69 lines · c
1// REQUIRES: arm-target-arch || armv6m-target-arch2// RUN: %clang_builtins %s %librt -o %t && %run %t3 4#include "int_lib.h"5#include <stdio.h>6 7#if __arm__8// Based on udivmodsi4_test.c9 10extern du_int __aeabi_uidivmod(su_int a, su_int b);11 12int 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, struct18 // fields come in the same order regardless of endianness. However since19 // the result is received here as a 64-bit integer, in which endianness20 // does matter, the position of each component (quotient and remainder)21 // varies depending on endianness.22# if _YUGA_BIG_ENDIAN23 su_int rem = ret & 0xFFFFFFFF;24 si_int result = ret >> 32;25# else26 su_int rem = ret >> 32;27 si_int result = ret & 0xFFFFFFFF;28# endif29 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#endif44 45 46int 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#else64 printf("skipped\n");65#endif66 67 return 0;68}69