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