-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy patharm.mcs
553 lines (536 loc) · 8.25 KB
/
arm.mcs
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
;
; ARM Macros file
;
; Triple register is R4|R3|R2
; MUL_START. Initialise registers. Make R5 and R6 point to multipliers a
; and b. R7 points at result c.
; Initialise Triple register to 0
; See makemcs.txt for more information about this file
;
;
MACRO PMUL_START
__asm {
MOV r5,a
MOV r6,b
MOV r7,c
MOV r4,sn
MOV r3,#0
MOV r2,#0
ENDM
MACRO PMUL
LDR r0,[r5,#(4*%d)]
UMULL r8,r9,r0,r4
ADDS r8,r8,r3
ADC r3,r9,r2
STR r2,[r6,#(4*%d)]
STR r8,[r7,#(4*%d)]
ENDM
MACRO PMUL_END
UMULL r8,r9,r3,r4
STR r8,[r6]
STR r9,[r6,#4]
}
ENDM
MACRO H2_MUL_START
__asm {
MOV r5,a
MOV r6,b
MOV r7,c
MOV r4,#0
MOV r3,#0
MOV r2,#0
MOV r10,#0
MOV r11,#0
ENDM
MACRO H2_STEP
LDR r8,[r5,#(4*%d)]
LDR r9,[r5,#(4*%d+4)]
LDR r12,[r6,#(4*%d)]
UMULL r0,r1,r8,r12
ADDS r2,r2,r0
ADCS r3,r3,r1
ADC r11,r11,#0
UMULL r0,r1,r9,r12
ADDS r3,r3,r0
ADCS r4,r4,r1
ADDCS r11,r11,0x100
LDR r12,[r6,#(4*%d+4)]
UMULL r0,r1,r8,r12
ADDS r3,r3,r0
ADCS r4,r4,r1
ADDCS r11,r11,0x100
UMULL r0,r1,r9,r12
ADDS r4,r4,r0
ADCS r10,r10,r1
ADDCS r11,r11,0x10000
ENDM
MACRO H2_LAST
LDR r8,[r5,#(4*%d)]
LDR r9,[r5,#(4*%d+4)]
LDR r12,[r6,#(4*%d)]
UMULL r0,r1,r8,r12
ADDS r2,r2,r0
ADCS r3,r3,r1
UMULL r0,r1,r9,r12
ADD r3,r3,r0
LDR r12,[r6,#(4*%d+4)]
UMULL r0,r1,r8,r12
ADD r3,r3,r0
ENDM
MACRO H2_MFIN
STR r2,[r7,#(4*%d)]
STR r3,[r7,#(4*%d)]
AND r0,r11,0xFF
ADDS r2,r4,r0
AND r0,r11,0xFF00
ADCS r3,r10,r0,LSR#8
ADDCS r11,r11,0x10000
MOV r4,r11,LSR#16
MOV r10,#0
MOV r11,#0
ENDM
MACRO H2_MUL_END
STR r2,[r7,#(4*%d)]
STR r3,[r7,#(4*%d)]
}
ENDM
MACRO MUL_START
__asm {
MOV r5,a
MOV r6,b
MOV r7,c
MOV r4,#0
MOV r3,#0
MOV r2,#0
ENDM
;
; STEP macro. Calculates a double-register partial product
; and adds it to the triple register total
; Parameters 1 & 2: Indices i and j for partial product multipliers a[i]
; and b[j]
; STEP 1 even
MACRO STEP
LDR r0,[r5,#(4*%d)]
LDR r1,[r6,#(4*%d)]
UMULL r8,r9,r0,r1
ADDS r2,r2,r8
ADCS r3,r3,r9
ADC r4,r4,#0
ENDM
;
; MFIN macro. Finish column calculation. Store Sum for this column
; and get Carry for next
; Parameter 1: Index k for Column Sum c[k]
MACRO MFIN
STR r2,[r7,#(4*%d)]
MOV r2,r3
MOV r3,r4
MOV r4,#0
ENDM
;
; LAST
;
MACRO LAST
LDR r0,[r5,#(4*%d)]
LDR r1,[r6,#(4*%d)]
MLA r2,r0,r1,r2
ENDM
;
; MUL_END
; Parameter 1: Index for final carry c[.]
MACRO MUL_END
STR r2,[r7,#(4*%d)]
}
ENDM
MACRO H2_SQR_START
__asm {
MOV r5,a
MOV r7,c
MOV r4,#0
MOV r3,#0
MOV r2,#0
MOV r10,#0
MOV r11,#0
ENDM
MACRO H2_DSTEP
LDR r8,[r5,#(4*%d)]
LDR r9,[r5,#(4*%d+4)]
LDR r12,[r5,#(4*%d)]
UMULL r0,r1,r8,r12
ADDS r2,r2,r0
ADCS r3,r3,r1
ADC r11,r11,#0
ADDS r2,r2,r0
ADCS r3,r3,r1
ADC r11,r11,#0
UMULL r0,r1,r9,r12
ADDS r3,r3,r0
ADCS r4,r4,r1
ADDCS r11,r11,0x100
ADDS r3,r3,r0
ADCS r4,r4,r1
ADDCS r11,r11,0x100
LDR r12,[r5,#(4*%d+4)]
UMULL r0,r1,r8,r12
ADDS r3,r3,r0
ADCS r4,r4,r1
ADDCS r11,r11,0x100
ADDS r3,r3,r0
ADCS r4,r4,r1
ADDCS r11,r11,0x100
UMULL r0,r1,r9,r12
ADDS r4,r4,r0
ADCS r10,r10,r1
ADDCS r11,r11,0x10000
ADDS r4,r4,r0
ADCS r10,r10,r1
ADDCS r11,r11,0x10000
ENDM
MACRO H2_SELF
LDR r8,[r5,#(4*%d)]
LDR r9,[r5,#(4*%d+4)]
UMULL r0,r1,r8,r8
ADDS r2,r2,r0
ADCS r3,r3,r1
ADC r11,r11,#0
UMULL r0,r1,r8,r9
ADDS r3,r3,r0
ADCS r4,r4,r1
ADDCS r11,r11,0x100
ADDS r3,r3,r0
ADCS r4,r4,r1
ADDCS r11,r11,0x100
UMULL r0,r1,r9,r9
ADDS r4,r4,r0
ADCS r10,r10,r1
ADDCS r11,r11,0x10000
ENDM
MACRO H2_SFIN
STR r2,[r7,#(4*%d)]
STR r3,[r7,#(4*%d)]
AND r0,r11,0xFF
ADDS r2,r4,r0
AND r0,r11,0xFF00
ADCS r3,r10,r0,LSR#8
ADDCS r11,r11,0x10000
MOV r4,r11,LSR#16
MOV r10,#0
MOV r11,#0
ENDM
MACRO H2_SQR_END
STR r2,[r7,#(4*%d)]
STR r3,[r7,#(4*%d)]
}
ENDM
;
; SQR_START
;
MACRO SQR_START
__asm {
MOV r5,a
MOV r7,c
MOV r4,#0
MOV r3,#0
MOV r2,#0
ENDM
;
; DSTEP macro. Calculates a double-register partial product
; and add it twice to a triple register total
; Parameters 1 & 2 : Indices of partial product multipliers
MACRO DSTEP
LDR r0,[r5,#(4*%d)]
LDR r1,[r5,#(4*%d)]
UMULL r8,r9,r0,r1
ADDS r2,r2,r8
ADCS r3,r3,r9
ADC r4,r4,#0
ADDS r2,r2,r8
ADCS r3,r3,r9
ADC r4,r4,#0
ENDM
;
; SELF macro. Calculate the double-register square and
; add it to a triple register total
; Parameter 1 : Index of diagonal element
MACRO SELF
LDR r0,[r5,#(4*%d)]
UMULL r8,r9,r0,r0
ADDS r2,r2,r8
ADCS r3,r3,r9
ADC r4,r4,#0
ENDM
;
; SFIN macro. Finish column calculation for squaring. Store Sum
; and get Carry for next column.
; Parameter 1: Index of Column Sum
MACRO SFIN
STR r2,[r7,#(4*%d)]
MOV r2,r3
MOV r3,r4
MOV r4,#0
ENDM
;
; SQR_END
; Parameter 1: Index for final carry
MACRO SQR_END
STR r2,[r7,#(4*%d)]
}
ENDM
;
; REDC_START macro
;
MACRO REDC_START
__asm {
MOV r5,a
MOV r6,b
MOV r7,ndash
MOV r4,#0
MOV r3,#0
LDR r2,[r5]
ENDM
;
; RFINU macro
;
MACRO RFINU
MUL r1,r7,r2
STR r1,[r5,#(4*%d)]
LDR r0,[r6]
UMULL r8,r9,r0,r1
ADDS r0,r2,r8
ADCS r2,r3,r9
ADC r3,r4,#0
LDR r0,[r5,#(4*(%d+1))]
ADDS r2,r2,r0
ADC r3,r3,#0
MOV r4,#0
ENDM
;
; RFIND macro
;
MACRO RFIND
STR r2,[r5,#(4*%d)]
LDR r0,[r5,#(4*(%d+1))]
ADDS r2,r3,r0
ADC r3,r4,#0
MOV r4,#0
ENDM
;
; REDC_END
;
MACRO REDC_END
STR r2,[r5,#(4*%d)]
STR r3,[r5,#(4*(%d+1))]
}
ENDM
;
; ADD_START macro - initialise for add/subtract, do first one
;
MACRO ADD_START
__asm {
MOV r6,a
MOV r7,b
MOV r8,c
LDR r0,[r6]
LDR r1,[r7]
ADDS r0,r0,r1
STR r0,[r8]
ENDM
;
; ADD macro. Add two numbers from memory and store result in memory.
; Don't forget carry bit
;
MACRO ADD
LDR r0,[r6,#(4*%d)]
LDR r1,[r7,#(4*%d)]
ADCS r0,r0,r1
STR r0,[r8,#(4*%d)]
ENDM
;
; ADD_END macro. Catch carry
;
MACRO ADD_END
MOV r0,#0
MOVCS r0,#1
MOV carry,r0
}
ENDM
;
; INC_START macro. Do first one
;
MACRO INC_START
__asm {
MOV r6,a
MOV r7,b
LDR r0,[r6]
LDR r1,[r7]
ADDS r0,r0,r1
STR r0,[r6]
ENDM
;
; INC macro. Add two numbers from memory and store result in memory.
; Don't forget carry bit
;
MACRO INC
LDR r0,[r6,#(4*%d)]
LDR r1,[r7,#(4*%d)]
ADCS r0,r0,r1
STR r0,[r6,#(4*%d)]
ENDM
;
; INC_END macro. Catch carry
;
MACRO INC_END
MOV r0,#0
MOVCS r0,#1
MOV carry,r0
}
ENDM
;
; SUB_START macro
;
MACRO SUB_START
__asm {
MOV r6,a
MOV r7,b
MOV r8,c
LDR r0,[r6]
LDR r1,[r7]
SUBS r0,r0,r1
STR r0,[r8]
ENDM
;
; SUB macro. Subtract two numbers in memory and store result in memory.
;
MACRO SUB
LDR r0,[r6,#(4*%d)]
LDR r1,[r7,#(4*%d)]
SBCS r0,r0,r1
STR r0,[r8,#(4*%d)]
ENDM
;
; SUB_END macro. Catch carry
;
MACRO SUB_END
MOV r0,#0
MOVCC r0,#1
MOV carry,r0
}
ENDM
;
; DEC_START macro
;
MACRO DEC_START
__asm {
MOV r6,a
MOV r7,b
LDR r0,[r6]
LDR r1,[r7]
SUBS r0,r0,r1
STR r0,[r6]
ENDM
;
; DEC macro. Subtract two numbers in memory and store result in memory.
;
MACRO DEC
LDR r0,[r6,#(4*%d)]
LDR r1,[r7,#(4*%d)]
SBCS r0,r0,r1
STR r0,[r6,#(4*%d)]
ENDM
;
; DEC_END macro. Catch carry
;
MACRO DEC_END
MOV r0,#0
MOVCC r0,#1
MOV carry,r0
}
ENDM
;
; KADD_START macro. Zero Carry flag
;
MACRO KADD_START
__asm {
MOV r6,a
MOV r7,b
MOV r8,c
MOV r9,n
MOV r0,#0
ADDS r0,r0,r0
k%d:
ENDM
;
; KASL macro. Important that carry flag is undisturbed!
;
MACRO KASL
SUB r9,r9,#1
TEQ r9,#0
BEQ k%d
ADD r6,r6,#(4*%d)
ADD r7,r7,#(4*%d)
ADD r8,r8,#(4*%d)
B k%d
k%d:
ENDM
;
; KADD_END macro
;
MACRO KADD_END
MOV r0,#0
MOVCS r0,#1
MOV carry,r0
}
ENDM
;
; KINC_START macro. Set carry to Zero
;
MACRO KINC_START
__asm {
MOV r6,a
MOV r7,b
MOV r9,n
MOV r0,#0
ADDS r0,r0,r0
k%d:
ENDM
;
; KIDL macro. Important that carry flag is undisturbed!
;
MACRO KIDL
SUB r9,r9,#1
TEQ r9,#0
BEQ k%d
ADD r6,r6,#(4*%d)
ADD r7,r7,#(4*%d)
B k%d
k%d:
ENDM
;
; KINC_END macro
;
MACRO KINC_END
MOV r0,#0
MOVCS r0,#1
MOV carry,r0
}
ENDM
;
; KDEC_START macro. Set carry
;
MACRO KDEC_START
__asm {
MOV r6,a
MOV r7,b
MOV r9,n
SUBS r0,r0,r0
k%d:
ENDM
;
; KDEC_END macro
;
MACRO KDEC_END
MOV r0,#0
MOVCC r0,#1
MOV carry,r0
}
ENDM