gf_2vect_mad_sve.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_2vect_mad_sve)
  32. #ifndef __APPLE__
  33. .type gf_2vect_mad_sve, %function
  34. #endif
  35. /* gf_2vect_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_dest1 .req x12
  51. /* vectors */
  52. z_mask0f .req z0
  53. z_src .req z1
  54. z_src_lo .req z2
  55. z_src_hi .req z_src
  56. z_dest1 .req z3
  57. z_tmp_lo .req z4
  58. z_tmp_hi .req z5
  59. z_gft1_lo .req z6
  60. z_gft1_hi .req z7
  61. q_gft1_lo .req q6
  62. q_gft1_hi .req q7
  63. /* bottom 64-bit of v8..v15 must be preserved if used */
  64. z_gft2_lo .req z17
  65. z_gft2_hi .req z18
  66. q_gft2_lo .req q17
  67. q_gft2_hi .req q18
  68. z_dest2 .req z27
  69. cdecl(gf_2vect_mad_sve):
  70. /* less than 16 bytes, return_fail */
  71. cmp x_len, #16
  72. blt .return_fail
  73. mov z_mask0f.b, #0x0f /* z_mask0f = 0x0F0F...0F */
  74. /* load table 1 */
  75. add x_tbl, x_tbl, x_vec_i, LSL #5 /* x_tbl += x_vec_i * 2^5 */
  76. /* Load table 1 with NEON instruction ldp */
  77. ldp q_gft1_lo, q_gft1_hi, [x_tbl]
  78. /* load table 2 */
  79. add x_tbl, x_tbl, x_vec, LSL #5 /* x_tbl += x_vec * 2^5 */
  80. ldp q_gft2_lo, q_gft2_hi, [x_tbl]
  81. ldr x_dest1, [x_dest, #8*0] /* pointer to dest1 */
  82. ldr x_dest2, [x_dest, #8*1] /* pointer to dest2 */
  83. mov x_pos, #0
  84. /* vector length agnostic */
  85. .Lloopsve_vl:
  86. whilelo p0.b, x_pos, x_len
  87. b.none .return_pass
  88. /* prefetch dest data */
  89. prfb pldl2strm, p0, [x_dest1, x_pos]
  90. prfb pldl2strm, p0, [x_dest2, x_pos]
  91. /* load src data, governed by p0 */
  92. ld1b z_src.b, p0/z, [x_src, x_pos]
  93. /* split 4-bit lo; 4-bit hi */
  94. and z_src_lo.d, z_src.d, z_mask0f.d
  95. lsr z_src_hi.b, z_src.b, #4
  96. /* load dest data, governed by p0 */
  97. ld1b z_dest1.b, p0/z, [x_dest1, x_pos]
  98. ld1b z_dest2.b, p0/z, [x_dest2, x_pos]
  99. /* dest1 */
  100. /* table indexing, ie. gf(2^8) multiplication */
  101. tbl z_tmp_lo.b, {z_gft1_lo.b}, z_src_lo.b
  102. tbl z_tmp_hi.b, {z_gft1_hi.b}, z_src_hi.b
  103. /* exclusive or, ie. gf(2^8) add */
  104. eor z_dest1.d, z_tmp_lo.d, z_dest1.d
  105. eor z_dest1.d, z_tmp_hi.d, z_dest1.d
  106. /* dest2 */
  107. tbl z_tmp_lo.b, {z_gft2_lo.b}, z_src_lo.b
  108. tbl z_tmp_hi.b, {z_gft2_hi.b}, z_src_hi.b
  109. eor z_dest2.d, z_tmp_lo.d, z_dest2.d
  110. eor z_dest2.d, z_tmp_hi.d, z_dest2.d
  111. /* store dest data, governed by p0 */
  112. st1b z_dest1.b, p0, [x_dest1, x_pos]
  113. st1b z_dest2.b, p0, [x_dest2, x_pos]
  114. /* increment one vector length */
  115. incb x_pos
  116. b .Lloopsve_vl
  117. .return_pass:
  118. mov w_ret, #0
  119. ret
  120. .return_fail:
  121. mov w_ret, #1
  122. ret