mulqi3.S 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //===------------ mulhi3.S - int8 multiplication --------------------------===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // The corresponding C code is something like:
  10. //
  11. // char __mulqi3(char A, char B) {
  12. // int S = 0;
  13. // while (A != 0) {
  14. // if (A & 1)
  15. // S += B;
  16. // B <<= 1;
  17. // A = ((unsigned char) A) >> 1;
  18. // }
  19. // return S;
  20. // }
  21. //
  22. // __mulqi3 has special ABI, as the implementation of libgcc, the result is
  23. // returned via R24, while Rtmp and R22 are clobbered.
  24. //
  25. //===----------------------------------------------------------------------===//
  26. .text
  27. .align 2
  28. #ifdef __AVR_TINY__
  29. .set __tmp_reg__, 16
  30. #else
  31. .set __tmp_reg__, 0
  32. #endif
  33. .globl __mulqi3
  34. .type __mulqi3, @function
  35. __mulqi3:
  36. clr __tmp_reg__ ; S = 0;
  37. __mulqi3_loop:
  38. cpi r24, 0
  39. breq __mulqi3_end ; while (A != 0) {
  40. sbrc r24, 0 ; if (A & 1)
  41. add __tmp_reg__, r22 ; S += B;
  42. add r22, r22 ; B <<= 1;
  43. lsr r24 ; A = ((unsigned char) A) >> 1;
  44. rjmp __mulqi3_loop ; }
  45. __mulqi3_end:
  46. mov r24, __tmp_reg__
  47. ret ; return S;