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_ia64.h 10 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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_IA64
  39. #define COMMON_IA64
  40. #ifndef ASSEMBLER
  41. #ifndef MAP_WRITECOMBINED
  42. #define MAP_WRITECOMBINED 0x10000
  43. #endif
  44. #define MB
  45. #define WMB
  46. #ifdef __ECC
  47. #include <ia64intrin.h>
  48. #endif
  49. #define RPCC64BIT
  50. #ifndef __ECC
  51. static __inline void blas_lock(volatile unsigned long *address){
  52. unsigned long ret;
  53. do {
  54. while (*address) {YIELDING;};
  55. __asm__ __volatile__ ("mov ar.ccv=r0\n;;\n"
  56. "cmpxchg4.acq %0=[%2],%1,ar.ccv\n"
  57. : "=r"(ret) : "r"(1), "r"(address)
  58. : "ar.ccv", "memory");
  59. } while (ret);
  60. }
  61. static __inline unsigned long rpcc(void) {
  62. unsigned long clocks;
  63. __asm__ __volatile__ ("mov %0=ar.itc" : "=r"(clocks));
  64. return clocks;
  65. }
  66. #define RPCC_DEFINED
  67. static __inline unsigned long stmxcsr(void){
  68. unsigned long fp;
  69. __asm__ __volatile__ ("mov.m %0=ar.fpsr" : "=r" (fp));
  70. return fp;
  71. }
  72. static __inline void ldmxcsr(unsigned long fp) {
  73. __asm__ __volatile__ ("mov.m ar.fpsr=%0" :: "r" (fp));
  74. }
  75. #define GET_IMAGE(res) asm __volatile__("mov %0 = f9" : "=f"(res) : : "memory")
  76. #else
  77. static __inline void blas_lock(volatile unsigned long *address){
  78. while (*address || _InterlockedCompareExchange((volatile int *) address,1,0))
  79. ;
  80. }
  81. static __inline unsigned int rpcc(void) {
  82. return __getReg(_IA64_REG_AR_ITC);
  83. }
  84. #define RPCC_DEFINED
  85. static __inline unsigned int stmxcsr(void) {
  86. return __getReg(_IA64_REG_AR_FPSR);
  87. }
  88. static __inline void ldmxcsr(unsigned long fp) {
  89. return __setReg(_IA64_REG_AR_FPSR, fp);
  90. }
  91. #ifdef DOUBLE
  92. #define GET_IMAGE(res) __stfd(&res, 9)
  93. #else
  94. #define GET_IMAGE(res) __stfs(&res, 9)
  95. #endif
  96. #endif
  97. #define GET_IMAGE_CANCEL
  98. #ifdef ENABLE_SSE_EXCEPTION
  99. #define IDEBUG_START \
  100. { \
  101. unsigned long fp_sse_mode, new_fp_mode; \
  102. fp_sse_mode = stmxcsr();\
  103. new_fp_mode = (fp_sse_mode & ~(FE_UNDERFLOW | FE_OVERFLOW | FE_UNNORMAL | FE_INVALID));\
  104. ldmxcsr(new_fp_mode);
  105. #define IDEBUG_END \
  106. ldmxcsr(fp_sse_mode); \
  107. }
  108. #endif
  109. #ifdef SMP
  110. #ifdef USE64BITINT
  111. /* 64bit version */
  112. extern unsigned long blas_quick_divide_table[];
  113. #ifndef __ECC
  114. static __inline long blas_quickdivide(unsigned long int x, unsigned long int y){
  115. unsigned long ret;
  116. if (y <= 1) return x;
  117. __asm__ __volatile__("setf.sig f6 = %1\n\t"
  118. "ldf8 f7 = [%2];;\n\t"
  119. "xmpy.hu f6= f6, f7;;\n\t"
  120. "getf.sig %0 = f6;;\n"
  121. : "=r"(ret)
  122. : "r"(x), "r"(&blas_quick_divide_table[y]) : "f6", "f7"
  123. );
  124. return ret;
  125. }
  126. #else
  127. /* Using Intel Compiler */
  128. static __inline long blas_quickdivide(unsigned long int x, unsigned long int y){
  129. if (y <= 1) return x;
  130. return _m64_xmahu(x, blas_quick_divide_table[y], 0);
  131. }
  132. #endif
  133. #else
  134. /* 32bit version */
  135. extern unsigned int blas_quick_divide_table[];
  136. static __inline int blas_quickdivide(unsigned int x, unsigned int y){
  137. if (y <= 1) return x;
  138. return (int)((x * (unsigned long)blas_quick_divide_table[y]) >> 32);
  139. }
  140. #endif
  141. #endif
  142. #endif
  143. #if 0
  144. #ifdef DOUBLE
  145. #define GEMM_NCOPY dgemm_ncopy
  146. #define GEMM_TCOPY dgemm_tcopy
  147. #define ZGEMM_NCOPY zgemm_ncopy
  148. #define ZGEMM_TCOPY zgemm_tcopy
  149. #define GEMM_KERNEL dgemm_kernel
  150. #if defined(NN) || defined(NT) || defined(TN) || defined(TT)
  151. #define ZGEMM_KERNEL zgemm_kernel_n
  152. #endif
  153. #if defined(CN) || defined(CT) || defined(RN) || defined(RT)
  154. #define ZGEMM_KERNEL zgemm_kernel_l
  155. #endif
  156. #if defined(NC) || defined(TC) || defined(NR) || defined(TR)
  157. #define ZGEMM_KERNEL zgemm_kernel_r
  158. #endif
  159. #if defined(CC) || defined(CR) || defined(RC) || defined(RR)
  160. #define ZGEMM_KERNEL zgemm_kernel_b
  161. #endif
  162. #else
  163. #define GEMM_NCOPY sgemm_ncopy
  164. #define GEMM_TCOPY sgemm_tcopy
  165. #define ZGEMM_NCOPY cgemm_ncopy
  166. #define ZGEMM_TCOPY cgemm_tcopy
  167. #define GEMM_KERNEL sgemm_kernel
  168. #if defined(NN) || defined(NT) || defined(TN) || defined(TT)
  169. #define ZGEMM_KERNEL cgemm_kernel_n
  170. #endif
  171. #if defined(CN) || defined(CT) || defined(RN) || defined(RT)
  172. #define ZGEMM_KERNEL cgemm_kernel_l
  173. #endif
  174. #if defined(NC) || defined(TC) || defined(NR) || defined(TR)
  175. #define ZGEMM_KERNEL cgemm_kernel_r
  176. #endif
  177. #if defined(CC) || defined(CR) || defined(RC) || defined(RR)
  178. #define ZGEMM_KERNEL cgemm_kernel_b
  179. #endif
  180. #endif
  181. #endif
  182. #ifdef USE64BITINT
  183. #define LDINT ld8
  184. #define INTSIZE 8
  185. #define CMP4GE cmp.ge
  186. #define CMP4NE cmp.ge
  187. #define CMP4EQ cmp.eq
  188. #else
  189. #define LDINT ld4
  190. #define INTSIZE 4
  191. #define CMP4GE cmp4.ge
  192. #define CMP4NE cmp4.ne
  193. #define CMP4EQ cmp4.eq
  194. #endif
  195. #define HALT mov r0 = 0
  196. #ifdef XDOUBLE
  197. #define LD8 ld8
  198. #define ST8 st8
  199. #define LDFD ldfe
  200. #define LDFPD ldfpe
  201. #define LDFD_T1 ldfe.t1
  202. #define LDFD_NT1 ldfe.nt1
  203. #define LDFD_NT2 ldfe.nt2
  204. #define LDFD_NTA ldfe.nta
  205. #define LDFPD_NT1 ldfpe.nt1
  206. #define LDFPD_NT2 ldfpe.nt2
  207. #define LDFPD_NTA ldfpe.nta
  208. #define STFD stfe
  209. #define STFD_NTA stfe.nta
  210. #define FADD fadd
  211. #define FSUB fsub
  212. #define FMPY fmpy
  213. #define FMA fma
  214. #define FMS fms
  215. #define FNMA fnma
  216. #define FPMA fpma
  217. #define SETF setf.d
  218. #elif defined(DOUBLE)
  219. #define LD8 ld8
  220. #define ST8 st8
  221. #define LDF8 ldf8
  222. #define LDF8_NT1 ldf8.nt1
  223. #define LDF8_NTA ldf8.nta
  224. #define STF8 stf8
  225. #define STF8_NTA stf8.nta
  226. #define LDFD ldfd
  227. #define LDFPD ldfpd
  228. #define LDFD_T1 ldfd.t1
  229. #define LDFD_NT1 ldfd.nt1
  230. #define LDFD_NT2 ldfd.nt2
  231. #define LDFD_NTA ldfd.nta
  232. #define LDFPD_NT1 ldfpd.nt1
  233. #define LDFPD_NT2 ldfpd.nt2
  234. #define LDFPD_NTA ldfpd.nta
  235. #define STFD stfd
  236. #define STFD_NTA stfd.nta
  237. #define FADD fadd.d
  238. #define FSUB fsub.d
  239. #define FMPY fmpy.d
  240. #define FMA fma.d
  241. #define FMS fms.d
  242. #define FNMA fnma.d
  243. #define FPMA fpma.d
  244. #define SETF setf.d
  245. #else
  246. #define LD8 ld4
  247. #define ST8 st4
  248. #define LDF8 ldfs
  249. #define LDF8_NT1 ldfs.nt1
  250. #define LDF8_NTA ldfs.nta
  251. #define STF8 stfs
  252. #define STF8_NTA stfs.nta
  253. #define LDFD ldfs
  254. #define LDFPD ldfps
  255. #define LDFD_T1 ldfs.t1
  256. #define LDFD_NT1 ldfs.nt1
  257. #define LDFD_NT2 ldfs.nt2
  258. #define LDFD_NTA ldfs.nta
  259. #define LDFPD_NT1 ldfps.nt1
  260. #define LDFPD_NT2 ldfps.nt2
  261. #define LDFPD_NTA ldfps.nta
  262. #define STFD stfs
  263. #define STFD_NTA stfs.nta
  264. #if 0
  265. #define FADD fadd.s
  266. #define FSUB fsub.s
  267. #define FMPY fmpy.s
  268. #define FMA fma.s
  269. #define FMS fms.s
  270. #define FNMA fnma.s
  271. #define FPMA fpma.s
  272. #else
  273. #define FADD fadd
  274. #define FSUB fsub
  275. #define FMPY fmpy
  276. #define FMA fma
  277. #define FMS fms
  278. #define FNMA fnma
  279. #define FPMA fpma
  280. #endif
  281. #define SETF setf.s
  282. #endif
  283. #ifndef F_INTERFACE
  284. #define REALNAME ASMNAME
  285. #else
  286. #define REALNAME ASMFNAME
  287. #endif
  288. #ifdef F_INTERFACE_G77
  289. #define RETURN_BY_STACK
  290. #endif
  291. #ifdef F_INTERFACE_G95
  292. #define RETURN_BY_STACK
  293. #endif
  294. #ifdef F_INTERFACE_GFORT
  295. #define RETURN_BY_REGS
  296. #endif
  297. #ifdef F_INTERFACE_INTEL
  298. #define RETURN_BY_STACK
  299. #endif
  300. #define PROLOGUE \
  301. .explicit; \
  302. .text; \
  303. .align 128; \
  304. .global REALNAME; \
  305. .proc REALNAME; \
  306. REALNAME:
  307. #ifdef PROFILE
  308. #define PROFCODE \
  309. .data; \
  310. .align 8; \
  311. .LP0:; \
  312. data8 0; \
  313. .text; \
  314. alloc out0 = ar.pfs, 8, 0, 4, 0; \
  315. mov out1 = r1; \
  316. mov out2 = b0; \
  317. addl out3 = @ltoff(.LP0), r1;;; \
  318. br.call.sptk.many b0 = _mcount;;
  319. #else
  320. #define PROFCODE
  321. #endif
  322. #if defined(__linux__) && defined(__ELF__)
  323. #define GNUSTACK .section .note.GNU-stack,"",@progbits
  324. #else
  325. #define GNUSTACK
  326. #endif
  327. #define EPILOGUE \
  328. .endp REALNAME ; \
  329. GNUSTACK
  330. #define START_ADDRESS 0x20000fc800000000UL
  331. #undef SEEK_ADDRESS
  332. #if 0
  333. #ifdef CONFIG_IA64_PAGE_SIZE_4KB
  334. #define SEEK_ADDRESS
  335. #endif
  336. #ifdef CONFIG_IA64_PAGE_SIZE_8KB
  337. #define SEEK_ADDRESS
  338. #endif
  339. #endif
  340. #define BUFFER_SIZE (128 << 20)
  341. #ifndef PAGESIZE
  342. #define PAGESIZE (16UL << 10)
  343. #endif
  344. #define HUGE_PAGESIZE ( 4 << 20)
  345. #define BASE_ADDRESS (START_ADDRESS - (BLASULONG)BUFFER_SIZE * MAX_CPU_NUMBER)
  346. #endif