blob: 9f6801d6f41bee6a0dd6dc7fec7fd0a5cb53cdfc [file] [log] [blame]
Daniel Dunbarb3a69012009-06-26 16:47:03 +00001//===-- moddi3_test.c - Test __moddi3 -------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnant9ad441f2010-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 Dunbarb3a69012009-06-26 16:47:03 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file tests __moddi3 for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
14#include "int_lib.h"
15#include <stdio.h>
16
17// Returns: a % b
18
19di_int __moddi3(di_int a, di_int b);
20
21int test__moddi3(di_int a, di_int b, di_int expected)
22{
23 di_int x = __moddi3(a, b);
24 if (x != expected)
25 printf("error in __moddi3: %lld %% %lld = %lld, expected %lld\n",
26 a, b, x, expected);
27 return x != expected;
28}
29
30char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
31
32int main()
33{
34 if (test__moddi3(0, 1, 0))
35 return 1;
36 if (test__moddi3(0, -1, 0))
37 return 1;
38
39 if (test__moddi3(5, 3, 2))
40 return 1;
41 if (test__moddi3(5, -3, 2))
42 return 1;
43 if (test__moddi3(-5, 3, -2))
44 return 1;
45 if (test__moddi3(-5, -3, -2))
46 return 1;
47
48 if (test__moddi3(0x8000000000000000LL, 1, 0x0LL))
49 return 1;
50 if (test__moddi3(0x8000000000000000LL, -1, 0x0LL))
51 return 1;
52 if (test__moddi3(0x8000000000000000LL, 2, 0x0LL))
53 return 1;
54 if (test__moddi3(0x8000000000000000LL, -2, 0x0LL))
55 return 1;
56 if (test__moddi3(0x8000000000000000LL, 3, -2))
57 return 1;
58 if (test__moddi3(0x8000000000000000LL, -3, -2))
59 return 1;
60
61 return 0;
62}