blob: 99413aaa2f6a06e6bae3ffff4afcb35240e4e3d9 [file] [log] [blame]
Daniel Dunbarfd089992009-06-26 16:47:03 +00001//===-- modti3_test.c - Test __modti3 -------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnant5b791f62010-11-16 22:13:33 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Daniel Dunbarfd089992009-06-26 16:47:03 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file tests __modti3 for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
Daniel Dunbarfd089992009-06-26 16:47:03 +000014#include "int_lib.h"
15#include <stdio.h>
16
Joerg Sonnenberger14743122014-03-18 21:35:30 +000017#ifdef CRT_HAS_128BIT
18
Daniel Dunbarfd089992009-06-26 16:47:03 +000019// Returns: a % b
20
Derek Schuffeb0ebc32015-04-24 15:45:57 +000021COMPILER_RT_ABI ti_int __modti3(ti_int a, ti_int b);
Daniel Dunbarfd089992009-06-26 16:47:03 +000022
23int test__modti3(ti_int a, ti_int b, ti_int expected)
24{
25 ti_int x = __modti3(a, b);
26 if (x != expected)
27 {
28 twords at;
29 at.all = a;
30 twords bt;
31 bt.all = b;
32 twords xt;
33 xt.all = x;
34 twords expectedt;
35 expectedt.all = expected;
36 printf("error in __modti3: 0x%.16llX%.16llX %% 0x%.16llX%.16llX = "
37 "0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
Daniel Dunbar64857202009-10-27 17:49:07 +000038 at.s.high, at.s.low, bt.s.high, bt.s.low, xt.s.high, xt.s.low,
39 expectedt.s.high, expectedt.s.low);
Daniel Dunbarfd089992009-06-26 16:47:03 +000040 }
41 return x != expected;
42}
43
44char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
45
46#endif
47
48int main()
49{
Joerg Sonnenberger14743122014-03-18 21:35:30 +000050#ifdef CRT_HAS_128BIT
Daniel Dunbarfd089992009-06-26 16:47:03 +000051 if (test__modti3(0, 1, 0))
52 return 1;
53 if (test__modti3(0, -1, 0))
54 return 1;
55
56 if (test__modti3(5, 3, 2))
57 return 1;
58 if (test__modti3(5, -3, 2))
59 return 1;
60 if (test__modti3(-5, 3, -2))
61 return 1;
62 if (test__modti3(-5, -3, -2))
63 return 1;
64
65 if (test__modti3(0x8000000000000000LL, 1, 0x0LL))
66 return 1;
67 if (test__modti3(0x8000000000000000LL, -1, 0x0LL))
68 return 1;
69 if (test__modti3(0x8000000000000000LL, 2, 0x0LL))
70 return 1;
71 if (test__modti3(0x8000000000000000LL, -2, 0x0LL))
72 return 1;
73 if (test__modti3(0x8000000000000000LL, 3, 2))
74 return 1;
75 if (test__modti3(0x8000000000000000LL, -3, 2))
76 return 1;
77
78 if (test__modti3(make_ti(0x8000000000000000LL, 0), 1, 0x0LL))
79 return 1;
80 if (test__modti3(make_ti(0x8000000000000000LL, 0), -1, 0x0LL))
81 return 1;
82 if (test__modti3(make_ti(0x8000000000000000LL, 0), 2, 0x0LL))
83 return 1;
84 if (test__modti3(make_ti(0x8000000000000000LL, 0), -2, 0x0LL))
85 return 1;
86 if (test__modti3(make_ti(0x8000000000000000LL, 0), 3, -2))
87 return 1;
88 if (test__modti3(make_ti(0x8000000000000000LL, 0), -3, -2))
89 return 1;
90
Joerg Sonnenbergerd9bcddd2011-05-29 21:43:29 +000091#else
92 printf("skipped\n");
Daniel Dunbarfd089992009-06-26 16:47:03 +000093#endif
94 return 0;
95}