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