Optimize cdot function for POWER10
[platform/upstream/openblas.git] / common_arm64.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_ARM64
34 #define COMMON_ARM64
35
36 #define MB   __asm__ __volatile__ ("dmb  ish" : : : "memory")
37 #define WMB  __asm__ __volatile__ ("dmb  ishst" : : : "memory")
38 #define RMB  __asm__ __volatile__ ("dmb  ishld" : : : "memory")
39
40 #define INLINE inline
41
42 #if defined( F_INTERFACE_FLANG) || defined(F_INTERFACE_PGI)
43 #define RETURN_BY_STACK
44 #else
45 #define RETURN_BY_COMPLEX
46 #endif
47
48 #ifndef ASSEMBLER
49
50
51 static void __inline blas_lock(volatile BLASULONG *address){
52
53   BLASULONG ret;
54
55   do {
56     __asm__ __volatile__(
57                          "mov   x4, #1                                                  \n\t"
58                          "sevl                                                          \n\t"
59                          "1:                                                            \n\t"
60                          "wfe                                                           \n\t"
61                          "2:                                                            \n\t"
62                          "ldaxr x2, [%1]                                                \n\t"
63                          "cbnz  x2, 1b                                                  \n\t"
64                          "stxr  w3, x4, [%1]                                            \n\t"
65                          "cbnz  w3, 2b                                                  \n\t"
66                          "mov   %0, #0                                                  \n\t"
67                          : "=r"(ret), "=r"(address)
68                          : "1"(address)
69                          : "memory", "x2" , "x3", "x4"
70
71
72     );
73
74
75   } while (ret);
76
77 }
78
79 #define BLAS_LOCK_DEFINED
80
81 #if !defined(OS_DARWIN) && !defined (OS_ANDROID)
82 static __inline BLASULONG rpcc(void){
83   BLASULONG ret = 0;
84   blasint shift;
85  
86   __asm__ __volatile__ ("isb; mrs %0,cntvct_el0":"=r"(ret));
87   __asm__ __volatile__ ("mrs %0,cntfrq_el0; clz %w0, %w0":"=&r"(shift));
88
89   return ret << shift;
90 }
91
92 #define RPCC_DEFINED
93 #define RPCC64BIT
94 #endif 
95
96 static inline int blas_quickdivide(blasint x, blasint y){
97   return x / y;
98 }
99
100 #if defined(DOUBLE)
101 #define GET_IMAGE(res)  __asm__ __volatile__("str d1, %0" : "=m"(res) : : "memory")
102 #else
103 #define GET_IMAGE(res)  __asm__ __volatile__("str s1, %0" : "=m"(res) : : "memory")
104 #endif
105
106 #define GET_IMAGE_CANCEL
107
108 #endif
109
110
111 #ifndef F_INTERFACE
112 #define REALNAME ASMNAME
113 #else
114 #define REALNAME ASMFNAME
115 #endif
116
117 #if defined(ASSEMBLER) && !defined(NEEDPARAM)
118
119 .macro PROLOGUE 
120         .text ;
121         .p2align 2 ;
122         .global REALNAME ;
123 #ifndef __APPLE__
124         .type   REALNAME, %function ;
125 #endif
126 REALNAME:
127 .endm
128
129
130 #define EPILOGUE
131
132 #define PROFCODE
133
134 #endif
135
136
137 #define SEEK_ADDRESS
138
139 #ifndef PAGESIZE
140 #define PAGESIZE        ( 4 << 10)
141 #endif
142 #define HUGE_PAGESIZE   ( 4 << 20)
143
144 #ifndef BUFFERSIZE
145 #define BUFFER_SIZE     (32 << 20)
146 #else
147 #define BUFFER_SIZE     (32 << BUFFERSIZE)
148 #endif
149
150 #define BASE_ADDRESS (START_ADDRESS - BUFFER_SIZE * MAX_CPU_NUMBER)
151
152 #ifndef MAP_ANONYMOUS
153 #define MAP_ANONYMOUS MAP_ANON
154 #endif
155
156 #endif
157