modsi3.S 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * This program computes 32 bit signed remainder. It calls div32 function
  3. * for quotient estimation.
  4. * Registers in: R0, R1 = Numerator/ Denominator
  5. * Registers out: R0 = Remainder
  6. *
  7. * Copyright 2004-2009 Analog Devices Inc.
  8. *
  9. * Licensed under the Clear BSD license or the GPL-2 (or later)
  10. */
  11. .global ___modsi3;
  12. .type ___modsi3, STT_FUNC;
  13. .extern ___divsi3;
  14. .type ___divsi3, STT_FUNC;
  15. #ifdef CONFIG_ARITHMETIC_OPS_L1
  16. .section .l1.text
  17. #else
  18. .text
  19. #endif
  20. ___modsi3:
  21. CC=R0==0;
  22. IF CC JUMP .LRETURN_R0; /* Return 0, if numerator == 0 */
  23. CC=R1==0;
  24. IF CC JUMP .LRETURN_ZERO; /* Return 0, if denominator == 0 */
  25. CC=R0==R1;
  26. IF CC JUMP .LRETURN_ZERO; /* Return 0, if numerator == denominator */
  27. CC = R1 == 1;
  28. IF CC JUMP .LRETURN_ZERO; /* Return 0, if denominator == 1 */
  29. CC = R1 == -1;
  30. IF CC JUMP .LRETURN_ZERO; /* Return 0, if denominator == -1 */
  31. /* Valid input. Use __divsi3() to compute the quotient, and then
  32. * derive the remainder from that. */
  33. [--SP] = (R7:6); /* Push R7 and R6 */
  34. [--SP] = RETS; /* and return address */
  35. R7 = R0; /* Copy of R0 */
  36. R6 = R1; /* Save for later */
  37. SP += -12; /* Should always provide this space */
  38. CALL ___divsi3; /* Compute signed quotient using ___divsi3()*/
  39. SP += 12;
  40. R0 *= R6; /* Quotient * divisor */
  41. R0 = R7 - R0; /* Dividend - (quotient * divisor) */
  42. RETS = [SP++]; /* Get back return address */
  43. (R7:6) = [SP++]; /* Pop registers R7 and R4 */
  44. RTS; /* Store remainder */
  45. .LRETURN_ZERO:
  46. R0 = 0;
  47. .LRETURN_R0:
  48. RTS;
  49. .size ___modsi3, .-___modsi3