Path: blob/main/contrib/llvm-project/compiler-rt/lib/builtins/avr/mulhi3.S
35290 views
//===------------ mulhi3.S - int16 multiplication -------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// The corresponding C code is something like:9//10// int __mulhi3(int A, int B) {11// int S = 0;12// while (A != 0) {13// if (A & 1)14// S += B;15// A = ((unsigned int) A) >> 1;16// B <<= 1;17// }18// return S;19// }20//21// __mulhi3 has special ABI, as the implementation of libgcc, R25:R24 is used22// to return result, while Rtmp/R21/R22/R23 are clobbered.23//24//===----------------------------------------------------------------------===//2526.text27.align 22829#ifdef __AVR_TINY__30.set __tmp_reg__, 1631.set __zero_reg__, 1732#else33.set __tmp_reg__, 034.set __zero_reg__, 135#endif3637.globl __mulhi338.type __mulhi3, @function3940__mulhi3:41; Use Rzero:Rtmp to store the result.42clr __tmp_reg__43clr __zero_reg__ ; S = 0;4445__mulhi3_loop:46clr r2147cp r24, r2148cpc r25, r2149breq __mulhi3_end ; while (A != 0) {5051mov r21, r2452andi r21, 153breq __mulhi3_loop_a ; if (A & 1)54add __tmp_reg__, r2255adc __zero_reg__, r23 ; S += B;5657__mulhi3_loop_a:58lsr r2559ror r24 ; A = ((unsigned int) A) >> 1;60lsl r2261rol r23 ; B <<= 1;62rjmp __mulhi3_loop ; }6364__mulhi3_end:65; Return the result via R25:R24.66mov r24, __tmp_reg__67mov r25, __zero_reg__68; Restore __zero_reg__ to 0.69clr __zero_reg__70ret ; return S;717273