1//===-- divti3_test.c - Test __divti3 -------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
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",
38               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);
40    }
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
74#endif
75    return 0;
76}
77