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.

znrm2.S 7.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /***************************************************************************
  2. Copyright (c) 2021, The OpenBLAS Project
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in
  11. the documentation and/or other materials provided with the
  12. distribution.
  13. 3. Neither the name of the OpenBLAS project nor the names of
  14. its contributors may be used to endorse or promote products
  15. derived from this software without specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
  20. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  25. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *****************************************************************************/
  27. #define ASSEMBLER
  28. #include "common.h"
  29. #define N $r4
  30. #define X $r5
  31. #define INCX $r6
  32. #define XX $r7
  33. #define I $r17
  34. #define TEMP $r18
  35. #define a1 $f10
  36. #define a2 $f11
  37. #define a3 $f12
  38. #define a4 $f13
  39. #define a5 $f14
  40. #define a6 $f15
  41. #define a7 $f16
  42. #define a8 $f17
  43. #define t1 $f0
  44. #define t2 $f1
  45. #define t3 $f2
  46. #define t4 $f3
  47. #define s1 $f22
  48. #define s2 $f8
  49. #define s3 $f23
  50. #define s4 $f9
  51. #define ALPHA $f4
  52. #define max $f5
  53. PROLOGUE
  54. #ifdef F_INTERFACE
  55. LDINT N, 0(N)
  56. LDINT INCX, 0(INCX)
  57. #endif
  58. MTC s1, $r0
  59. bge $r0, N, .L999
  60. slli.d INCX, INCX, ZBASE_SHIFT
  61. beq $r0, INCX, .L999
  62. move XX, X
  63. MOV s2, s1
  64. srai.d I, N, 2
  65. MOV s3, s1
  66. MOV s4, s1
  67. bge $r0, I, .L15
  68. LD a1, X, 0 * SIZE
  69. LD a2, X, 1 * SIZE
  70. add.d X, X, INCX
  71. LD a3, X, 0 * SIZE
  72. LD a4, X, 1 * SIZE
  73. add.d X, X, INCX
  74. LD a5, X, 0 * SIZE
  75. LD a6, X, 1 * SIZE
  76. add.d X, X, INCX
  77. LD a7, X, 0 * SIZE
  78. LD a8, X, 1 * SIZE
  79. addi.d I, I, -1
  80. add.d X, X, INCX
  81. bge $r0, I, .L13
  82. .align 3
  83. .L12:
  84. FABS t1, a1
  85. LD a1, X, 0 * SIZE
  86. FABS t2, a2
  87. NOP
  88. FABS t3, a3
  89. LD a2, X, 1 * SIZE
  90. FABS t4, a4
  91. add.d X, X, INCX
  92. CMPLT $fcc0, s1, t1
  93. LD a3, X, 0 * SIZE
  94. CMPLT $fcc1, s2, t2
  95. NOP
  96. CMPLT $fcc2, s3, t3
  97. LD a4, X, 1 * SIZE
  98. CMPLT $fcc3, s4, t4
  99. add.d X, X, INCX
  100. CMOVT s1, s1, t1, $fcc0
  101. CMOVT s2, s2, t2, $fcc1
  102. CMOVT s3, s3, t3, $fcc2
  103. CMOVT s4, s4, t4, $fcc3
  104. FABS t1, a5
  105. LD a5, X, 0 * SIZE
  106. FABS t2, a6
  107. NOP
  108. FABS t3, a7
  109. LD a6, X, 1 * SIZE
  110. FABS t4, a8
  111. add.d X, X, INCX
  112. CMPLT $fcc0, s1, t1
  113. LD a7, X, 0 * SIZE
  114. CMPLT $fcc1, s2, t2
  115. NOP
  116. CMPLT $fcc2, s3, t3
  117. LD a8, X, 1 * SIZE
  118. CMPLT $fcc3, s4, t4
  119. add.d X, X, INCX
  120. CMOVT s1, s1, t1, $fcc0
  121. addi.d I, I, -1
  122. CMOVT s2, s2, t2, $fcc1
  123. CMOVT s3, s3, t3, $fcc2
  124. CMOVT s4, s4, t4, $fcc3
  125. blt $r0, I, .L12
  126. .align 3
  127. .L13:
  128. FABS t1, a1
  129. FABS t2, a2
  130. FABS t3, a3
  131. FABS t4, a4
  132. CMPLT $fcc0, s1, t1
  133. CMPLT $fcc1, s2, t2
  134. CMPLT $fcc2, s3, t3
  135. CMPLT $fcc3, s4, t4
  136. CMOVT s1, s1, t1, $fcc0
  137. CMOVT s2, s2, t2, $fcc1
  138. CMOVT s3, s3, t3, $fcc2
  139. CMOVT s4, s4, t4, $fcc3
  140. FABS t1, a5
  141. FABS t2, a6
  142. FABS t3, a7
  143. FABS t4, a8
  144. CMPLT $fcc0, s1, t1
  145. CMPLT $fcc1, s2, t2
  146. CMPLT $fcc2, s3, t3
  147. CMPLT $fcc3, s4, t4
  148. CMOVT s1, s1, t1, $fcc0
  149. CMOVT s2, s2, t2, $fcc1
  150. CMOVT s3, s3, t3, $fcc2
  151. CMOVT s4, s4, t4, $fcc3
  152. .align 3
  153. .L15:
  154. andi I, N, 3
  155. bge $r0, I, .L100
  156. .align 3
  157. .L16:
  158. LD a1, X, 0 * SIZE
  159. LD a2, X, 1 * SIZE
  160. addi.d I, I, -1
  161. FABS t1, a1
  162. FABS t2, a2
  163. CMPLT $fcc0, s1, t1
  164. CMPLT $fcc1, s2, t2
  165. CMOVT s1, s1, t1, $fcc0
  166. CMOVT s2, s2, t2, $fcc1
  167. add.d X, X, INCX
  168. blt $r0, I, .L16
  169. .align 3
  170. .L100:
  171. CMPLT $fcc0, s1, s2
  172. CMPLT $fcc1, s3, s4
  173. CMOVT s1, s1, s2, $fcc0
  174. CMOVT s3, s3, s4, $fcc1
  175. CMPLT $fcc0, s1, s3
  176. CMOVT s1, s1, s3, $fcc0
  177. lu12i.w TEMP, 0x3f800
  178. movgr2fr.d a1, $r0
  179. movgr2fr.w ALPHA, TEMP
  180. CMPEQ $fcc0, s1, a1
  181. fcvt.d.s ALPHA, ALPHA
  182. bcnez $fcc0, .L999
  183. fdiv.d ALPHA, ALPHA, s1
  184. MOV max, s1
  185. MOV s1, a1
  186. MOV s2, a1
  187. MOV s3, a1
  188. MOV s4, a1
  189. srai.d I, N, 2
  190. bge $r0, I, .L105
  191. LD a1, XX, 0 * SIZE
  192. LD a2, XX, 1 * SIZE
  193. add.d XX, XX, INCX
  194. LD a3, XX, 0 * SIZE
  195. LD a4, XX, 1 * SIZE
  196. add.d XX, XX, INCX
  197. LD a5, XX, 0 * SIZE
  198. LD a6, XX, 1 * SIZE
  199. add.d XX, XX, INCX
  200. LD a7, XX, 0 * SIZE
  201. LD a8, XX, 1 * SIZE
  202. addi.d I, I, -1
  203. add.d XX, XX, INCX
  204. bge $r0, I, .L104
  205. .align 3
  206. .L103:
  207. MUL t1, ALPHA, a1
  208. LD a1, XX, 0 * SIZE
  209. MUL t2, ALPHA, a2
  210. addi.d I, I, -1
  211. MUL t3, ALPHA, a3
  212. LD a2, XX, 1 * SIZE
  213. MUL t4, ALPHA, a4
  214. add.d XX, XX, INCX
  215. MADD s1, t1, t1, s1
  216. LD a3, XX, 0 * SIZE
  217. MADD s2, t2, t2, s2
  218. NOP
  219. MADD s3, t3, t3, s3
  220. LD a4, XX, 1 * SIZE
  221. MADD s4, t4, t4, s4
  222. add.d XX, XX, INCX
  223. MUL t1, ALPHA, a5
  224. LD a5, XX, 0 * SIZE
  225. MUL t2, ALPHA, a6
  226. NOP
  227. MUL t3, ALPHA, a7
  228. LD a6, XX, 1 * SIZE
  229. MUL t4, ALPHA, a8
  230. add.d XX, XX, INCX
  231. MADD s1, t1, t1, s1
  232. LD a7, XX, 0 * SIZE
  233. MADD s2, t2, t2, s2
  234. LD a8, XX, 1 * SIZE
  235. MADD s3, t3, t3, s3
  236. add.d XX, XX, INCX
  237. MADD s4, t4, t4, s4
  238. blt $r0, I, .L103
  239. .align 3
  240. .L104:
  241. MUL t1, ALPHA, a1
  242. MUL t2, ALPHA, a2
  243. MUL t3, ALPHA, a3
  244. MUL t4, ALPHA, a4
  245. MADD s1, t1, t1, s1
  246. MADD s2, t2, t2, s2
  247. MADD s3, t3, t3, s3
  248. MADD s4, t4, t4, s4
  249. MUL t1, ALPHA, a5
  250. MUL t2, ALPHA, a6
  251. MUL t3, ALPHA, a7
  252. MUL t4, ALPHA, a8
  253. MADD s1, t1, t1, s1
  254. MADD s2, t2, t2, s2
  255. MADD s3, t3, t3, s3
  256. MADD s4, t4, t4, s4
  257. .align 3
  258. .L105:
  259. andi I, N, 3
  260. bge $r0, I, .L998
  261. .align 3
  262. .L106:
  263. LD a1, XX, 0 * SIZE
  264. LD a2, XX, 1 * SIZE
  265. addi.d I, I, -1
  266. MUL t1, ALPHA, a1
  267. MUL t2, ALPHA, a2
  268. MADD s1, t1, t1, s1
  269. add.d XX, XX, INCX
  270. MADD s2, t2, t2, s2
  271. blt $r0, I, .L106
  272. .align 3
  273. .L998:
  274. ADD s1, s1, s2
  275. ADD s3, s3, s4
  276. ADD s1, s1, s3
  277. fsqrt.d s1, s1
  278. move $r4, $r17
  279. MUL $f0, max, s1
  280. jirl $r0, $r1, 0x0
  281. .align 3
  282. .L999:
  283. move $r4, $r17
  284. fmov.d $f0, $f22
  285. jirl $r0, $r1, 0x0
  286. EPILOGUE