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_sparc.h 7.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*********************************************************************/
  2. /* Copyright 2009, 2010 The University of Texas at Austin. */
  3. /* All rights reserved. */
  4. /* */
  5. /* Redistribution and use in source and binary forms, with or */
  6. /* without modification, are permitted provided that the following */
  7. /* conditions are met: */
  8. /* */
  9. /* 1. Redistributions of source code must retain the above */
  10. /* copyright notice, this list of conditions and the following */
  11. /* disclaimer. */
  12. /* */
  13. /* 2. Redistributions in binary form must reproduce the above */
  14. /* copyright notice, this list of conditions and the following */
  15. /* disclaimer in the documentation and/or other materials */
  16. /* provided with the distribution. */
  17. /* */
  18. /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
  19. /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  20. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  21. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  22. /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
  23. /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
  24. /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
  25. /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
  26. /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
  27. /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  28. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  29. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
  30. /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  31. /* POSSIBILITY OF SUCH DAMAGE. */
  32. /* */
  33. /* The views and conclusions contained in the software and */
  34. /* documentation are those of the authors and should not be */
  35. /* interpreted as representing official policies, either expressed */
  36. /* or implied, of The University of Texas at Austin. */
  37. /*********************************************************************/
  38. #ifndef COMMON_POWER
  39. #define COMMON_POWER
  40. #define MB __asm__ __volatile__ ("nop")
  41. #define WMB __asm__ __volatile__ ("nop")
  42. #ifndef ASSEMBLER
  43. static void __inline blas_lock(volatile unsigned long *address){
  44. long int ret = 1;
  45. do {
  46. while (*address) {YIELDING;};
  47. __asm__ __volatile__(
  48. "ldstub [%1], %0"
  49. : "=&r"(ret)
  50. : "r" (address)
  51. : "memory");
  52. } while (ret);
  53. }
  54. #define BLAS_LOCK_DEFINED
  55. static __inline unsigned long rpcc(void){
  56. unsigned long clocks;
  57. __asm__ __volatile__ ("rd %%tick, %0" : "=r" (clocks));
  58. return clocks;
  59. };
  60. #define RPCC_DEFINED
  61. #ifdef __64BIT__
  62. #define RPCC64BIT
  63. #endif
  64. #ifndef __BIG_ENDIAN__
  65. #define __BIG_ENDIAN__
  66. #endif
  67. #ifdef DOUBLE
  68. #define GET_IMAGE(res) __asm__ __volatile__("fmovd %%f2, %0" : "=f"(res) : : "memory")
  69. #else
  70. #define GET_IMAGE(res) __asm__ __volatile__("fmovs %%f1, %0" : "=f"(res) : : "memory")
  71. #endif
  72. #define GET_IMAGE_CANCEL
  73. #ifdef SMP
  74. static __inline int blas_quickdivide(blasint x, blasint y){
  75. return x / y;
  76. }
  77. #endif
  78. #endif
  79. #ifdef ASSEMBLER
  80. #ifndef __64BIT__
  81. #define STACK_START 128
  82. #define SAVESP save %sp, -64, %sp
  83. #else
  84. #define STACK_START 2423
  85. #define SAVESP save %sp, -256, %sp
  86. #endif
  87. #define NOP or %g1, %g1, %g1
  88. #ifdef DOUBLE
  89. #define LDF ldd
  90. #define STF std
  91. #define FADD faddd
  92. #define FMUL fmuld
  93. #define FMOV fmovd
  94. #define FABS fabsd
  95. #define FSUB fsubd
  96. #define FCMP fcmpd
  97. #define FMOVG fmovdg
  98. #define FMOVL fmovdl
  99. #define FSQRT fsqrtd
  100. #define FDIV fdivd
  101. #else
  102. #define LDF ld
  103. #define STF st
  104. #define FADD fadds
  105. #define FMUL fmuls
  106. #define FMOV fmovs
  107. #define FABS fabss
  108. #define FSUB fsubs
  109. #define FCMP fcmps
  110. #define FMOVG fmovsg
  111. #define FMOVL fmovsl
  112. #define FSQRT fsqrts
  113. #define FDIV fdivs
  114. #endif
  115. #define HALT prefetch [%g0], 5
  116. #define FMADDS(rs1, rs2, rs3, rd) \
  117. .word ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 1 << 5) | (rs2))
  118. #define FMADDD(rs1, rs2, rs3, rd) \
  119. .word ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 2 << 5) | (rs2))
  120. #define FMSUBS(rs1, rs2, rs3, rd) \
  121. .word ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 5 << 5) | (rs2))
  122. #define FMSUBD(rs1, rs2, rs3, rd) \
  123. .word ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 6 << 5) | (rs2))
  124. #define FNMSUBS(rs1, rs2, rs3, rd) \
  125. .word ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 9 << 5) | (rs2))
  126. #define FNMSUBD(rs1, rs2, rs3, rd) \
  127. .word ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | (10 << 5) | (rs2))
  128. #define FNMADDS(rs1, rs2, rs3, rd) \
  129. .word ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | (13 << 5) | (rs2))
  130. #define FNMADDD(rs1, rs2, rs3, rd) \
  131. .word ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | (14 << 5) | (rs2))
  132. #define FCLRS(rd) \
  133. .word ((2 << 30) | ((rd) << 25) | ( 0x36 << 19) | ( 0x61 << 5))
  134. #define FCLRD(rd) \
  135. .word ((2 << 30) | ((rd) << 25) | ( 0x36 << 19) | ( 0x60 << 5))
  136. #define FONES(rd) \
  137. .word ((2 << 30) | ((rd) << 25) | ( 0x36 << 19) | ( 0x7f << 5))
  138. #define FONED(rd) \
  139. .word ((2 << 30) | ((rd) << 25) | ( 0x36 << 19) | ( 0x7e << 5))
  140. #ifndef DOUBLE
  141. #define FCLR(a) FCLRS(a)
  142. #define FONE(a) FONES(a)
  143. #define FMADD(a, b, c, d) FMADDS(a, b, c, d)
  144. #define FMSUB(a, b, c, d) FMSUBS(a, b, c, d)
  145. #define FNMADD(a, b, c, d) FNMADDS(a, b, c, d)
  146. #define FNMSUB(a, b, c, d) FNMSUBS(a, b, c, d)
  147. #else
  148. #define FCLR(a) FCLRD(a)
  149. #define FONE(a) FONED(a)
  150. #define FMADD(a, b, c, d) FMADDD(a, b, c, d)
  151. #define FMSUB(a, b, c, d) FMSUBD(a, b, c, d)
  152. #define FNMADD(a, b, c, d) FNMADDD(a, b, c, d)
  153. #define FNMSUB(a, b, c, d) FNMSUBD(a, b, c, d)
  154. #endif
  155. #ifndef F_INTERFACE
  156. #define REALNAME ASMNAME
  157. #else
  158. #define REALNAME ASMFNAME
  159. #endif
  160. #ifdef sparc
  161. #define PROLOGUE \
  162. .section ".text"; \
  163. .align 32; \
  164. .global REALNAME;\
  165. .type REALNAME, #function; \
  166. .proc 07; \
  167. REALNAME:;
  168. #if defined(__linux__) && defined(__ELF__)
  169. #define GNUSTACK .section .note.GNU-stack,"",@progbits
  170. #else
  171. #define GNUSTACK
  172. #endif
  173. #define EPILOGUE \
  174. .size REALNAME, .-REALNAME; \
  175. GNUSTACK
  176. #endif
  177. #endif
  178. #ifdef sparc
  179. #define SEEK_ADDRESS
  180. #endif
  181. #define BUFFER_SIZE (32 << 20)
  182. #ifndef PAGESIZE
  183. #define PAGESIZE ( 8 << 10)
  184. #endif
  185. #define HUGE_PAGESIZE ( 4 << 20)
  186. #define BASE_ADDRESS (START_ADDRESS - BUFFER_SIZE * MAX_CPU_NUMBER)
  187. #ifndef MAP_ANONYMOUS
  188. #define MAP_ANONYMOUS MAP_ANON
  189. #endif
  190. #endif