1 // RUN: %clang_builtins %s %librt -o %t && %run %t
2 // REQUIRES: librt_has_mulvsi3
3 //===-- mulvsi3_test.c - Test __mulvsi3 -----------------------------------===//
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 __mulvsi3 for the compiler_rt library.
13 //===----------------------------------------------------------------------===//
20 // Effects: aborts if a * b overflows
22 COMPILER_RT_ABI si_int
__mulvsi3(si_int a
, si_int b
);
24 int test__mulvsi3(si_int a
, si_int b
, si_int expected
)
26 si_int x
= __mulvsi3(a
, b
);
28 printf("error in __mulvsi3: %d * %d = %d, expected %d\n",
35 if (test__mulvsi3(0, 0, 0))
37 if (test__mulvsi3(0, 1, 0))
39 if (test__mulvsi3(1, 0, 0))
41 if (test__mulvsi3(0, 10, 0))
43 if (test__mulvsi3(10, 0, 0))
45 if (test__mulvsi3(0, 0x1234567, 0))
47 if (test__mulvsi3(0x1234567, 0, 0))
50 if (test__mulvsi3(0, -1, 0))
52 if (test__mulvsi3(-1, 0, 0))
54 if (test__mulvsi3(0, -10, 0))
56 if (test__mulvsi3(-10, 0, 0))
58 if (test__mulvsi3(0, -0x1234567, 0))
60 if (test__mulvsi3(-0x1234567, 0, 0))
63 if (test__mulvsi3(1, 1, 1))
65 if (test__mulvsi3(1, 10, 10))
67 if (test__mulvsi3(10, 1, 10))
69 if (test__mulvsi3(1, 0x1234567, 0x1234567))
71 if (test__mulvsi3(0x1234567, 1, 0x1234567))
74 if (test__mulvsi3(1, -1, -1))
76 if (test__mulvsi3(1, -10, -10))
78 if (test__mulvsi3(-10, 1, -10))
80 if (test__mulvsi3(1, -0x1234567, -0x1234567))
82 if (test__mulvsi3(-0x1234567, 1, -0x1234567))
85 // if (test__mulvsi3(0x7FFFFFFF, -2, 0x80000001)) // abort
87 // if (test__mulvsi3(-2, 0x7FFFFFFF, 0x80000001)) // abort
89 if (test__mulvsi3(0x7FFFFFFF, -1, 0x80000001))
91 if (test__mulvsi3(-1, 0x7FFFFFFF, 0x80000001))
93 if (test__mulvsi3(0x7FFFFFFF, 0, 0))
95 if (test__mulvsi3(0, 0x7FFFFFFF, 0))
97 if (test__mulvsi3(0x7FFFFFFF, 1, 0x7FFFFFFF))
99 if (test__mulvsi3(1, 0x7FFFFFFF, 0x7FFFFFFF))
101 // if (test__mulvsi3(0x7FFFFFFF, 2, 0x80000001)) // abort
103 // if (test__mulvsi3(2, 0x7FFFFFFF, 0x80000001)) // abort
106 // if (test__mulvsi3(0x80000000, -2, 0x80000000)) // abort
108 // if (test__mulvsi3(-2, 0x80000000, 0x80000000)) // abort
110 // if (test__mulvsi3(0x80000000, -1, 0x80000000)) // abort
112 // if (test__mulvsi3(-1, 0x80000000, 0x80000000)) // abort
114 if (test__mulvsi3(0x80000000, 0, 0))
116 if (test__mulvsi3(0, 0x80000000, 0))
118 if (test__mulvsi3(0x80000000, 1, 0x80000000))
120 if (test__mulvsi3(1, 0x80000000, 0x80000000))
122 // if (test__mulvsi3(0x80000000, 2, 0x80000000)) // abort
124 // if (test__mulvsi3(2, 0x80000000, 0x80000000)) // abort
127 // if (test__mulvsi3(0x80000001, -2, 0x80000001)) // abort
129 // if (test__mulvsi3(-2, 0x80000001, 0x80000001)) // abort
131 if (test__mulvsi3(0x80000001, -1, 0x7FFFFFFF))
133 if (test__mulvsi3(-1, 0x80000001, 0x7FFFFFFF))
135 if (test__mulvsi3(0x80000001, 0, 0))
137 if (test__mulvsi3(0, 0x80000001, 0))
139 if (test__mulvsi3(0x80000001, 1, 0x80000001))
141 if (test__mulvsi3(1, 0x80000001, 0x80000001))
143 // if (test__mulvsi3(0x80000001, 2, 0x80000000)) // abort
145 // if (test__mulvsi3(2, 0x80000001, 0x80000000)) // abort