blob: 7c8e2970fa6e535173f7d5b9c9dbdfd8071fc3d4 [file] [log] [blame]
Daniel Dunbarb3a69012009-06-26 16:47:03 +00001//===-- divti3_test.c - Test __divti3 -------------------------------------===//
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 __divti3 for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
14#if __x86_64
15
16#include "int_lib.h"
17#include <stdio.h>
18
19// Returns: a / b
20
21ti_int __divti3(ti_int a, ti_int b);
22
23int test__divti3(ti_int a, ti_int b, ti_int expected)
24{
25 ti_int x = __divti3(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 __divti3: 0x%llX%.16llX / 0x%llX%.16llX = "
37 "0x%llX%.16llX, expected 0x%llX%.16llX\n",
Daniel Dunbarcff52482009-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 Dunbarb3a69012009-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{
50#if __x86_64
51 if (test__divti3(0, 1, 0))
52 return 1;
53 if (test__divti3(0, -1, 0))
54 return 1;
55
56 if (test__divti3(2, 1, 2))
57 return 1;
58 if (test__divti3(2, -1, -2))
59 return 1;
60 if (test__divti3(-2, 1, -2))
61 return 1;
62 if (test__divti3(-2, -1, 2))
63 return 1;
64
65 if (test__divti3(make_ti(0x8000000000000000LL, 0), 1, make_ti(0x8000000000000000LL, 0)))
66 return 1;
67 if (test__divti3(make_ti(0x8000000000000000LL, 0), -1, make_ti(0x8000000000000000LL, 0)))
68 return 1;
69 if (test__divti3(make_ti(0x8000000000000000LL, 0), -2, make_ti(0x4000000000000000LL, 0)))
70 return 1;
71 if (test__divti3(make_ti(0x8000000000000000LL, 0), 2, make_ti(0xC000000000000000LL, 0)))
72 return 1;
73
Joerg Sonnenberger74828152011-05-29 21:43:29 +000074#else
75 printf("skipped\n");
Daniel Dunbarb3a69012009-06-26 16:47:03 +000076#endif
77 return 0;
78}