Complete cgemm function, but no optimization.
[platform/upstream/openblas.git] / common_mips64.h
1 /*****************************************************************************
2 Copyright (c) 2011, Lab of Parallel Software and Computational Science,ICSAS
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 ISCAS nor the names of its contributors may 
17       be used to endorse or promote products derived from this software 
18       without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
25 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
26 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
27 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
28 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 
29 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
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
102 static inline unsigned int rpcc(void){
103   unsigned long ret;
104 #if defined(LOONGSON3A)
105   unsigned long long tmp;
106   __asm__ __volatile__("dmfc0 %0, $25, 1": "=r"(tmp):: "memory");
107   ret=tmp;
108 #else
109   __asm__ __volatile__(".set   push    \n"                                     
110           ".set   mips32r2\n"                                                  
111           "rdhwr %0, $30  \n"                                                  
112           ".set pop" : "=r"(ret) : : "memory");
113 #endif
114   return ret;
115 }
116
117 static inline int blas_quickdivide(blasint x, blasint y){
118   return x / y;
119 }
120
121 #ifdef DOUBLE
122 #define GET_IMAGE(res)  __asm__ __volatile__("mov.d %0, $f2" : "=f"(res)  : : "memory")
123 #else
124 #define GET_IMAGE(res)  __asm__ __volatile__("mov.s %0, $f2" : "=f"(res)  : : "memory")
125 #endif
126
127 #define GET_IMAGE_CANCEL
128
129 #endif
130
131
132 #ifdef ASSEMBLER
133
134 #define HALT    teq     $0, $0
135 #define NOP     move    $0, $0
136
137 #ifdef DOUBLE
138 #define LD      ldc1
139 #define ST      sdc1
140 #define MADD    madd.d
141 #define NMADD   nmadd.d
142 #define MSUB    msub.d
143 #define NMSUB   nmsub.d
144 #define ADD     add.d
145 #define SUB     sub.d
146 #define MUL     mul.d
147 #define MOV     mov.d
148 #define CMOVF   movf.d
149 #define CMOVT   movt.d
150 #define MTC     dmtc1
151 #define FABS    abs.d
152 #define CMPEQ   c.eq.d
153 #define CMPLE   c.le.d
154 #define CMPLT   c.lt.d
155 #define NEG     neg.d
156 #else
157 #define LD      lwc1
158 #define ST      swc1
159 #define MADD    madd.s
160 #define NMADD   nmadd.s
161 #define MSUB    msub.s
162 #define NMSUB   nmsub.s
163 #define ADD     add.s
164 #define SUB     sub.s
165 #define MUL     mul.s
166 #define MOV     mov.s
167 #define CMOVF   movf.s
168 #define CMOVT   movt.s
169 #define MTC     mtc1
170 #define FABS    abs.s
171 #define CMPEQ   c.eq.s
172 #define CMPLE   c.le.s
173 #define CMPLT   c.lt.s
174 #define PLU     plu.ps                                                    
175 #define PLL     pll.ps   
176 #define PUU     puu.ps    
177 #define PUL     pul.ps   
178 #define MADPS   madd.ps   
179 #define CVTU    cvt.s.pu    
180 #define CVTL    cvt.s.pl 
181 #define NEG     neg.s
182 #endif
183
184 #if   defined(__64BIT__) &&  defined(USE64BITINT)
185 #define LDINT   ld
186 #define LDARG   ld
187 #define SDARG   sd
188 #elif defined(__64BIT__) && !defined(USE64BITINT)
189 #define LDINT   lw
190 #define LDARG   ld
191 #define SDARG   sd
192 #else
193 #define LDINT   lw
194 #define LDARG   lw
195 #define SDARG   sw
196 #endif
197
198
199 #ifndef F_INTERFACE
200 #define REALNAME ASMNAME
201 #else
202 #define REALNAME ASMFNAME
203 #endif
204
205 #if defined(ASSEMBLER) && !defined(NEEDPARAM)
206
207 #define PROLOGUE \
208         .text ;\
209         .set    mips64 ;\
210         .align 5 ;\
211         .globl  REALNAME ;\
212         .ent    REALNAME ;\
213         .type   REALNAME, @function ;\
214 REALNAME: ;\
215         .set    noreorder ;\
216         .set    nomacro
217
218 #define EPILOGUE \
219         .set    macro ;\
220         .set    reorder ;\
221         .end    REALNAME
222
223 #define PROFCODE
224 #endif
225
226 #endif
227
228 #define SEEK_ADDRESS
229
230 #define BUFFER_SIZE     ( 32 << 20)
231
232 #if defined(LOONGSON3A)
233 #define PAGESIZE        (16UL << 10)
234 #define FIXED_PAGESIZE  (16UL << 10)
235 #endif
236
237 #ifndef PAGESIZE
238 #define PAGESIZE        (64UL << 10)
239 #endif
240 #define HUGE_PAGESIZE   ( 2 << 20)
241
242 #define BASE_ADDRESS (START_ADDRESS - BUFFER_SIZE * MAX_CPU_NUMBER)
243
244 #ifndef MAP_ANONYMOUS
245 #define MAP_ANONYMOUS MAP_ANON
246 #endif
247
248 #if defined(LOONGSON3A)
249 #define PREFETCHD_(x) ld $0, x
250 #define PREFETCHD(x)  PREFETCHD_(x)  
251 #else
252 #define PREFETCHD(x) 
253 #endif
254
255 #endif