Merge pull request #1226 from ashwinyes/develop_arm_clang_ual_fix
[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  __sync_synchronize()
75 #define WMB __sync_synchronize()
76
77 #define INLINE inline
78
79 #ifndef ASSEMBLER
80
81 static inline unsigned int rpcc(void){
82   unsigned long ret;
83
84   //  unsigned long long tmp;
85   //__asm__ __volatile__("dmfc0 %0, $25, 1": "=r"(tmp):: "memory");
86   //ret=tmp;
87   __asm__ __volatile__(".set push \n"
88                        ".set mips32r2\n"
89                        "rdhwr %0, $2\n"
90                        ".set pop": "=r"(ret):: "memory");
91
92   return ret;
93 }
94 #define RPCC_DEFINED
95
96 #ifndef NO_AFFINITY
97 #define WHEREAMI
98 static inline int WhereAmI(void){
99   int ret=0;
100   __asm__ __volatile__(".set push \n"
101                        ".set mips32r2\n"
102                        "rdhwr %0, $0\n"
103                        ".set pop": "=r"(ret):: "memory");
104   return ret;
105
106 }
107 #endif
108
109 static inline int blas_quickdivide(blasint x, blasint y){
110   return x / y;
111 }
112
113 #ifdef DOUBLE
114 #define GET_IMAGE(res)  __asm__ __volatile__("mov.d %0, $f2" : "=f"(res)  : : "memory")
115 #else
116 #define GET_IMAGE(res)  __asm__ __volatile__("mov.s %0, $f2" : "=f"(res)  : : "memory")
117 #endif
118
119 #define GET_IMAGE_CANCEL
120
121 #endif
122
123
124 #ifdef ASSEMBLER
125
126 #define HALT    teq     $0, $0
127 #define NOP     move    $0, $0
128
129 #ifdef DOUBLE
130 #define LD      ldc1
131 #define ST      sdc1
132 #define MADD    madd.d
133 #define NMADD   nmadd.d
134 #define MSUB    msub.d
135 #define NMSUB   nmsub.d
136 #define ADD     add.d
137 #define SUB     sub.d
138 #define MUL     mul.d
139 #define MOV     mov.d
140 #define CMOVF   movf.d
141 #define CMOVT   movt.d
142 #define MTC     dmtc1
143 #define FABS    abs.d
144 #define CMPEQ   c.eq.d
145 #define CMPLE   c.le.d
146 #define CMPLT   c.lt.d
147 #define NEG     neg.d
148 #else
149 #define LD      lwc1
150 #define ST      swc1
151 #define MADD    madd.s
152 #define NMADD   nmadd.s
153 #define MSUB    msub.s
154 #define NMSUB   nmsub.s
155 #define ADD     add.s
156 #define SUB     sub.s
157 #define MUL     mul.s
158 #define MOV     mov.s
159 #define CMOVF   movf.s
160 #define CMOVT   movt.s
161 #define MTC     mtc1
162 #define FABS    abs.s
163 #define CMPEQ   c.eq.s
164 #define CMPLE   c.le.s
165 #define CMPLT   c.lt.s
166 #define PLU     plu.ps
167 #define PLL     pll.ps
168 #define PUU     puu.ps
169 #define PUL     pul.ps
170 #define MADPS   madd.ps
171 #define CVTU    cvt.s.pu
172 #define CVTL    cvt.s.pl
173 #define NEG     neg.s
174 #endif
175
176 #if   defined(__64BIT__) &&  defined(USE64BITINT)
177 #define LDINT   ld
178 #define LDARG   ld
179 #define SDARG   sd
180 #elif defined(__64BIT__) && !defined(USE64BITINT)
181 #define LDINT   lw
182 #define LDARG   ld
183 #define SDARG   sd
184 #else
185 #define LDINT   lw
186 #define LDARG   lw
187 #define SDARG   sw
188 #endif
189
190
191 #ifndef F_INTERFACE
192 #define REALNAME ASMNAME
193 #else
194 #define REALNAME ASMFNAME
195 #endif
196
197 #if defined(ASSEMBLER) && !defined(NEEDPARAM)
198
199 #define PROLOGUE \
200         .text ;\
201         .set    mips64 ;\
202         .align 5 ;\
203         .globl  REALNAME ;\
204         .ent    REALNAME ;\
205         .type   REALNAME, @function ;\
206 REALNAME: ;\
207         .set    noreorder ;\
208         .set    nomacro
209
210 #if defined(__linux__) && defined(__ELF__)
211 #define GNUSTACK .section .note.GNU-stack,"",@progbits
212 #else
213 #define GNUSTACK
214 #endif
215
216 #define EPILOGUE \
217         .set    macro ;\
218         .set    reorder ;\
219         .end    REALNAME ;\
220         GNUSTACK
221
222 #define PROFCODE
223 #endif
224
225 #endif
226
227 #define SEEK_ADDRESS
228
229 #define BUFFER_SIZE     ( 32 << 20)
230
231 #if defined(LOONGSON3A)
232 #define PAGESIZE        (16UL << 10)
233 #define FIXED_PAGESIZE  (16UL << 10)
234 #endif
235
236 #if defined(LOONGSON3B)
237 #define PAGESIZE        (16UL << 10)
238 #define FIXED_PAGESIZE  (16UL << 10)
239 #endif
240
241 #ifndef PAGESIZE
242 #define PAGESIZE        (64UL << 10)
243 #endif
244 #define HUGE_PAGESIZE   ( 2 << 20)
245
246 #define BASE_ADDRESS (START_ADDRESS - BUFFER_SIZE * MAX_CPU_NUMBER)
247
248 #ifndef MAP_ANONYMOUS
249 #define MAP_ANONYMOUS MAP_ANON
250 #endif
251
252 #if defined(LOONGSON3A) || defined(LOONGSON3B)
253 #define PREFETCHD_(x) ld $0, x
254 #define PREFETCHD(x)  PREFETCHD_(x)
255 #else
256 #define PREFETCHD(x)
257 #endif
258
259 #endif