1// RUN: %clang_builtins %s %librt -o %t && %run %t
2// REQUIRES: librt_has_divsi3
3
4#include "int_lib.h"
5#include <stdio.h>
6
7// Returns: a / b
8
9COMPILER_RT_ABI si_int __divsi3(si_int a, si_int b);
10
11int test__divsi3(si_int a, si_int b, si_int expected)
12{
13 si_int x = __divsi3(a, b);
14 if (x != expected)
15 printf("error in __divsi3: %d / %d = %d, expected %d\n",
16 a, b, x, expected);
17 return x != expected;
18}
19
20int main()
21{
22 if (test__divsi3(0, 1, 0))
23 return 1;
24 if (test__divsi3(0, -1, 0))
25 return 1;
26
27 if (test__divsi3(2, 1, 2))
28 return 1;
29 if (test__divsi3(2, -1, -2))
30 return 1;
31 if (test__divsi3(-2, 1, -2))
32 return 1;
33 if (test__divsi3(-2, -1, 2))
34 return 1;
35
36 if (test__divsi3(0x80000000, 1, 0x80000000))
37 return 1;
38 if (test__divsi3(0x80000000, -1, 0x80000000))
39 return 1;
40 if (test__divsi3(0x80000000, -2, 0x40000000))
41 return 1;
42 if (test__divsi3(0x80000000, 2, 0xC0000000))
43 return 1;
44
45 return 0;
46}
47