1*810390e3Srobert//===------------ mulhi3.S - int8 multiplication --------------------------===//
2*810390e3Srobert//
3*810390e3Srobert// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*810390e3Srobert// See https://llvm.org/LICENSE.txt for license information.
5*810390e3Srobert// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*810390e3Srobert//
7*810390e3Srobert//===----------------------------------------------------------------------===//
8*810390e3Srobert//
9*810390e3Srobert// The corresponding C code is something like:
10*810390e3Srobert//
11*810390e3Srobert// char __mulqi3(char A, char B) {
12*810390e3Srobert//   int S = 0;
13*810390e3Srobert//   while (A != 0) {
14*810390e3Srobert//     if (A & 1)
15*810390e3Srobert//       S += B;
16*810390e3Srobert//     B <<= 1;
17*810390e3Srobert//     A = ((unsigned char) A) >> 1;
18*810390e3Srobert//   }
19*810390e3Srobert//   return S;
20*810390e3Srobert// }
21*810390e3Srobert//
22*810390e3Srobert// __mulqi3 has special ABI, as the implementation of libgcc, the result is
23*810390e3Srobert// returned via R24, while Rtmp and R22 are clobbered.
24*810390e3Srobert//
25*810390e3Srobert//===----------------------------------------------------------------------===//
26*810390e3Srobert
27*810390e3Srobert	.text
28*810390e3Srobert	.align 2
29*810390e3Srobert
30*810390e3Srobert#ifdef __AVR_TINY__
31*810390e3Srobert	.set __tmp_reg__, 16
32*810390e3Srobert#else
33*810390e3Srobert	.set __tmp_reg__, 0
34*810390e3Srobert#endif
35*810390e3Srobert
36*810390e3Srobert	.globl __mulqi3
37*810390e3Srobert	.type  __mulqi3, @function
38*810390e3Srobert
39*810390e3Srobert__mulqi3:
40*810390e3Srobert	clr   __tmp_reg__              ; S = 0;
41*810390e3Srobert
42*810390e3Srobert__mulqi3_loop:
43*810390e3Srobert	cpi   r24, 0
44*810390e3Srobert	breq  __mulqi3_end             ; while (A != 0) {
45*810390e3Srobert	sbrc  r24, 0                   ;   if (A & 1)
46*810390e3Srobert	add   __tmp_reg__, r22         ;     S += B;
47*810390e3Srobert	add   r22, r22                 ;   B <<= 1;
48*810390e3Srobert	lsr   r24                      ;   A = ((unsigned char) A) >> 1;
49*810390e3Srobert	rjmp  __mulqi3_loop            ; }
50*810390e3Srobert
51*810390e3Srobert__mulqi3_end:
52*810390e3Srobert	mov   r24, __tmp_reg__
53*810390e3Srobert	ret                            ; return S;
54