Merge pull request #577 from wernsaar/develop
[platform/upstream/openblas.git] / common_arm.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_ARM
72 #define COMMON_ARM
73
74 #if defined(ARMV5) || defined(ARMV6)
75
76 #define MB
77 #define WMB
78
79 #else
80
81 #define MB   __asm__ __volatile__ ("dmb  ish" : : : "memory")
82 #define WMB  __asm__ __volatile__ ("dmb  ishst" : : : "memory")
83
84 #endif
85
86 #define INLINE inline
87
88 #define RETURN_BY_COMPLEX
89
90 #ifndef ASSEMBLER
91
92 static void __inline blas_lock(volatile BLASULONG *address){
93
94   int register ret;
95
96   do {
97     while (*address) {YIELDING;};
98
99     __asm__ __volatile__(
100                          "1:                                                            \n\t"
101                          "ldrex r2, [%1]                                                \n\t"
102                          "mov   r2, #0                                                  \n\t"
103                          "strex r3, r2, [%1]                                            \n\t"
104                          "cmp   r3, #0                                                  \n\t"
105                          "bne   1b                                                      \n\t"
106                          "mov   %0 , r3                                                 \n\t"
107                          : "=r"(ret), "=r"(address)
108                          : "1"(address)
109                          : "memory", "r2" , "r3"
110
111
112     );
113
114   } while (ret);
115
116 }
117
118
119 static inline unsigned long long rpcc(void){
120   unsigned long long ret=0;
121   double v;
122   struct timeval tv;
123   gettimeofday(&tv,NULL);
124   v=(double) tv.tv_sec + (double) tv.tv_usec * 1e-6;
125   ret = (unsigned long long) ( v * 1000.0d );
126   return ret;
127 }
128
129 static inline int blas_quickdivide(blasint x, blasint y){
130   return x / y;
131 }
132
133 #if defined(DOUBLE)
134 #define GET_IMAGE(res)  __asm__ __volatile__("vstr.f64 d1, %0" : "=m"(res) : : "memory")
135 #else
136 #define GET_IMAGE(res)  __asm__ __volatile__("vstr.f32 s1, %0" : "=m"(res) : : "memory")
137 #endif
138
139 #define GET_IMAGE_CANCEL
140
141 #endif
142
143
144 #ifndef F_INTERFACE
145 #define REALNAME ASMNAME
146 #else
147 #define REALNAME ASMFNAME
148 #endif
149
150 #if defined(ASSEMBLER) && !defined(NEEDPARAM)
151
152 #define PROLOGUE \
153         .arm             ;\
154         .global REALNAME ;\
155         .func   REALNAME  ;\
156 REALNAME:
157
158 #define EPILOGUE
159
160 #define PROFCODE
161
162 #endif
163
164
165 #define SEEK_ADDRESS
166
167 #ifndef PAGESIZE
168 #define PAGESIZE        ( 4 << 10)
169 #endif
170 #define HUGE_PAGESIZE   ( 4 << 20)
171
172 #define BUFFER_SIZE     (16 << 20)
173
174
175 #define BASE_ADDRESS (START_ADDRESS - BUFFER_SIZE * MAX_CPU_NUMBER)
176
177 #ifndef MAP_ANONYMOUS
178 #define MAP_ANONYMOUS MAP_ANON
179 #endif
180
181 #endif