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_alpha.h 5.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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_ALPHA
  39. #define COMMON_ALPHA
  40. #ifndef ASSEMBLER
  41. #define MB asm("mb")
  42. #define WMB asm("wmb")
  43. #define RMB asm("mb")
  44. static __inline void blas_lock(unsigned long *address){
  45. #ifndef __DECC
  46. unsigned long tmp1, tmp2;
  47. asm volatile(
  48. "1: ldq %1, %0\n"
  49. " bne %1, 2f\n"
  50. " ldq_l %1, %0\n"
  51. " bne %1, 2f\n"
  52. " or %1, 1, %2\n"
  53. " stq_c %2, %0\n"
  54. " beq %2, 2f\n"
  55. " mb\n "
  56. " br $31, 3f\n"
  57. "2: br $31, 1b\n"
  58. "3:\n" : "=m"(*address), "=&r"(tmp1), "=&r"(tmp2) : : "memory");
  59. #else
  60. asm (
  61. "10:"
  62. " ldq %t0, 0(%a0); "
  63. " bne %t0, 20f; "
  64. " ldq_l %t0, 0(%a0); "
  65. " bne %t0, 20f; "
  66. " or %t0, 1, %t1;"
  67. " stq_c %t1, 0(%a0); "
  68. " beq %t1, 20f; "
  69. " mb; "
  70. " br %r31,30f; "
  71. "20: "
  72. " br %r31,10b; "
  73. "30:", address);
  74. #endif
  75. }
  76. #define BLAS_LOCK_DEFINED
  77. static __inline unsigned int rpcc(void){
  78. unsigned int r0;
  79. #ifndef __DECC
  80. asm __volatile__("rpcc %0" : "=r"(r0) : : "memory");
  81. #else
  82. r0 = asm("rpcc %v0");
  83. #endif
  84. return r0;
  85. }
  86. #define RPCC_DEFINED
  87. #define HALT ldq $0, 0($0)
  88. #ifndef __DECC
  89. #define GET_IMAGE(res) asm __volatile__("fmov $f1, %0" : "=f"(res) : : "memory")
  90. #else
  91. #define GET_IMAGE(res) res = dasm("fmov $f1, %f0")
  92. #endif
  93. #ifdef SMP
  94. #ifdef USE64BITINT
  95. static __inline long blas_quickdivide(long x, long y){
  96. return x/y;
  97. }
  98. #else
  99. extern unsigned int blas_quick_divide_table[];
  100. static __inline int blas_quickdivide(unsigned int x, unsigned int y){
  101. if (y <= 1) return x;
  102. return (int)((x * (unsigned long)blas_quick_divide_table[y]) >> 32);
  103. }
  104. #endif
  105. #endif
  106. #define BASE_ADDRESS ((0x1b0UL << 33) | (0x1c0UL << 23) | (0x000UL << 13))
  107. #ifndef PAGESIZE
  108. #define PAGESIZE ( 8UL << 10)
  109. #define HUGE_PAGESIZE ( 4 << 20)
  110. #endif
  111. #define BUFFER_SIZE (32UL << 20)
  112. #else
  113. #ifndef F_INTERFACE
  114. #define REALNAME ASMNAME
  115. #else
  116. #define REALNAME ASMFNAME
  117. #endif
  118. #define PROLOGUE \
  119. .arch ev6; \
  120. .set noat; \
  121. .set noreorder; \
  122. .text; \
  123. .align 5; \
  124. .globl REALNAME; \
  125. .ent REALNAME; \
  126. REALNAME:
  127. #ifdef PROFILE
  128. #define PROFCODE \
  129. ldgp $gp, 0($27); \
  130. lda $28, _mcount; \
  131. jsr $28, ($28), _mcount; \
  132. .prologue 1
  133. #else
  134. #define PROFCODE .prologue 0
  135. #endif
  136. #if defined(__linux__) && defined(__ELF__)
  137. #define GNUSTACK .section .note.GNU-stack,"",@progbits
  138. #else
  139. #define GNUSTACK
  140. #endif
  141. #define EPILOGUE \
  142. .end REALNAME; \
  143. .ident VERSION; \
  144. GNUSTACK
  145. #endif
  146. #ifdef DOUBLE
  147. #define SXADDQ s8addq
  148. #define SXSUBL s8subl
  149. #define LD ldt
  150. #define ST stt
  151. #define STQ stq
  152. #define ADD addt/su
  153. #define SUB subt/su
  154. #define MUL mult/su
  155. #define DIV divt/su
  156. #else
  157. #define SXADDQ s4addq
  158. #define SXSUBL s4subl
  159. #define LD lds
  160. #define ST sts
  161. #define STQ stl
  162. #define ADD adds/su
  163. #define SUB subs/su
  164. #define MUL muls/su
  165. #define DIV divs/su
  166. #endif
  167. #endif