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

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