reml.S 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Copyright (C) 2004-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library. If not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #include "div_libc.h"
  15. /* 32-bit signed int remainder. This is not a normal C function. Argument
  16. registers are t10 and t11, the result goes in t12. Only t12 and AT may
  17. be clobbered.
  18. The FPU can handle the division for all input values except zero.
  19. All we have to do is compute the remainder via multiply-and-subtract.
  20. The FPCR save/restore is due to the fact that the EV6 _will_ set FPCR_INE
  21. for cvttq/c even without /sui being set. It will not, however, properly
  22. raise the exception, so we don't have to worry about FPCR_INED being clear
  23. and so dying by SIGFPE. */
  24. #ifndef EXTEND
  25. #define EXTEND(S,D) sextl S, D
  26. #endif
  27. .text
  28. .align 4
  29. .globl __reml
  30. .type __reml, @funcnoplt
  31. .usepv __reml, no
  32. cfi_startproc
  33. cfi_return_column (RA)
  34. __reml:
  35. lda sp, -FRAME(sp)
  36. cfi_def_cfa_offset (FRAME)
  37. CALL_MCOUNT
  38. stt $f0, 0(sp)
  39. excb
  40. beq Y, DIVBYZERO
  41. stt $f1, 8(sp)
  42. stt $f2, 16(sp)
  43. cfi_rel_offset ($f0, 0)
  44. cfi_rel_offset ($f1, 8)
  45. cfi_rel_offset ($f2, 16)
  46. mf_fpcr $f2
  47. EXTEND (X, RV)
  48. EXTEND (Y, AT)
  49. _ITOFT2 RV, $f0, 24, AT, $f1, 32
  50. cvtqt $f0, $f0
  51. cvtqt $f1, $f1
  52. divt/c $f0, $f1, $f0
  53. cvttq/c $f0, $f0
  54. excb
  55. mt_fpcr $f2
  56. _FTOIT $f0, RV, 24
  57. ldt $f0, 0(sp)
  58. mull RV, Y, RV
  59. ldt $f1, 8(sp)
  60. ldt $f2, 16(sp)
  61. lda sp, FRAME(sp)
  62. cfi_restore ($f0)
  63. cfi_restore ($f1)
  64. cfi_restore ($f2)
  65. cfi_def_cfa_offset (0)
  66. subl X, RV, RV
  67. ret $31, (RA), 1
  68. cfi_endproc
  69. .size __reml, .-__reml
  70. DO_DIVBYZERO