-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathfuncs_arm.h
543 lines (472 loc) · 18.5 KB
/
funcs_arm.h
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
/******************************************************************************
* funcs_arm.h
*
* All Test Functions in 32-bit ARM assembly code: they are codenamed as
* Scan/Perm Read/Write 32/64 Ptr/Index Simple/Unroll/Multi Loop.
*
* Scan = consecutive scanning, Perm = walk permutation cycle.
* Read/Write = obvious
* 32/64 = size of access
* Ptr = with pointer, Index = access as array[i]
* Simple/Unroll = 1 or 16 operations per loop,
* Multi = ARM multi-register operation
*
******************************************************************************
* Copyright (C) 2013 Timo Bingmann <[email protected]>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
// ****************************************************************************
// ----------------------------------------------------------------------------
// 32-bit Operations
// ----------------------------------------------------------------------------
// ****************************************************************************
// 32-bit writer in a simple loop (C version)
void cScanWrite32PtrSimpleLoop(char* memarea, size_t size, size_t repeats)
{
uint32_t* begin = (uint32_t*)memarea;
uint32_t* end = begin + size / sizeof(uint32_t);
uint32_t value = 0xC0FFEEEE;
do {
uint32_t* p = begin;
do {
*p++ = value;
}
while (p < end);
}
while (--repeats != 0);
}
//REGISTER(cScanWrite32PtrSimpleLoop, 4, 4, 1);
// 32-bit writer in a simple loop (Assembler version)
void ScanWrite32PtrSimpleLoop(char* memarea, size_t size, size_t repeats)
{
uint32_t value = 0xC0FFEEEE;
asm volatile(
"1: \n" // start of repeat loop
"mov ip, %[memarea] \n" // ip = reset loop iterator
"2: \n" // start of write loop
"str %[value], [ip], #4 \n" // store and advance 4
// test write loop condition
"cmp ip, %[end] \n" // compare to end iterator
"blo 2b \n"
// test repeat loop condition
"subs %[repeats], %[repeats], #1 \n" // until repeats = 0
"bne 1b \n"
: [repeats] "+r" (repeats)
: [value] "r" (value), [memarea] "r" (memarea), [end] "r" (memarea+size)
: "ip", "cc", "memory");
}
REGISTER(ScanWrite32PtrSimpleLoop, 4, 4, 1);
// 32-bit writer in an unrolled loop (Assembler version)
void ScanWrite32PtrUnrollLoop(char* memarea, size_t size, size_t repeats)
{
uint32_t value = 0xC0FFEEEE;
asm volatile(
"1: \n" // start of repeat loop
"mov ip, %[memarea] \n" // ip = reset loop iterator
"2: \n" // start of write loop
"str %[value], [ip,#0*4] \n"
"str %[value], [ip,#1*4] \n"
"str %[value], [ip,#2*4] \n"
"str %[value], [ip,#3*4] \n"
"str %[value], [ip,#4*4] \n"
"str %[value], [ip,#5*4] \n"
"str %[value], [ip,#6*4] \n"
"str %[value], [ip,#7*4] \n"
"str %[value], [ip,#8*4] \n"
"str %[value], [ip,#9*4] \n"
"str %[value], [ip,#10*4] \n"
"str %[value], [ip,#11*4] \n"
"str %[value], [ip,#12*4] \n"
"str %[value], [ip,#13*4] \n"
"str %[value], [ip,#14*4] \n"
"str %[value], [ip,#15*4] \n"
"add ip, ip, #16*4 \n" // add offset
// test write loop condition
"cmp ip, %[end] \n" // compare to end iterator
"blo 2b \n"
// test repeat loop condition
"subs %[repeats], %[repeats], #1 \n" // until repeats = 0
"bne 1b \n"
: [repeats] "+r" (repeats)
: [value] "r" (value), [memarea] "r" (memarea), [end] "r" (memarea+size)
: "ip", "cc", "memory");
}
REGISTER(ScanWrite32PtrUnrollLoop, 4, 4, 16);
// 32-bit writer with multistore operations (Assembler version)
void ScanWrite32PtrMultiLoop(char* memarea, size_t size, size_t repeats)
{
uint32_t value = 0xC0FFEEEE;
asm volatile(
"ldr r4, %[value] \n" // load values
"ldr r5, %[value] \n"
"ldr r6, %[value] \n"
"ldr r7, %[value] \n"
"ldr r8, %[value] \n"
"ldr r9, %[value] \n"
"ldr r10, %[value] \n"
"ldr r11, %[value] \n"
"1: \n" // start of repeat loop
"mov ip, %[memarea] \n" // ip = reset loop iterator
"2: \n" // start of write loop
"stmia ip!, {r4-r11} \n" // store and advance
// test write loop condition
"cmp ip, %[end] \n" // compare to end iterator
"blo 2b \n"
// test repeat loop condition
"subs %[repeats], %[repeats], #1 \n" // until repeats = 0
"bne 1b \n"
: [repeats] "+r" (repeats)
: [value] "m" (value), [memarea] "r" (memarea), [end] "r" (memarea+size)
: "ip", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "cc", "memory");
}
REGISTER(ScanWrite32PtrMultiLoop, 4, 4, 8);
// 32-bit read in a simple loop (Assembler version)
void ScanRead32PtrSimpleLoop(char* memarea, size_t size, size_t repeats)
{
asm volatile(
"1: \n" // start of repeat loop
"mov ip, %[memarea] \n" // ip = reset loop iterator
"2: \n" // start of read loop
"ldr r0, [ip], #4 \n" // retrieve and advance 4
// test read loop condition
"cmp ip, %[end] \n" // compare to end iterator
"blo 2b \n"
// test repeat loop condition
"subs %[repeats], %[repeats], #1 \n" // until repeats = 0
"bne 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size)
: "ip", "r0", "cc", "memory");
}
REGISTER(ScanRead32PtrSimpleLoop, 4, 4, 1);
// 32-bit reader in an unrolled loop (Assembler version)
void ScanRead32PtrUnrollLoop(char* memarea, size_t size, size_t repeats)
{
asm volatile(
"1: \n" // start of repeat loop
"mov ip, %[memarea] \n" // ip = reset loop iterator
"2: \n" // start of read loop
"ldr r0, [ip,#0*4] \n"
"ldr r0, [ip,#1*4] \n"
"ldr r0, [ip,#2*4] \n"
"ldr r0, [ip,#3*4] \n"
"ldr r0, [ip,#4*4] \n"
"ldr r0, [ip,#5*4] \n"
"ldr r0, [ip,#6*4] \n"
"ldr r0, [ip,#7*4] \n"
"ldr r0, [ip,#8*4] \n"
"ldr r0, [ip,#9*4] \n"
"ldr r0, [ip,#10*4] \n"
"ldr r0, [ip,#11*4] \n"
"ldr r0, [ip,#12*4] \n"
"ldr r0, [ip,#13*4] \n"
"ldr r0, [ip,#14*4] \n"
"ldr r0, [ip,#15*4] \n"
"add ip, ip, #16*4 \n" // add offset
// test read loop condition
"cmp ip, %[end] \n" // compare to end iterator
"blo 2b \n"
// test repeat loop condition
"subs %[repeats], %[repeats], #1 \n" // until repeats = 0
"bne 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size)
: "ip", "r0", "cc", "memory");
}
REGISTER(ScanRead32PtrUnrollLoop, 4, 4, 16);
// 32-bit reader with multistore operations (Assembler version)
void ScanRead32PtrMultiLoop(char* memarea, size_t size, size_t repeats)
{
asm volatile(
"1: \n" // start of repeat loop
"mov ip, %[memarea] \n" // ip = reset loop iterator
"2: \n" // start of read loop
"ldmia ip!, {r4-r11} \n" // retrieve and advance
// test read loop condition
"cmp ip, %[end] \n" // compare to end iterator
"blo 2b \n"
// test repeat loop condition
"subs %[repeats], %[repeats], #1 \n" // until repeats = 0
"bne 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size)
: "ip", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "cc", "memory");
}
REGISTER(ScanRead32PtrMultiLoop, 4, 4, 1);
// -----------------------------------------------------------------------------
// 32-bit writer in an indexed loop (C version)
void cScanWrite32IndexSimpleLoop(char* _memarea, size_t _size, size_t repeats)
{
uint32_t* memarea = (uint32_t*)_memarea;
uint32_t size = _size / sizeof(uint32_t);
uint32_t value = 0xC0FFEEEE;
do {
for (size_t i = 0; i < size; ++i)
memarea[i] = value;
}
while (--repeats != 0);
}
//REGISTER(cScanWrite32IndexSimpleLoop, 4, 4, 1);
// 32-bit writer in an indexed loop (Assembler version)
void ScanWrite32IndexSimpleLoop(char* memarea, size_t size, size_t repeats)
{
uint32_t value = 0xC0FFEEEE;
asm volatile(
"1: \n" // start of repeat loop
"mov ip, #0 \n" // ip = reset index
"2: \n" // start of write loop
"str %[value], [%[memarea], ip] \n" // store and advance 4
"add ip, #4 \n"
// test write loop condition
"cmp ip, %[size] \n" // compare to total size
"blo 2b \n"
// test repeat loop condition
"subs %[repeats], %[repeats], #1 \n" // until repeats = 0
"bne 1b \n"
: [repeats] "+r" (repeats)
: [value] "r" (value), [memarea] "r" (memarea), [size] "r" (size)
: "ip", "cc", "memory");
}
REGISTER(ScanWrite32IndexSimpleLoop, 4, 4, 1);
// 32-bit reader in an indexed loop (Assembler version)
void ScanRead32IndexSimpleLoop(char* memarea, size_t size, size_t repeats)
{
asm volatile(
"1: \n" // start of repeat loop
"mov ip, #0 \n" // ip = reset index
"2: \n" // start of read loop
"ldr r0, [%[memarea], ip] \n" // store and advance 4
"add ip, #4 \n"
// test read loop condition
"cmp ip, %[size] \n" // compare to total size
"blo 2b \n"
// test repeat loop condition
"subs %[repeats], %[repeats], #1 \n" // until repeats = 0
"bne 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [size] "r" (size)
: "ip", "r0", "cc", "memory");
}
REGISTER(ScanRead32IndexSimpleLoop, 4, 4, 1);
// ****************************************************************************
// ----------------------------------------------------------------------------
// 64-bit Operations
// ----------------------------------------------------------------------------
// ****************************************************************************
// 64-bit writer in a simple loop (C version)
void cScanWrite64PtrSimpleLoop(char* memarea, size_t size, size_t repeats)
{
typedef std::pair<uint32_t,uint32_t> uint64;
uint64* begin = (uint64*)memarea;
uint64* end = begin + size / sizeof(uint64);
uint32_t val32 = 0xC0FFEEEE;
uint64 value = uint64(val32,val32);
do {
uint64* p = begin;
do {
*p++ = value;
}
while(p < end);
}
while (--repeats != 0);
}
//REGISTER(cScanWrite64PtrSimpleLoop, 8, 8, 1);
// 64-bit writer in a simple loop (Assembler version)
void ScanWrite64PtrSimpleLoop(char* memarea, size_t size, size_t repeats)
{
uint32_t value = 0xC0FFEEEE;
asm volatile(
"mov r4, %[value] \n" // r4+r5 = 64-bit value
"mov r5, %[value] \n"
"1: \n" // start of repeat loop
"mov ip, %[memarea] \n" // ip = reset loop iterator
"2: \n" // start of write loop
"strd r4, [ip], #8 \n" // store and advance 8
// test write loop condition
"cmp ip, %[end] \n" // compare to end iterator
"blo 2b \n"
// test repeat loop condition
"subs %[repeats], %[repeats], #1 \n" // until repeats = 0
"bne 1b \n"
: [repeats] "+r" (repeats)
: [value] "r" (value), [memarea] "r" (memarea), [end] "r" (memarea+size)
: "ip", "r4", "r5", "cc", "memory");
}
REGISTER(ScanWrite64PtrSimpleLoop, 8, 8, 1);
// 64-bit writer in an unrolled loop (Assembler version)
void ScanWrite64PtrUnrollLoop(char* memarea, size_t size, size_t repeats)
{
uint32_t value = 0xC0FFEEEE;
asm volatile(
"mov r4, %[value] \n" // r4+r5 = 64-bit value
"mov r5, %[value] \n"
"1: \n" // start of repeat loop
"mov ip, %[memarea] \n" // ip = reset loop iterator
"2: \n" // start of write loop
"strd r4, [ip,#0*8] \n"
"strd r4, [ip,#1*8] \n"
"strd r4, [ip,#2*8] \n"
"strd r4, [ip,#3*8] \n"
"strd r4, [ip,#4*8] \n"
"strd r4, [ip,#5*8] \n"
"strd r4, [ip,#6*8] \n"
"strd r4, [ip,#7*8] \n"
"strd r4, [ip,#8*8] \n"
"strd r4, [ip,#9*8] \n"
"strd r4, [ip,#10*8] \n"
"strd r4, [ip,#11*8] \n"
"strd r4, [ip,#12*8] \n"
"strd r4, [ip,#13*8] \n"
"strd r4, [ip,#14*8] \n"
"strd r4, [ip,#15*8] \n"
"add ip, #16*8 \n"
// test write loop condition
"cmp ip, %[end] \n" // compare to end iterator
"blo 2b \n"
// test repeat loop condition
"subs %[repeats], %[repeats], #1 \n" // until repeats = 0
"bne 1b \n"
: [repeats] "+r" (repeats)
: [value] "r" (value), [memarea] "r" (memarea), [end] "r" (memarea+size)
: "ip", "r4", "r5", "cc", "memory");
}
REGISTER(ScanWrite64PtrUnrollLoop, 8, 8, 16);
// 64-bit reader in a simple loop (Assembler version)
void ScanRead64PtrSimpleLoop(char* memarea, size_t size, size_t repeats)
{
asm volatile(
"1: \n" // start of repeat loop
"mov ip, %[memarea] \n" // ip = reset loop iterator
"2: \n" // start of read loop
"ldrd r4, [ip], #8 \n" // retrieve and advance 8
// test read loop condition
"cmp ip, %[end] \n" // compare to end iterator
"blo 2b \n"
// test repeat loop condition
"subs %[repeats], %[repeats], #1 \n" // until repeats = 0
"bne 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size)
: "ip", "r4", "r5", "cc", "memory");
}
REGISTER(ScanRead64PtrSimpleLoop, 8, 8, 1);
// 64-bit reader in an unrolled loop (Assembler version)
void ScanRead64PtrUnrollLoop(char* memarea, size_t size, size_t repeats)
{
asm volatile(
"1: \n" // start of repeat loop
"mov ip, %[memarea] \n" // ip = reset loop iterator
"2: \n" // start of read loop
"ldrd r4, [ip,#0*8] \n"
"ldrd r4, [ip,#1*8] \n"
"ldrd r4, [ip,#2*8] \n"
"ldrd r4, [ip,#3*8] \n"
"ldrd r4, [ip,#4*8] \n"
"ldrd r4, [ip,#5*8] \n"
"ldrd r4, [ip,#6*8] \n"
"ldrd r4, [ip,#7*8] \n"
"ldrd r4, [ip,#8*8] \n"
"ldrd r4, [ip,#9*8] \n"
"ldrd r4, [ip,#10*8] \n"
"ldrd r4, [ip,#11*8] \n"
"ldrd r4, [ip,#12*8] \n"
"ldrd r4, [ip,#13*8] \n"
"ldrd r4, [ip,#14*8] \n"
"ldrd r4, [ip,#15*8] \n"
"add ip, #16*8 \n"
// test read loop condition
"cmp ip, %[end] \n" // compare to end iterator
"blo 2b \n"
// test repeat loop condition
"subs %[repeats], %[repeats], #1 \n" // until repeats = 0
"bne 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size)
: "ip", "r4", "r5", "cc", "memory");
}
REGISTER(ScanRead64PtrUnrollLoop, 8, 8, 16);
// ****************************************************************************
// ----------------------------------------------------------------------------
// Permutation Walking
// ----------------------------------------------------------------------------
// ****************************************************************************
// follow 32-bit permutation in a simple loop (C version)
void cPermRead32SimpleLoop(char* memarea, size_t, size_t repeats)
{
uint32_t* begin = (uint32_t*)memarea;
do {
uint32_t* p = begin;
do {
p = (uint32_t*)*p;
}
while (p != begin);
}
while (--repeats != 0);
}
//REGISTER_PERM(cPermRead32SimpleLoop, 4);
// follow 32-bit permutation in a simple loop (Assembler version)
void PermRead32SimpleLoop(char* memarea, size_t, size_t repeats)
{
asm volatile(
"1: \n" // start of repeat loop
"mov ip, %[memarea] \n" // ip = reset iterator
"2: \n" // start of loop
"ldr ip, [ip] \n"
// test loop condition
"cmp ip, %[memarea] \n" // compare to end iterator
"bne 2b \n"
// test repeat loop condition
"subs %[repeats], %[repeats], #1 \n" // until repeats = 0
"bne 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea)
: "ip", "cc", "memory");
}
REGISTER_PERM(PermRead32SimpleLoop, 4);
// follow 32-bit permutation in an unrolled loop (Assembler version)
void PermRead32UnrollLoop(char* memarea, size_t, size_t repeats)
{
asm volatile(
"1: \n" // start of repeat loop
"mov ip, %[memarea] \n" // ip = reset iterator
"2: \n" // start of loop
"ldr ip, [ip] \n"
"ldr ip, [ip] \n"
"ldr ip, [ip] \n"
"ldr ip, [ip] \n"
"ldr ip, [ip] \n"
"ldr ip, [ip] \n"
"ldr ip, [ip] \n"
"ldr ip, [ip] \n"
"ldr ip, [ip] \n"
"ldr ip, [ip] \n"
"ldr ip, [ip] \n"
"ldr ip, [ip] \n"
"ldr ip, [ip] \n"
"ldr ip, [ip] \n"
"ldr ip, [ip] \n"
"ldr ip, [ip] \n"
// test loop condition
"cmp ip, %[memarea] \n" // compare to end iterator
"bne 2b \n"
// test repeat loop condition
"subs %[repeats], %[repeats], #1 \n" // until repeats = 0
"bne 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea)
: "ip", "cc", "memory");
}
REGISTER_PERM(PermRead32UnrollLoop, 4);
// -----------------------------------------------------------------------------