Merge branch 'cmake' of https://github.com/hpanderson/OpenBLAS into hpanderson_cmake
[platform/upstream/openblas.git] / common_arm.h
1 /*****************************************************************************
2 Copyright (c) 2011-2015, 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 #ifndef COMMON_ARM
34 #define COMMON_ARM
35
36 #if defined(ARMV5) || defined(ARMV6)
37
38 #define MB
39 #define WMB
40
41 #else
42
43 #define MB   __asm__ __volatile__ ("dmb  ish" : : : "memory")
44 #define WMB  __asm__ __volatile__ ("dmb  ishst" : : : "memory")
45
46 #endif
47
48 #define INLINE inline
49
50 #define RETURN_BY_COMPLEX
51
52 #ifndef ASSEMBLER
53
54 static void __inline blas_lock(volatile BLASULONG *address){
55
56   int register ret;
57
58   do {
59     while (*address) {YIELDING;};
60
61     __asm__ __volatile__(
62                          "1:                                                            \n\t"
63                          "ldrex r2, [%1]                                                \n\t"
64                          "mov   r2, #0                                                  \n\t"
65                          "strex r3, r2, [%1]                                            \n\t"
66                          "cmp   r3, #0                                                  \n\t"
67                          "bne   1b                                                      \n\t"
68                          "mov   %0 , r3                                                 \n\t"
69                          : "=r"(ret), "=r"(address)
70                          : "1"(address)
71                          : "memory", "r2" , "r3"
72
73
74     );
75
76   } while (ret);
77
78 }
79
80
81 static inline unsigned long long rpcc(void){
82   unsigned long long ret=0;
83   double v;
84   struct timeval tv;
85   gettimeofday(&tv,NULL);
86   v=(double) tv.tv_sec + (double) tv.tv_usec * 1e-6;
87   ret = (unsigned long long) ( v * 1000.0d );
88   return ret;
89 }
90
91 static inline int blas_quickdivide(blasint x, blasint y){
92   return x / y;
93 }
94
95 #if defined(DOUBLE)
96 #define GET_IMAGE(res)  __asm__ __volatile__("vstr.f64 d1, %0" : "=m"(res) : : "memory")
97 #else
98 #define GET_IMAGE(res)  __asm__ __volatile__("vstr.f32 s1, %0" : "=m"(res) : : "memory")
99 #endif
100
101 #define GET_IMAGE_CANCEL
102
103 #endif
104
105
106 #ifndef F_INTERFACE
107 #define REALNAME ASMNAME
108 #else
109 #define REALNAME ASMFNAME
110 #endif
111
112 #if defined(ASSEMBLER) && !defined(NEEDPARAM)
113
114 #define PROLOGUE \
115         .arm             ;\
116         .global REALNAME ;\
117         .func   REALNAME  ;\
118 REALNAME:
119
120 #define EPILOGUE
121
122 #define PROFCODE
123
124 #endif
125
126
127 #define SEEK_ADDRESS
128
129 #ifndef PAGESIZE
130 #define PAGESIZE        ( 4 << 10)
131 #endif
132 #define HUGE_PAGESIZE   ( 4 << 20)
133
134 #define BUFFER_SIZE     (16 << 20)
135
136
137 #define BASE_ADDRESS (START_ADDRESS - BUFFER_SIZE * MAX_CPU_NUMBER)
138
139 #ifndef MAP_ANONYMOUS
140 #define MAP_ANONYMOUS MAP_ANON
141 #endif
142
143 #endif