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.

symm_ucopy_sve.c 5.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*********************************************************************/
  2. /* Copyright 2009, 2010 The University of Texas at Austin. */
  3. /* Copyright 2023 The OpenBLAS Project */
  4. /* All rights reserved. */
  5. /* */
  6. /* Redistribution and use in source and binary forms, with or */
  7. /* without modification, are permitted provided that the following */
  8. /* conditions are met: */
  9. /* */
  10. /* 1. Redistributions of source code must retain the above */
  11. /* copyright notice, this list of conditions and the following */
  12. /* disclaimer. */
  13. /* */
  14. /* 2. Redistributions in binary form must reproduce the above */
  15. /* copyright notice, this list of conditions and the following */
  16. /* disclaimer in the documentation and/or other materials */
  17. /* provided with the distribution. */
  18. /* */
  19. /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
  20. /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  21. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  22. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  23. /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
  24. /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
  25. /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
  26. /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
  27. /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
  28. /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  29. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  30. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
  31. /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  32. /* POSSIBILITY OF SUCH DAMAGE. */
  33. /* */
  34. /* The views and conclusions contained in the software and */
  35. /* documentation are those of the authors and should not be */
  36. /* interpreted as representing official policies, either expressed */
  37. /* or implied, of The University of Texas at Austin. */
  38. /*********************************************************************/
  39. #include <stdio.h>
  40. #include "common.h"
  41. #include <arm_sve.h>
  42. int CNAME(BLASLONG m, BLASLONG n, FLOAT *a, BLASLONG lda, BLASLONG posX, BLASLONG posY, FLOAT *b){
  43. BLASLONG i, offset;
  44. #if defined(DOUBLE)
  45. uint64_t sve_size = svcntd();
  46. svint64_t posY_vec = svdup_s64(posY);
  47. svint64_t posX_vec = svdup_s64(posX);
  48. svint64_t lda_vec = svdup_s64(lda);
  49. svint64_t one_vec = svdup_s64(1LL);
  50. int64_t j = 0;
  51. svbool_t pg = svwhilelt_b64((uint64_t)j, (uint64_t)n);
  52. int64_t active = svcntp_b64(svptrue_b64(), pg);
  53. svint64_t index_neg = svindex_s64(0LL, -1LL);
  54. svint64_t index = svindex_s64(0LL, 1LL);
  55. do {
  56. offset = posX - posY;
  57. svint64_t vec_off = svdup_s64(offset);
  58. svbool_t cmp = svcmpgt(pg, vec_off, index_neg);
  59. svint64_t temp = svadd_z(pg, posX_vec, index);
  60. svint64_t temp1 = svmla_z(pg, temp, posY_vec, lda_vec);
  61. svint64_t temp2 = svmla_z(pg, posY_vec, temp, lda);
  62. svint64_t gat_ind = svsel(cmp, temp2, temp1);
  63. i = m;
  64. while (i>0) {
  65. svfloat64_t data_vec = svld1_gather_index(pg, a, gat_ind);
  66. gat_ind = svadd_m(cmp, gat_ind, one_vec);
  67. gat_ind = svadd_m(svnot_z(pg, cmp) , gat_ind, lda_vec);
  68. svst1(pg, b, data_vec);
  69. b += active;
  70. offset --;
  71. vec_off = svsub_z(pg, vec_off, one_vec);
  72. cmp = svcmpgt(pg, vec_off, index_neg);
  73. i--;
  74. }
  75. posX += sve_size;
  76. posX_vec = svdup_s64(posX);
  77. j += sve_size;
  78. pg = svwhilelt_b64((uint64_t)j, (uint64_t)n);
  79. active = svcntp_b64(svptrue_b64(), pg);
  80. } while (svptest_any(svptrue_b64(), pg));
  81. #else
  82. uint32_t sve_size = svcntw();
  83. svint32_t posY_vec = svdup_s32(posY);
  84. svint32_t posX_vec = svdup_s32(posX);
  85. svint32_t lda_vec = svdup_s32(lda);
  86. svint32_t one_vec = svdup_s32(1);
  87. int32_t N = n;
  88. int32_t j = 0;
  89. svbool_t pg = svwhilelt_b32((uint32_t)j, (uint32_t)N);
  90. int32_t active = svcntp_b32(svptrue_b32(), pg);
  91. svint32_t index_neg = svindex_s32(0, -1);
  92. svint32_t index = svindex_s32(0, 1);
  93. do {
  94. offset = posX - posY;
  95. svint32_t vec_off = svdup_s32(offset);
  96. svbool_t cmp = svcmpgt(pg, vec_off, index_neg);
  97. svint32_t temp = svadd_z(pg, posX_vec, index);
  98. svint32_t temp1 = svmla_z(pg, temp, posY_vec, lda_vec);
  99. svint32_t temp2 = svmla_z(pg, posY_vec, temp, lda);
  100. svint32_t gat_ind = svsel(cmp, temp2, temp1);
  101. i = m;
  102. while (i>0) {
  103. svfloat32_t data_vec = svld1_gather_index(pg, a, gat_ind);
  104. gat_ind = svadd_m(cmp, gat_ind, one_vec);
  105. gat_ind = svadd_m(svnot_z(pg, cmp) , gat_ind, lda_vec);
  106. svst1(pg, b, data_vec);
  107. b += active;
  108. offset --;
  109. vec_off = svsub_z(pg, vec_off, one_vec);
  110. cmp = svcmpgt(pg, vec_off, index_neg);
  111. i--;
  112. }
  113. posX += sve_size;
  114. posX_vec = svdup_s32(posX);
  115. j += sve_size;
  116. pg = svwhilelt_b32((uint32_t)j, (uint32_t)N);
  117. active = svcntp_b32(svptrue_b32(), pg);
  118. } while (svptest_any(svptrue_b32(), pg));
  119. #endif
  120. return 0;
  121. }