-
Notifications
You must be signed in to change notification settings - Fork 27
/
funcs_x86_32.h
840 lines (753 loc) · 30.5 KB
/
funcs_x86_32.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
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
/******************************************************************************
* funcs_x86_32.h
*
* All Test Functions in 32-bit x86 assembly code: they are codenamed as
* Scan/Perm Read/Write 32/64 Ptr/Index Simple/Unroll 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
*
******************************************************************************
* 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)
{
asm volatile(
"mov $0xC0FFEEEE, %%eax \n" // rax = test value
"1: \n" // start of repeat loop
"mov %[memarea], %%ecx \n" // rcx = reset loop iterator
"2: \n" // start of write loop
"mov %%eax, (%%ecx) \n"
"add $4, %%ecx \n"
// test write loop condition
"cmp %[end], %%ecx \n" // compare to end iterator
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size)
: "eax", "ecx", "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)
{
asm volatile(
"mov $0xC0FFEEEE, %%eax \n" // rax = test value
"1: \n" // start of repeat loop
"mov %[memarea], %%ecx \n" // rcx = reset loop iterator
"2: \n" // start of write loop
"mov %%eax, 0*4(%%ecx) \n"
"mov %%eax, 1*4(%%ecx) \n"
"mov %%eax, 2*4(%%ecx) \n"
"mov %%eax, 3*4(%%ecx) \n"
"mov %%eax, 4*4(%%ecx) \n"
"mov %%eax, 5*4(%%ecx) \n"
"mov %%eax, 6*4(%%ecx) \n"
"mov %%eax, 7*4(%%ecx) \n"
"mov %%eax, 8*4(%%ecx) \n"
"mov %%eax, 9*4(%%ecx) \n"
"mov %%eax, 10*4(%%ecx) \n"
"mov %%eax, 11*4(%%ecx) \n"
"mov %%eax, 12*4(%%ecx) \n"
"mov %%eax, 13*4(%%ecx) \n"
"mov %%eax, 14*4(%%ecx) \n"
"mov %%eax, 15*4(%%ecx) \n"
"add $16*4, %%ecx \n"
// test write loop condition
"cmp %[end], %%ecx \n" // compare to end iterator
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size)
: "eax", "ecx", "cc", "memory");
}
REGISTER(ScanWrite32PtrUnrollLoop, 4, 4, 16);
// 32-bit reader 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 %[memarea], %%ecx \n" // rcx = reset loop iterator
"2: \n" // start of read loop
"mov (%%ecx), %%eax \n"
"add $4, %%ecx \n"
// test read loop condition
"cmp %[end], %%ecx \n" // compare to end iterator
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size)
: "eax", "ecx", "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 %[memarea], %%ecx \n" // rcx = reset loop iterator
"2: \n" // start of read loop
"mov 0*4(%%ecx), %%eax \n"
"mov 1*4(%%ecx), %%eax \n"
"mov 2*4(%%ecx), %%eax \n"
"mov 3*4(%%ecx), %%eax \n"
"mov 4*4(%%ecx), %%eax \n"
"mov 5*4(%%ecx), %%eax \n"
"mov 6*4(%%ecx), %%eax \n"
"mov 7*4(%%ecx), %%eax \n"
"mov 8*4(%%ecx), %%eax \n"
"mov 9*4(%%ecx), %%eax \n"
"mov 10*4(%%ecx), %%eax \n"
"mov 11*4(%%ecx), %%eax \n"
"mov 12*4(%%ecx), %%eax \n"
"mov 13*4(%%ecx), %%eax \n"
"mov 14*4(%%ecx), %%eax \n"
"mov 15*4(%%ecx), %%eax \n"
"add $16*4, %%ecx \n"
// test read loop condition
"cmp %[end], %%ecx \n" // compare to end iterator
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size)
: "eax", "ecx", "cc", "memory");
}
REGISTER(ScanRead32PtrUnrollLoop, 4, 4, 16);
// -----------------------------------------------------------------------------
// 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;
size_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)
{
asm volatile(
"mov $0xC0FFEEEE, %%eax \n" // rax = test value
"1: \n" // start of repeat loop
"xor %%ecx, %%ecx \n" // rcx = reset index
"2: \n" // start of write loop
"mov %%eax, (%[memarea],%%ecx) \n"
"add $4, %%ecx \n"
// test write loop condition
"cmp %[size], %%ecx \n" // compare to total size
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [size] "r" (size)
: "eax", "ecx", "cc", "memory");
}
REGISTER(ScanWrite32IndexSimpleLoop, 4, 4, 1);
// 32-bit writer in an indexed unrolled loop (Assembler version)
void ScanWrite32IndexUnrollLoop(char* memarea, size_t size, size_t repeats)
{
asm volatile(
"mov $0xC0FFEEEE, %%eax \n" // rax = test value
"1: \n" // start of repeat loop
"xor %%ecx, %%ecx \n" // rcx = reset index
"2: \n" // start of write loop
"mov %%eax, 0*4(%[memarea],%%ecx) \n"
"mov %%eax, 1*4(%[memarea],%%ecx) \n"
"mov %%eax, 2*4(%[memarea],%%ecx) \n"
"mov %%eax, 3*4(%[memarea],%%ecx) \n"
"mov %%eax, 4*4(%[memarea],%%ecx) \n"
"mov %%eax, 5*4(%[memarea],%%ecx) \n"
"mov %%eax, 6*4(%[memarea],%%ecx) \n"
"mov %%eax, 7*4(%[memarea],%%ecx) \n"
"mov %%eax, 8*4(%[memarea],%%ecx) \n"
"mov %%eax, 9*4(%[memarea],%%ecx) \n"
"mov %%eax, 10*4(%[memarea],%%ecx) \n"
"mov %%eax, 11*4(%[memarea],%%ecx) \n"
"mov %%eax, 12*4(%[memarea],%%ecx) \n"
"mov %%eax, 13*4(%[memarea],%%ecx) \n"
"mov %%eax, 14*4(%[memarea],%%ecx) \n"
"mov %%eax, 15*4(%[memarea],%%ecx) \n"
"add $16*4, %%ecx \n"
// test write loop condition
"cmp %[size], %%ecx \n" // compare to total size
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [size] "r" (size)
: "eax", "ecx", "cc", "memory");
}
REGISTER(ScanWrite32IndexUnrollLoop, 4, 4, 16);
// 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
"xor %%ecx, %%ecx \n" // rcx = reset index
"2: \n" // start of read loop
"mov (%[memarea],%%ecx), %%eax \n"
"add $4, %%ecx \n"
// test read loop condition
"cmp %[size], %%ecx \n" // compare to total size
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [size] "r" (size)
: "eax", "ecx", "cc", "memory");
}
REGISTER(ScanRead32IndexSimpleLoop, 4, 4, 1);
// 32-bit reader in an indexed unrolled loop (Assembler version)
void ScanRead32IndexUnrollLoop(char* memarea, size_t size, size_t repeats)
{
asm volatile(
"1: \n" // start of repeat loop
"xor %%ecx, %%ecx \n" // rcx = reset index
"2: \n" // start of read loop
"mov 0*4(%[memarea],%%ecx), %%eax \n"
"mov 1*4(%[memarea],%%ecx), %%eax \n"
"mov 2*4(%[memarea],%%ecx), %%eax \n"
"mov 3*4(%[memarea],%%ecx), %%eax \n"
"mov 4*4(%[memarea],%%ecx), %%eax \n"
"mov 5*4(%[memarea],%%ecx), %%eax \n"
"mov 6*4(%[memarea],%%ecx), %%eax \n"
"mov 7*4(%[memarea],%%ecx), %%eax \n"
"mov 8*4(%[memarea],%%ecx), %%eax \n"
"mov 9*4(%[memarea],%%ecx), %%eax \n"
"mov 10*4(%[memarea],%%ecx), %%eax \n"
"mov 11*4(%[memarea],%%ecx), %%eax \n"
"mov 12*4(%[memarea],%%ecx), %%eax \n"
"mov 13*4(%[memarea],%%ecx), %%eax \n"
"mov 14*4(%[memarea],%%ecx), %%eax \n"
"mov 15*4(%[memarea],%%ecx), %%eax \n"
"add $16*4, %%ecx \n"
// test read loop condition
"cmp %[size], %%ecx \n" // compare to total size
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [size] "r" (size)
: "eax", "ecx", "cc", "memory");
}
REGISTER(ScanRead32IndexUnrollLoop, 4, 4, 16);
// ****************************************************************************
// ----------------------------------------------------------------------------
// 64-bit Operations
// ----------------------------------------------------------------------------
// ****************************************************************************
// 64-bit writer in a simple loop (Assembler version)
void ScanWrite64PtrSimpleLoop(char* memarea, size_t size, size_t repeats)
{
char fxsave[512] __attribute__((aligned(16)));
asm volatile(
"fxsave %[fxsave] \n" // save FPU state
"mov $0xC0FFEEEE, %%eax \n"
"movd %%eax, %%mm0 \n"
"punpckldq %%mm0, %%mm0 \n"
"1: \n" // start of repeat loop
"mov %[memarea], %%eax \n" // rax = reset loop iterator
"2: \n" // start of write loop
"movq %%mm0, (%%eax) \n"
"add $8, %%eax \n"
// test write loop condition
"cmp %[end], %%eax \n" // compare to end iterator
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
"fxrstor %[fxsave] \n" // restore FPU state
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size),
[fxsave] "m" (*fxsave)
: "eax", "cc", "memory");
}
REGISTER_CPUFEAT(ScanWrite64PtrSimpleLoop, "mmx", 8, 8, 1);
// 64-bit writer in an unrolled loop (Assembler version)
void ScanWrite64PtrUnrollLoop(char* memarea, size_t size, size_t repeats)
{
char fxsave[512] __attribute__((aligned(16)));
asm volatile(
"fxsave %[fxsave] \n" // save FPU state
"mov $0xC0FFEEEE, %%eax \n"
"movd %%eax, %%mm0 \n"
"punpckldq %%mm0, %%mm0 \n"
"1: \n" // start of repeat loop
"mov %[memarea], %%eax \n" // rax = reset loop iterator
"2: \n" // start of write loop
"movq %%mm0, 0*16(%%eax) \n"
"movq %%mm0, 1*16(%%eax) \n"
"movq %%mm0, 2*16(%%eax) \n"
"movq %%mm0, 3*16(%%eax) \n"
"movq %%mm0, 4*16(%%eax) \n"
"movq %%mm0, 5*16(%%eax) \n"
"movq %%mm0, 6*16(%%eax) \n"
"movq %%mm0, 7*16(%%eax) \n"
"movq %%mm0, 8*16(%%eax) \n"
"movq %%mm0, 9*16(%%eax) \n"
"movq %%mm0, 10*16(%%eax) \n"
"movq %%mm0, 11*16(%%eax) \n"
"movq %%mm0, 12*16(%%eax) \n"
"movq %%mm0, 13*16(%%eax) \n"
"movq %%mm0, 14*16(%%eax) \n"
"movq %%mm0, 15*16(%%eax) \n"
"add $16*8, %%eax \n"
// test write loop condition
"cmp %[end], %%eax \n" // compare to end iterator
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
"fxrstor %[fxsave] \n" // restore FPU state
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size),
[fxsave] "m" (*fxsave)
: "eax", "cc", "memory");
}
REGISTER_CPUFEAT(ScanWrite64PtrUnrollLoop, "mmx", 8, 8, 16);
// 64-bit reader in a simple loop (Assembler version)
void ScanRead64PtrSimpleLoop(char* memarea, size_t size, size_t repeats)
{
char fxsave[512] __attribute__((aligned(16)));
asm volatile(
"fxsave %[fxsave] \n" // save FPU state
"1: \n" // start of repeat loop
"mov %[memarea], %%eax \n" // rax = reset loop iterator
"2: \n" // start of read loop
"movq (%%eax), %%mm0 \n"
"add $8, %%eax \n"
// test read loop condition
"cmp %[end], %%eax \n" // compare to end iterator
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
"fxrstor %[fxsave] \n" // restore FPU state
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size),
[fxsave] "m" (*fxsave)
: "eax", "cc", "memory");
}
REGISTER_CPUFEAT(ScanRead64PtrSimpleLoop, "mmx", 8, 8, 1);
// 64-bit reader in an unrolled loop (Assembler version)
void ScanRead64PtrUnrollLoop(char* memarea, size_t size, size_t repeats)
{
char fxsave[512] __attribute__((aligned(16)));
asm volatile(
"fxsave %[fxsave] \n" // save FPU state
"1: \n" // start of repeat loop
"mov %[memarea], %%eax \n" // rax = reset loop iterator
"2: \n" // start of read loop
"movq 0*8(%%eax), %%mm0 \n"
"movq 1*8(%%eax), %%mm0 \n"
"movq 2*8(%%eax), %%mm0 \n"
"movq 3*8(%%eax), %%mm0 \n"
"movq 4*8(%%eax), %%mm0 \n"
"movq 5*8(%%eax), %%mm0 \n"
"movq 6*8(%%eax), %%mm0 \n"
"movq 7*8(%%eax), %%mm0 \n"
"movq 8*8(%%eax), %%mm0 \n"
"movq 9*8(%%eax), %%mm0 \n"
"movq 10*8(%%eax), %%mm0 \n"
"movq 11*8(%%eax), %%mm0 \n"
"movq 12*8(%%eax), %%mm0 \n"
"movq 13*8(%%eax), %%mm0 \n"
"movq 14*8(%%eax), %%mm0 \n"
"movq 15*8(%%eax), %%mm0 \n"
"add $16*8, %%eax \n"
// test read loop condition
"cmp %[end], %%eax \n" // compare to end iterator
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
"fxrstor %[fxsave] \n" // restore FPU state
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size),
[fxsave] "m" (*fxsave)
: "eax", "cc", "memory");
}
REGISTER_CPUFEAT(ScanRead64PtrUnrollLoop, "mmx", 8, 8, 16);
// ****************************************************************************
// ----------------------------------------------------------------------------
// 128-bit Operations
// ----------------------------------------------------------------------------
// ****************************************************************************
// 128-bit writer in a simple loop (Assembler version)
void ScanWrite128PtrSimpleLoop(char* memarea, size_t size, size_t repeats)
{
char fxsave[512] __attribute__((aligned(16)));
asm volatile(
"fxsave %[fxsave] \n" // save FPU state
"mov $0xC0FFEEEE, %%eax \n"
"movd %%eax, %%xmm0 \n"
"punpckldq %%xmm0, %%xmm0 \n"
"movlhps %%xmm0, %%xmm0 \n" // xmm0 = test value
"1: \n" // start of repeat loop
"mov %[memarea], %%eax \n" // rax = reset loop iterator
"2: \n" // start of write loop
"movdqa %%xmm0, (%%eax) \n"
"add $16, %%eax \n"
// test write loop condition
"cmp %[end], %%eax \n" // compare to end iterator
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
"fxrstor %[fxsave] \n" // restore FPU state
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size),
[fxsave] "m" (*fxsave)
: "eax", "cc", "memory");
}
REGISTER_CPUFEAT(ScanWrite128PtrSimpleLoop, "sse", 16, 16, 1);
// 128-bit writer in an unrolled loop (Assembler version)
void ScanWrite128PtrUnrollLoop(char* memarea, size_t size, size_t repeats)
{
char fxsave[512] __attribute__((aligned(16)));
asm volatile(
"fxsave %[fxsave] \n" // save FPU state
"mov $0xC0FFEEEE, %%eax \n"
"movd %%eax, %%xmm0 \n"
"punpckldq %%xmm0, %%xmm0 \n"
"movlhps %%xmm0, %%xmm0 \n" // xmm0 = test value
"1: \n" // start of repeat loop
"mov %[memarea], %%eax \n" // rax = reset loop iterator
"2: \n" // start of write loop
"movdqa %%xmm0, 0*16(%%eax) \n"
"movdqa %%xmm0, 1*16(%%eax) \n"
"movdqa %%xmm0, 2*16(%%eax) \n"
"movdqa %%xmm0, 3*16(%%eax) \n"
"movdqa %%xmm0, 4*16(%%eax) \n"
"movdqa %%xmm0, 5*16(%%eax) \n"
"movdqa %%xmm0, 6*16(%%eax) \n"
"movdqa %%xmm0, 7*16(%%eax) \n"
"movdqa %%xmm0, 8*16(%%eax) \n"
"movdqa %%xmm0, 9*16(%%eax) \n"
"movdqa %%xmm0, 10*16(%%eax) \n"
"movdqa %%xmm0, 11*16(%%eax) \n"
"movdqa %%xmm0, 12*16(%%eax) \n"
"movdqa %%xmm0, 13*16(%%eax) \n"
"movdqa %%xmm0, 14*16(%%eax) \n"
"movdqa %%xmm0, 15*16(%%eax) \n"
"add $16*16, %%eax \n"
// test write loop condition
"cmp %[end], %%eax \n" // compare to end iterator
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
"fxrstor %[fxsave] \n" // restore FPU state
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size),
[fxsave] "m" (*fxsave)
: "eax", "cc", "memory");
}
REGISTER_CPUFEAT(ScanWrite128PtrUnrollLoop, "sse", 16, 16, 16);
// 128-bit reader in a simple loop (Assembler version)
void ScanRead128PtrSimpleLoop(char* memarea, size_t size, size_t repeats)
{
char fxsave[512] __attribute__((aligned(16)));
asm volatile(
"fxsave %[fxsave] \n" // save FPU state
"1: \n" // start of repeat loop
"mov %[memarea], %%eax \n" // rax = reset loop iterator
"2: \n" // start of read loop
"movdqa (%%eax), %%xmm0 \n"
"add $16, %%eax \n"
// test read loop condition
"cmp %[end], %%eax \n" // compare to end iterator
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
"fxrstor %[fxsave] \n" // restore FPU state
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size),
[fxsave] "m" (*fxsave)
: "eax", "cc", "memory");
}
REGISTER_CPUFEAT(ScanRead128PtrSimpleLoop, "sse", 16, 16, 1);
// 128-bit reader in an unrolled loop (Assembler version)
void ScanRead128PtrUnrollLoop(char* memarea, size_t size, size_t repeats)
{
char fxsave[512] __attribute__((aligned(16)));
asm volatile(
"fxsave %[fxsave] \n" // save FPU state
"1: \n" // start of repeat loop
"mov %[memarea], %%eax \n" // rax = reset loop iterator
"2: \n" // start of read loop
"movdqa 0*16(%%eax), %%xmm0 \n"
"movdqa 1*16(%%eax), %%xmm0 \n"
"movdqa 2*16(%%eax), %%xmm0 \n"
"movdqa 3*16(%%eax), %%xmm0 \n"
"movdqa 4*16(%%eax), %%xmm0 \n"
"movdqa 5*16(%%eax), %%xmm0 \n"
"movdqa 6*16(%%eax), %%xmm0 \n"
"movdqa 7*16(%%eax), %%xmm0 \n"
"movdqa 8*16(%%eax), %%xmm0 \n"
"movdqa 9*16(%%eax), %%xmm0 \n"
"movdqa 10*16(%%eax), %%xmm0 \n"
"movdqa 11*16(%%eax), %%xmm0 \n"
"movdqa 12*16(%%eax), %%xmm0 \n"
"movdqa 13*16(%%eax), %%xmm0 \n"
"movdqa 14*16(%%eax), %%xmm0 \n"
"movdqa 15*16(%%eax), %%xmm0 \n"
"add $16*16, %%eax \n"
// test read loop condition
"cmp %[end], %%eax \n" // compare to end iterator
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
"fxrstor %[fxsave] \n" // restore FPU state
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size),
[fxsave] "m" (*fxsave)
: "eax", "cc", "memory");
}
REGISTER_CPUFEAT(ScanRead128PtrUnrollLoop, "sse", 16, 16, 16);
// ****************************************************************************
// ----------------------------------------------------------------------------
// 16-bit Operations
// ----------------------------------------------------------------------------
// ****************************************************************************
// 16-bit writer in a simple loop (Assembler version)
void ScanWrite16PtrSimpleLoop(char* memarea, size_t size, size_t repeats)
{
asm volatile(
"mov $0xCFFE, %%ax \n" // ax = test value
"1: \n" // start of repeat loop
"mov %[memarea], %%ecx \n" // rcx = reset loop iterator
"2: \n" // start of write loop
"mov %%ax, (%%ecx) \n"
"add $2, %%ecx \n"
// test write loop condition
"cmp %[end], %%ecx \n" // compare to end iterator
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size)
: "eax", "ecx", "cc", "memory");
}
REGISTER(ScanWrite16PtrSimpleLoop, 2, 2, 1);
// 16-bit writer in an unrolled loop (Assembler version)
void ScanWrite16PtrUnrollLoop(char* memarea, size_t size, size_t repeats)
{
asm volatile(
"mov $0xC0FFEEEE, %%eax \n" // eax = test value
"1: \n" // start of repeat loop
"mov %[memarea], %%ecx \n" // rcx = reset loop iterator
"2: \n" // start of write loop
"mov %%ax, 0*2(%%ecx) \n"
"mov %%ax, 1*2(%%ecx) \n"
"mov %%ax, 2*2(%%ecx) \n"
"mov %%ax, 3*2(%%ecx) \n"
"mov %%ax, 4*2(%%ecx) \n"
"mov %%ax, 5*2(%%ecx) \n"
"mov %%ax, 6*2(%%ecx) \n"
"mov %%ax, 7*2(%%ecx) \n"
"mov %%ax, 8*2(%%ecx) \n"
"mov %%ax, 9*2(%%ecx) \n"
"mov %%ax, 10*2(%%ecx) \n"
"mov %%ax, 11*2(%%ecx) \n"
"mov %%ax, 12*2(%%ecx) \n"
"mov %%ax, 13*2(%%ecx) \n"
"mov %%ax, 14*2(%%ecx) \n"
"mov %%ax, 15*2(%%ecx) \n"
"add $16*2, %%ecx \n"
// test write loop condition
"cmp %[end], %%ecx \n" // compare to end iterator
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size)
: "eax", "ecx", "cc", "memory");
}
REGISTER(ScanWrite16PtrUnrollLoop, 2, 2, 16);
// 16-bit reader in a simple loop (Assembler version)
void ScanRead16PtrSimpleLoop(char* memarea, size_t size, size_t repeats)
{
asm volatile(
"1: \n" // start of repeat loop
"mov %[memarea], %%ecx \n" // rcx = reset loop iterator
"2: \n" // start of read loop
"mov (%%ecx), %%eax \n"
"add $2, %%ecx \n"
// test read loop condition
"cmp %[end], %%ecx \n" // compare to end iterator
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size)
: "eax", "ecx", "cc", "memory");
}
REGISTER(ScanRead16PtrSimpleLoop, 2, 2, 1);
// 16-bit reader in an unrolled loop (Assembler version)
void ScanRead16PtrUnrollLoop(char* memarea, size_t size, size_t repeats)
{
asm volatile(
"1: \n" // start of repeat loop
"mov %[memarea], %%ecx \n" // rcx = reset loop iterator
"2: \n" // start of read loop
"mov 0*2(%%ecx), %%eax \n"
"mov 1*2(%%ecx), %%eax \n"
"mov 2*2(%%ecx), %%eax \n"
"mov 3*2(%%ecx), %%eax \n"
"mov 4*2(%%ecx), %%eax \n"
"mov 5*2(%%ecx), %%eax \n"
"mov 6*2(%%ecx), %%eax \n"
"mov 7*2(%%ecx), %%eax \n"
"mov 8*2(%%ecx), %%eax \n"
"mov 9*2(%%ecx), %%eax \n"
"mov 10*2(%%ecx), %%eax \n"
"mov 11*2(%%ecx), %%eax \n"
"mov 12*2(%%ecx), %%eax \n"
"mov 13*2(%%ecx), %%eax \n"
"mov 14*2(%%ecx), %%eax \n"
"mov 15*2(%%ecx), %%eax \n"
"add $16*2, %%ecx \n"
// test read loop condition
"cmp %[end], %%ecx \n" // compare to end iterator
"jb 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea), [end] "r" (memarea+size)
: "eax", "ecx", "cc", "memory");
}
REGISTER(ScanRead16PtrUnrollLoop, 2, 2, 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 %[memarea], %%eax \n" // rax = reset iterator
"2: \n" // start of read loop
"mov (%%eax), %%eax \n"
// test read loop condition
"cmp %%eax, %[memarea] \n" // compare to first iterator
"jne 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea)
: "eax", "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 %[memarea], %%eax \n" // rax = reset iterator
"2: \n" // start of read loop
"mov (%%eax), %%eax \n"
"mov (%%eax), %%eax \n"
"mov (%%eax), %%eax \n"
"mov (%%eax), %%eax \n"
"mov (%%eax), %%eax \n"
"mov (%%eax), %%eax \n"
"mov (%%eax), %%eax \n"
"mov (%%eax), %%eax \n"
"mov (%%eax), %%eax \n"
"mov (%%eax), %%eax \n"
"mov (%%eax), %%eax \n"
"mov (%%eax), %%eax \n"
"mov (%%eax), %%eax \n"
"mov (%%eax), %%eax \n"
"mov (%%eax), %%eax \n"
"mov (%%eax), %%eax \n"
// test read loop condition
"cmp %%eax, %[memarea] \n" // compare to first iterator
"jne 2b \n"
// test repeat loop condition
"dec %[repeats] \n" // until repeats = 0
"jnz 1b \n"
: [repeats] "+r" (repeats)
: [memarea] "r" (memarea)
: "eax", "cc", "memory");
}
REGISTER_PERM(PermRead32UnrollLoop, 4);
// -----------------------------------------------------------------------------