gf_vect_mad_sve.S 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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_vect_mad_sve)
  32. #ifndef __APPLE__
  33. .type gf_vect_mad_sve, %function
  34. #endif
  35. /* gf_vect_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. /* vectors */
  50. z_mask0f .req z0
  51. z_src .req z1
  52. z_src_lo .req z2
  53. z_src_hi .req z_src
  54. z_dest .req z3
  55. z_tmp1_lo .req z4
  56. z_tmp1_hi .req z5
  57. z_gft1_lo .req z6
  58. z_gft1_hi .req z7
  59. q_gft1_lo .req q6
  60. q_gft1_hi .req q7
  61. cdecl(gf_vect_mad_sve):
  62. /* less than 16 bytes, return_fail */
  63. cmp x_len, #16
  64. blt .return_fail
  65. mov z_mask0f.b, #0x0f /* z_mask0f = 0x0F0F...0F */
  66. add x_tbl, x_tbl, x_vec_i, LSL #5 /* x_tbl += x_vec_i * 2^5 */
  67. /* Load with NEON instruction ldp */
  68. ldp q_gft1_lo, q_gft1_hi, [x_tbl]
  69. mov x_pos, #0
  70. /* vector length agnostic */
  71. .Lloopsve_vl:
  72. whilelo p0.b, x_pos, x_len
  73. b.none .return_pass
  74. /* prefetch dest data */
  75. prfb pldl2strm, p0, [x_dest, x_pos]
  76. /* load src data, governed by p0 */
  77. ld1b z_src.b, p0/z, [x_src, x_pos]
  78. /* split 4-bit lo; 4-bit hi */
  79. and z_src_lo.d, z_src.d, z_mask0f.d
  80. lsr z_src_hi.b, z_src.b, #4
  81. /* load dest data, governed by p0 */
  82. ld1b z_dest.b, p0/z, [x_dest, x_pos]
  83. /* table indexing, ie. gf(2^8) multiplication */
  84. tbl z_tmp1_lo.b, {z_gft1_lo.b}, z_src_lo.b
  85. tbl z_tmp1_hi.b, {z_gft1_hi.b}, z_src_hi.b
  86. /* exclusive or, ie. gf(2^8) add */
  87. eor z_dest.d, z_tmp1_lo.d, z_dest.d
  88. eor z_dest.d, z_tmp1_hi.d, z_dest.d
  89. /* store dest data, governed by p0 */
  90. st1b z_dest.b, p0, [x_dest, x_pos]
  91. /* increment one vector length */
  92. incb x_pos
  93. b .Lloopsve_vl
  94. .return_pass:
  95. mov w_ret, #0
  96. ret
  97. .return_fail:
  98. mov w_ret, #1
  99. ret