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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. static __inline unsigned long rpcc(void){
  55. unsigned long clocks;
  56. __asm__ __volatile__ ("rd %%tick, %0" : "=r" (clocks));
  57. return clocks;
  58. };
  59. #define RPCC_DEFINED
  60. #ifdef __64BIT__
  61. #define RPCC64BIT
  62. #endif
  63. #ifndef __BIG_ENDIAN__
  64. #define __BIG_ENDIAN__
  65. #endif
  66. #ifdef DOUBLE
  67. #define GET_IMAGE(res) __asm__ __volatile__("fmovd %%f2, %0" : "=f"(res) : : "memory")
  68. #else
  69. #define GET_IMAGE(res) __asm__ __volatile__("fmovs %%f1, %0" : "=f"(res) : : "memory")
  70. #endif
  71. #define GET_IMAGE_CANCEL
  72. #ifdef SMP
  73. static __inline int blas_quickdivide(blasint x, blasint y){
  74. return x / y;
  75. }
  76. #endif
  77. #endif
  78. #ifdef ASSEMBLER
  79. #ifndef __64BIT__
  80. #define STACK_START 128
  81. #define SAVESP save %sp, -64, %sp
  82. #else
  83. #define STACK_START 2423
  84. #define SAVESP save %sp, -256, %sp
  85. #endif
  86. #define NOP or %g1, %g1, %g1
  87. #ifdef DOUBLE
  88. #define LDF ldd
  89. #define STF std
  90. #define FADD faddd
  91. #define FMUL fmuld
  92. #define FMOV fmovd
  93. #define FABS fabsd
  94. #define FSUB fsubd
  95. #define FCMP fcmpd
  96. #define FMOVG fmovdg
  97. #define FMOVL fmovdl
  98. #define FSQRT fsqrtd
  99. #define FDIV fdivd
  100. #else
  101. #define LDF ld
  102. #define STF st
  103. #define FADD fadds
  104. #define FMUL fmuls
  105. #define FMOV fmovs
  106. #define FABS fabss
  107. #define FSUB fsubs
  108. #define FCMP fcmps
  109. #define FMOVG fmovsg
  110. #define FMOVL fmovsl
  111. #define FSQRT fsqrts
  112. #define FDIV fdivs
  113. #endif
  114. #define HALT prefetch [%g0], 5
  115. #define FMADDS(rs1, rs2, rs3, rd) \
  116. .word ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 1 << 5) | (rs2))
  117. #define FMADDD(rs1, rs2, rs3, rd) \
  118. .word ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 2 << 5) | (rs2))
  119. #define FMSUBS(rs1, rs2, rs3, rd) \
  120. .word ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 5 << 5) | (rs2))
  121. #define FMSUBD(rs1, rs2, rs3, rd) \
  122. .word ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 6 << 5) | (rs2))
  123. #define FNMSUBS(rs1, rs2, rs3, rd) \
  124. .word ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 9 << 5) | (rs2))
  125. #define FNMSUBD(rs1, rs2, rs3, rd) \
  126. .word ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | (10 << 5) | (rs2))
  127. #define FNMADDS(rs1, rs2, rs3, rd) \
  128. .word ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | (13 << 5) | (rs2))
  129. #define FNMADDD(rs1, rs2, rs3, rd) \
  130. .word ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | (14 << 5) | (rs2))
  131. #define FCLRS(rd) \
  132. .word ((2 << 30) | ((rd) << 25) | ( 0x36 << 19) | ( 0x61 << 5))
  133. #define FCLRD(rd) \
  134. .word ((2 << 30) | ((rd) << 25) | ( 0x36 << 19) | ( 0x60 << 5))
  135. #define FONES(rd) \
  136. .word ((2 << 30) | ((rd) << 25) | ( 0x36 << 19) | ( 0x7f << 5))
  137. #define FONED(rd) \
  138. .word ((2 << 30) | ((rd) << 25) | ( 0x36 << 19) | ( 0x7e << 5))
  139. #ifndef DOUBLE
  140. #define FCLR(a) FCLRS(a)
  141. #define FONE(a) FONES(a)
  142. #define FMADD(a, b, c, d) FMADDS(a, b, c, d)
  143. #define FMSUB(a, b, c, d) FMSUBS(a, b, c, d)
  144. #define FNMADD(a, b, c, d) FNMADDS(a, b, c, d)
  145. #define FNMSUB(a, b, c, d) FNMSUBS(a, b, c, d)
  146. #else
  147. #define FCLR(a) FCLRD(a)
  148. #define FONE(a) FONED(a)
  149. #define FMADD(a, b, c, d) FMADDD(a, b, c, d)
  150. #define FMSUB(a, b, c, d) FMSUBD(a, b, c, d)
  151. #define FNMADD(a, b, c, d) FNMADDD(a, b, c, d)
  152. #define FNMSUB(a, b, c, d) FNMSUBD(a, b, c, d)
  153. #endif
  154. #ifndef F_INTERFACE
  155. #define REALNAME ASMNAME
  156. #else
  157. #define REALNAME ASMFNAME
  158. #endif
  159. #ifdef sparc
  160. #define PROLOGUE \
  161. .section ".text"; \
  162. .align 32; \
  163. .global REALNAME;\
  164. .type REALNAME, #function; \
  165. .proc 07; \
  166. REALNAME:;
  167. #if defined(__linux__) && defined(__ELF__)
  168. #define GNUSTACK .section .note.GNU-stack,"",@progbits
  169. #else
  170. #define GNUSTACK
  171. #endif
  172. #define EPILOGUE \
  173. .size REALNAME, .-REALNAME; \
  174. GNUSTACK
  175. #endif
  176. #endif
  177. #ifdef sparc
  178. #define SEEK_ADDRESS
  179. #endif
  180. #define BUFFER_SIZE (32 << 20)
  181. #ifndef PAGESIZE
  182. #define PAGESIZE ( 8 << 10)
  183. #endif
  184. #define HUGE_PAGESIZE ( 4 << 20)
  185. #define BASE_ADDRESS (START_ADDRESS - BUFFER_SIZE * MAX_CPU_NUMBER)
  186. #ifndef MAP_ANONYMOUS
  187. #define MAP_ANONYMOUS MAP_ANON
  188. #endif
  189. #endif