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.7 kB

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