1 // REQUIRES: riscv32-target-arch
2 // RUN: %clang_builtins %s %librt -o %t && %run %t
3 //===-- mulsi3_test.c - Test __mulsi3 -------------------------------------===//
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
9 //===----------------------------------------------------------------------===//
11 // This file tests __mulsi3 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
19 #if !defined(__riscv_mul) && __riscv_xlen == 32
20 // Based on mulsi3_test.c
22 COMPILER_RT_ABI si_int
__mulsi3(si_int a
, si_int b
);
24 int test__mulsi3(si_int a
, si_int b
, si_int expected
)
26 si_int x
= __mulsi3(a
, b
);
28 printf("error in __mulsi3: %d * %d = %d, expected %d\n",
29 a
, b
, __mulsi3(a
, b
), expected
);
36 #if !defined(__riscv_mul) && __riscv_xlen == 32
37 if (test__mulsi3(0, 0, 0))
39 if (test__mulsi3(0, 1, 0))
41 if (test__mulsi3(1, 0, 0))
43 if (test__mulsi3(0, 10, 0))
45 if (test__mulsi3(10, 0, 0))
47 if (test__mulsi3(0, INT_MAX
, 0))
49 if (test__mulsi3(INT_MAX
, 0, 0))
52 if (test__mulsi3(0, -1, 0))
54 if (test__mulsi3(-1, 0, 0))
56 if (test__mulsi3(0, -10, 0))
58 if (test__mulsi3(-10, 0, 0))
60 if (test__mulsi3(0, INT_MIN
, 0))
62 if (test__mulsi3(INT_MIN
, 0, 0))
65 if (test__mulsi3(1, 1, 1))
67 if (test__mulsi3(1, 10, 10))
69 if (test__mulsi3(10, 1, 10))
71 if (test__mulsi3(1, INT_MAX
, INT_MAX
))
73 if (test__mulsi3(INT_MAX
, 1, INT_MAX
))
76 if (test__mulsi3(1, -1, -1))
78 if (test__mulsi3(1, -10, -10))
80 if (test__mulsi3(-10, 1, -10))
82 if (test__mulsi3(1, INT_MIN
, INT_MIN
))
84 if (test__mulsi3(INT_MIN
, 1, INT_MIN
))
87 if (test__mulsi3(46340, 46340, 2147395600))
89 if (test__mulsi3(-46340, 46340, -2147395600))
91 if (test__mulsi3(46340, -46340, -2147395600))
93 if (test__mulsi3(-46340, -46340, 2147395600))
96 if (test__mulsi3(4194303, 8192, 34359730176))
98 if (test__mulsi3(-4194303, 8192, -34359730176))
100 if (test__mulsi3(4194303, -8192, -34359730176))
102 if (test__mulsi3(-4194303, -8192, 34359730176))
105 if (test__mulsi3(8192, 4194303, 34359730176))
107 if (test__mulsi3(-8192, 4194303, -34359730176))
109 if (test__mulsi3(8192, -4194303, -34359730176))
111 if (test__mulsi3(-8192, -4194303, 34359730176))