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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 __sync_synchronize()
  68. #define WMB __sync_synchronize()
  69. #define RMB __sync_synchronize()
  70. #define INLINE inline
  71. #ifndef ASSEMBLER
  72. static inline unsigned int rpcc(void){
  73. unsigned long ret;
  74. // unsigned long long tmp;
  75. //__asm__ __volatile__("dmfc0 %0, $25, 1": "=r"(tmp):: "memory");
  76. //ret=tmp;
  77. __asm__ __volatile__(".set push \n"
  78. #if !defined(__mips_isa_rev) || __mips_isa_rev < 2
  79. ".set mips32r2\n"
  80. #endif
  81. "rdhwr %0, $2\n"
  82. ".set pop": "=r"(ret):: "memory");
  83. return ret;
  84. }
  85. #define RPCC_DEFINED
  86. #ifndef NO_AFFINITY
  87. //#define WHEREAMI
  88. static inline int WhereAmI(void){
  89. int ret=0;
  90. __asm__ __volatile__(".set push \n"
  91. #if !defined(__mips_isa_rev) || __mips_isa_rev < 2
  92. ".set mips32r2\n"
  93. #endif
  94. "rdhwr %0, $0\n"
  95. ".set pop": "=r"(ret):: "memory");
  96. return ret;
  97. }
  98. #endif
  99. static inline int blas_quickdivide(blasint x, blasint y){
  100. return x / y;
  101. }
  102. #ifdef DOUBLE
  103. #define GET_IMAGE(res) __asm__ __volatile__("mov.d %0, $f2" : "=f"(res) : : "memory")
  104. #else
  105. #define GET_IMAGE(res) __asm__ __volatile__("mov.s %0, $f2" : "=f"(res) : : "memory")
  106. #endif
  107. #define GET_IMAGE_CANCEL
  108. #endif
  109. #ifdef ASSEMBLER
  110. #define HALT teq $0, $0
  111. #define NOP move $0, $0
  112. #ifdef DOUBLE
  113. #define LD ldc1
  114. #define ST sdc1
  115. #define MADD madd.d
  116. #define NMADD nmadd.d
  117. #define MSUB msub.d
  118. #define NMSUB nmsub.d
  119. #define ADD add.d
  120. #define SUB sub.d
  121. #define MUL mul.d
  122. #define MOV mov.d
  123. #define CMOVF movf.d
  124. #define CMOVT movt.d
  125. #define MTC dmtc1
  126. #define FABS abs.d
  127. #define CMPEQ c.eq.d
  128. #define CMPLE c.le.d
  129. #define CMPLT c.lt.d
  130. #define NEG neg.d
  131. #else
  132. #define LD lwc1
  133. #define ST swc1
  134. #define MADD madd.s
  135. #define NMADD nmadd.s
  136. #define MSUB msub.s
  137. #define NMSUB nmsub.s
  138. #define ADD add.s
  139. #define SUB sub.s
  140. #define MUL mul.s
  141. #define MOV mov.s
  142. #define CMOVF movf.s
  143. #define CMOVT movt.s
  144. #define MTC mtc1
  145. #define FABS abs.s
  146. #define CMPEQ c.eq.s
  147. #define CMPLE c.le.s
  148. #define CMPLT c.lt.s
  149. #define PLU plu.ps
  150. #define PLL pll.ps
  151. #define PUU puu.ps
  152. #define PUL pul.ps
  153. #define MADPS madd.ps
  154. #define CVTU cvt.s.pu
  155. #define CVTL cvt.s.pl
  156. #define NEG neg.s
  157. #endif
  158. #if defined(__64BIT__) && defined(USE64BITINT)
  159. #define LDINT ld
  160. #define LDARG ld
  161. #define SDARG sd
  162. #elif defined(__64BIT__) && !defined(USE64BITINT)
  163. #define LDINT lw
  164. #define LDARG ld
  165. #define SDARG sd
  166. #else
  167. #define LDINT lw
  168. #define LDARG lw
  169. #define SDARG sw
  170. #endif
  171. #ifndef F_INTERFACE
  172. #define REALNAME ASMNAME
  173. #else
  174. #define REALNAME ASMFNAME
  175. #endif
  176. #if defined(ASSEMBLER) && !defined(NEEDPARAM)
  177. #if defined(__mips_isa_rev) && __mips_isa_rev >= 6
  178. #define ASSEMBLER_ARCH mips64r6
  179. #else
  180. #define ASSEMBLER_ARCH mips64
  181. #endif
  182. #define PROLOGUE \
  183. .text ;\
  184. .set ASSEMBLER_ARCH ;\
  185. .align 5 ;\
  186. .globl REALNAME ;\
  187. .ent REALNAME ;\
  188. .type REALNAME, @function ;\
  189. REALNAME: ;\
  190. .set noreorder ;\
  191. .set nomacro
  192. #if defined(__linux__) && defined(__ELF__)
  193. #define GNUSTACK .section .note.GNU-stack,"",@progbits
  194. #else
  195. #define GNUSTACK
  196. #endif
  197. #define EPILOGUE \
  198. .set macro ;\
  199. .set reorder ;\
  200. .end REALNAME ;\
  201. GNUSTACK
  202. #define PROFCODE
  203. #endif
  204. #endif
  205. #define SEEK_ADDRESS
  206. #define BUFFER_SIZE ( 32 << 21)
  207. #if defined(LOONGSON3R3) || defined(LOONGSON3R4)
  208. #define PAGESIZE (16UL << 10)
  209. #define FIXED_PAGESIZE (16UL << 10)
  210. #endif
  211. #ifndef PAGESIZE
  212. #define PAGESIZE (64UL << 10)
  213. #endif
  214. #define HUGE_PAGESIZE ( 2 << 20)
  215. #define BASE_ADDRESS (START_ADDRESS - BUFFER_SIZE * MAX_CPU_NUMBER)
  216. #ifndef MAP_ANONYMOUS
  217. #define MAP_ANONYMOUS MAP_ANON
  218. #endif
  219. #if defined(LOONGSON3R3) || defined(LOONGSON3R4)
  220. #define PREFETCHD_(x) ld $0, x
  221. #define PREFETCHD(x) PREFETCHD_(x)
  222. #else
  223. #define PREFETCHD(x)
  224. #endif
  225. #endif