gf_5vect_mad_sve.S 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /**************************************************************
  2. Copyright (c) 2021 Linaro Ltd.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions
  5. are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in
  10. the documentation and/or other materials provided with the
  11. distribution.
  12. * Neither the name of Huawei Corporation nor the names of its
  13. contributors may be used to endorse or promote products derived
  14. from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  18. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  19. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. **********************************************************************/
  27. .text
  28. .align 6
  29. .arch armv8-a+sve
  30. #include "../include/aarch64_label.h"
  31. .global cdecl(gf_5vect_mad_sve)
  32. #ifndef __APPLE__
  33. .type gf_5vect_mad_sve, %function
  34. #endif
  35. /* gf_5vect_mad_sve(int len, int vec, int vec_i, unsigned char *gftbls,
  36. unsigned char *src, unsigned char **dest);
  37. */
  38. /* arguments */
  39. x_len .req x0
  40. x_vec .req x1
  41. x_vec_i .req x2
  42. x_tbl .req x3
  43. x_src .req x4
  44. x_dest .req x5
  45. /* returns */
  46. w_ret .req w0
  47. /* local variables */
  48. x_pos .req x6
  49. x_dest2 .req x7
  50. x_dest3 .req x8
  51. x_dest4 .req x9
  52. x_dest5 .req x10
  53. x_dest1 .req x12
  54. /* vectors */
  55. z_mask0f .req z0
  56. z_src .req z1
  57. z_src_lo .req z2
  58. z_src_hi .req z_src
  59. z_dest1 .req z3
  60. z_tmp_lo .req z4
  61. z_tmp_hi .req z5
  62. z_gft1_lo .req z6
  63. z_gft1_hi .req z7
  64. q_gft1_lo .req q6
  65. q_gft1_hi .req q7
  66. /* bottom 64-bit of v8..v15 must be preserved if used */
  67. z_gft2_lo .req z17
  68. z_gft2_hi .req z18
  69. q_gft2_lo .req q17
  70. q_gft2_hi .req q18
  71. z_gft3_lo .req z19
  72. z_gft3_hi .req z20
  73. q_gft3_lo .req q19
  74. q_gft3_hi .req q20
  75. z_gft4_lo .req z21
  76. z_gft4_hi .req z22
  77. q_gft4_lo .req q21
  78. q_gft4_hi .req q22
  79. z_gft5_lo .req z23
  80. z_gft5_hi .req z24
  81. q_gft5_lo .req q23
  82. q_gft5_hi .req q24
  83. z_dest2 .req z27
  84. z_dest3 .req z28
  85. z_dest4 .req z29
  86. z_dest5 .req z30
  87. cdecl(gf_5vect_mad_sve):
  88. /* less than 16 bytes, return_fail */
  89. cmp x_len, #16
  90. blt .return_fail
  91. mov z_mask0f.b, #0x0f /* z_mask0f = 0x0F0F...0F */
  92. /* load table 1 */
  93. add x_tbl, x_tbl, x_vec_i, LSL #5 /* x_tbl += x_vec_i * 2^5 */
  94. /* Load with NEON instruction ldp */
  95. ldp q_gft1_lo, q_gft1_hi, [x_tbl]
  96. /* load table 2 */
  97. add x_tbl, x_tbl, x_vec, LSL #5 /* x_tbl += x_vec * 2^5 */
  98. ldp q_gft2_lo, q_gft2_hi, [x_tbl]
  99. /* load table 3 */
  100. add x_tbl, x_tbl, x_vec, LSL #5 /* x_tbl += x_vec * 2^5 */
  101. ldp q_gft3_lo, q_gft3_hi, [x_tbl]
  102. /* load table 4 */
  103. add x_tbl, x_tbl, x_vec, LSL #5 /* x_tbl += x_vec * 2^5 */
  104. ldp q_gft4_lo, q_gft4_hi, [x_tbl]
  105. /* load table 5 */
  106. add x_tbl, x_tbl, x_vec, LSL #5 /* x_tbl += x_vec * 2^5 */
  107. ldp q_gft5_lo, q_gft5_hi, [x_tbl]
  108. ldr x_dest1, [x_dest, #8*0] /* pointer to dest1 */
  109. ldr x_dest2, [x_dest, #8*1] /* pointer to dest2 */
  110. ldr x_dest3, [x_dest, #8*2] /* pointer to dest3 */
  111. ldr x_dest4, [x_dest, #8*3] /* pointer to dest4 */
  112. ldr x_dest5, [x_dest, #8*4] /* pointer to dest5 */
  113. mov x_pos, #0
  114. /* vector length agnostic */
  115. .Lloopsve_vl:
  116. whilelo p0.b, x_pos, x_len
  117. b.none .return_pass
  118. prfb pldl2strm, p0, [x_dest1, x_pos]
  119. prfb pldl2strm, p0, [x_dest2, x_pos]
  120. /* load src data, governed by p0 */
  121. ld1b z_src.b, p0/z, [x_src, x_pos]
  122. /* split 4-bit lo; 4-bit hi */
  123. and z_src_lo.d, z_src.d, z_mask0f.d
  124. lsr z_src_hi.b, z_src.b, #4
  125. /* load dest data, governed by p0 */
  126. ld1b z_dest1.b, p0/z, [x_dest1, x_pos]
  127. ld1b z_dest2.b, p0/z, [x_dest2, x_pos]
  128. prfb pldl2strm, p0, [x_dest3, x_pos]
  129. prfb pldl2strm, p0, [x_dest4, x_pos]
  130. /* dest1 */
  131. /* table indexing, ie. gf(2^8) multiplication */
  132. tbl z_tmp_lo.b, {z_gft1_lo.b}, z_src_lo.b
  133. tbl z_tmp_hi.b, {z_gft1_hi.b}, z_src_hi.b
  134. /* exclusive or, ie. gf(2^8) add */
  135. eor z_dest1.d, z_tmp_lo.d, z_dest1.d
  136. eor z_dest1.d, z_tmp_hi.d, z_dest1.d
  137. ld1b z_dest3.b, p0/z, [x_dest3, x_pos]
  138. ld1b z_dest4.b, p0/z, [x_dest4, x_pos]
  139. prfb pldl2strm, p0, [x_dest5, x_pos]
  140. /* dest2 */
  141. tbl z_tmp_lo.b, {z_gft2_lo.b}, z_src_lo.b
  142. tbl z_tmp_hi.b, {z_gft2_hi.b}, z_src_hi.b
  143. eor z_dest2.d, z_tmp_lo.d, z_dest2.d
  144. eor z_dest2.d, z_tmp_hi.d, z_dest2.d
  145. ld1b z_dest5.b, p0/z, [x_dest5, x_pos]
  146. /* store dest data, governed by p0 */
  147. st1b z_dest1.b, p0, [x_dest1, x_pos]
  148. /* dest3 */
  149. tbl z_tmp_lo.b, {z_gft3_lo.b}, z_src_lo.b
  150. tbl z_tmp_hi.b, {z_gft3_hi.b}, z_src_hi.b
  151. eor z_dest3.d, z_tmp_lo.d, z_dest3.d
  152. eor z_dest3.d, z_tmp_hi.d, z_dest3.d
  153. /* dest4 */
  154. tbl z_tmp_lo.b, {z_gft4_lo.b}, z_src_lo.b
  155. tbl z_tmp_hi.b, {z_gft4_hi.b}, z_src_hi.b
  156. eor z_dest4.d, z_tmp_lo.d, z_dest4.d
  157. eor z_dest4.d, z_tmp_hi.d, z_dest4.d
  158. /* store dest data, governed by p0 */
  159. st1b z_dest2.b, p0, [x_dest2, x_pos]
  160. st1b z_dest3.b, p0, [x_dest3, x_pos]
  161. /* dest5 */
  162. tbl z_tmp_lo.b, {z_gft5_lo.b}, z_src_lo.b
  163. tbl z_tmp_hi.b, {z_gft5_hi.b}, z_src_hi.b
  164. eor z_dest5.d, z_tmp_lo.d, z_dest5.d
  165. eor z_dest5.d, z_tmp_hi.d, z_dest5.d
  166. /* store dest data, governed by p0 */
  167. st1b z_dest4.b, p0, [x_dest4, x_pos]
  168. st1b z_dest5.b, p0, [x_dest5, x_pos]
  169. /* increment one vector length */
  170. incb x_pos
  171. b .Lloopsve_vl
  172. .return_pass:
  173. mov w_ret, #0
  174. ret
  175. .return_fail:
  176. mov w_ret, #1
  177. ret