modsi3.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * File: arch/blackfin/lib/modsi3.S
  3. * Based on:
  4. * Author:
  5. *
  6. * Created:
  7. * Description: This program computes 32 bit signed remainder. It calls div32 function
  8. * for quotient estimation.
  9. *
  10. * Registers used :
  11. * Numerator/ Denominator in R0, R1
  12. * R0 - returns remainder.
  13. * R2-R7
  14. *
  15. * Modified:
  16. * Copyright 2004-2006 Analog Devices Inc.
  17. *
  18. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  19. *
  20. * This program is free software; you can redistribute it and/or modify
  21. * it under the terms of the GNU General Public License as published by
  22. * the Free Software Foundation; either version 2 of the License, or
  23. * (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this program; if not, see the file COPYING, or write
  32. * to the Free Software Foundation, Inc.,
  33. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  34. */
  35. .global ___modsi3;
  36. .type ___modsi3, STT_FUNC;
  37. .extern ___divsi3;
  38. .type ___divsi3, STT_FUNC;
  39. #ifdef CONFIG_ARITHMETIC_OPS_L1
  40. .section .l1.text
  41. #else
  42. .text
  43. #endif
  44. ___modsi3:
  45. CC=R0==0;
  46. IF CC JUMP .LRETURN_R0; /* Return 0, if numerator == 0 */
  47. CC=R1==0;
  48. IF CC JUMP .LRETURN_ZERO; /* Return 0, if denominator == 0 */
  49. CC=R0==R1;
  50. IF CC JUMP .LRETURN_ZERO; /* Return 0, if numerator == denominator */
  51. CC = R1 == 1;
  52. IF CC JUMP .LRETURN_ZERO; /* Return 0, if denominator == 1 */
  53. CC = R1 == -1;
  54. IF CC JUMP .LRETURN_ZERO; /* Return 0, if denominator == -1 */
  55. /* Valid input. Use __divsi3() to compute the quotient, and then
  56. * derive the remainder from that. */
  57. [--SP] = (R7:6); /* Push R7 and R6 */
  58. [--SP] = RETS; /* and return address */
  59. R7 = R0; /* Copy of R0 */
  60. R6 = R1; /* Save for later */
  61. SP += -12; /* Should always provide this space */
  62. CALL ___divsi3; /* Compute signed quotient using ___divsi3()*/
  63. SP += 12;
  64. R0 *= R6; /* Quotient * divisor */
  65. R0 = R7 - R0; /* Dividend - (quotient * divisor) */
  66. RETS = [SP++]; /* Get back return address */
  67. (R7:6) = [SP++]; /* Pop registers R7 and R4 */
  68. RTS; /* Store remainder */
  69. .LRETURN_ZERO:
  70. R0 = 0;
  71. .LRETURN_R0:
  72. RTS;
  73. .size ___modsi3, .-___modsi3