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
9COMPILER_RT_ABI di_int __moddi3(di_int a, di_int b);
10
11int 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("error in __moddi3: %lld %% %lld = %lld, expected %lld\n",
16 a, b, x, expected);
17 return x != expected;
18}
19
20char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
21
22int main()
23{
24 if (test__moddi3(0, 1, 0))
25 return 1;
26 if (test__moddi3(0, -1, 0))
27 return 1;
28
29 if (test__moddi3(5, 3, 2))
30 return 1;
31 if (test__moddi3(5, -3, 2))
32 return 1;
33 if (test__moddi3(-5, 3, -2))
34 return 1;
35 if (test__moddi3(-5, -3, -2))
36 return 1;
37
38 if (test__moddi3(0x8000000000000000LL, 1, 0x0LL))
39 return 1;
40 if (test__moddi3(0x8000000000000000LL, -1, 0x0LL))
41 return 1;
42 if (test__moddi3(0x8000000000000000LL, 2, 0x0LL))
43 return 1;
44 if (test__moddi3(0x8000000000000000LL, -2, 0x0LL))
45 return 1;
46 if (test__moddi3(0x8000000000000000LL, 3, -2))
47 return 1;
48 if (test__moddi3(0x8000000000000000LL, -3, -2))
49 return 1;
50
51 return 0;
52}
53