1 | // RUN: %clang_builtins %s %librt -o %t && %run %t |
2 | // REQUIRES: librt_has_moddi3 |
3 | |
4 | #include "int_lib.h" |
5 | #include <stdio.h> |
6 | |
7 | // Returns: a % b |
8 | |
9 | COMPILER_RT_ABI di_int __moddi3(di_int a, di_int b); |
10 | |
11 | int test__moddi3(di_int a, di_int b, di_int expected) |
12 | { |
13 | di_int x = __moddi3(a, b); |
14 | if (x != expected) |
15 | printf(format: "error in __moddi3: %lld %% %lld = %lld, expected %lld\n" , |
16 | a, b, x, expected); |
17 | return x != expected; |
18 | } |
19 | |
20 | char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0}; |
21 | |
22 | int main() |
23 | { |
24 | if (test__moddi3(a: 0, b: 1, expected: 0)) |
25 | return 1; |
26 | if (test__moddi3(a: 0, b: -1, expected: 0)) |
27 | return 1; |
28 | |
29 | if (test__moddi3(a: 5, b: 3, expected: 2)) |
30 | return 1; |
31 | if (test__moddi3(a: 5, b: -3, expected: 2)) |
32 | return 1; |
33 | if (test__moddi3(a: -5, b: 3, expected: -2)) |
34 | return 1; |
35 | if (test__moddi3(a: -5, b: -3, expected: -2)) |
36 | return 1; |
37 | |
38 | if (test__moddi3(a: 0x8000000000000000LL, b: 1, expected: 0x0LL)) |
39 | return 1; |
40 | if (test__moddi3(a: 0x8000000000000000LL, b: -1, expected: 0x0LL)) |
41 | return 1; |
42 | if (test__moddi3(a: 0x8000000000000000LL, b: 2, expected: 0x0LL)) |
43 | return 1; |
44 | if (test__moddi3(a: 0x8000000000000000LL, b: -2, expected: 0x0LL)) |
45 | return 1; |
46 | if (test__moddi3(a: 0x8000000000000000LL, b: 3, expected: -2)) |
47 | return 1; |
48 | if (test__moddi3(a: 0x8000000000000000LL, b: -3, expected: -2)) |
49 | return 1; |
50 | |
51 | return 0; |
52 | } |
53 | |