[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / builtins / Unit / divmodsi4_test.c
blob326457f66caa8b5727f22c3535d05b628cc1e280
1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_divmodsi4
3 //===-- divmodsi4_test.c - Test __divmodsi4 -------------------------------===//
4 //
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //
9 //===----------------------------------------------------------------------===//
11 // This file tests __divmodsi4 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
15 #include "int_lib.h"
16 #include <stdio.h>
18 // Returns: a / b
20 extern COMPILER_RT_ABI si_int __divmodsi4(si_int a, si_int b, si_int* rem);
23 int test__divmodsi4(si_int a, si_int b,
24 si_int expected_result, si_int expected_rem)
26 si_int rem;
27 si_int result = __divmodsi4(a, b, &rem);
28 if (result != expected_result) {
29 printf("error in __divmodsi4: %d / %d = %d, expected %d\n",
30 a, b, result, expected_result);
31 return 1;
33 if (rem != expected_rem) {
34 printf("error in __divmodsi4: %d mod %d = %d, expected %d\n",
35 a, b, rem, expected_rem);
36 return 1;
39 return 0;
43 int main()
45 if (test__divmodsi4(0, 1, 0, 0))
46 return 1;
47 if (test__divmodsi4(0, -1, 0, 0))
48 return 1;
50 if (test__divmodsi4(2, 1, 2, 0))
51 return 1;
52 if (test__divmodsi4(2, -1, -2, 0))
53 return 1;
54 if (test__divmodsi4(-2, 1, -2, 0))
55 return 1;
56 if (test__divmodsi4(-2, -1, 2, 0))
57 return 1;
59 if (test__divmodsi4(7, 5, 1, 2))
60 return 1;
61 if (test__divmodsi4(-7, 5, -1, -2))
62 return 1;
63 if (test__divmodsi4(19, 5, 3, 4))
64 return 1;
65 if (test__divmodsi4(19, -5, -3, 4))
66 return 1;
68 if (test__divmodsi4(0x80000000, 8, 0xf0000000, 0))
69 return 1;
70 if (test__divmodsi4(0x80000007, 8, 0xf0000001, -1))
71 return 1;
73 return 0;