summaryrefslogtreecommitdiff
path: root/MdePkg/Library/BaseLib/Arm/Math64.S
blob: 76a3c5516073d69bc322276106c7203f09266298 (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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#------------------------------------------------------------------------------ 
#
# Replacement for Math64.c that is coded to use older GCC intrinsics. 
# Doing this reduces the number of intrinsics that are required when
# you port to a new version of gcc. 
#
# Need to split this into multple files to size optimize the image.
#
# Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution.  The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php.
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#------------------------------------------------------------------------------

	.text
	.align 2
	.globl ASM_PFX(InternalMathLShiftU64)
	INTERWORK_FUNC(InternalMathLShiftU64)

ASM_PFX(InternalMathLShiftU64):
	stmfd	sp!, {r4, r5, r6}
	mov	r6, r1
	rsb	ip, r2, #32
	mov	r4, r6, asl r2
	subs	r1, r2, #32
	orr	r4, r4, r0, lsr ip
	mov	r3, r0, asl r2
	movpl	r4, r0, asl r1
	mov	r5, r0
	mov	r0, r3
	mov	r1, r4
	ldmfd	sp!, {r4, r5, r6}
	bx	lr

	.align 2
	.globl ASM_PFX(InternalMathRShiftU64)
	INTERWORK_FUNC(InternalMathRShiftU64)

ASM_PFX(InternalMathRShiftU64):
	stmfd	sp!, {r4, r5, r6}
	mov	r5, r0
	rsb	ip, r2, #32
	mov	r3, r5, lsr r2
	subs	r0, r2, #32
	orr	r3, r3, r1, asl ip
	mov	r4, r1, lsr r2
	movpl	r3, r1, lsr r0
	mov	r6, r1
	mov	r0, r3
	mov	r1, r4
	ldmfd	sp!, {r4, r5, r6}
	bx	lr

	.align 2
	.globl ASM_PFX(InternalMathARShiftU64)
	INTERWORK_FUNC(InternalMathARShiftU64)

ASM_PFX(InternalMathARShiftU64):
	stmfd	sp!, {r4, r5, r6}
	mov	r5, r0
	rsb	ip, r2, #32
	mov	r3, r5, lsr r2
	subs	r0, r2, #32
	orr	r3, r3, r1, asl ip
	mov	r4, r1, asr r2
	movpl	r3, r1, asr r0
	mov	r6, r1
	mov	r0, r3
	mov	r1, r4
	ldmfd	sp!, {r4, r5, r6}
	bx	lr

	.align 2
	.globl ASM_PFX(InternalMathLRotU64)
	INTERWORK_FUNC(InternalMathLRotU64)

ASM_PFX(InternalMathLRotU64):
	stmfd	sp!, {r4, r5, r6, r7, lr}
	add	r7, sp, #12
	mov	r6, r1
	rsb	ip, r2, #32
	mov	r4, r6, asl r2
	rsb	lr, r2, #64
	subs	r1, r2, #32
	orr	r4, r4, r0, lsr ip
	mov	r3, r0, asl r2
	movpl	r4, r0, asl r1
	sub	ip, r2, #32
	mov	r5, r0
	mov	r0, r0, lsr lr
	rsbs	r2, r2, #32
	orr	r0, r0, r6, asl ip
	mov	r1, r6, lsr lr
	movpl	r0, r6, lsr r2
	orr	r1, r1, r4
	orr	r0, r0, r3
	ldmfd	sp!, {r4, r5, r6, r7, pc}


	.align 2
	.globl ASM_PFX(InternalMathRRotU64)
	INTERWORK_FUNC(InternalMathRRotU64)

ASM_PFX(InternalMathRRotU64):
	stmfd	sp!, {r4, r5, r6, r7, lr}
	add	r7, sp, #12
	mov	r5, r0
	rsb	ip, r2, #32
	mov	r3, r5, lsr r2
	rsb	lr, r2, #64
	subs	r0, r2, #32
	orr	r3, r3, r1, asl ip
	mov	r4, r1, lsr r2
	movpl	r3, r1, lsr r0
	sub	ip, r2, #32
	mov	r6, r1
	mov	r1, r1, asl lr
	rsbs	r2, r2, #32
	orr	r1, r1, r5, lsr ip
	mov	r0, r5, asl lr
	movpl	r1, r5, asl r2
	orr	r0, r0, r3
	orr	r1, r1, r4
	ldmfd	sp!, {r4, r5, r6, r7, pc}

	.align 2
	.globl ASM_PFX(InternalMathMultU64x32)
	INTERWORK_FUNC(InternalMathMultU64x32)

ASM_PFX(InternalMathMultU64x32):
	stmfd	sp!, {r7, lr}
	add	r7, sp, #0
	mov	r3, #0
	mov	ip, r0
	mov	lr, r1
	umull	r0, r1, ip, r2
	mla	r1, lr, r2, r1
	mla	r1, ip, r3, r1
	ldmfd	sp!, {r7, pc}

	.align 2
	.globl ASM_PFX(InternalMathMultU64x64)
	INTERWORK_FUNC(InternalMathMultU64x64)

ASM_PFX(InternalMathMultU64x64):
	stmfd	sp!, {r7, lr}
	add	r7, sp, #0
	mov	ip, r0
	mov	lr, r1
	umull	r0, r1, ip, r2
	mla	r1, lr, r2, r1
	mla	r1, ip, r3, r1
	ldmfd	sp!, {r7, pc}

	.align 2
	.globl ASM_PFX(InternalMathDivU64x32)
	INTERWORK_FUNC(InternalMathDivU64x32)

ASM_PFX(InternalMathDivU64x32):
	stmfd	sp!, {r7, lr}
	add	r7, sp, #0
	mov	r3, #0
	bl 	ASM_PFX(__udivdi3)
	ldmfd	sp!, {r7, pc}
	
	
	.align 2
	.globl ASM_PFX(InternalMathModU64x32)
	INTERWORK_FUNC(InternalMathModU64x32)

ASM_PFX(InternalMathModU64x32):
	stmfd	sp!, {r7, lr}
	add	r7, sp, #0
	mov	r3, #0
	bl 	ASM_PFX(__umoddi3)
	ldmfd	sp!, {r7, pc}
	
	
	.align 2
	.globl ASM_PFX(InternalMathDivRemU64x32)
	INTERWORK_FUNC(InternalMathDivRemU64x32)

ASM_PFX(InternalMathDivRemU64x32):
	stmfd	sp!, {r4, r5, r6, r7, lr}
	add	r7, sp, #12
	stmfd	sp!, {r10, r11}
	subs	r6, r3, #0
	mov	r10, r0
	mov	r11, r1
	moveq	r4, r2
	moveq	r5, #0
	beq	L22
	mov	r4, r2
	mov	r5, #0
	mov	r3, #0
	bl 	ASM_PFX(__umoddi3)
	str	r0, [r6, #0]
L22:
	mov	r0, r10
	mov	r1, r11
	mov	r2, r4
	mov	r3, r5
	bl 	ASM_PFX(__udivdi3)
	ldmfd	sp!, {r10, r11}
	ldmfd	sp!, {r4, r5, r6, r7, pc}
	
	
	.align 2
	.globl ASM_PFX(InternalMathDivRemU64x64)
	INTERWORK_FUNC(InternalMathDivRemU64x64)

ASM_PFX(InternalMathDivRemU64x64):
	stmfd	sp!, {r4, r5, r6, r7, lr}
	add	r7, sp, #12
	stmfd	sp!, {r10, r11}
	ldr	r6, [sp, #28]
	mov	r4, r0
	cmp	r6, #0
	mov	r5, r1
	mov	r10, r2
	mov	r11, r3
	beq	L26
	bl 	ASM_PFX(__umoddi3)
	stmia	r6, {r0-r1}
L26:
	mov	r0, r4
	mov	r1, r5
	mov	r2, r10
	mov	r3, r11
	bl 	ASM_PFX(__udivdi3)
	ldmfd	sp!, {r10, r11}
	ldmfd	sp!, {r4, r5, r6, r7, pc}
	
	
	.align 2
	.globl ASM_PFX(InternalMathDivRemS64x64)
	INTERWORK_FUNC(InternalMathDivRemS64x64)

ASM_PFX(InternalMathDivRemS64x64):
	stmfd	sp!, {r4, r5, r6, r7, lr}
	add	r7, sp, #12
	stmfd	sp!, {r10, r11}
	ldr	r6, [sp, #28]
	mov	r4, r0
	cmp	r6, #0
	mov	r5, r1
	mov	r10, r2
	mov	r11, r3
	beq	L30
	bl 	ASM_PFX(__moddi3)
	stmia	r6, {r0-r1}
L30:
	mov	r0, r4
	mov	r1, r5
	mov	r2, r10
	mov	r3, r11
	bl 	ASM_PFX(__divdi3)
	ldmfd	sp!, {r10, r11}
	ldmfd	sp!, {r4, r5, r6, r7, pc}
	
	
	.align 2
	.globl ASM_PFX(InternalMathSwapBytes64)
	INTERWORK_FUNC(InternalMathSwapBytes64)

ASM_PFX(InternalMathSwapBytes64):
	@ args = 0, pretend = 0, frame = 0
	@ frame_needed = 1, uses_anonymous_args = 0
	stmfd	sp!, {r4, r5, r6, r7, lr}
	add	r7, sp, #12
	mov	r5, r1
	bl	ASM_PFX(SwapBytes32)
	mov	r6, r0
	mov	r0, r5
	bl	ASM_PFX(SwapBytes32)
	mov	r4, r6
	mov	r5, r4, asr #31
	mov	r2, #0
	mov	r1, r0, asr #31
	orr	r0, r0, r2
	orr	r1, r1, r4
	ldmfd	sp!, {r4, r5, r6, r7, pc}


ASM_FUNCTION_REMOVE_IF_UNREFERENCED