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