1 //===------------ mulhi3.S - int16 multiplication -------------------------===//
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 // The corresponding C code is something like:
11 // int __mulhi3(int A, int B) {
16 // A = ((unsigned int) A) >> 1;
22 // __mulhi3 has special ABI, as the implementation of libgcc, R25:R24 is used
23 // to return result, while Rtmp/R21/R22/R23 are clobbered.
25 //===----------------------------------------------------------------------===//
39 .type __mulhi3, @function
42 ; Use Rzero:Rtmp to store the result.
44 clr __zero_reg__ ; S = 0;
50 breq __mulhi3_end ; while (A != 0) {
54 breq __mulhi3_loop_a ; if (A & 1)
56 adc __zero_reg__, r23 ; S += B;
60 ror r24 ; A = ((unsigned int) A) >> 1;
63 rjmp __mulhi3_loop ; }
66 ; Return the result via R25:R24.
69 ; Restore __zero_reg__ to 0.