umodsi3.S 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Unsigned 32 bit modulo optimized for Epiphany.
  2. Copyright (C) 2009-2022 Free Software Foundation, Inc.
  3. Contributed by Embecosm on behalf of Adapteva, Inc.
  4. This file is part of GCC.
  5. This file is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published by the
  7. Free Software Foundation; either version 3, or (at your option) any
  8. later version.
  9. This file is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. Under Section 7 of GPL version 3, you are granted additional
  14. permissions described in the GCC Runtime Library Exception, version
  15. 3.1, as published by the Free Software Foundation.
  16. You should have received a copy of the GNU General Public License and
  17. a copy of the GCC Runtime Library Exception along with this program;
  18. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. <http://www.gnu.org/licenses/>. */
  20. #include "epiphany-asm.h"
  21. FSTAB (__umodsi3,T_UINT)
  22. .global SYM(__umodsi3)
  23. .balign 4
  24. HIDDEN_FUNC(__umodsi3)
  25. SYM(__umodsi3):
  26. mov r2,5
  27. lsl r2,r2,29 ; 0xa0000000
  28. orr r3,r2,r0
  29. lsr r15,r0,16
  30. movt r15,0xa800
  31. movne r3,r15
  32. lsr r16,r2,2 ; 0x28000000
  33. and r15,r3,r16
  34. fadd r12,r3,r15
  35. orr r3,r2,r1
  36. lsr r2,r1,16
  37. movt r2,0xa800
  38. movne r3,r2
  39. and r2,r16,r3
  40. fadd r3,r3,r2
  41. sub r2,r0,r1
  42. bltu .Lret_a
  43. lsr r12,r12,23
  44. mov r2,%low(.L0step)
  45. movt r2,%high(.L0step)
  46. lsr r3,r3,23
  47. sub r3,r12,r3 ; calculate bit number difference.
  48. lsl r3,r3,3
  49. sub r2,r2,r3
  50. jr r2
  51. /* lsl_l r2,r1,n` sub r2,r0,r2` movgteu r0,r2 */
  52. #define STEP(n) .long 0x0006441f | (n) << 5` sub r2,r0,r2` movgteu r0,r2
  53. .balign 8,,2
  54. STEP(31)` STEP(30)` STEP(29)` STEP(28)`
  55. STEP(27)` STEP(26)` STEP(25)` STEP(24)`
  56. STEP(23)` STEP(22)` STEP(21)` STEP(20)`
  57. STEP(19)` STEP(18)` STEP(17)` STEP(16)`
  58. STEP(15)` STEP(14)` STEP(13)` STEP(12)`
  59. STEP(11)` STEP(10)` STEP(9)` STEP(8)`
  60. STEP(7)` STEP(6)` STEP(5)` STEP(4)` STEP(3)` STEP(2)` STEP(1)
  61. .L0step:STEP(0)
  62. .Lret_a:rts
  63. ENDFUNC(__umodsi3)