1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_udivmodsi4
3 //===-- udivmodsi4_test.c - Test __udivmodsi4 -----------------------------===//
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 __udivmodsi4 for the compiler_rt library.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "int_lib.h"
16 #include <stdio.h>
17
18 // Returns: a / b
19
20 extern COMPILER_RT_ABI su_int __udivmodsi4(su_int a, su_int b, su_int* rem);
21
test__udivmodsi4(su_int a,su_int b,su_int expected_result,su_int expected_rem)22 int test__udivmodsi4(su_int a, su_int b,
23 su_int expected_result, su_int expected_rem)
24 {
25 su_int rem;
26 su_int result = __udivmodsi4(a, b, &rem);
27 if (result != expected_result) {
28 printf("error in __udivmodsi4: %u / %u = %u, expected %u\n",
29 a, b, result, expected_result);
30 return 1;
31 }
32 if (rem != expected_rem) {
33 printf("error in __udivmodsi4: %u mod %u = %u, expected %u\n",
34 a, b, rem, expected_rem);
35 return 1;
36 }
37
38 return 0;
39 }
40
41
main()42 int main()
43 {
44 if (test__udivmodsi4(0, 1, 0, 0))
45 return 1;
46
47 if (test__udivmodsi4(2, 1, 2, 0))
48 return 1;
49
50 if (test__udivmodsi4(19, 5, 3, 4))
51 return 1;
52
53 if (test__udivmodsi4(0x80000000, 8, 0x10000000, 0))
54 return 1;
55
56 if (test__udivmodsi4(0x80000003, 8, 0x10000000, 3))
57 return 1;
58
59 return 0;
60 }
61