You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dot_kernel_sve.c 5.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /***************************************************************************
  2. Copyright (c) 2023, The OpenBLAS Project
  3. Copyright (c) 2022, Arm Ltd
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions are
  7. met:
  8. 1. Redistributions of source code must retain the above copyright
  9. notice, this list of conditions and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright
  11. notice, this list of conditions and the following disclaimer in
  12. the documentation and/or other materials provided with the
  13. distribution.
  14. 3. Neither the name of the OpenBLAS project nor the names of
  15. its contributors may be used to endorse or promote products
  16. derived from this software without specific prior written permission.
  17. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
  21. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  23. GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  26. THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *****************************************************************************/
  28. #include "common.h"
  29. #include <arm_sve.h>
  30. #ifdef DOUBLE
  31. #define DTYPE "d"
  32. #define WIDTH "d"
  33. #define SHIFT "3"
  34. #else
  35. #define DTYPE "s"
  36. #define WIDTH "w"
  37. #define SHIFT "2"
  38. #endif
  39. #define COUNT \
  40. " cnt"WIDTH" x9 \n"
  41. #define SETUP_TRUE \
  42. " ptrue p0."DTYPE" \n"
  43. #define OFFSET_INPUTS \
  44. " add x12, %[X_], x9, lsl #"SHIFT" \n" \
  45. " add x13, %[Y_], x9, lsl #"SHIFT" \n"
  46. #define TAIL_WHILE \
  47. " whilelo p1."DTYPE", x8, x0 \n"
  48. #define UPDATE(pg, x,y,out) \
  49. " ld1"WIDTH" { z2."DTYPE" }, "pg"/z, ["x", x8, lsl #"SHIFT"] \n" \
  50. " ld1"WIDTH" { z3."DTYPE" }, "pg"/z, ["y", x8, lsl #"SHIFT"] \n" \
  51. " fmla "out"."DTYPE", "pg"/m, z2."DTYPE", z3."DTYPE" \n"
  52. #define SUM_VECTOR(v) \
  53. " faddv "DTYPE""v", p0, z"v"."DTYPE" \n"
  54. #define RET \
  55. " fadd %"DTYPE"[RET_], "DTYPE"1, "DTYPE"0 \n"
  56. #define DOT_KERNEL \
  57. COUNT \
  58. " mov z1.d, #0 \n" \
  59. " mov z0.d, #0 \n" \
  60. " mov x8, #0 \n" \
  61. " movi d1, #0x0 \n" \
  62. SETUP_TRUE \
  63. " neg x10, x9, lsl #1 \n" \
  64. " ands x11, x10, x0 \n" \
  65. " b.eq 2f // skip_2x \n" \
  66. OFFSET_INPUTS \
  67. "1: // vector_2x \n" \
  68. UPDATE("p0", "%[X_]", "%[Y_]", "z1") \
  69. UPDATE("p0", "x12", "x13", "z0") \
  70. " sub x8, x8, x10 \n" \
  71. " cmp x8, x11 \n" \
  72. " b.lo 1b // vector_2x \n" \
  73. SUM_VECTOR("1") \
  74. "2: // skip_2x \n" \
  75. " neg x10, x9 \n" \
  76. " and x10, x10, x0 \n" \
  77. " cmp x8, x10 \n" \
  78. " b.hs 4f // tail \n" \
  79. "3: // vector_1x \n" \
  80. UPDATE("p0", "%[X_]", "%[Y_]", "z0") \
  81. " add x8, x8, x9 \n" \
  82. " cmp x8, x10 \n" \
  83. " b.lo 3b // vector_1x \n" \
  84. "4: // tail \n" \
  85. " cmp x10, x0 \n" \
  86. " b.eq 5f // end \n" \
  87. TAIL_WHILE \
  88. UPDATE("p1", "%[X_]", "%[Y_]", "z0") \
  89. "5: // end \n" \
  90. SUM_VECTOR("0") \
  91. RET
  92. static
  93. FLOAT
  94. dot_kernel_sve(BLASLONG n, FLOAT* x, FLOAT* y)
  95. {
  96. FLOAT ret;
  97. asm(DOT_KERNEL
  98. :
  99. [RET_] "=&w" (ret)
  100. :
  101. [N_] "r" (n),
  102. [X_] "r" (x),
  103. [Y_] "r" (y)
  104. : "cc",
  105. "memory",
  106. "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
  107. "x8", "x9", "x10", "x11", "x12", "x13", "d1",
  108. "z0", "z1"
  109. );
  110. return ret;
  111. }