divsi3-float.S 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Signed 32 bit division 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 (__divsi3,T_UINT)
  22. .global SYM(__divsi3)
  23. .balign 4
  24. HIDDEN_FUNC(__divsi3)
  25. SYM(__divsi3):
  26. float TMP2,r0
  27. mov TMP4,0
  28. float TMP1,r1
  29. sub TMP0,TMP4,r0
  30. beq .Lret_r0
  31. movgt r0,TMP0
  32. sub TMP0,TMP4,r1
  33. movgt r1,TMP0
  34. mov TMP0,1
  35. sub TMP2,TMP2,TMP1
  36. asr TMP3,TMP2,31 ; save sign
  37. lsl TMP2,TMP2,1
  38. blt .Lret0
  39. sub TMP1,TMP2,1 ; rounding compensation, avoid overflow
  40. movgte TMP2,TMP1
  41. lsr TMP2,TMP2,24
  42. lsl r1,r1,TMP2
  43. lsl TMP0,TMP0,TMP2
  44. sub TMP1,r0,r1
  45. movgteu r0,TMP1
  46. movgteu TMP4,TMP0
  47. lsl TMP5,TMP0,1
  48. sub TMP1,r0,r1
  49. movgteu r0,TMP1
  50. movgteu TMP4,TMP5
  51. sub TMP1,r1,1
  52. mov r1,%low(.L0step)
  53. movt r1,%high(.L0step)
  54. lsl TMP2,TMP2,3
  55. sub r1,r1,TMP2
  56. jr r1
  57. .rep 30
  58. lsl r0,r0,1
  59. sub.l r1,r0,TMP1
  60. movgteu r0,r1
  61. .endr
  62. .L0step:sub r1,TMP0,1 ; mask result bits from steps ...
  63. and r0,r0,r1
  64. orr r0,r0,TMP4 ; ... and combine with first bit.
  65. eor r0,r0,TMP3 ; restore sign
  66. sub r0,r0,TMP3
  67. .Lret_r0:rts
  68. .Lret0: mov r0,0
  69. rts
  70. ENDFUNC(__divsi3)