gf_vect_mul_sve.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_mul_sve)
  32. #ifndef __APPLE__
  33. .type gf_vect_mul_sve, %function
  34. #endif
  35. /* Refer to include/gf_vect_mul.h
  36. *
  37. * @param len Length of vector in bytes. Must be aligned to 32B.
  38. * @param gftbl Pointer to 32-byte array of pre-calculated constants based on C.
  39. * @param src Pointer to src data array. Must be aligned to 32B.
  40. * @param dest Pointer to destination data array. Must be aligned to 32B.
  41. * @returns 0 pass, other fail
  42. *
  43. * int gf_vect_mul(int len, unsigned char *gftbl, void *src, void *dest);
  44. */
  45. /* arguments */
  46. x_len .req x0
  47. x_tbl .req x1
  48. x_src .req x2
  49. x_dest .req x3
  50. x_tmp .req x4
  51. /* returns */
  52. w_ret .req w0
  53. /* local variables */
  54. x_pos .req x5
  55. /* vectors */
  56. z_mask0f .req z0
  57. z_src .req z1
  58. z_src_lo .req z2
  59. z_src_hi .req z_src /* reuse */
  60. z_dest .req z3
  61. z_tmp1_lo .req z4
  62. z_tmp1_hi .req z_dest /* reuse */
  63. z_gft1_lo .req z6
  64. z_gft1_hi .req z7
  65. q_gft1_lo .req q6
  66. q_gft1_hi .req q7
  67. cdecl(gf_vect_mul_sve):
  68. /* len not aligned to 32B, return_fail */
  69. and x_tmp, x_len, #0x1f
  70. cmp x_tmp, #0
  71. bne .return_fail
  72. mov z_mask0f.b, #0x0f /* z_mask0f = 0x0F0F...0F */
  73. mov x_pos, #0
  74. /* Load with NEON instruction ldp */
  75. ldp q_gft1_lo, q_gft1_hi, [x_tbl]
  76. /* vector length agnostic */
  77. .Lloopsve_vl:
  78. whilelo p0.b, x_pos, x_len
  79. b.none .return_pass
  80. /* load src data, governed by p0 */
  81. ld1b z_src.b, p0/z, [x_src, x_pos]
  82. /* split 4-bit lo; 4-bit hi */
  83. and z_src_lo.d, z_src.d, z_mask0f.d
  84. lsr z_src_hi.b, z_src.b, #4
  85. /* table indexing, ie. gf(2^8) multiplication */
  86. tbl z_tmp1_lo.b, {z_gft1_lo.b}, z_src_lo.b
  87. tbl z_tmp1_hi.b, {z_gft1_hi.b}, z_src_hi.b
  88. /* exclusive or, ie. gf(2^8) add */
  89. eor z_dest.d, z_tmp1_hi.d, z_tmp1_lo.d
  90. /* store dest data, governed by p0 */
  91. st1b z_dest.b, p0, [x_dest, x_pos]
  92. /* increment one vector length */
  93. incb x_pos
  94. b .Lloopsve_vl
  95. .return_pass:
  96. mov w_ret, #0
  97. ret
  98. .return_fail:
  99. mov w_ret, #1
  100. ret