Import GotoBLAS2 1.13 BSD version codes.
[platform/upstream/openblas.git] / common_mips64.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_MIPS64
40 #define COMMON_MIPS64
41
42 #define MB
43 #define WMB
44
45 #define INLINE inline
46
47 #ifndef ASSEMBLER
48
49 static void INLINE blas_lock(volatile unsigned long *address){
50
51   long int ret, val = 1;
52
53   do {
54     while (*address) {YIELDING;};
55
56     __asm__ __volatile__(
57                          "1:    ll      %0, %3\n"
58                          "      ori     %2, %0, 1\n"
59                          "      sc      %2, %1\n"
60                          "      beqz    %2, 1b\n"
61                          "       andi   %2, %0, 1\n"
62                          "      sync\n"
63                          : "=&r" (val), "=m" (address), "=&r" (ret)
64                          : "m" (address)
65                          : "memory");
66
67   } while (ret);
68 }
69
70 static inline unsigned int rpcc(void){
71   unsigned long ret;
72
73   __asm__ __volatile__(".set   push    \n"                                     
74           ".set   mips32r2\n"                                                  
75           "rdhwr %0, $30  \n"                                                  
76           ".set pop" : "=r"(ret) : : "memory");
77
78   return ret;
79 }
80
81 static inline int blas_quickdivide(blasint x, blasint y){
82   return x / y;
83 }
84
85 #ifdef DOUBLE
86 #define GET_IMAGE(res)  __asm__ __volatile__("mov.d %0, $f2" : "=f"(res)  : : "memory")
87 #else
88 #define GET_IMAGE(res)  __asm__ __volatile__("mov.s %0, $f2" : "=f"(res)  : : "memory")
89 #endif
90
91 #define GET_IMAGE_CANCEL
92
93 #endif
94
95
96 #ifdef ASSEMBLER
97
98 #define HALT    teq     $0, $0
99 #define NOP     move    $0, $0
100
101 #ifdef DOUBLE
102 #define LD      ldc1
103 #define ST      sdc1
104 #define MADD    madd.d
105 #define NMADD   nmadd.d
106 #define MSUB    msub.d
107 #define NMSUB   nmsub.d
108 #define ADD     add.d
109 #define SUB     sub.d
110 #define MUL     mul.d
111 #define MOV     mov.d
112 #define CMOVF   movf.d
113 #define CMOVT   movt.d
114 #define MTC     dmtc1
115 #define FABS    abs.d
116 #define CMPEQ   c.eq.d
117 #define CMPLE   c.le.d
118 #define CMPLT   c.lt.d
119 #else
120 #define LD      lwc1
121 #define ST      swc1
122 #define MADD    madd.s
123 #define NMADD   nmadd.s
124 #define MSUB    msub.s
125 #define NMSUB   nmsub.s
126 #define ADD     add.s
127 #define SUB     sub.s
128 #define MUL     mul.s
129 #define MOV     mov.s
130 #define CMOVF   movf.s
131 #define CMOVT   movt.s
132 #define MTC     mtc1
133 #define FABS    abs.s
134 #define CMPEQ   c.eq.s
135 #define CMPLE   c.le.s
136 #define CMPLT   c.lt.s
137 #endif
138
139 #if   defined(__64BIT__) &&  defined(USE64BITINT)
140 #define LDINT   ld
141 #define LDARG   ld
142 #define SDARG   sd
143 #elif defined(__64BIT__) && !defined(USE64BITINT)
144 #define LDINT   lw
145 #define LDARG   ld
146 #define SDARG   sd
147 #else
148 #define LDINT   lw
149 #define LDARG   lw
150 #define SDARG   sw
151 #endif
152
153
154 #ifndef F_INTERFACE
155 #define REALNAME ASMNAME
156 #else
157 #define REALNAME ASMFNAME
158 #endif
159
160 #if defined(ASSEMBLER) && !defined(NEEDPARAM)
161
162 #define PROLOGUE \
163         .text ;\
164         .set    mips64 ;\
165         .align 5 ;\
166         .globl  REALNAME ;\
167         .ent    REALNAME ;\
168         .type   REALNAME, @function ;\
169 REALNAME: ;\
170         .set    noreorder ;\
171         .set    nomacro
172
173 #define EPILOGUE \
174         .set    macro ;\
175         .set    reorder ;\
176         .end    REALNAME
177
178 #define PROFCODE
179 #endif
180
181 #endif
182
183 #define SEEK_ADDRESS
184
185 #define BUFFER_SIZE     ( 8 << 20)
186
187 #ifndef PAGESIZE
188 #define PAGESIZE        (64UL << 10)
189 #endif
190 #define HUGE_PAGESIZE   ( 2 << 20)
191
192 #define BASE_ADDRESS (START_ADDRESS - BUFFER_SIZE * MAX_CPU_NUMBER)
193
194 #ifndef MAP_ANONYMOUS
195 #define MAP_ANONYMOUS MAP_ANON
196 #endif
197 #endif