Merge branch 'z13' into develop
[platform/upstream/openblas.git] / common_mips64.h
1 /*****************************************************************************
2 Copyright (c) 2011-2014, The OpenBLAS Project
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9    1. Redistributions of source code must retain the above copyright
10       notice, this list of conditions and the following disclaimer.
11
12    2. Redistributions in binary form must reproduce the above copyright
13       notice, this list of conditions and the following disclaimer in
14       the documentation and/or other materials provided with the
15       distribution.
16    3. Neither the name of the OpenBLAS project nor the names of 
17       its contributors may be used to endorse or promote products 
18       derived from this software without specific prior written 
19       permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 **********************************************************************************/
32
33 /*********************************************************************/
34 /* Copyright 2009, 2010 The University of Texas at Austin.           */
35 /* All rights reserved.                                              */
36 /*                                                                   */
37 /* Redistribution and use in source and binary forms, with or        */
38 /* without modification, are permitted provided that the following   */
39 /* conditions are met:                                               */
40 /*                                                                   */
41 /*   1. Redistributions of source code must retain the above         */
42 /*      copyright notice, this list of conditions and the following  */
43 /*      disclaimer.                                                  */
44 /*                                                                   */
45 /*   2. Redistributions in binary form must reproduce the above      */
46 /*      copyright notice, this list of conditions and the following  */
47 /*      disclaimer in the documentation and/or other materials       */
48 /*      provided with the distribution.                              */
49 /*                                                                   */
50 /*    THIS  SOFTWARE IS PROVIDED  BY THE  UNIVERSITY OF  TEXAS AT    */
51 /*    AUSTIN  ``AS IS''  AND ANY  EXPRESS OR  IMPLIED WARRANTIES,    */
52 /*    INCLUDING, BUT  NOT LIMITED  TO, THE IMPLIED  WARRANTIES OF    */
53 /*    MERCHANTABILITY  AND FITNESS FOR  A PARTICULAR  PURPOSE ARE    */
54 /*    DISCLAIMED.  IN  NO EVENT SHALL THE UNIVERSITY  OF TEXAS AT    */
55 /*    AUSTIN OR CONTRIBUTORS BE  LIABLE FOR ANY DIRECT, INDIRECT,    */
56 /*    INCIDENTAL,  SPECIAL, EXEMPLARY,  OR  CONSEQUENTIAL DAMAGES    */
57 /*    (INCLUDING, BUT  NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE    */
58 /*    GOODS  OR  SERVICES; LOSS  OF  USE,  DATA,  OR PROFITS;  OR    */
59 /*    BUSINESS INTERRUPTION) HOWEVER CAUSED  AND ON ANY THEORY OF    */
60 /*    LIABILITY, WHETHER  IN CONTRACT, STRICT  LIABILITY, OR TORT    */
61 /*    (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY WAY OUT    */
62 /*    OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF ADVISED  OF  THE    */
63 /*    POSSIBILITY OF SUCH DAMAGE.                                    */
64 /*                                                                   */
65 /* The views and conclusions contained in the software and           */
66 /* documentation are those of the authors and should not be          */
67 /* interpreted as representing official policies, either expressed   */
68 /* or implied, of The University of Texas at Austin.                 */
69 /*********************************************************************/
70
71 #ifndef COMMON_MIPS64
72 #define COMMON_MIPS64
73
74 #define MB
75 #define WMB
76
77 #define INLINE inline
78
79 #ifndef ASSEMBLER
80
81 static void INLINE blas_lock(volatile unsigned long *address){
82
83   long int ret, val = 1;
84
85   do {
86     while (*address) {YIELDING;};
87
88     __asm__ __volatile__(
89                          "1:    ll      %0, %3\n"
90                          "      ori     %2, %0, 1\n"
91                          "      sc      %2, %1\n"
92                          "      beqz    %2, 1b\n"
93                          "       andi   %2, %0, 1\n"
94                          "      sync\n"
95                          : "=&r" (val), "=m" (address), "=&r" (ret)
96                          : "m" (address)
97                          : "memory");
98
99   } while (ret);
100 }
101 #define BLAS_LOCK_DEFINED
102
103 static inline unsigned int rpcc(void){
104   unsigned long ret;
105
106   //  unsigned long long tmp;
107   //__asm__ __volatile__("dmfc0 %0, $25, 1": "=r"(tmp):: "memory");
108   //ret=tmp;
109   __asm__ __volatile__(".set push \n"
110                        ".set mips32r2\n"
111                        "rdhwr %0, $2\n"
112                        ".set pop": "=r"(ret):: "memory");
113
114   return ret;
115 }
116 #define RPCC_DEFINED
117
118 #ifndef NO_AFFINITY
119 #define WHEREAMI
120 static inline int WhereAmI(void){
121   int ret=0;
122   __asm__ __volatile__(".set push \n"
123                        ".set mips32r2\n"
124                        "rdhwr %0, $0\n"
125                        ".set pop": "=r"(ret):: "memory");
126   return ret;
127
128 }
129 #endif
130
131 static inline int blas_quickdivide(blasint x, blasint y){
132   return x / y;
133 }
134
135 #ifdef DOUBLE
136 #define GET_IMAGE(res)  __asm__ __volatile__("mov.d %0, $f2" : "=f"(res)  : : "memory")
137 #else
138 #define GET_IMAGE(res)  __asm__ __volatile__("mov.s %0, $f2" : "=f"(res)  : : "memory")
139 #endif
140
141 #define GET_IMAGE_CANCEL
142
143 #endif
144
145
146 #ifdef ASSEMBLER
147
148 #define HALT    teq     $0, $0
149 #define NOP     move    $0, $0
150
151 #ifdef DOUBLE
152 #define LD      ldc1
153 #define ST      sdc1
154 #define MADD    madd.d
155 #define NMADD   nmadd.d
156 #define MSUB    msub.d
157 #define NMSUB   nmsub.d
158 #define ADD     add.d
159 #define SUB     sub.d
160 #define MUL     mul.d
161 #define MOV     mov.d
162 #define CMOVF   movf.d
163 #define CMOVT   movt.d
164 #define MTC     dmtc1
165 #define FABS    abs.d
166 #define CMPEQ   c.eq.d
167 #define CMPLE   c.le.d
168 #define CMPLT   c.lt.d
169 #define NEG     neg.d
170 #else
171 #define LD      lwc1
172 #define ST      swc1
173 #define MADD    madd.s
174 #define NMADD   nmadd.s
175 #define MSUB    msub.s
176 #define NMSUB   nmsub.s
177 #define ADD     add.s
178 #define SUB     sub.s
179 #define MUL     mul.s
180 #define MOV     mov.s
181 #define CMOVF   movf.s
182 #define CMOVT   movt.s
183 #define MTC     mtc1
184 #define FABS    abs.s
185 #define CMPEQ   c.eq.s
186 #define CMPLE   c.le.s
187 #define CMPLT   c.lt.s
188 #define PLU     plu.ps
189 #define PLL     pll.ps
190 #define PUU     puu.ps
191 #define PUL     pul.ps
192 #define MADPS   madd.ps
193 #define CVTU    cvt.s.pu
194 #define CVTL    cvt.s.pl
195 #define NEG     neg.s
196 #endif
197
198 #if   defined(__64BIT__) &&  defined(USE64BITINT)
199 #define LDINT   ld
200 #define LDARG   ld
201 #define SDARG   sd
202 #elif defined(__64BIT__) && !defined(USE64BITINT)
203 #define LDINT   lw
204 #define LDARG   ld
205 #define SDARG   sd
206 #else
207 #define LDINT   lw
208 #define LDARG   lw
209 #define SDARG   sw
210 #endif
211
212
213 #ifndef F_INTERFACE
214 #define REALNAME ASMNAME
215 #else
216 #define REALNAME ASMFNAME
217 #endif
218
219 #if defined(ASSEMBLER) && !defined(NEEDPARAM)
220
221 #define PROLOGUE \
222         .text ;\
223         .set    mips64 ;\
224         .align 5 ;\
225         .globl  REALNAME ;\
226         .ent    REALNAME ;\
227         .type   REALNAME, @function ;\
228 REALNAME: ;\
229         .set    noreorder ;\
230         .set    nomacro
231
232 #if defined(__linux__) && defined(__ELF__)
233 #define GNUSTACK .section .note.GNU-stack,"",@progbits
234 #else
235 #define GNUSTACK
236 #endif
237
238 #define EPILOGUE \
239         .set    macro ;\
240         .set    reorder ;\
241         .end    REALNAME ;\
242         GNUSTACK
243
244 #define PROFCODE
245 #endif
246
247 #endif
248
249 #define SEEK_ADDRESS
250
251 #define BUFFER_SIZE     ( 32 << 20)
252
253 #if defined(LOONGSON3A)
254 #define PAGESIZE        (16UL << 10)
255 #define FIXED_PAGESIZE  (16UL << 10)
256 #endif
257
258 #if defined(LOONGSON3B)
259 #define PAGESIZE        (16UL << 10)
260 #define FIXED_PAGESIZE  (16UL << 10)
261 #endif
262
263 #ifndef PAGESIZE
264 #define PAGESIZE        (64UL << 10)
265 #endif
266 #define HUGE_PAGESIZE   ( 2 << 20)
267
268 #define BASE_ADDRESS (START_ADDRESS - BUFFER_SIZE * MAX_CPU_NUMBER)
269
270 #ifndef MAP_ANONYMOUS
271 #define MAP_ANONYMOUS MAP_ANON
272 #endif
273
274 #if defined(LOONGSON3A) || defined(LOONGSON3B)
275 #define PREFETCHD_(x) ld $0, x
276 #define PREFETCHD(x)  PREFETCHD_(x)
277 #else
278 #define PREFETCHD(x)
279 #endif
280
281 #endif