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