checksumcopy.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * A fast checksum+copy routine using movem
  3. * Copyright (c) 1998, 2001 Axis Communications AB
  4. *
  5. * Authors: Bjorn Wesen
  6. *
  7. * csum_partial_copy_nocheck(const char *src, char *dst,
  8. * int len, unsigned int sum)
  9. */
  10. .globl csum_partial_copy_nocheck
  11. csum_partial_copy_nocheck:
  12. ;; r10 - src
  13. ;; r11 - dst
  14. ;; r12 - length
  15. ;; r13 - checksum
  16. ;; check for breakeven length between movem and normal word looping versions
  17. ;; we also do _NOT_ want to compute a checksum over more than the
  18. ;; actual length when length < 40
  19. cmpu.w 80, $r12
  20. blo _word_loop
  21. nop
  22. ;; need to save the registers we use below in the movem loop
  23. ;; this overhead is why we have a check above for breakeven length
  24. ;; only r0 - r8 have to be saved, the other ones are clobber-able
  25. ;; according to the ABI
  26. subq 9*4, $sp
  27. movem $r8, [$sp]
  28. ;; do a movem copy and checksum
  29. subq 10*4, $r12 ; update length for the first loop
  30. _mloop: movem [$r10+],$r9 ; read 10 longwords
  31. 1: ;; A failing userspace access will have this as PC.
  32. movem $r9,[$r11+] ; write 10 longwords
  33. ;; perform dword checksumming on the 10 longwords
  34. add.d $r0,$r13
  35. ax
  36. add.d $r1,$r13
  37. ax
  38. add.d $r2,$r13
  39. ax
  40. add.d $r3,$r13
  41. ax
  42. add.d $r4,$r13
  43. ax
  44. add.d $r5,$r13
  45. ax
  46. add.d $r6,$r13
  47. ax
  48. add.d $r7,$r13
  49. ax
  50. add.d $r8,$r13
  51. ax
  52. add.d $r9,$r13
  53. ;; fold the carry into the checksum, to avoid having to loop the carry
  54. ;; back into the top
  55. ax
  56. addq 0,$r13
  57. subq 10*4,$r12
  58. bge _mloop
  59. nop
  60. addq 10*4,$r12 ; compensate for last loop underflowing length
  61. movem [$sp+],$r8 ; restore regs
  62. _word_loop:
  63. ;; only fold if there is anything to fold.
  64. cmpq 0,$r13
  65. beq _no_fold
  66. ;; fold 32-bit checksum into a 16-bit checksum, to avoid carries below
  67. ;; r9 can be used as temporary.
  68. move.d $r13,$r9
  69. lsrq 16,$r9 ; r0 = checksum >> 16
  70. and.d 0xffff,$r13 ; checksum = checksum & 0xffff
  71. add.d $r9,$r13 ; checksum += r0
  72. _no_fold:
  73. cmpq 2,$r12
  74. blt _no_words
  75. nop
  76. ;; copy and checksum the rest of the words
  77. subq 2,$r12
  78. _wloop: move.w [$r10+],$r9
  79. 2: ;; A failing userspace access will have this as PC.
  80. addu.w $r9,$r13
  81. subq 2,$r12
  82. bge _wloop
  83. move.w $r9,[$r11+]
  84. addq 2,$r12
  85. _no_words:
  86. ;; see if we have one odd byte more
  87. cmpq 1,$r12
  88. beq _do_byte
  89. nop
  90. ret
  91. move.d $r13, $r10
  92. _do_byte:
  93. ;; copy and checksum the last byte
  94. move.b [$r10],$r9
  95. 3: ;; A failing userspace access will have this as PC.
  96. addu.b $r9,$r13
  97. move.b $r9,[$r11]
  98. ret
  99. move.d $r13, $r10