1
0

blake2s_amd64.s 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. // Copyright 2016 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build amd64,!gccgo,!appengine
  5. #include "textflag.h"
  6. DATA iv0<>+0x00(SB)/4, $0x6a09e667
  7. DATA iv0<>+0x04(SB)/4, $0xbb67ae85
  8. DATA iv0<>+0x08(SB)/4, $0x3c6ef372
  9. DATA iv0<>+0x0c(SB)/4, $0xa54ff53a
  10. GLOBL iv0<>(SB), (NOPTR+RODATA), $16
  11. DATA iv1<>+0x00(SB)/4, $0x510e527f
  12. DATA iv1<>+0x04(SB)/4, $0x9b05688c
  13. DATA iv1<>+0x08(SB)/4, $0x1f83d9ab
  14. DATA iv1<>+0x0c(SB)/4, $0x5be0cd19
  15. GLOBL iv1<>(SB), (NOPTR+RODATA), $16
  16. DATA rol16<>+0x00(SB)/8, $0x0504070601000302
  17. DATA rol16<>+0x08(SB)/8, $0x0D0C0F0E09080B0A
  18. GLOBL rol16<>(SB), (NOPTR+RODATA), $16
  19. DATA rol8<>+0x00(SB)/8, $0x0407060500030201
  20. DATA rol8<>+0x08(SB)/8, $0x0C0F0E0D080B0A09
  21. GLOBL rol8<>(SB), (NOPTR+RODATA), $16
  22. DATA counter<>+0x00(SB)/8, $0x40
  23. DATA counter<>+0x08(SB)/8, $0x0
  24. GLOBL counter<>(SB), (NOPTR+RODATA), $16
  25. #define ROTL_SSE2(n, t, v) \
  26. MOVO v, t; \
  27. PSLLL $n, t; \
  28. PSRLL $(32-n), v; \
  29. PXOR t, v
  30. #define ROTL_SSSE3(c, v) \
  31. PSHUFB c, v
  32. #define ROUND_SSE2(v0, v1, v2, v3, m0, m1, m2, m3, t) \
  33. PADDL m0, v0; \
  34. PADDL v1, v0; \
  35. PXOR v0, v3; \
  36. ROTL_SSE2(16, t, v3); \
  37. PADDL v3, v2; \
  38. PXOR v2, v1; \
  39. ROTL_SSE2(20, t, v1); \
  40. PADDL m1, v0; \
  41. PADDL v1, v0; \
  42. PXOR v0, v3; \
  43. ROTL_SSE2(24, t, v3); \
  44. PADDL v3, v2; \
  45. PXOR v2, v1; \
  46. ROTL_SSE2(25, t, v1); \
  47. PSHUFL $0x39, v1, v1; \
  48. PSHUFL $0x4E, v2, v2; \
  49. PSHUFL $0x93, v3, v3; \
  50. PADDL m2, v0; \
  51. PADDL v1, v0; \
  52. PXOR v0, v3; \
  53. ROTL_SSE2(16, t, v3); \
  54. PADDL v3, v2; \
  55. PXOR v2, v1; \
  56. ROTL_SSE2(20, t, v1); \
  57. PADDL m3, v0; \
  58. PADDL v1, v0; \
  59. PXOR v0, v3; \
  60. ROTL_SSE2(24, t, v3); \
  61. PADDL v3, v2; \
  62. PXOR v2, v1; \
  63. ROTL_SSE2(25, t, v1); \
  64. PSHUFL $0x39, v3, v3; \
  65. PSHUFL $0x4E, v2, v2; \
  66. PSHUFL $0x93, v1, v1
  67. #define ROUND_SSSE3(v0, v1, v2, v3, m0, m1, m2, m3, t, c16, c8) \
  68. PADDL m0, v0; \
  69. PADDL v1, v0; \
  70. PXOR v0, v3; \
  71. ROTL_SSSE3(c16, v3); \
  72. PADDL v3, v2; \
  73. PXOR v2, v1; \
  74. ROTL_SSE2(20, t, v1); \
  75. PADDL m1, v0; \
  76. PADDL v1, v0; \
  77. PXOR v0, v3; \
  78. ROTL_SSSE3(c8, v3); \
  79. PADDL v3, v2; \
  80. PXOR v2, v1; \
  81. ROTL_SSE2(25, t, v1); \
  82. PSHUFL $0x39, v1, v1; \
  83. PSHUFL $0x4E, v2, v2; \
  84. PSHUFL $0x93, v3, v3; \
  85. PADDL m2, v0; \
  86. PADDL v1, v0; \
  87. PXOR v0, v3; \
  88. ROTL_SSSE3(c16, v3); \
  89. PADDL v3, v2; \
  90. PXOR v2, v1; \
  91. ROTL_SSE2(20, t, v1); \
  92. PADDL m3, v0; \
  93. PADDL v1, v0; \
  94. PXOR v0, v3; \
  95. ROTL_SSSE3(c8, v3); \
  96. PADDL v3, v2; \
  97. PXOR v2, v1; \
  98. ROTL_SSE2(25, t, v1); \
  99. PSHUFL $0x39, v3, v3; \
  100. PSHUFL $0x4E, v2, v2; \
  101. PSHUFL $0x93, v1, v1
  102. #define LOAD_MSG_SSE4(m0, m1, m2, m3, src, i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15) \
  103. MOVL i0*4(src), m0; \
  104. PINSRD $1, i1*4(src), m0; \
  105. PINSRD $2, i2*4(src), m0; \
  106. PINSRD $3, i3*4(src), m0; \
  107. MOVL i4*4(src), m1; \
  108. PINSRD $1, i5*4(src), m1; \
  109. PINSRD $2, i6*4(src), m1; \
  110. PINSRD $3, i7*4(src), m1; \
  111. MOVL i8*4(src), m2; \
  112. PINSRD $1, i9*4(src), m2; \
  113. PINSRD $2, i10*4(src), m2; \
  114. PINSRD $3, i11*4(src), m2; \
  115. MOVL i12*4(src), m3; \
  116. PINSRD $1, i13*4(src), m3; \
  117. PINSRD $2, i14*4(src), m3; \
  118. PINSRD $3, i15*4(src), m3
  119. #define PRECOMPUTE_MSG(dst, off, src, R8, R9, R10, R11, R12, R13, R14, R15) \
  120. MOVQ 0*4(src), R8; \
  121. MOVQ 2*4(src), R9; \
  122. MOVQ 4*4(src), R10; \
  123. MOVQ 6*4(src), R11; \
  124. MOVQ 8*4(src), R12; \
  125. MOVQ 10*4(src), R13; \
  126. MOVQ 12*4(src), R14; \
  127. MOVQ 14*4(src), R15; \
  128. \
  129. MOVL R8, 0*4+off+0(dst); \
  130. MOVL R8, 9*4+off+64(dst); \
  131. MOVL R8, 5*4+off+128(dst); \
  132. MOVL R8, 14*4+off+192(dst); \
  133. MOVL R8, 4*4+off+256(dst); \
  134. MOVL R8, 2*4+off+320(dst); \
  135. MOVL R8, 8*4+off+384(dst); \
  136. MOVL R8, 12*4+off+448(dst); \
  137. MOVL R8, 3*4+off+512(dst); \
  138. MOVL R8, 15*4+off+576(dst); \
  139. SHRQ $32, R8; \
  140. MOVL R8, 4*4+off+0(dst); \
  141. MOVL R8, 8*4+off+64(dst); \
  142. MOVL R8, 14*4+off+128(dst); \
  143. MOVL R8, 5*4+off+192(dst); \
  144. MOVL R8, 12*4+off+256(dst); \
  145. MOVL R8, 11*4+off+320(dst); \
  146. MOVL R8, 1*4+off+384(dst); \
  147. MOVL R8, 6*4+off+448(dst); \
  148. MOVL R8, 10*4+off+512(dst); \
  149. MOVL R8, 3*4+off+576(dst); \
  150. \
  151. MOVL R9, 1*4+off+0(dst); \
  152. MOVL R9, 13*4+off+64(dst); \
  153. MOVL R9, 6*4+off+128(dst); \
  154. MOVL R9, 8*4+off+192(dst); \
  155. MOVL R9, 2*4+off+256(dst); \
  156. MOVL R9, 0*4+off+320(dst); \
  157. MOVL R9, 14*4+off+384(dst); \
  158. MOVL R9, 11*4+off+448(dst); \
  159. MOVL R9, 12*4+off+512(dst); \
  160. MOVL R9, 4*4+off+576(dst); \
  161. SHRQ $32, R9; \
  162. MOVL R9, 5*4+off+0(dst); \
  163. MOVL R9, 15*4+off+64(dst); \
  164. MOVL R9, 9*4+off+128(dst); \
  165. MOVL R9, 1*4+off+192(dst); \
  166. MOVL R9, 11*4+off+256(dst); \
  167. MOVL R9, 7*4+off+320(dst); \
  168. MOVL R9, 13*4+off+384(dst); \
  169. MOVL R9, 3*4+off+448(dst); \
  170. MOVL R9, 6*4+off+512(dst); \
  171. MOVL R9, 10*4+off+576(dst); \
  172. \
  173. MOVL R10, 2*4+off+0(dst); \
  174. MOVL R10, 1*4+off+64(dst); \
  175. MOVL R10, 15*4+off+128(dst); \
  176. MOVL R10, 10*4+off+192(dst); \
  177. MOVL R10, 6*4+off+256(dst); \
  178. MOVL R10, 8*4+off+320(dst); \
  179. MOVL R10, 3*4+off+384(dst); \
  180. MOVL R10, 13*4+off+448(dst); \
  181. MOVL R10, 14*4+off+512(dst); \
  182. MOVL R10, 5*4+off+576(dst); \
  183. SHRQ $32, R10; \
  184. MOVL R10, 6*4+off+0(dst); \
  185. MOVL R10, 11*4+off+64(dst); \
  186. MOVL R10, 2*4+off+128(dst); \
  187. MOVL R10, 9*4+off+192(dst); \
  188. MOVL R10, 1*4+off+256(dst); \
  189. MOVL R10, 13*4+off+320(dst); \
  190. MOVL R10, 4*4+off+384(dst); \
  191. MOVL R10, 8*4+off+448(dst); \
  192. MOVL R10, 15*4+off+512(dst); \
  193. MOVL R10, 7*4+off+576(dst); \
  194. \
  195. MOVL R11, 3*4+off+0(dst); \
  196. MOVL R11, 7*4+off+64(dst); \
  197. MOVL R11, 13*4+off+128(dst); \
  198. MOVL R11, 12*4+off+192(dst); \
  199. MOVL R11, 10*4+off+256(dst); \
  200. MOVL R11, 1*4+off+320(dst); \
  201. MOVL R11, 9*4+off+384(dst); \
  202. MOVL R11, 14*4+off+448(dst); \
  203. MOVL R11, 0*4+off+512(dst); \
  204. MOVL R11, 6*4+off+576(dst); \
  205. SHRQ $32, R11; \
  206. MOVL R11, 7*4+off+0(dst); \
  207. MOVL R11, 14*4+off+64(dst); \
  208. MOVL R11, 10*4+off+128(dst); \
  209. MOVL R11, 0*4+off+192(dst); \
  210. MOVL R11, 5*4+off+256(dst); \
  211. MOVL R11, 9*4+off+320(dst); \
  212. MOVL R11, 12*4+off+384(dst); \
  213. MOVL R11, 1*4+off+448(dst); \
  214. MOVL R11, 13*4+off+512(dst); \
  215. MOVL R11, 2*4+off+576(dst); \
  216. \
  217. MOVL R12, 8*4+off+0(dst); \
  218. MOVL R12, 5*4+off+64(dst); \
  219. MOVL R12, 4*4+off+128(dst); \
  220. MOVL R12, 15*4+off+192(dst); \
  221. MOVL R12, 14*4+off+256(dst); \
  222. MOVL R12, 3*4+off+320(dst); \
  223. MOVL R12, 11*4+off+384(dst); \
  224. MOVL R12, 10*4+off+448(dst); \
  225. MOVL R12, 7*4+off+512(dst); \
  226. MOVL R12, 1*4+off+576(dst); \
  227. SHRQ $32, R12; \
  228. MOVL R12, 12*4+off+0(dst); \
  229. MOVL R12, 2*4+off+64(dst); \
  230. MOVL R12, 11*4+off+128(dst); \
  231. MOVL R12, 4*4+off+192(dst); \
  232. MOVL R12, 0*4+off+256(dst); \
  233. MOVL R12, 15*4+off+320(dst); \
  234. MOVL R12, 10*4+off+384(dst); \
  235. MOVL R12, 7*4+off+448(dst); \
  236. MOVL R12, 5*4+off+512(dst); \
  237. MOVL R12, 9*4+off+576(dst); \
  238. \
  239. MOVL R13, 9*4+off+0(dst); \
  240. MOVL R13, 4*4+off+64(dst); \
  241. MOVL R13, 8*4+off+128(dst); \
  242. MOVL R13, 13*4+off+192(dst); \
  243. MOVL R13, 3*4+off+256(dst); \
  244. MOVL R13, 5*4+off+320(dst); \
  245. MOVL R13, 7*4+off+384(dst); \
  246. MOVL R13, 15*4+off+448(dst); \
  247. MOVL R13, 11*4+off+512(dst); \
  248. MOVL R13, 0*4+off+576(dst); \
  249. SHRQ $32, R13; \
  250. MOVL R13, 13*4+off+0(dst); \
  251. MOVL R13, 10*4+off+64(dst); \
  252. MOVL R13, 0*4+off+128(dst); \
  253. MOVL R13, 3*4+off+192(dst); \
  254. MOVL R13, 9*4+off+256(dst); \
  255. MOVL R13, 6*4+off+320(dst); \
  256. MOVL R13, 15*4+off+384(dst); \
  257. MOVL R13, 4*4+off+448(dst); \
  258. MOVL R13, 2*4+off+512(dst); \
  259. MOVL R13, 12*4+off+576(dst); \
  260. \
  261. MOVL R14, 10*4+off+0(dst); \
  262. MOVL R14, 12*4+off+64(dst); \
  263. MOVL R14, 1*4+off+128(dst); \
  264. MOVL R14, 6*4+off+192(dst); \
  265. MOVL R14, 13*4+off+256(dst); \
  266. MOVL R14, 4*4+off+320(dst); \
  267. MOVL R14, 0*4+off+384(dst); \
  268. MOVL R14, 2*4+off+448(dst); \
  269. MOVL R14, 8*4+off+512(dst); \
  270. MOVL R14, 14*4+off+576(dst); \
  271. SHRQ $32, R14; \
  272. MOVL R14, 14*4+off+0(dst); \
  273. MOVL R14, 3*4+off+64(dst); \
  274. MOVL R14, 7*4+off+128(dst); \
  275. MOVL R14, 2*4+off+192(dst); \
  276. MOVL R14, 15*4+off+256(dst); \
  277. MOVL R14, 12*4+off+320(dst); \
  278. MOVL R14, 6*4+off+384(dst); \
  279. MOVL R14, 0*4+off+448(dst); \
  280. MOVL R14, 9*4+off+512(dst); \
  281. MOVL R14, 11*4+off+576(dst); \
  282. \
  283. MOVL R15, 11*4+off+0(dst); \
  284. MOVL R15, 0*4+off+64(dst); \
  285. MOVL R15, 12*4+off+128(dst); \
  286. MOVL R15, 7*4+off+192(dst); \
  287. MOVL R15, 8*4+off+256(dst); \
  288. MOVL R15, 14*4+off+320(dst); \
  289. MOVL R15, 2*4+off+384(dst); \
  290. MOVL R15, 5*4+off+448(dst); \
  291. MOVL R15, 1*4+off+512(dst); \
  292. MOVL R15, 13*4+off+576(dst); \
  293. SHRQ $32, R15; \
  294. MOVL R15, 15*4+off+0(dst); \
  295. MOVL R15, 6*4+off+64(dst); \
  296. MOVL R15, 3*4+off+128(dst); \
  297. MOVL R15, 11*4+off+192(dst); \
  298. MOVL R15, 7*4+off+256(dst); \
  299. MOVL R15, 10*4+off+320(dst); \
  300. MOVL R15, 5*4+off+384(dst); \
  301. MOVL R15, 9*4+off+448(dst); \
  302. MOVL R15, 4*4+off+512(dst); \
  303. MOVL R15, 8*4+off+576(dst)
  304. #define BLAKE2s_SSE2() \
  305. PRECOMPUTE_MSG(SP, 16, SI, R8, R9, R10, R11, R12, R13, R14, R15); \
  306. ROUND_SSE2(X4, X5, X6, X7, 16(SP), 32(SP), 48(SP), 64(SP), X8); \
  307. ROUND_SSE2(X4, X5, X6, X7, 16+64(SP), 32+64(SP), 48+64(SP), 64+64(SP), X8); \
  308. ROUND_SSE2(X4, X5, X6, X7, 16+128(SP), 32+128(SP), 48+128(SP), 64+128(SP), X8); \
  309. ROUND_SSE2(X4, X5, X6, X7, 16+192(SP), 32+192(SP), 48+192(SP), 64+192(SP), X8); \
  310. ROUND_SSE2(X4, X5, X6, X7, 16+256(SP), 32+256(SP), 48+256(SP), 64+256(SP), X8); \
  311. ROUND_SSE2(X4, X5, X6, X7, 16+320(SP), 32+320(SP), 48+320(SP), 64+320(SP), X8); \
  312. ROUND_SSE2(X4, X5, X6, X7, 16+384(SP), 32+384(SP), 48+384(SP), 64+384(SP), X8); \
  313. ROUND_SSE2(X4, X5, X6, X7, 16+448(SP), 32+448(SP), 48+448(SP), 64+448(SP), X8); \
  314. ROUND_SSE2(X4, X5, X6, X7, 16+512(SP), 32+512(SP), 48+512(SP), 64+512(SP), X8); \
  315. ROUND_SSE2(X4, X5, X6, X7, 16+576(SP), 32+576(SP), 48+576(SP), 64+576(SP), X8)
  316. #define BLAKE2s_SSSE3() \
  317. PRECOMPUTE_MSG(SP, 16, SI, R8, R9, R10, R11, R12, R13, R14, R15); \
  318. ROUND_SSSE3(X4, X5, X6, X7, 16(SP), 32(SP), 48(SP), 64(SP), X8, X13, X14); \
  319. ROUND_SSSE3(X4, X5, X6, X7, 16+64(SP), 32+64(SP), 48+64(SP), 64+64(SP), X8, X13, X14); \
  320. ROUND_SSSE3(X4, X5, X6, X7, 16+128(SP), 32+128(SP), 48+128(SP), 64+128(SP), X8, X13, X14); \
  321. ROUND_SSSE3(X4, X5, X6, X7, 16+192(SP), 32+192(SP), 48+192(SP), 64+192(SP), X8, X13, X14); \
  322. ROUND_SSSE3(X4, X5, X6, X7, 16+256(SP), 32+256(SP), 48+256(SP), 64+256(SP), X8, X13, X14); \
  323. ROUND_SSSE3(X4, X5, X6, X7, 16+320(SP), 32+320(SP), 48+320(SP), 64+320(SP), X8, X13, X14); \
  324. ROUND_SSSE3(X4, X5, X6, X7, 16+384(SP), 32+384(SP), 48+384(SP), 64+384(SP), X8, X13, X14); \
  325. ROUND_SSSE3(X4, X5, X6, X7, 16+448(SP), 32+448(SP), 48+448(SP), 64+448(SP), X8, X13, X14); \
  326. ROUND_SSSE3(X4, X5, X6, X7, 16+512(SP), 32+512(SP), 48+512(SP), 64+512(SP), X8, X13, X14); \
  327. ROUND_SSSE3(X4, X5, X6, X7, 16+576(SP), 32+576(SP), 48+576(SP), 64+576(SP), X8, X13, X14)
  328. #define BLAKE2s_SSE4() \
  329. LOAD_MSG_SSE4(X8, X9, X10, X11, SI, 0, 2, 4, 6, 1, 3, 5, 7, 8, 10, 12, 14, 9, 11, 13, 15); \
  330. ROUND_SSSE3(X4, X5, X6, X7, X8, X9, X10, X11, X8, X13, X14); \
  331. LOAD_MSG_SSE4(X8, X9, X10, X11, SI, 14, 4, 9, 13, 10, 8, 15, 6, 1, 0, 11, 5, 12, 2, 7, 3); \
  332. ROUND_SSSE3(X4, X5, X6, X7, X8, X9, X10, X11, X8, X13, X14); \
  333. LOAD_MSG_SSE4(X8, X9, X10, X11, SI, 11, 12, 5, 15, 8, 0, 2, 13, 10, 3, 7, 9, 14, 6, 1, 4); \
  334. ROUND_SSSE3(X4, X5, X6, X7, X8, X9, X10, X11, X8, X13, X14); \
  335. LOAD_MSG_SSE4(X8, X9, X10, X11, SI, 7, 3, 13, 11, 9, 1, 12, 14, 2, 5, 4, 15, 6, 10, 0, 8); \
  336. ROUND_SSSE3(X4, X5, X6, X7, X8, X9, X10, X11, X8, X13, X14); \
  337. LOAD_MSG_SSE4(X8, X9, X10, X11, SI, 9, 5, 2, 10, 0, 7, 4, 15, 14, 11, 6, 3, 1, 12, 8, 13); \
  338. ROUND_SSSE3(X4, X5, X6, X7, X8, X9, X10, X11, X8, X13, X14); \
  339. LOAD_MSG_SSE4(X8, X9, X10, X11, SI, 2, 6, 0, 8, 12, 10, 11, 3, 4, 7, 15, 1, 13, 5, 14, 9); \
  340. ROUND_SSSE3(X4, X5, X6, X7, X8, X9, X10, X11, X8, X13, X14); \
  341. LOAD_MSG_SSE4(X8, X9, X10, X11, SI, 12, 1, 14, 4, 5, 15, 13, 10, 0, 6, 9, 8, 7, 3, 2, 11); \
  342. ROUND_SSSE3(X4, X5, X6, X7, X8, X9, X10, X11, X8, X13, X14); \
  343. LOAD_MSG_SSE4(X8, X9, X10, X11, SI, 13, 7, 12, 3, 11, 14, 1, 9, 5, 15, 8, 2, 0, 4, 6, 10); \
  344. ROUND_SSSE3(X4, X5, X6, X7, X8, X9, X10, X11, X8, X13, X14); \
  345. LOAD_MSG_SSE4(X8, X9, X10, X11, SI, 6, 14, 11, 0, 15, 9, 3, 8, 12, 13, 1, 10, 2, 7, 4, 5); \
  346. ROUND_SSSE3(X4, X5, X6, X7, X8, X9, X10, X11, X8, X13, X14); \
  347. LOAD_MSG_SSE4(X8, X9, X10, X11, SI, 10, 8, 7, 1, 2, 4, 6, 5, 15, 9, 3, 13, 11, 14, 12, 0); \
  348. ROUND_SSSE3(X4, X5, X6, X7, X8, X9, X10, X11, X8, X13, X14)
  349. #define HASH_BLOCKS(h, c, flag, blocks_base, blocks_len, BLAKE2s_FUNC) \
  350. MOVQ h, AX; \
  351. MOVQ c, BX; \
  352. MOVL flag, CX; \
  353. MOVQ blocks_base, SI; \
  354. MOVQ blocks_len, DX; \
  355. \
  356. MOVQ SP, BP; \
  357. MOVQ SP, R9; \
  358. ADDQ $15, R9; \
  359. ANDQ $~15, R9; \
  360. MOVQ R9, SP; \
  361. \
  362. MOVQ 0(BX), R9; \
  363. MOVQ R9, 0(SP); \
  364. XORQ R9, R9; \
  365. MOVQ R9, 8(SP); \
  366. MOVL CX, 8(SP); \
  367. \
  368. MOVOU 0(AX), X0; \
  369. MOVOU 16(AX), X1; \
  370. MOVOU iv0<>(SB), X2; \
  371. MOVOU iv1<>(SB), X3 \
  372. \
  373. MOVOU counter<>(SB), X12; \
  374. MOVOU rol16<>(SB), X13; \
  375. MOVOU rol8<>(SB), X14; \
  376. MOVO 0(SP), X15; \
  377. \
  378. loop: \
  379. MOVO X0, X4; \
  380. MOVO X1, X5; \
  381. MOVO X2, X6; \
  382. MOVO X3, X7; \
  383. \
  384. PADDQ X12, X15; \
  385. PXOR X15, X7; \
  386. \
  387. BLAKE2s_FUNC(); \
  388. \
  389. PXOR X4, X0; \
  390. PXOR X5, X1; \
  391. PXOR X6, X0; \
  392. PXOR X7, X1; \
  393. \
  394. LEAQ 64(SI), SI; \
  395. SUBQ $64, DX; \
  396. JNE loop; \
  397. \
  398. MOVO X15, 0(SP); \
  399. MOVQ 0(SP), R9; \
  400. MOVQ R9, 0(BX); \
  401. \
  402. MOVOU X0, 0(AX); \
  403. MOVOU X1, 16(AX); \
  404. \
  405. MOVQ BP, SP
  406. // func hashBlocksSSE2(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte)
  407. TEXT ·hashBlocksSSE2(SB), 0, $672-48 // frame = 656 + 16 byte alignment
  408. HASH_BLOCKS(h+0(FP), c+8(FP), flag+16(FP), blocks_base+24(FP), blocks_len+32(FP), BLAKE2s_SSE2)
  409. RET
  410. // func hashBlocksSSSE3(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte)
  411. TEXT ·hashBlocksSSSE3(SB), 0, $672-48 // frame = 656 + 16 byte alignment
  412. HASH_BLOCKS(h+0(FP), c+8(FP), flag+16(FP), blocks_base+24(FP), blocks_len+32(FP), BLAKE2s_SSSE3)
  413. RET
  414. // func hashBlocksSSE4(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte)
  415. TEXT ·hashBlocksSSE4(SB), 0, $32-48 // frame = 16 + 16 byte alignment
  416. HASH_BLOCKS(h+0(FP), c+8(FP), flag+16(FP), blocks_base+24(FP), blocks_len+32(FP), BLAKE2s_SSE4)
  417. RET
  418. // func supportSSE4() bool
  419. TEXT ·supportSSE4(SB), 4, $0-1
  420. MOVL $1, AX
  421. CPUID
  422. SHRL $19, CX // Bit 19 indicates SSE4.1.
  423. ANDL $1, CX
  424. MOVB CX, ret+0(FP)
  425. RET
  426. // func supportSSSE3() bool
  427. TEXT ·supportSSSE3(SB), 4, $0-1
  428. MOVL $1, AX
  429. CPUID
  430. MOVL CX, BX
  431. ANDL $0x1, BX // Bit zero indicates SSE3 support.
  432. JZ FALSE
  433. ANDL $0x200, CX // Bit nine indicates SSSE3 support.
  434. JZ FALSE
  435. MOVB $1, ret+0(FP)
  436. RET
  437. FALSE:
  438. MOVB $0, ret+0(FP)
  439. RET