csum_copy.S 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /* csum_copy.S: Checksum+copy code for sparc64
  2. *
  3. * Copyright (C) 2005 David S. Miller <davem@davemloft.net>
  4. */
  5. #include <asm/export.h>
  6. #ifdef __KERNEL__
  7. #define GLOBAL_SPARE %g7
  8. #else
  9. #define GLOBAL_SPARE %g5
  10. #endif
  11. #ifndef EX_LD
  12. #define EX_LD(x) x
  13. #endif
  14. #ifndef EX_ST
  15. #define EX_ST(x) x
  16. #endif
  17. #ifndef EX_RETVAL
  18. #define EX_RETVAL(x) x
  19. #endif
  20. #ifndef LOAD
  21. #define LOAD(type,addr,dest) type [addr], dest
  22. #endif
  23. #ifndef STORE
  24. #define STORE(type,src,addr) type src, [addr]
  25. #endif
  26. #ifndef FUNC_NAME
  27. #define FUNC_NAME csum_partial_copy_nocheck
  28. #endif
  29. .register %g2, #scratch
  30. .register %g3, #scratch
  31. .text
  32. 90:
  33. /* We checked for zero length already, so there must be
  34. * at least one byte.
  35. */
  36. be,pt %icc, 1f
  37. nop
  38. EX_LD(LOAD(ldub, %o0 + 0x00, %o4))
  39. add %o0, 1, %o0
  40. sub %o2, 1, %o2
  41. EX_ST(STORE(stb, %o4, %o1 + 0x00))
  42. add %o1, 1, %o1
  43. 1: andcc %o0, 0x2, %g0
  44. be,pn %icc, 80f
  45. cmp %o2, 2
  46. blu,pn %icc, 60f
  47. nop
  48. EX_LD(LOAD(lduh, %o0 + 0x00, %o5))
  49. add %o0, 2, %o0
  50. sub %o2, 2, %o2
  51. EX_ST(STORE(sth, %o5, %o1 + 0x00))
  52. add %o1, 2, %o1
  53. ba,pt %xcc, 80f
  54. add %o5, %o4, %o4
  55. .globl FUNC_NAME
  56. EXPORT_SYMBOL(FUNC_NAME)
  57. FUNC_NAME: /* %o0=src, %o1=dst, %o2=len, %o3=sum */
  58. LOAD(prefetch, %o0 + 0x000, #n_reads)
  59. xor %o0, %o1, %g1
  60. clr %o4
  61. andcc %g1, 0x3, %g0
  62. bne,pn %icc, 95f
  63. LOAD(prefetch, %o0 + 0x040, #n_reads)
  64. brz,pn %o2, 70f
  65. andcc %o0, 0x3, %g0
  66. /* We "remember" whether the lowest bit in the address
  67. * was set in GLOBAL_SPARE. Because if it is, we have to swap
  68. * upper and lower 8 bit fields of the sum we calculate.
  69. */
  70. bne,pn %icc, 90b
  71. andcc %o0, 0x1, GLOBAL_SPARE
  72. 80:
  73. LOAD(prefetch, %o0 + 0x080, #n_reads)
  74. andncc %o2, 0x3f, %g3
  75. LOAD(prefetch, %o0 + 0x0c0, #n_reads)
  76. sub %o2, %g3, %o2
  77. brz,pn %g3, 2f
  78. LOAD(prefetch, %o0 + 0x100, #n_reads)
  79. /* So that we don't need to use the non-pairing
  80. * add-with-carry instructions we accumulate 32-bit
  81. * values into a 64-bit register. At the end of the
  82. * loop we fold it down to 32-bits and so on.
  83. */
  84. ba,pt %xcc, 1f
  85. LOAD(prefetch, %o0 + 0x140, #n_reads)
  86. .align 32
  87. 1: EX_LD(LOAD(lduw, %o0 + 0x00, %o5))
  88. EX_LD(LOAD(lduw, %o0 + 0x04, %g1))
  89. EX_LD(LOAD(lduw, %o0 + 0x08, %g2))
  90. add %o4, %o5, %o4
  91. EX_ST(STORE(stw, %o5, %o1 + 0x00))
  92. EX_LD(LOAD(lduw, %o0 + 0x0c, %o5))
  93. add %o4, %g1, %o4
  94. EX_ST(STORE(stw, %g1, %o1 + 0x04))
  95. EX_LD(LOAD(lduw, %o0 + 0x10, %g1))
  96. add %o4, %g2, %o4
  97. EX_ST(STORE(stw, %g2, %o1 + 0x08))
  98. EX_LD(LOAD(lduw, %o0 + 0x14, %g2))
  99. add %o4, %o5, %o4
  100. EX_ST(STORE(stw, %o5, %o1 + 0x0c))
  101. EX_LD(LOAD(lduw, %o0 + 0x18, %o5))
  102. add %o4, %g1, %o4
  103. EX_ST(STORE(stw, %g1, %o1 + 0x10))
  104. EX_LD(LOAD(lduw, %o0 + 0x1c, %g1))
  105. add %o4, %g2, %o4
  106. EX_ST(STORE(stw, %g2, %o1 + 0x14))
  107. EX_LD(LOAD(lduw, %o0 + 0x20, %g2))
  108. add %o4, %o5, %o4
  109. EX_ST(STORE(stw, %o5, %o1 + 0x18))
  110. EX_LD(LOAD(lduw, %o0 + 0x24, %o5))
  111. add %o4, %g1, %o4
  112. EX_ST(STORE(stw, %g1, %o1 + 0x1c))
  113. EX_LD(LOAD(lduw, %o0 + 0x28, %g1))
  114. add %o4, %g2, %o4
  115. EX_ST(STORE(stw, %g2, %o1 + 0x20))
  116. EX_LD(LOAD(lduw, %o0 + 0x2c, %g2))
  117. add %o4, %o5, %o4
  118. EX_ST(STORE(stw, %o5, %o1 + 0x24))
  119. EX_LD(LOAD(lduw, %o0 + 0x30, %o5))
  120. add %o4, %g1, %o4
  121. EX_ST(STORE(stw, %g1, %o1 + 0x28))
  122. EX_LD(LOAD(lduw, %o0 + 0x34, %g1))
  123. add %o4, %g2, %o4
  124. EX_ST(STORE(stw, %g2, %o1 + 0x2c))
  125. EX_LD(LOAD(lduw, %o0 + 0x38, %g2))
  126. add %o4, %o5, %o4
  127. EX_ST(STORE(stw, %o5, %o1 + 0x30))
  128. EX_LD(LOAD(lduw, %o0 + 0x3c, %o5))
  129. add %o4, %g1, %o4
  130. EX_ST(STORE(stw, %g1, %o1 + 0x34))
  131. LOAD(prefetch, %o0 + 0x180, #n_reads)
  132. add %o4, %g2, %o4
  133. EX_ST(STORE(stw, %g2, %o1 + 0x38))
  134. subcc %g3, 0x40, %g3
  135. add %o0, 0x40, %o0
  136. add %o4, %o5, %o4
  137. EX_ST(STORE(stw, %o5, %o1 + 0x3c))
  138. bne,pt %icc, 1b
  139. add %o1, 0x40, %o1
  140. 2: and %o2, 0x3c, %g3
  141. brz,pn %g3, 2f
  142. sub %o2, %g3, %o2
  143. 1: EX_LD(LOAD(lduw, %o0 + 0x00, %o5))
  144. subcc %g3, 0x4, %g3
  145. add %o0, 0x4, %o0
  146. add %o4, %o5, %o4
  147. EX_ST(STORE(stw, %o5, %o1 + 0x00))
  148. bne,pt %icc, 1b
  149. add %o1, 0x4, %o1
  150. 2:
  151. /* fold 64-->32 */
  152. srlx %o4, 32, %o5
  153. srl %o4, 0, %o4
  154. add %o4, %o5, %o4
  155. srlx %o4, 32, %o5
  156. srl %o4, 0, %o4
  157. add %o4, %o5, %o4
  158. /* fold 32-->16 */
  159. sethi %hi(0xffff0000), %g1
  160. srl %o4, 16, %o5
  161. andn %o4, %g1, %g2
  162. add %o5, %g2, %o4
  163. srl %o4, 16, %o5
  164. andn %o4, %g1, %g2
  165. add %o5, %g2, %o4
  166. 60:
  167. /* %o4 has the 16-bit sum we have calculated so-far. */
  168. cmp %o2, 2
  169. blu,pt %icc, 1f
  170. nop
  171. EX_LD(LOAD(lduh, %o0 + 0x00, %o5))
  172. sub %o2, 2, %o2
  173. add %o0, 2, %o0
  174. add %o4, %o5, %o4
  175. EX_ST(STORE(sth, %o5, %o1 + 0x00))
  176. add %o1, 0x2, %o1
  177. 1: brz,pt %o2, 1f
  178. nop
  179. EX_LD(LOAD(ldub, %o0 + 0x00, %o5))
  180. sub %o2, 1, %o2
  181. add %o0, 1, %o0
  182. EX_ST(STORE(stb, %o5, %o1 + 0x00))
  183. sllx %o5, 8, %o5
  184. add %o1, 1, %o1
  185. add %o4, %o5, %o4
  186. 1:
  187. /* fold 32-->16 */
  188. sethi %hi(0xffff0000), %g1
  189. srl %o4, 16, %o5
  190. andn %o4, %g1, %g2
  191. add %o5, %g2, %o4
  192. srl %o4, 16, %o5
  193. andn %o4, %g1, %g2
  194. add %o5, %g2, %o4
  195. 1: brz,pt GLOBAL_SPARE, 1f
  196. nop
  197. /* We started with an odd byte, byte-swap the result. */
  198. srl %o4, 8, %o5
  199. and %o4, 0xff, %g1
  200. sll %g1, 8, %g1
  201. or %o5, %g1, %o4
  202. 1: addcc %o3, %o4, %o3
  203. addc %g0, %o3, %o3
  204. 70:
  205. retl
  206. srl %o3, 0, %o0
  207. 95: mov 0, GLOBAL_SPARE
  208. brlez,pn %o2, 4f
  209. andcc %o0, 1, %o5
  210. be,a,pt %icc, 1f
  211. srl %o2, 1, %g1
  212. sub %o2, 1, %o2
  213. EX_LD(LOAD(ldub, %o0, GLOBAL_SPARE))
  214. add %o0, 1, %o0
  215. EX_ST(STORE(stb, GLOBAL_SPARE, %o1))
  216. srl %o2, 1, %g1
  217. add %o1, 1, %o1
  218. 1: brz,a,pn %g1, 3f
  219. andcc %o2, 1, %g0
  220. andcc %o0, 2, %g0
  221. be,a,pt %icc, 1f
  222. srl %g1, 1, %g1
  223. EX_LD(LOAD(lduh, %o0, %o4))
  224. sub %o2, 2, %o2
  225. srl %o4, 8, %g2
  226. sub %g1, 1, %g1
  227. EX_ST(STORE(stb, %g2, %o1))
  228. add %o4, GLOBAL_SPARE, GLOBAL_SPARE
  229. EX_ST(STORE(stb, %o4, %o1 + 1))
  230. add %o0, 2, %o0
  231. srl %g1, 1, %g1
  232. add %o1, 2, %o1
  233. 1: brz,a,pn %g1, 2f
  234. andcc %o2, 2, %g0
  235. EX_LD(LOAD(lduw, %o0, %o4))
  236. 5: srl %o4, 24, %g2
  237. srl %o4, 16, %g3
  238. EX_ST(STORE(stb, %g2, %o1))
  239. srl %o4, 8, %g2
  240. EX_ST(STORE(stb, %g3, %o1 + 1))
  241. add %o0, 4, %o0
  242. EX_ST(STORE(stb, %g2, %o1 + 2))
  243. addcc %o4, GLOBAL_SPARE, GLOBAL_SPARE
  244. EX_ST(STORE(stb, %o4, %o1 + 3))
  245. addc GLOBAL_SPARE, %g0, GLOBAL_SPARE
  246. add %o1, 4, %o1
  247. subcc %g1, 1, %g1
  248. bne,a,pt %icc, 5b
  249. EX_LD(LOAD(lduw, %o0, %o4))
  250. sll GLOBAL_SPARE, 16, %g2
  251. srl GLOBAL_SPARE, 16, GLOBAL_SPARE
  252. srl %g2, 16, %g2
  253. andcc %o2, 2, %g0
  254. add %g2, GLOBAL_SPARE, GLOBAL_SPARE
  255. 2: be,a,pt %icc, 3f
  256. andcc %o2, 1, %g0
  257. EX_LD(LOAD(lduh, %o0, %o4))
  258. andcc %o2, 1, %g0
  259. srl %o4, 8, %g2
  260. add %o0, 2, %o0
  261. EX_ST(STORE(stb, %g2, %o1))
  262. add GLOBAL_SPARE, %o4, GLOBAL_SPARE
  263. EX_ST(STORE(stb, %o4, %o1 + 1))
  264. add %o1, 2, %o1
  265. 3: be,a,pt %icc, 1f
  266. sll GLOBAL_SPARE, 16, %o4
  267. EX_LD(LOAD(ldub, %o0, %g2))
  268. sll %g2, 8, %o4
  269. EX_ST(STORE(stb, %g2, %o1))
  270. add GLOBAL_SPARE, %o4, GLOBAL_SPARE
  271. sll GLOBAL_SPARE, 16, %o4
  272. 1: addcc %o4, GLOBAL_SPARE, GLOBAL_SPARE
  273. srl GLOBAL_SPARE, 16, %o4
  274. addc %g0, %o4, GLOBAL_SPARE
  275. brz,pt %o5, 4f
  276. srl GLOBAL_SPARE, 8, %o4
  277. and GLOBAL_SPARE, 0xff, %g2
  278. and %o4, 0xff, %o4
  279. sll %g2, 8, %g2
  280. or %g2, %o4, GLOBAL_SPARE
  281. 4: addcc %o3, GLOBAL_SPARE, %o3
  282. addc %g0, %o3, %o0
  283. retl
  284. srl %o0, 0, %o0
  285. .size FUNC_NAME, .-FUNC_NAME