82 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 divmodsi4_test.c9 10extern du_int __aeabi_idivmod(si_int a, si_int b);11 12int 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 // __aeabi_idivmod actually returns a struct { quotient; remainder; } using18 // value_in_regs calling convention. Due to the ABI rules, struct fields19 // come in the same order regardless of endianness. However since the20 // result is received here as a 64-bit integer, in which endianness does21 // matter, the position of each component (quotient and remainder) varies22 // depending on endianness.23# if _YUGA_BIG_ENDIAN24 rem = ret & 0xFFFFFFFF;25 si_int result = ret >> 32;26# else27 rem = ret >> 32;28 si_int result = ret & 0xFFFFFFFF;29# endif30 if (result != expected_result) {31 printf("error in __aeabi_idivmod: %d / %d = %d, expected %d\n",32 a, b, result, expected_result);33 return 1;34 }35 if (rem != expected_rem) {36 printf("error in __aeabi_idivmod: %d mod %d = %d, expected %d\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_idivmod(0, 1, 0, 0))50 return 1;51 if (test__aeabi_idivmod(0, -1, 0, 0))52 return 1;53 54 if (test__aeabi_idivmod(2, 1, 2, 0))55 return 1;56 if (test__aeabi_idivmod(2, -1, -2, 0))57 return 1;58 if (test__aeabi_idivmod(-2, 1, -2, 0))59 return 1;60 if (test__aeabi_idivmod(-2, -1, 2, 0))61 return 1;62 63 if (test__aeabi_idivmod(7, 5, 1, 2))64 return 1;65 if (test__aeabi_idivmod(-7, 5, -1, -2))66 return 1;67 if (test__aeabi_idivmod(19, 5, 3, 4))68 return 1;69 if (test__aeabi_idivmod(19, -5, -3, 4))70 return 1;71 72 if (test__aeabi_idivmod(0x80000000, 8, 0xf0000000, 0))73 return 1;74 if (test__aeabi_idivmod(0x80000007, 8, 0xf0000001, -1))75 return 1;76#else77 printf("skipped\n");78#endif79 80 return 0;81}82