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

source code of compiler-rt/test/builtins/Unit/modsi3_test.c