vr4120-div.S 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Support file for -mfix-vr4120.
  2. Copyright (C) 2002-2022 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. /* An executable stack is *not* required for these functions. */
  20. #include "gnustack.h"
  21. /* This file contains functions which implement divsi3 and modsi3 for
  22. -mfix-vr4120. div and ddiv do not give the correct result when one
  23. of the operands is negative. */
  24. .set nomips16
  25. #define DIV \
  26. xor $3,$4,$5 /* t = x ^ y */ ; \
  27. li $2,0x80000000; \
  28. .set noreorder; \
  29. bgez $4,1f /* x >= 0 */; \
  30. and $3,$3,$2 /* t = (x ^ y) & 0x80000000 in delay slot */ ;\
  31. .set reorder; \
  32. subu $4,$0,$4 /* x = -x */ ; \
  33. 1:; \
  34. .set noreorder; \
  35. bgez $5,2f /* y >= 0 */ ; \
  36. nop; \
  37. subu $5,$0,$5 /* y = -y */ ; \
  38. .set reorder; \
  39. 2:; \
  40. divu $0,$4,$5; /* we use divu because of INT_MIN */ \
  41. .set noreorder; \
  42. bne $5,$0,3f; \
  43. nop; \
  44. break 7 /* division on zero y */ ; \
  45. 3:; \
  46. .set reorder; \
  47. mflo $2 /* r = x / y */ ; \
  48. .set noreorder; \
  49. beq $3,$0,4f /* t == 0 */ ; \
  50. nop; \
  51. subu $2,$0,$2 /* r = -r */ ; \
  52. .set reorder; \
  53. 4:
  54. .globl __vr4120_divsi3
  55. .ent __vr4120_divsi3
  56. __vr4120_divsi3:
  57. DIV
  58. j $31
  59. .end __vr4120_divsi3
  60. .globl __vr4120_modsi3
  61. .ent __vr4120_modsi3
  62. __vr4120_modsi3:
  63. move $6,$4 # x1 = x
  64. move $7,$5 # y1 = y
  65. DIV
  66. mult $2,$7 # r = r * y1
  67. mflo $2
  68. .set noreorder
  69. j $31
  70. subu $2,$6,$2 # r = x1 - r in delay slot
  71. .end __vr4120_modsi3