[GlobalISel] Avoid repeated hash lookups (NFC) (#124393)
[llvm-project.git] / compiler-rt / test / builtins / Unit / divmodsi4_test.c
blobb6160d25391cab9729ef3558100a73e6e65fc590
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_divmodsi4
4 #include "int_lib.h"
5 #include <stdio.h>
7 // Returns: a / b
9 extern COMPILER_RT_ABI si_int __divmodsi4(si_int a, si_int b, si_int* rem);
12 int test__divmodsi4(si_int a, si_int b,
13 si_int expected_result, si_int expected_rem)
15 si_int rem;
16 si_int result = __divmodsi4(a, b, &rem);
17 if (result != expected_result) {
18 printf("error in __divmodsi4: %d / %d = %d, expected %d\n",
19 a, b, result, expected_result);
20 return 1;
22 if (rem != expected_rem) {
23 printf("error in __divmodsi4: %d mod %d = %d, expected %d\n",
24 a, b, rem, expected_rem);
25 return 1;
28 return 0;
32 int main()
34 if (test__divmodsi4(0, 1, 0, 0))
35 return 1;
36 if (test__divmodsi4(0, -1, 0, 0))
37 return 1;
39 if (test__divmodsi4(2, 1, 2, 0))
40 return 1;
41 if (test__divmodsi4(2, -1, -2, 0))
42 return 1;
43 if (test__divmodsi4(-2, 1, -2, 0))
44 return 1;
45 if (test__divmodsi4(-2, -1, 2, 0))
46 return 1;
48 if (test__divmodsi4(7, 5, 1, 2))
49 return 1;
50 if (test__divmodsi4(-7, 5, -1, -2))
51 return 1;
52 if (test__divmodsi4(19, 5, 3, 4))
53 return 1;
54 if (test__divmodsi4(19, -5, -3, 4))
55 return 1;
57 if (test__divmodsi4(0x80000000, 8, 0xf0000000, 0))
58 return 1;
59 if (test__divmodsi4(0x80000007, 8, 0xf0000001, -1))
60 return 1;
62 return 0;