1// REQUIRES-ANY: arm-target-arch,armv6m-target-arch 2// RUN: %clang_builtins %s %librt -o %t && %run %t 3//===-- aeabi_uidivmod_test.c - Test __aeabi_uidivmod ---------------------===// 4// 5// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 6// See https://llvm.org/LICENSE.txt for license information. 7// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 8// 9//===----------------------------------------------------------------------===// 10// 11// This file tests __aeabi_uidivmod for the compiler_rt library. 12// 13//===----------------------------------------------------------------------===// 14 15#include "int_lib.h" 16#include <stdio.h> 17 18#if __arm__ 19// Based on udivmodsi4_test.c 20 21extern du_int __aeabi_uidivmod(su_int a, su_int b); 22 23int test__aeabi_uidivmod(su_int a, su_int b, 24 su_int expected_result, su_int expected_rem) 25{ 26 du_int ret = __aeabi_uidivmod(a, b); 27 su_int rem = ret >> 32; 28 si_int result = ret & 0xFFFFFFFF; 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 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#else 64 printf("skipped\n"); 65#endif 66 67 return 0; 68} 69