umodsi3.S 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 */
  2. #include <linux/linkage.h>
  3. #include <asm/asmmacro.h>
  4. #include <asm/core.h>
  5. ENTRY(__umodsi3)
  6. abi_entry_default
  7. #if XCHAL_HAVE_DIV32
  8. remu a2, a2, a3
  9. #else
  10. bltui a3, 2, .Lle_one /* check if the divisor is <= 1 */
  11. do_nsau a5, a2, a6, a7 /* dividend_shift = nsau (dividend) */
  12. do_nsau a4, a3, a6, a7 /* divisor_shift = nsau (divisor) */
  13. bgeu a5, a4, .Lspecial
  14. sub a4, a4, a5 /* count = divisor_shift - dividend_shift */
  15. ssl a4
  16. sll a3, a3 /* divisor <<= count */
  17. /* test-subtract-and-shift loop */
  18. #if XCHAL_HAVE_LOOPS
  19. loopnez a4, .Lloopend
  20. #endif /* XCHAL_HAVE_LOOPS */
  21. .Lloop:
  22. bltu a2, a3, .Lzerobit
  23. sub a2, a2, a3
  24. .Lzerobit:
  25. srli a3, a3, 1
  26. #if !XCHAL_HAVE_LOOPS
  27. addi a4, a4, -1
  28. bnez a4, .Lloop
  29. #endif /* !XCHAL_HAVE_LOOPS */
  30. .Lloopend:
  31. .Lspecial:
  32. bltu a2, a3, .Lreturn
  33. sub a2, a2, a3 /* subtract once more if dividend >= divisor */
  34. .Lreturn:
  35. abi_ret_default
  36. .Lle_one:
  37. bnez a3, .Lreturn0
  38. /* Divide by zero: Use an illegal instruction to force an exception.
  39. The subsequent "DIV0" string can be recognized by the exception
  40. handler to identify the real cause of the exception. */
  41. ill
  42. .ascii "DIV0"
  43. .Lreturn0:
  44. movi a2, 0
  45. #endif /* XCHAL_HAVE_DIV32 */
  46. abi_ret_default
  47. ENDPROC(__umodsi3)