mpvecadd.s 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #define BDNZ BC 16,0,
  2. #define BDNE BC 0,2,
  3. /*
  4. * mpvecadd(mpdigit *a, int alen, mpdigit *b, int blen, mpdigit *sum)
  5. *
  6. * sum[0:alen] = a[0:alen-1] + b[0:blen-1]
  7. *
  8. * prereq: alen >= blen, sum has room for alen+1 digits
  9. *
  10. * R3 == a (first arg passed in R3)
  11. * R4 == alen
  12. * R5 == b
  13. * R6 == blen
  14. * R7 == sum
  15. * R8 == temporary
  16. * R9 == temporary
  17. */
  18. TEXT mpvecadd(SB),$-4
  19. MOVW alen+4(FP), R4
  20. MOVW b+8(FP), R5
  21. MOVW blen+12(FP), R6
  22. MOVW sum+16(FP), R7
  23. SUB R6, R4 /* calculate counter for second loop (alen > blen) */
  24. SUB $4, R3 /* pre decrement for MOVWU's */
  25. SUB $4, R5 /* pre decrement for MOVWU's */
  26. SUB $4, R7 /* pre decrement for MOVWU's */
  27. MOVW R0, XER /* zero carry going in */
  28. /* if blen == 0, don't need to add it in */
  29. CMP R0, R6
  30. BEQ _add1
  31. /* sum[0:blen-1],carry = a[0:blen-1] + b[0:blen-1] */
  32. MOVW R6, CTR
  33. _addloop1:
  34. MOVWU 4(R3), R8
  35. MOVWU 4(R5), R9
  36. ADDE R8, R9
  37. MOVWU R9, 4(R7)
  38. BDNZ _addloop1
  39. _add1:
  40. /* if alen == blen, we're done */
  41. CMP R0, R4
  42. BEQ _addend
  43. /* sum[blen:alen-1],carry = a[blen:alen-1] + 0 + carry */
  44. MOVW R4, CTR
  45. _addloop2:
  46. MOVWU 4(R3), R8
  47. ADDE R0, R8
  48. MOVWU R8, 4(R7)
  49. BDNZ _addloop2
  50. /* sum[alen] = carry */
  51. _addend:
  52. ADDE R0, R0, R8
  53. MOVW R8, 4(R7)
  54. RETURN