1 //===-- muldi3.c - Implement __muldi3 -------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements __muldi3 for the compiler_rt library.
11 //===----------------------------------------------------------------------===//
17 static di_int
__muldsi3(su_int a
, su_int b
) {
19 const int bits_in_word_2
= (int)(sizeof(si_int
) * CHAR_BIT
) / 2;
20 const su_int lower_mask
= (su_int
)~0 >> bits_in_word_2
;
21 r
.s
.low
= (a
& lower_mask
) * (b
& lower_mask
);
22 su_int t
= r
.s
.low
>> bits_in_word_2
;
23 r
.s
.low
&= lower_mask
;
24 t
+= (a
>> bits_in_word_2
) * (b
& lower_mask
);
25 r
.s
.low
+= (t
& lower_mask
) << bits_in_word_2
;
26 r
.s
.high
= t
>> bits_in_word_2
;
27 t
= r
.s
.low
>> bits_in_word_2
;
28 r
.s
.low
&= lower_mask
;
29 t
+= (b
>> bits_in_word_2
) * (a
& lower_mask
);
30 r
.s
.low
+= (t
& lower_mask
) << bits_in_word_2
;
31 r
.s
.high
+= t
>> bits_in_word_2
;
32 r
.s
.high
+= (a
>> bits_in_word_2
) * (b
>> bits_in_word_2
);
38 COMPILER_RT_ABI di_int
__muldi3(di_int a
, di_int b
) {
44 r
.all
= __muldsi3(x
.s
.low
, y
.s
.low
);
45 r
.s
.high
+= x
.s
.high
* y
.s
.low
+ x
.s
.low
* y
.s
.high
;
49 #if defined(__ARM_EABI__)
50 COMPILER_RT_ALIAS(__muldi3
, __aeabi_lmul
)