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

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