Path: blob/main/contrib/llvm-project/compiler-rt/lib/builtins/avr/mulqi3.S
35290 views
//===------------ mulhi3.S - int8 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// char __mulqi3(char A, char B) {11// int S = 0;12// while (A != 0) {13// if (A & 1)14// S += B;15// B <<= 1;16// A = ((unsigned char) A) >> 1;17// }18// return S;19// }20//21// __mulqi3 has special ABI, as the implementation of libgcc, the result is22// returned via R24, while Rtmp and R22 are clobbered.23//24//===----------------------------------------------------------------------===//2526.text27.align 22829#ifdef __AVR_TINY__30.set __tmp_reg__, 1631#else32.set __tmp_reg__, 033#endif3435.globl __mulqi336.type __mulqi3, @function3738__mulqi3:39clr __tmp_reg__ ; S = 0;4041__mulqi3_loop:42cpi r24, 043breq __mulqi3_end ; while (A != 0) {44sbrc r24, 0 ; if (A & 1)45add __tmp_reg__, r22 ; S += B;46add r22, r22 ; B <<= 1;47lsr r24 ; A = ((unsigned char) A) >> 1;48rjmp __mulqi3_loop ; }4950__mulqi3_end:51mov r24, __tmp_reg__52ret ; return S;535455