divmodqi4.S 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //===------------- divmodqi4.S - sint8 div & mod --------------------------===//
  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. // As described at
  10. // https://gcc.gnu.org/wiki/avr-gcc#Exceptions_to_the_Calling_Convention, the
  11. // prototype is `struct {sint8, sint8} __divmodqi4(sint8, sint8)`.
  12. // The sint8 quotient is returned via R24, and the sint8 remainder is returned
  13. // via R25, while registers R23/Rtmp and bit T in SREG are clobbered.
  14. //
  15. //===----------------------------------------------------------------------===//
  16. .text
  17. .align 2
  18. #ifdef __AVR_TINY__
  19. .set __tmp_reg__, 16
  20. #else
  21. .set __tmp_reg__, 0
  22. #endif
  23. .globl __divmodqi4
  24. .type __divmodqi4, @function
  25. __divmodqi4:
  26. bst r24, 7
  27. mov __tmp_reg__, r24
  28. eor __tmp_reg__, r22
  29. sbrc r24, 7
  30. neg r24
  31. sbrc r22, 7
  32. neg r22
  33. rcall __udivmodqi4 ; Call __udivmodqi4 to do real calculation.
  34. brtc __divmodqi4_1
  35. neg r25
  36. __divmodqi4_1:
  37. sbrc __tmp_reg__, 7
  38. neg r24
  39. ret ; Return quotient via R24 and remainder via R25.