1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_modti3
3 // REQUIRES: int128
4
5 #include "int_lib.h"
6 #include <stdio.h>
7
8 #ifdef CRT_HAS_128BIT
9
10 // Returns: a % b
11
12 COMPILER_RT_ABI ti_int __modti3(ti_int a, ti_int b);
13
test__modti3(ti_int a,ti_int b,ti_int expected)14 int test__modti3(ti_int a, ti_int b, ti_int expected)
15 {
16 ti_int x = __modti3(a, b);
17 if (x != expected)
18 {
19 twords at;
20 at.all = a;
21 twords bt;
22 bt.all = b;
23 twords xt;
24 xt.all = x;
25 twords expectedt;
26 expectedt.all = expected;
27 printf("error in __modti3: 0x%.16llX%.16llX %% 0x%.16llX%.16llX = "
28 "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
29 at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low,
30 expectedt.s.high, expectedt.s.low);
31 }
32 return x != expected;
33 }
34
35 char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
36
37 #endif
38
main()39 int main()
40 {
41 #ifdef CRT_HAS_128BIT
42 if (test__modti3(0, 1, 0))
43 return 1;
44 if (test__modti3(0, -1, 0))
45 return 1;
46
47 if (test__modti3(5, 3, 2))
48 return 1;
49 if (test__modti3(5, -3, 2))
50 return 1;
51 if (test__modti3(-5, 3, -2))
52 return 1;
53 if (test__modti3(-5, -3, -2))
54 return 1;
55
56 if (test__modti3(0x8000000000000000ULL, 1, 0x0LL))
57 return 1;
58 if (test__modti3(0x8000000000000000ULL, -1, 0x0LL))
59 return 1;
60 if (test__modti3(0x8000000000000000ULL, 2, 0x0LL))
61 return 1;
62 if (test__modti3(0x8000000000000000ULL, -2, 0x0LL))
63 return 1;
64 if (test__modti3(0x8000000000000000ULL, 3, 2))
65 return 1;
66 if (test__modti3(0x8000000000000000ULL, -3, 2))
67 return 1;
68
69 if (test__modti3(make_ti(0x8000000000000000LL, 0), 1, 0x0LL))
70 return 1;
71 if (test__modti3(make_ti(0x8000000000000000LL, 0), -1, 0x0LL))
72 return 1;
73 if (test__modti3(make_ti(0x8000000000000000LL, 0), 2, 0x0LL))
74 return 1;
75 if (test__modti3(make_ti(0x8000000000000000LL, 0), -2, 0x0LL))
76 return 1;
77 if (test__modti3(make_ti(0x8000000000000000LL, 0), 3, -2))
78 return 1;
79 if (test__modti3(make_ti(0x8000000000000000LL, 0), -3, -2))
80 return 1;
81
82 #else
83 printf("skipped\n");
84 #endif
85 return 0;
86 }
87