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.

isamax.c 8.9 kB

7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /***************************************************************************
  2. Copyright (c) 2013-2019, 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. #include "common.h"
  28. #include <math.h>
  29. #define ABS fabsf
  30. static BLASLONG isamax_kernel_64(BLASLONG n, FLOAT *x, FLOAT *amax) {
  31. BLASLONG iamax;
  32. __asm__("vl %%v0,0(%[x])\n\t"
  33. "vflpsb %%v0,%%v0\n\t"
  34. "vleig %%v1,0,0\n\t"
  35. "vleig %%v1,2,1\n\t"
  36. "vleig %%v2,1,0\n\t"
  37. "vleig %%v2,3,1\n\t"
  38. "vrepig %%v3,32\n\t"
  39. "vzero %%v4\n\t"
  40. "vleif %%v24,0,0\n\t"
  41. "vleif %%v24,1,1\n\t"
  42. "vleif %%v24,2,2\n\t"
  43. "vleif %%v24,3,3\n\t"
  44. "vleif %%v25,4,0\n\t"
  45. "vleif %%v25,5,1\n\t"
  46. "vleif %%v25,6,2\n\t"
  47. "vleif %%v25,7,3\n\t"
  48. "vleif %%v26,8,0\n\t"
  49. "vleif %%v26,9,1\n\t"
  50. "vleif %%v26,10,2\n\t"
  51. "vleif %%v26,11,3\n\t"
  52. "vleif %%v27,12,0\n\t"
  53. "vleif %%v27,13,1\n\t"
  54. "vleif %%v27,14,2\n\t"
  55. "vleif %%v27,15,3\n\t"
  56. "vleif %%v28,16,0\n\t"
  57. "vleif %%v28,17,1\n\t"
  58. "vleif %%v28,18,2\n\t"
  59. "vleif %%v28,19,3\n\t"
  60. "vleif %%v29,20,0\n\t"
  61. "vleif %%v29,21,1\n\t"
  62. "vleif %%v29,22,2\n\t"
  63. "vleif %%v29,23,3\n\t"
  64. "vleif %%v30,24,0\n\t"
  65. "vleif %%v30,25,1\n\t"
  66. "vleif %%v30,26,2\n\t"
  67. "vleif %%v30,27,3\n\t"
  68. "vleif %%v31,28,0\n\t"
  69. "vleif %%v31,29,1\n\t"
  70. "vleif %%v31,30,2\n\t"
  71. "vleif %%v31,31,3\n\t"
  72. "srlg %[n],%[n],6\n\t"
  73. "xgr %%r1,%%r1\n\t"
  74. "0:\n\t"
  75. "pfd 1, 1024(%%r1,%[x])\n\t"
  76. "vl %%v16,0(%%r1,%[x])\n\t"
  77. "vl %%v17,16(%%r1,%[x])\n\t"
  78. "vl %%v18,32(%%r1,%[x])\n\t"
  79. "vl %%v19,48(%%r1,%[x])\n\t"
  80. "vl %%v20,64(%%r1,%[x])\n\t"
  81. "vl %%v21,80(%%r1,%[x])\n\t"
  82. "vl %%v22,96(%%r1,%[x])\n\t"
  83. "vl %%v23,112(%%r1,%[x])\n\t"
  84. "vflpsb %%v16, %%v16\n\t"
  85. "vflpsb %%v17, %%v17\n\t"
  86. "vflpsb %%v18, %%v18\n\t"
  87. "vflpsb %%v19, %%v19\n\t"
  88. "vflpsb %%v20, %%v20\n\t"
  89. "vflpsb %%v21, %%v21\n\t"
  90. "vflpsb %%v22, %%v22\n\t"
  91. "vflpsb %%v23, %%v23\n\t"
  92. "vfchesb %%v5,%%v16,%%v17\n\t"
  93. "vfchesb %%v6,%%v18,%%v19\n\t"
  94. "vfchesb %%v7,%%v20,%%v21\n\t"
  95. "vfchesb %%v8,%%v22,%%v23\n\t"
  96. "vsel %%v16,%%v16,%%v17,%%v5\n\t"
  97. "vsel %%v5,%%v24,%%v25,%%v5\n\t"
  98. "vsel %%v17,%%v18,%%v19,%%v6\n\t"
  99. "vsel %%v6,%%v26,%%v27,%%v6\n\t"
  100. "vsel %%v18,%%v20,%%v21,%%v7\n\t"
  101. "vsel %%v7,%%v28,%%v29,%%v7\n\t"
  102. "vsel %%v19,%%v22,%%v23,%%v8\n\t"
  103. "vsel %%v8,%%v30,%%v31,%%v8\n\t"
  104. "vfchesb %%v20,%%v16,%%v17\n\t"
  105. "vfchesb %%v21,%%v18,%%v19\n\t"
  106. "vsel %%v16,%%v16,%%v17,%%v20\n\t"
  107. "vsel %%v5,%%v5,%%v6,%%v20\n\t"
  108. "vsel %%v17,%%v18,%%v19,%%v21\n\t"
  109. "vsel %%v6,%%v7,%%v8,%%v21\n\t"
  110. "vfchesb %%v18,%%v16,%%v17\n\t"
  111. "vsel %%v16,%%v16,%%v17,%%v18\n\t"
  112. "vsel %%v5,%%v5,%%v6,%%v18\n\t"
  113. "vsegf %%v6,%%v5\n\t"
  114. "vesrlg %%v5,%%v5,32\n\t"
  115. "vag %%v5,%%v5,%%v4\n\t"
  116. "vag %%v6,%%v6,%%v4\n\t"
  117. "vfchesb %%v7,%%v0,%%v16\n\t"
  118. "vsel %%v0,%%v0,%%v16,%%v7\n\t"
  119. "vsegf %%v8,%%v7\n\t"
  120. "vesrlg %%v7,%%v7,32\n\t"
  121. "vsegf %%v7,%%v7\n\t"
  122. "vsel %%v1,%%v1,%%v5,%%v7\n\t"
  123. "vsel %%v2,%%v2,%%v6,%%v8\n\t"
  124. "vag %%v4,%%v4,%%v3\n\t"
  125. "vl %%v16,128(%%r1,%[x])\n\t"
  126. "vl %%v17,144(%%r1,%[x])\n\t"
  127. "vl %%v18,160(%%r1,%[x])\n\t"
  128. "vl %%v19,176(%%r1,%[x])\n\t"
  129. "vl %%v20,192(%%r1,%[x])\n\t"
  130. "vl %%v21,208(%%r1,%[x])\n\t"
  131. "vl %%v22,224(%%r1,%[x])\n\t"
  132. "vl %%v23,240(%%r1,%[x])\n\t"
  133. "vflpsb %%v16, %%v16\n\t"
  134. "vflpsb %%v17, %%v17\n\t"
  135. "vflpsb %%v18, %%v18\n\t"
  136. "vflpsb %%v19, %%v19\n\t"
  137. "vflpsb %%v20, %%v20\n\t"
  138. "vflpsb %%v21, %%v21\n\t"
  139. "vflpsb %%v22, %%v22\n\t"
  140. "vflpsb %%v23, %%v23\n\t"
  141. "vfchesb %%v5,%%v16,%%v17\n\t"
  142. "vfchesb %%v6,%%v18,%%v19\n\t"
  143. "vfchesb %%v7,%%v20,%%v21\n\t"
  144. "vfchesb %%v8,%%v22,%%v23\n\t"
  145. "vsel %%v16,%%v16,%%v17,%%v5\n\t"
  146. "vsel %%v5,%%v24,%%v25,%%v5\n\t"
  147. "vsel %%v17,%%v18,%%v19,%%v6\n\t"
  148. "vsel %%v6,%%v26,%%v27,%%v6\n\t"
  149. "vsel %%v18,%%v20,%%v21,%%v7\n\t"
  150. "vsel %%v7,%%v28,%%v29,%%v7\n\t"
  151. "vsel %%v19,%%v22,%%v23,%%v8\n\t"
  152. "vsel %%v8,%%v30,%%v31,%%v8\n\t"
  153. "vfchesb %%v20,%%v16,%%v17\n\t"
  154. "vfchesb %%v21,%%v18,%%v19\n\t"
  155. "vsel %%v16,%%v16,%%v17,%%v20\n\t"
  156. "vsel %%v5,%%v5,%%v6,%%v20\n\t"
  157. "vsel %%v17,%%v18,%%v19,%%v21\n\t"
  158. "vsel %%v6,%%v7,%%v8,%%v21\n\t"
  159. "vfchesb %%v18,%%v16,%%v17\n\t"
  160. "vsel %%v16,%%v16,%%v17,%%v18\n\t"
  161. "vsel %%v5,%%v5,%%v6,%%v18\n\t"
  162. "vsegf %%v6,%%v5\n\t"
  163. "vesrlg %%v5,%%v5,32\n\t"
  164. "vag %%v5,%%v5,%%v4\n\t"
  165. "vag %%v6,%%v6,%%v4\n\t"
  166. "vfchesb %%v7,%%v0,%%v16\n\t"
  167. "vsel %%v0,%%v0,%%v16,%%v7\n\t"
  168. "vsegf %%v8,%%v7\n\t"
  169. "vesrlg %%v7,%%v7,32\n\t"
  170. "vsegf %%v7,%%v7\n\t"
  171. "vsel %%v1,%%v1,%%v5,%%v7\n\t"
  172. "vsel %%v2,%%v2,%%v6,%%v8\n\t"
  173. "vag %%v4,%%v4,%%v3\n\t"
  174. "agfi %%r1, 256\n\t"
  175. "brctg %[n], 0b\n\t"
  176. "veslg %%v3,%%v0,32\n\t"
  177. "vfchsb %%v4,%%v0,%%v3\n\t"
  178. "vchlg %%v5,%%v2,%%v1\n\t"
  179. "vfcesb %%v6,%%v0,%%v3\n\t"
  180. "vn %%v5,%%v5,%%v6\n\t"
  181. "vo %%v4,%%v4,%%v5\n\t"
  182. "vsel %%v0,%%v0,%%v3,%%v4\n\t"
  183. "vesrlg %%v4,%%v4,32\n\t"
  184. "vsegf %%v4,%%v4\n\t"
  185. "vsel %%v1,%%v1,%%v2,%%v4\n\t"
  186. "vrepf %%v2,%%v0,2\n\t"
  187. "vrepg %%v3,%%v1,1\n\t"
  188. "wfcsb %%v2,%%v0\n\t"
  189. "jne 1f\n\t"
  190. "vstef %%v0,%[amax],0\n\t"
  191. "vmnlg %%v0,%%v1,%%v3\n\t"
  192. "vlgvg %[iamax],%%v0,0\n\t"
  193. "j 2f\n\t"
  194. "1:\n\t"
  195. "wfchsb %%v4,%%v2,%%v0\n\t"
  196. "vesrlg %%v4,%%v4,32\n\t"
  197. "vsegf %%v4,%%v4\n\t"
  198. "vsel %%v1,%%v3,%%v1,%%v4\n\t"
  199. "vsel %%v0,%%v2,%%v0,%%v4\n\t"
  200. "ste %%f0,%[amax]\n\t"
  201. "vlgvg %[iamax],%%v1,0\n\t"
  202. "2:\n\t"
  203. "nop 0"
  204. : [iamax] "=r"(iamax),[amax] "=Q"(*amax),[n] "+&r"(n)
  205. : "m"(*(const FLOAT(*)[n]) x),[x] "a"(x)
  206. : "cc", "r1", "v0", "v1", "v2", "v4", "v5", "v6", "v7", "v8", "v16",
  207. "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26",
  208. "v27", "v28", "v29", "v30", "v31");
  209. return iamax;
  210. }
  211. BLASLONG CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x) {
  212. BLASLONG i = 0;
  213. BLASLONG j = 0;
  214. FLOAT maxf = 0.0;
  215. BLASLONG max = 0;
  216. if (n <= 0 || inc_x <= 0)
  217. return (max);
  218. if (inc_x == 1) {
  219. BLASLONG n1 = n & -64;
  220. if (n1 > 0) {
  221. max = isamax_kernel_64(n1, x, &maxf);
  222. i = n1;
  223. } else {
  224. maxf = ABS(x[0]);
  225. i++;
  226. }
  227. while (i < n) {
  228. if (ABS(x[i]) > maxf) {
  229. max = i;
  230. maxf = ABS(x[i]);
  231. }
  232. i++;
  233. }
  234. return (max + 1);
  235. } else {
  236. max = 0;
  237. maxf = ABS(x[0]);
  238. BLASLONG n1 = n & -4;
  239. while (j < n1) {
  240. if (ABS(x[i]) > maxf) {
  241. max = j;
  242. maxf = ABS(x[i]);
  243. }
  244. if (ABS(x[i + inc_x]) > maxf) {
  245. max = j + 1;
  246. maxf = ABS(x[i + inc_x]);
  247. }
  248. if (ABS(x[i + 2 * inc_x]) > maxf) {
  249. max = j + 2;
  250. maxf = ABS(x[i + 2 * inc_x]);
  251. }
  252. if (ABS(x[i + 3 * inc_x]) > maxf) {
  253. max = j + 3;
  254. maxf = ABS(x[i + 3 * inc_x]);
  255. }
  256. i += inc_x * 4;
  257. j += 4;
  258. }
  259. while (j < n) {
  260. if (ABS(x[i]) > maxf) {
  261. max = j;
  262. maxf = ABS(x[i]);
  263. }
  264. i += inc_x;
  265. j++;
  266. }
  267. return (max + 1);
  268. }
  269. }