fix build error
[platform/upstream/openblas.git] / common_sparc.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_POWER
40 #define COMMON_POWER
41
42 #define MB      __asm__ __volatile__ ("nop")
43 #define WMB     __asm__ __volatile__ ("nop")
44
45 #ifndef ASSEMBLER
46
47 static void __inline blas_lock(volatile unsigned long *address){
48
49   long int ret = 1;
50
51   do {
52     while (*address) {YIELDING;};
53
54     __asm__ __volatile__(
55                          "ldstub [%1], %0"
56                          : "=&r"(ret)
57                          : "r" (address)
58                          : "memory");
59   } while (ret);
60 }
61 #define BLAS_LOCK_DEFINED
62
63 static __inline unsigned long rpcc(void){
64   unsigned long clocks;
65
66   __asm__ __volatile__ ("rd %%tick, %0" : "=r" (clocks));
67
68   return clocks;
69 };
70 #define RPCC_DEFINED
71
72 #ifdef __64BIT__
73 #define RPCC64BIT
74 #endif
75
76 #ifndef __BIG_ENDIAN__
77 #define __BIG_ENDIAN__
78 #endif
79
80 #ifdef DOUBLE
81 #define GET_IMAGE(res)  __asm__ __volatile__("fmovd %%f2, %0" : "=f"(res)  : : "memory")
82 #else
83 #define GET_IMAGE(res)  __asm__ __volatile__("fmovs %%f1, %0" : "=f"(res)  : : "memory")
84 #endif
85
86 #define GET_IMAGE_CANCEL
87
88 #ifdef SMP
89 static __inline int blas_quickdivide(blasint x, blasint y){
90   return x / y;
91 }
92 #endif
93 #endif
94
95
96 #ifdef ASSEMBLER
97
98 #ifndef __64BIT__
99 #define STACK_START 128
100 #define SAVESP          save    %sp,  -64, %sp
101 #else
102 #define STACK_START 2423
103 #define SAVESP          save    %sp, -256, %sp
104 #endif
105
106 #define NOP     or %g1, %g1, %g1
107
108 #ifdef DOUBLE
109 #define LDF     ldd
110 #define STF     std
111 #define FADD    faddd
112 #define FMUL    fmuld
113 #define FMOV    fmovd
114 #define FABS    fabsd
115 #define FSUB    fsubd
116 #define FCMP    fcmpd
117 #define FMOVG   fmovdg
118 #define FMOVL   fmovdl
119 #define FSQRT   fsqrtd
120 #define FDIV    fdivd
121 #else
122 #define LDF     ld
123 #define STF     st
124 #define FADD    fadds
125 #define FMUL    fmuls
126 #define FMOV    fmovs
127 #define FABS    fabss
128 #define FSUB    fsubs
129 #define FCMP    fcmps
130 #define FMOVG   fmovsg
131 #define FMOVL   fmovsl
132 #define FSQRT   fsqrts
133 #define FDIV    fdivs
134 #endif
135
136 #define HALT prefetch [%g0], 5
137
138 #define FMADDS(rs1, rs2, rs3, rd) \
139         .word   ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 1 << 5) | (rs2))
140
141 #define FMADDD(rs1, rs2, rs3, rd) \
142         .word   ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 2 << 5) | (rs2))
143
144 #define FMSUBS(rs1, rs2, rs3, rd) \
145         .word   ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 5 << 5) | (rs2))
146
147 #define FMSUBD(rs1, rs2, rs3, rd) \
148         .word   ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 6 << 5) | (rs2))
149
150 #define FNMSUBS(rs1, rs2, rs3, rd) \
151         .word   ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | ( 9 << 5) | (rs2))
152
153 #define FNMSUBD(rs1, rs2, rs3, rd) \
154         .word   ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | (10 << 5) | (rs2))
155
156 #define FNMADDS(rs1, rs2, rs3, rd) \
157         .word   ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | (13 << 5) | (rs2))
158
159 #define FNMADDD(rs1, rs2, rs3, rd) \
160         .word   ((2 << 30) | ((rd) << 25) | ( 0x37 << 19) | ((rs1) << 14) | ((rs3) << 9) | (14 << 5) | (rs2))
161
162 #define FCLRS(rd) \
163         .word   ((2 << 30) | ((rd) << 25) | ( 0x36 << 19) | ( 0x61 << 5))
164
165 #define FCLRD(rd) \
166         .word   ((2 << 30) | ((rd) << 25) | ( 0x36 << 19) | ( 0x60 << 5))
167
168 #define FONES(rd) \
169         .word   ((2 << 30) | ((rd) << 25) | ( 0x36 << 19) | ( 0x7f << 5))
170
171 #define FONED(rd) \
172         .word   ((2 << 30) | ((rd) << 25) | ( 0x36 << 19) | ( 0x7e << 5))
173
174 #ifndef DOUBLE
175 #define FCLR(a)                 FCLRS(a)
176 #define FONE(a)                 FONES(a)
177 #define FMADD(a, b, c, d)       FMADDS(a, b, c, d)
178 #define FMSUB(a, b, c, d)       FMSUBS(a, b, c, d)
179 #define FNMADD(a, b, c, d)      FNMADDS(a, b, c, d)
180 #define FNMSUB(a, b, c, d)      FNMSUBS(a, b, c, d)
181 #else
182 #define FCLR(a)                 FCLRD(a)
183 #define FONE(a)                 FONED(a)
184 #define FMADD(a, b, c, d)       FMADDD(a, b, c, d)
185 #define FMSUB(a, b, c, d)       FMSUBD(a, b, c, d)
186 #define FNMADD(a, b, c, d)      FNMADDD(a, b, c, d)
187 #define FNMSUB(a, b, c, d)      FNMSUBD(a, b, c, d)
188 #endif
189
190 #ifndef F_INTERFACE
191 #define REALNAME ASMNAME
192 #else
193 #define REALNAME ASMFNAME
194 #endif
195
196 #ifdef sparc
197 #define PROLOGUE \
198         .section        ".text"; \
199         .align 32; \
200         .global REALNAME;\
201         .type   REALNAME, #function; \
202         .proc   07; \
203 REALNAME:;
204
205 #if defined(__linux__) && defined(__ELF__)
206 #define GNUSTACK .section .note.GNU-stack,"",@progbits
207 #else
208 #define GNUSTACK
209 #endif
210
211 #define EPILOGUE \
212         .size    REALNAME, .-REALNAME; \
213         GNUSTACK
214
215 #endif
216
217 #endif
218
219 #ifdef sparc
220 #define SEEK_ADDRESS
221 #endif
222
223 #define BUFFER_SIZE     (32 << 20)
224
225 #ifndef PAGESIZE
226 #define PAGESIZE        ( 8 << 10)
227 #endif
228 #define HUGE_PAGESIZE   ( 4 << 20)
229
230 #define BASE_ADDRESS (START_ADDRESS - BUFFER_SIZE * MAX_CPU_NUMBER)
231
232 #ifndef MAP_ANONYMOUS
233 #define MAP_ANONYMOUS MAP_ANON
234 #endif
235 #endif