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.

common_mips64.h 8.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*****************************************************************************
  2. Copyright (c) 2011-2014, 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
  16. 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 COPYRIGHT OWNER OR CONTRIBUTORS BE
  21. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  23. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  25. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  26. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. **********************************************************************************/
  28. /*********************************************************************/
  29. /* Copyright 2009, 2010 The University of Texas at Austin. */
  30. /* All rights reserved. */
  31. /* */
  32. /* Redistribution and use in source and binary forms, with or */
  33. /* without modification, are permitted provided that the following */
  34. /* conditions are met: */
  35. /* */
  36. /* 1. Redistributions of source code must retain the above */
  37. /* copyright notice, this list of conditions and the following */
  38. /* disclaimer. */
  39. /* */
  40. /* 2. Redistributions in binary form must reproduce the above */
  41. /* copyright notice, this list of conditions and the following */
  42. /* disclaimer in the documentation and/or other materials */
  43. /* provided with the distribution. */
  44. /* */
  45. /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
  46. /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  47. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  48. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  49. /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
  50. /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
  51. /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
  52. /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
  53. /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
  54. /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  55. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  56. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
  57. /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  58. /* POSSIBILITY OF SUCH DAMAGE. */
  59. /* */
  60. /* The views and conclusions contained in the software and */
  61. /* documentation are those of the authors and should not be */
  62. /* interpreted as representing official policies, either expressed */
  63. /* or implied, of The University of Texas at Austin. */
  64. /*********************************************************************/
  65. #ifndef COMMON_MIPS64
  66. #define COMMON_MIPS64
  67. #define MB
  68. #define WMB
  69. #define INLINE inline
  70. #ifndef ASSEMBLER
  71. static void INLINE blas_lock(volatile unsigned long *address){
  72. long int ret, val = 1;
  73. do {
  74. while (*address) {YIELDING;};
  75. __asm__ __volatile__(
  76. "1: ll %0, %3\n"
  77. " ori %2, %0, 1\n"
  78. " sc %2, %1\n"
  79. " beqz %2, 1b\n"
  80. " andi %2, %0, 1\n"
  81. " sync\n"
  82. : "=&r" (val), "=m" (address), "=&r" (ret)
  83. : "m" (address)
  84. : "memory");
  85. } while (ret);
  86. }
  87. static inline unsigned int rpcc(void){
  88. unsigned long ret;
  89. #if defined(LOONGSON3A) || defined(LOONGSON3B)
  90. // unsigned long long tmp;
  91. //__asm__ __volatile__("dmfc0 %0, $25, 1": "=r"(tmp):: "memory");
  92. //ret=tmp;
  93. __asm__ __volatile__(".set push \n"
  94. ".set mips32r2\n"
  95. "rdhwr %0, $2\n"
  96. ".set pop": "=r"(ret):: "memory");
  97. #else
  98. __asm__ __volatile__(".set push \n"
  99. ".set mips32r2\n"
  100. "rdhwr %0, $30 \n"
  101. ".set pop" : "=r"(ret) : : "memory");
  102. #endif
  103. return ret;
  104. }
  105. #if defined(LOONGSON3A) || defined(LOONGSON3B)
  106. #ifndef NO_AFFINITY
  107. #define WHEREAMI
  108. static inline int WhereAmI(void){
  109. int ret=0;
  110. __asm__ __volatile__(".set push \n"
  111. ".set mips32r2\n"
  112. "rdhwr %0, $0\n"
  113. ".set pop": "=r"(ret):: "memory");
  114. return ret;
  115. }
  116. #endif
  117. #endif
  118. static inline int blas_quickdivide(blasint x, blasint y){
  119. return x / y;
  120. }
  121. #ifdef DOUBLE
  122. #define GET_IMAGE(res) __asm__ __volatile__("mov.d %0, $f2" : "=f"(res) : : "memory")
  123. #else
  124. #define GET_IMAGE(res) __asm__ __volatile__("mov.s %0, $f2" : "=f"(res) : : "memory")
  125. #endif
  126. #define GET_IMAGE_CANCEL
  127. #endif
  128. #ifdef ASSEMBLER
  129. #define HALT teq $0, $0
  130. #define NOP move $0, $0
  131. #ifdef DOUBLE
  132. #define LD ldc1
  133. #define ST sdc1
  134. #define MADD madd.d
  135. #define NMADD nmadd.d
  136. #define MSUB msub.d
  137. #define NMSUB nmsub.d
  138. #define ADD add.d
  139. #define SUB sub.d
  140. #define MUL mul.d
  141. #define MOV mov.d
  142. #define CMOVF movf.d
  143. #define CMOVT movt.d
  144. #define MTC dmtc1
  145. #define FABS abs.d
  146. #define CMPEQ c.eq.d
  147. #define CMPLE c.le.d
  148. #define CMPLT c.lt.d
  149. #define NEG neg.d
  150. #else
  151. #define LD lwc1
  152. #define ST swc1
  153. #define MADD madd.s
  154. #define NMADD nmadd.s
  155. #define MSUB msub.s
  156. #define NMSUB nmsub.s
  157. #define ADD add.s
  158. #define SUB sub.s
  159. #define MUL mul.s
  160. #define MOV mov.s
  161. #define CMOVF movf.s
  162. #define CMOVT movt.s
  163. #define MTC mtc1
  164. #define FABS abs.s
  165. #define CMPEQ c.eq.s
  166. #define CMPLE c.le.s
  167. #define CMPLT c.lt.s
  168. #define PLU plu.ps
  169. #define PLL pll.ps
  170. #define PUU puu.ps
  171. #define PUL pul.ps
  172. #define MADPS madd.ps
  173. #define CVTU cvt.s.pu
  174. #define CVTL cvt.s.pl
  175. #define NEG neg.s
  176. #endif
  177. #if defined(__64BIT__) && defined(USE64BITINT)
  178. #define LDINT ld
  179. #define LDARG ld
  180. #define SDARG sd
  181. #elif defined(__64BIT__) && !defined(USE64BITINT)
  182. #define LDINT lw
  183. #define LDARG ld
  184. #define SDARG sd
  185. #else
  186. #define LDINT lw
  187. #define LDARG lw
  188. #define SDARG sw
  189. #endif
  190. #ifndef F_INTERFACE
  191. #define REALNAME ASMNAME
  192. #else
  193. #define REALNAME ASMFNAME
  194. #endif
  195. #if defined(ASSEMBLER) && !defined(NEEDPARAM)
  196. #define PROLOGUE \
  197. .text ;\
  198. .set mips64 ;\
  199. .align 5 ;\
  200. .globl REALNAME ;\
  201. .ent REALNAME ;\
  202. .type REALNAME, @function ;\
  203. REALNAME: ;\
  204. .set noreorder ;\
  205. .set nomacro
  206. #if defined(__linux__) && defined(__ELF__)
  207. #define GNUSTACK .section .note.GNU-stack,"",@progbits
  208. #else
  209. #define GNUSTACK
  210. #endif
  211. #define EPILOGUE \
  212. .set macro ;\
  213. .set reorder ;\
  214. .end REALNAME ;\
  215. GNUSTACK
  216. #define PROFCODE
  217. #endif
  218. #endif
  219. #define SEEK_ADDRESS
  220. #define BUFFER_SIZE ( 32 << 20)
  221. #if defined(LOONGSON3A)
  222. #define PAGESIZE (16UL << 10)
  223. #define FIXED_PAGESIZE (16UL << 10)
  224. #endif
  225. #if defined(LOONGSON3B)
  226. #define PAGESIZE (16UL << 10)
  227. #define FIXED_PAGESIZE (16UL << 10)
  228. #endif
  229. #ifndef PAGESIZE
  230. #define PAGESIZE (64UL << 10)
  231. #endif
  232. #define HUGE_PAGESIZE ( 2 << 20)
  233. #define BASE_ADDRESS (START_ADDRESS - BUFFER_SIZE * MAX_CPU_NUMBER)
  234. #ifndef MAP_ANONYMOUS
  235. #define MAP_ANONYMOUS MAP_ANON
  236. #endif
  237. #if defined(LOONGSON3A) || defined(LOONGSON3B)
  238. #define PREFETCHD_(x) ld $0, x
  239. #define PREFETCHD(x) PREFETCHD_(x)
  240. #else
  241. #define PREFETCHD(x)
  242. #endif
  243. #endif