modsi3.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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(__modsi3)
  6. abi_entry_default
  7. #if XCHAL_HAVE_DIV32
  8. rems a2, a2, a3
  9. #else
  10. mov a7, a2 /* save original (signed) dividend */
  11. do_abs a2, a2, a4 /* udividend = abs (dividend) */
  12. do_abs a3, a3, a4 /* udivisor = abs (divisor) */
  13. bltui a3, 2, .Lle_one /* check if udivisor <= 1 */
  14. do_nsau a5, a2, a6, a8 /* udividend_shift = nsau (udividend) */
  15. do_nsau a4, a3, a6, a8 /* udivisor_shift = nsau (udivisor) */
  16. bgeu a5, a4, .Lspecial
  17. sub a4, a4, a5 /* count = udivisor_shift - udividend_shift */
  18. ssl a4
  19. sll a3, a3 /* udivisor <<= count */
  20. /* test-subtract-and-shift loop */
  21. #if XCHAL_HAVE_LOOPS
  22. loopnez a4, .Lloopend
  23. #endif /* XCHAL_HAVE_LOOPS */
  24. .Lloop:
  25. bltu a2, a3, .Lzerobit
  26. sub a2, a2, a3
  27. .Lzerobit:
  28. srli a3, a3, 1
  29. #if !XCHAL_HAVE_LOOPS
  30. addi a4, a4, -1
  31. bnez a4, .Lloop
  32. #endif /* !XCHAL_HAVE_LOOPS */
  33. .Lloopend:
  34. .Lspecial:
  35. bltu a2, a3, .Lreturn
  36. sub a2, a2, a3 /* subtract again if udividend >= udivisor */
  37. .Lreturn:
  38. bgez a7, .Lpositive
  39. neg a2, a2 /* if (dividend < 0), return -udividend */
  40. .Lpositive:
  41. abi_ret_default
  42. .Lle_one:
  43. bnez a3, .Lreturn0
  44. /* Divide by zero: Use an illegal instruction to force an exception.
  45. The subsequent "DIV0" string can be recognized by the exception
  46. handler to identify the real cause of the exception. */
  47. ill
  48. .ascii "DIV0"
  49. .Lreturn0:
  50. movi a2, 0
  51. #endif /* XCHAL_HAVE_DIV32 */
  52. abi_ret_default
  53. ENDPROC(__modsi3)
  54. #if !XCHAL_HAVE_NSA
  55. .section .rodata
  56. .align 4
  57. .global __nsau_data
  58. .type __nsau_data, @object
  59. __nsau_data:
  60. .byte 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4
  61. .byte 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
  62. .byte 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
  63. .byte 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
  64. .byte 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  65. .byte 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  66. .byte 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  67. .byte 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  68. .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  69. .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  70. .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  71. .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  72. .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  73. .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  74. .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  75. .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  76. .size __nsau_data, . - __nsau_data
  77. #endif /* !XCHAL_HAVE_NSA */