Update version to 0.3.21
[platform/upstream/openblas.git] / common_alpha.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_ALPHA
40 #define COMMON_ALPHA
41
42 #ifndef ASSEMBLER
43
44 #define MB  asm("mb")
45 #define WMB asm("wmb")
46 #define RMB asm("rmb")
47
48 static void __inline blas_lock(unsigned long *address){
49 #ifndef __DECC
50   unsigned long tmp1, tmp2;
51   asm volatile(
52     "1: ldq     %1,  %0\n"
53     "   bne     %1,  2f\n"
54     "   ldq_l   %1,  %0\n"
55     "   bne     %1,  2f\n"
56     "   or      %1,  1, %2\n"
57     "   stq_c   %2,  %0\n"
58     "   beq     %2,  2f\n"
59     "   mb\n              "
60     "   br      $31, 3f\n"
61     "2: br      $31, 1b\n"
62     "3:\n" : "=m"(*address), "=&r"(tmp1), "=&r"(tmp2) : :  "memory");
63 #else
64   asm (
65     "10:"
66     "   ldq     %t0,  0(%a0); "
67     "   bne     %t0, 20f;     "
68     "   ldq_l   %t0,  0(%a0); "
69     "   bne     %t0, 20f;     "
70     "   or      %t0, 1, %t1;"
71     "   stq_c   %t1,  0(%a0); "
72     "   beq     %t1, 20f;     "
73     "   mb;                   "
74     "   br      %r31,30f;     "
75     "20:                      "
76     "   br      %r31,10b;     "
77     "30:", address);
78 #endif
79 }
80 #define BLAS_LOCK_DEFINED
81
82 static __inline unsigned int rpcc(void){
83
84   unsigned int r0;
85
86 #ifndef __DECC
87   asm __volatile__("rpcc %0" : "=r"(r0)  : : "memory");
88 #else
89   r0 = asm("rpcc %v0");
90 #endif
91
92   return r0;
93 }
94 #define RPCC_DEFINED
95
96
97 #define HALT    ldq     $0, 0($0)
98
99 #ifndef __DECC
100 #define GET_IMAGE(res)  asm __volatile__("fmov $f1, %0" : "=f"(res)  : : "memory")
101 #else
102 #define GET_IMAGE(res) res = dasm("fmov $f1, %f0")
103 #endif
104
105 #ifdef SMP
106 #ifdef USE64BITINT
107 static __inline long blas_quickdivide(long x, long y){
108   return x/y;
109 }
110 #else
111 extern unsigned int blas_quick_divide_table[];
112
113 static __inline int blas_quickdivide(unsigned int x, unsigned int y){
114   if (y <= 1) return x;
115   return (int)((x * (unsigned long)blas_quick_divide_table[y]) >> 32);
116 }
117 #endif
118 #endif
119
120 #define BASE_ADDRESS ((0x1b0UL << 33) | (0x1c0UL << 23) | (0x000UL << 13))
121
122 #ifndef PAGESIZE
123 #define PAGESIZE        ( 8UL << 10)
124 #define HUGE_PAGESIZE   ( 4 << 20)
125 #endif
126 #define BUFFER_SIZE     (32UL << 20)
127
128 #else
129
130 #ifndef F_INTERFACE
131 #define REALNAME ASMNAME
132 #else
133 #define REALNAME ASMFNAME
134 #endif
135
136 #define PROLOGUE \
137         .arch ev6; \
138         .set noat; \
139         .set noreorder; \
140 .text; \
141         .align 5; \
142         .globl REALNAME; \
143         .ent REALNAME; \
144 REALNAME:
145
146 #ifdef PROFILE
147 #define PROFCODE \
148         ldgp    $gp, 0($27); \
149         lda     $28, _mcount; \
150         jsr     $28, ($28), _mcount; \
151         .prologue 1
152 #else
153 #define PROFCODE .prologue 0
154 #endif
155
156 #if defined(__linux__) && defined(__ELF__)
157 #define GNUSTACK .section .note.GNU-stack,"",@progbits
158 #else
159 #define GNUSTACK
160 #endif
161
162 #define EPILOGUE \
163         .end REALNAME; \
164         .ident VERSION; \
165         GNUSTACK
166
167 #endif
168
169 #ifdef DOUBLE
170 #define SXADDQ  s8addq
171 #define SXSUBL  s8subl
172 #define LD      ldt
173 #define ST      stt
174 #define STQ     stq
175 #define ADD     addt/su
176 #define SUB     subt/su
177 #define MUL     mult/su
178 #define DIV     divt/su
179 #else
180 #define SXADDQ  s4addq
181 #define SXSUBL  s4subl
182 #define LD      lds
183 #define ST      sts
184 #define STQ     stl
185 #define ADD     adds/su
186 #define SUB     subs/su
187 #define MUL     muls/su
188 #define DIV     divs/su
189 #endif
190 #endif