summaryrefslogtreecommitdiff
path: root/dl/api/arm/arm64COMM_s.h
blob: e19ceeed5c65a85bb0d665957c33da554749623d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
// -*- Mode: asm; -*-
//
//  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
//
//  Use of this source code is governed by a BSD-style license
//  that can be found in the LICENSE file in the root of the source
//  tree. An additional intellectual property rights grant can be found
//  in the file PATENTS.  All contributing project authors may
//  be found in the AUTHORS file in the root of the source tree.
//
//  This file was originally licensed as follows. It has been
//  relicensed with permission from the copyright holders.
//
	
// 
// File Name:  armCOMM_s.h
// OpenMAX DL: v1.0.2
// Last Modified Revision:   13871
// Last Modified Date:       Fri, 09 May 2008
// 
// (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
// 
// 
//
// ARM optimized OpenMAX common header file
//

	.set	_SBytes, 0	// Number of scratch bytes on stack
	.set	_Workspace, 0	// Stack offset of scratch workspace

	.set	_RRegList, 0	// R saved register list (last register number)
	.set	_DRegList, 0	// D saved register list (last register number)

	// Work out list of D saved registers, like for R registers.
	.macro	_M_GETDREGLIST dreg
	.ifeqs "\dreg", ""
	.set	_DRegList, 0
	.exitm
	.endif

	.ifeqs "\dreg", "d8"
	.set	_DRegList, 8
	.exitm
	.endif

	.ifeqs "\dreg", "d9"
	.set	_DRegList, 9
	.exitm
	.endif

	.ifeqs "\dreg", "d10"
	.set	_DRegList, 10
	.exitm
	.endif

	.ifeqs "\dreg", "d11"
	.set	_DRegList, 11
	.exitm
	.endif

	.ifeqs "\dreg", "d12"
	.set	_DRegList, 12
	.exitm
	.endif

	.ifeqs "\dreg", "d13"
	.set	_DRegList, 13
	.exitm
	.endif

	.ifeqs "\dreg", "d14"
	.set	_DRegList, 14
	.exitm
	.endif

	.ifeqs "\dreg", "d15"
	.set	_DRegList, 15
	.exitm
	.endif

	.warning "Unrecognized saved d register limit: \rreg"
	.endm

//////////////////////////////////////////////////////////
// Function header and footer macros
//////////////////////////////////////////////////////////      
	
        // Function Header Macro    
        // Generates the function prologue
        // Note that functions should all be "stack-moves-once"
        // The FNSTART and FNEND macros should be the only places
        // where the stack moves.
        //    
        //  name  = function name
        //  rreg  = ""   don't stack any registers
        //          "lr" stack "lr" only
        //          "rN" stack registers "r4-rN,lr"
        //  dreg  = ""   don't stack any D registers
        //          "dN" stack registers "d8-dN"
        //
        // Note: ARM Archicture procedure call standard AAPCS
        // states that r4-r11, sp, d8-d15 must be preserved by
        // a compliant function.
	.macro	M_START name, rreg, dreg
	.set	_Workspace, 0

	// Define the function and make it external.
	.global	\name
	.func	\name
	.section	.text.\name,"ax",%progbits
	.align	4
\name :		
//.fnstart
	// Save specified R registers
	_M_PUSH_RREG

	// Save specified D registers
        _M_GETDREGLIST  \dreg
	_M_PUSH_DREG

	// Ensure size claimed on stack is 16-byte aligned for ARM64
	.if (_SBytes & 15) != 0
	.set	_SBytes, _SBytes + (16 - (_SBytes & 15))
	.endif
	.if _SBytes != 0
		sub	sp, sp, #_SBytes
	.endif	
	.endm

        // Function Footer Macro        
        // Generates the function epilogue
	.macro M_END
	// Restore the stack pointer to its original value on function entry
	.if _SBytes != 0
		add	sp, sp, #_SBytes
	.endif
	// Restore any saved R or D registers.
	_M_RET
	//.fnend	
	.endfunc
        // Reset the global stack tracking variables back to their
	// initial values.
	.set _SBytes, 0
	.endm

	// Based on the value of _DRegList, push the specified set of registers 
	// to the stack.
	// The ARM64 ABI says only v8-v15 needs to be saved across calls and only 
	// the lower 64 bits need to be saved.
	.macro _M_PUSH_DREG
	.if _DRegList >= 8
		sub	sp, sp, (_DRegList - 7) * 16	// 16-byte alignment
		str	q8, [sp]
	.endif
	
	.if _DRegList >= 9
		str	q9, [sp, #16]
	.endif
	
	.if _DRegList >= 10
		str	q10, [sp, #32]
	.endif
	
	.if _DRegList >= 11
		str	q11, [sp, #48]
	.endif
	
	.if _DRegList >= 12
		str	q12, [sp, #64]
	.endif
	
	.if _DRegList >= 13
		str	q13, [sp, #80]
	.endif
	
	.if _DRegList >= 14
		str	q14, [sp, #96]
	.endif
	
	.if _DRegList >= 15
		str	q15, [sp, #112]
	.endif
	
	.exitm
	.endm

	// Based on the value of _RRegList, push the specified set of registers 
	// to the stack.
	// The ARM64 ABI says registers r19-r29 needs to be saved across calls.
	// But for the FFT routines, we don't need to save anything, so just
	// preserve the SP and LR.
	.macro _M_PUSH_RREG
	sub	sp, sp, #16
	str	x30, [sp]
	str	x29, [sp, #8]
	.exitm
	.endm

	// The opposite of _M_PUSH_DREG
	.macro  _M_POP_DREG
	.if _DRegList >= 8
		ldr	q8, [sp]
	.endif
	
	.if _DRegList >= 9
		ldr	q9, [sp, #16]
	.endif
	
	.if _DRegList >= 10
		ldr	q10, [sp, #32]
	.endif
	
	.if _DRegList >= 11
		ldr	q11, [sp, #48]
	.endif
	
	.if _DRegList >= 12
		ldr	q12, [sp, #64]
	.endif
	
	.if _DRegList >= 13
		ldr	q13, [sp, #80]
	.endif
	
	.if _DRegList >= 14
		ldr	q14, [sp, #96]
	.endif
	
	.if _DRegList >= 15
		ldr	q15, [sp, #112]
	.endif

	.if _DRegList >= 8
		add	sp, sp, (_DRegList - 7) * 16	// 16-byte alignment
	.endif
	.exitm
	.endm

	// The opposite of _M_PUSH_RREG
	.macro _M_POP_RREG cc
	ldr	x29, [sp, #8]
	ldr	x30, [sp]
	add	sp, sp, #16
	.exitm
	.endm
	
        // Produce function return instructions
	.macro	_M_RET cc
	_M_POP_DREG \cc
	_M_POP_RREG \cc
	ret
	.endm	
	// rsb - reverse subtract
	// compute dst = src2 - src1, useful when src2 is an immediate value
	.macro	rsb	dst, src1, src2
	sub	\dst, \src1, \src2
	neg	\dst, \dst
	.endm