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