forked from dhewm/dhewm3-sdk
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Simd_SSE.cpp
18089 lines (16082 loc) · 463 KB
/
Simd_SSE.cpp
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
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
Doom 3 Source Code 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.
Doom 3 Source Code 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 Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "sys/platform.h"
#include "idlib/geometry/DrawVert.h"
#include "idlib/math/Simd_SSE.h"
//===============================================================
// M
// SSE implementation of idSIMDProcessor MrE
// E
//===============================================================
#define DRAWVERT_SIZE 60
#define DRAWVERT_XYZ_OFFSET (0*4)
#define DRAWVERT_ST_OFFSET (3*4)
#define DRAWVERT_NORMAL_OFFSET (5*4)
#define DRAWVERT_TANGENT0_OFFSET (8*4)
#define DRAWVERT_TANGENT1_OFFSET (11*4)
#define DRAWVERT_COLOR_OFFSET (14*4)
#if defined(__GNUC__) && defined(__SSE__)
#include <xmmintrin.h>
#define SHUFFLEPS( x, y, z, w ) (( (x) & 3 ) << 6 | ( (y) & 3 ) << 4 | ( (z) & 3 ) << 2 | ( (w) & 3 ))
#define R_SHUFFLEPS( x, y, z, w ) (( (w) & 3 ) << 6 | ( (z) & 3 ) << 4 | ( (y) & 3 ) << 2 | ( (x) & 3 ))
/*
============
idSIMD_SSE::GetName
============
*/
const char * idSIMD_SSE::GetName( void ) const {
return "MMX & SSE";
}
/*
============
idSIMD_SSE::Dot
dst[i] = constant.Normal() * src[i].xyz + constant[3];
============
*/
void VPCALL idSIMD_SSE::Dot( float *dst, const idPlane &constant, const idDrawVert *src, const int count ) {
// 0, 1, 2
// 3, 4, 5
// 6, 7, 8
// 9, 10, 11
/*
mov eax, count
mov edi, constant
mov edx, eax
mov esi, src
mov ecx, dst
*/
__m128 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7; // Declare 8 xmm registers.
int count_l4 = count; // count_l4 = eax
int count_l1 = count; // count_l1 = edx
char *constant_p = (char *)&constant; // constant_p = edi
char *src_p = (char *) src; // src_p = esi
char *dst_p = (char *) dst; // dst_p = ecx
assert( sizeof( idDrawVert ) == DRAWVERT_SIZE );
assert( ptrdiff_t(&src->xyz) - ptrdiff_t(src) == DRAWVERT_XYZ_OFFSET );
/*
and eax, ~3
movss xmm4, [edi+0]
shufps xmm4, xmm4, R_SHUFFLEPS( 0, 0, 0, 0 )
movss xmm5, [edi+4]
shufps xmm5, xmm5, R_SHUFFLEPS( 0, 0, 0, 0 )
movss xmm6, [edi+8]
shufps xmm6, xmm6, R_SHUFFLEPS( 0, 0, 0, 0 )
movss xmm7, [edi+12]
shufps xmm7, xmm7, R_SHUFFLEPS( 0, 0, 0, 0 )
*/
count_l4 = count_l4 & ~3;
xmm4 = _mm_load_ss((float *) (constant_p));
xmm4 = _mm_shuffle_ps(xmm4, xmm4, R_SHUFFLEPS( 0, 0, 0, 0 ));
xmm5 = _mm_load_ss((float *) (constant_p + 4));
xmm5 = _mm_shuffle_ps(xmm5, xmm5, R_SHUFFLEPS( 0, 0, 0, 0 ));
xmm6 = _mm_load_ss((float *) (constant_p + 8));
xmm6 = _mm_shuffle_ps(xmm6, xmm6, R_SHUFFLEPS( 0, 0, 0, 0 ));
xmm7 = _mm_load_ss((float *) (constant_p + 12));
xmm7 = _mm_shuffle_ps(xmm7, xmm7, R_SHUFFLEPS( 0, 0, 0, 0 ));
/*
jz startVert1
*/
if(count_l4 != 0) {
/*
imul eax, DRAWVERT_SIZE
add esi, eax
neg eax
*/
count_l4 = count_l4 * DRAWVERT_SIZE;
src_p = src_p + count_l4;
count_l4 = -count_l4;
/*
loopVert4:
*/
do {
/*
movss xmm0, [esi+eax+1*DRAWVERT_SIZE+DRAWVERT_XYZ_OFFSET+0] // 3, X, X, X
movss xmm2, [esi+eax+0*DRAWVERT_SIZE+DRAWVERT_XYZ_OFFSET+8] // 2, X, X, X
movhps xmm0, [esi+eax+0*DRAWVERT_SIZE+DRAWVERT_XYZ_OFFSET+0] // 3, X, 0, 1
movaps xmm1, xmm0 // 3, X, 0, 1
*/
xmm0 = _mm_load_ss((float *) (src_p+count_l4+1*DRAWVERT_SIZE+DRAWVERT_XYZ_OFFSET+0)); // 3, X, X, X
xmm2 = _mm_load_ss((float *) (src_p+count_l4+0*DRAWVERT_SIZE+DRAWVERT_XYZ_OFFSET+8)); // 2, X, X, X
xmm0 = _mm_loadh_pi(xmm0, (__m64 *) (src_p+count_l4+0*DRAWVERT_SIZE+DRAWVERT_XYZ_OFFSET+0)); // 3, X, 0, 1
xmm1 = xmm0; // 3, X, 0, 1
/*
movlps xmm1, [esi+eax+1*DRAWVERT_SIZE+DRAWVERT_XYZ_OFFSET+4] // 4, 5, 0, 1
shufps xmm2, xmm1, R_SHUFFLEPS( 0, 1, 0, 1 ) // 2, X, 4, 5
*/
xmm1 = _mm_loadl_pi(xmm1, (__m64 *) (src_p+count_l4+1*DRAWVERT_SIZE+DRAWVERT_XYZ_OFFSET+4)); // 4, 5, 0, 1
xmm2 = _mm_shuffle_ps(xmm2, xmm1, R_SHUFFLEPS( 0, 1, 0, 1 )); // 2, X, 4, 5
/*
movss xmm3, [esi+eax+3*DRAWVERT_SIZE+DRAWVERT_XYZ_OFFSET+0] // 9, X, X, X
movhps xmm3, [esi+eax+2*DRAWVERT_SIZE+DRAWVERT_XYZ_OFFSET+0] // 9, X, 6, 7
shufps xmm0, xmm3, R_SHUFFLEPS( 2, 0, 2, 0 ) // 0, 3, 6, 9
*/
xmm3 = _mm_load_ss((float *) (src_p+count_l4+3*DRAWVERT_SIZE+DRAWVERT_XYZ_OFFSET+0)); // 9, X, X, X
xmm3 = _mm_loadh_pi(xmm3, (__m64 *) (src_p+count_l4+2*DRAWVERT_SIZE+DRAWVERT_XYZ_OFFSET+0)); // 9, X, 6, 7
xmm0 = _mm_shuffle_ps(xmm0, xmm3, R_SHUFFLEPS( 2, 0, 2, 0 )); // 0, 3, 6, 9
/*
movlps xmm3, [esi+eax+3*DRAWVERT_SIZE+DRAWVERT_XYZ_OFFSET+4] // 10, 11, 6, 7
shufps xmm1, xmm3, R_SHUFFLEPS( 3, 0, 3, 0 ) // 1, 4, 7, 10
*/
xmm3 = _mm_loadl_pi(xmm3, (__m64 *)(src_p+count_l4+3*DRAWVERT_SIZE+DRAWVERT_XYZ_OFFSET+4)); // 10, 11, 6, 7
xmm1 = _mm_shuffle_ps(xmm1, xmm3, R_SHUFFLEPS( 3, 0, 3, 0 )); // 1, 4, 7, 10
/*
movhps xmm3, [esi+eax+2*DRAWVERT_SIZE+DRAWVERT_XYZ_OFFSET+8] // 10, 11, 8, X
shufps xmm2, xmm3, R_SHUFFLEPS( 0, 3, 2, 1 ) // 2, 5, 8, 11
*/
xmm3 = _mm_loadh_pi(xmm3, (__m64 *)(src_p+count_l4+2*DRAWVERT_SIZE+DRAWVERT_XYZ_OFFSET+8)); // 10, 11, 8, X
xmm2 = _mm_shuffle_ps(xmm2, xmm3, R_SHUFFLEPS( 0, 3, 2, 1 )); // 2, 5, 8, 11
/*
add ecx, 16
add eax, 4*DRAWVERT_SIZE
*/
dst_p = dst_p + 16;
count_l4 = count_l4 + 4*DRAWVERT_SIZE;
/*
mulps xmm0, xmm4
mulps xmm1, xmm5
mulps xmm2, xmm6
addps xmm0, xmm7
addps xmm0, xmm1
addps xmm0, xmm2
*/
xmm0 = _mm_mul_ps(xmm0, xmm4);
xmm1 = _mm_mul_ps(xmm1, xmm5);
xmm2 = _mm_mul_ps(xmm2, xmm6);
xmm0 = _mm_add_ps(xmm0, xmm7);
xmm0 = _mm_add_ps(xmm0, xmm1);
xmm0 = _mm_add_ps(xmm0, xmm2);
/*
movlps [ecx-16+0], xmm0
movhps [ecx-16+8], xmm0
jl loopVert4
*/
_mm_storel_pi((__m64 *) (dst_p-16+0), xmm0);
_mm_storeh_pi((__m64 *) (dst_p-16+8), xmm0);
} while(count_l4 < 0);
}
/*
startVert1:
and edx, 3
jz done
*/
count_l1 = count_l1 & 3;
if(count_l1 != 0) {
/*
loopVert1:
movss xmm0, [esi+eax+DRAWVERT_XYZ_OFFSET+0]
movss xmm1, [esi+eax+DRAWVERT_XYZ_OFFSET+4]
movss xmm2, [esi+eax+DRAWVERT_XYZ_OFFSET+8]
mulss xmm0, xmm4
mulss xmm1, xmm5
mulss xmm2, xmm6
addss xmm0, xmm7
add ecx, 4
addss xmm0, xmm1
add eax, DRAWVERT_SIZE
addss xmm0, xmm2
dec edx
movss [ecx-4], xmm0
jnz loopVert1
*/
do {
xmm0 = _mm_load_ss((float *) (src_p+count_l4+DRAWVERT_XYZ_OFFSET+0));
xmm1 = _mm_load_ss((float *) (src_p+count_l4+DRAWVERT_XYZ_OFFSET+4));
xmm2 = _mm_load_ss((float *) (src_p+count_l4+DRAWVERT_XYZ_OFFSET+8));
xmm0 = _mm_mul_ss(xmm0, xmm4);
xmm1 = _mm_mul_ss(xmm1, xmm5);
xmm2 = _mm_mul_ss(xmm2, xmm6);
xmm0 = _mm_add_ss(xmm0, xmm7);
dst_p = dst_p + 4;
xmm0 = _mm_add_ss(xmm0, xmm1);
count_l4 = count_l4 + DRAWVERT_SIZE;
xmm0 = _mm_add_ss(xmm0, xmm2);
count_l1 = count_l1 - 1;
_mm_store_ss((float *) (dst_p-4), xmm0);
} while( count_l1 != 0);
}
/*
done:
*/
}
/*
============
idSIMD_SSE::MinMax
============
*/
void VPCALL idSIMD_SSE::MinMax( idVec3 &min, idVec3 &max, const idDrawVert *src, const int *indexes, const int count ) {
assert( sizeof( idDrawVert ) == DRAWVERT_SIZE );
assert( ptrdiff_t(&src->xyz) - ptrdiff_t(src) == DRAWVERT_XYZ_OFFSET );
__m128 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7;
char *indexes_p;
char *src_p;
int count_l;
int edx;
char *min_p;
char *max_p;
/*
movss xmm0, idMath::INFINITY
xorps xmm1, xmm1
shufps xmm0, xmm0, R_SHUFFLEPS( 0, 0, 0, 0 )
subps xmm1, xmm0
movaps xmm2, xmm0
movaps xmm3, xmm1
*/
xmm0 = _mm_load_ss(&idMath::INFINITY);
// To satisfy the compiler use xmm0 instead.
xmm1 = _mm_xor_ps(xmm0, xmm0);
xmm0 = _mm_shuffle_ps(xmm0, xmm0, R_SHUFFLEPS( 0, 0, 0, 0 ));
xmm1 = _mm_sub_ps(xmm1, xmm0);
xmm2 = xmm0;
xmm3 = xmm1;
/*
mov edi, indexes
mov esi, src
mov eax, count
and eax, ~3
jz done4
*/
indexes_p = (char *) indexes;
src_p = (char *) src;
count_l = count;
count_l = count_l & ~3;
if(count_l != 0) {
/*
shl eax, 2
add edi, eax
neg eax
*/
count_l = count_l << 2;
indexes_p = indexes_p + count_l;
count_l = -count_l;
/*
loop4:
// prefetchnta [edi+128]
// prefetchnta [esi+4*DRAWVERT_SIZE+DRAWVERT_XYZ_OFFSET]
*/
do {
/*
mov edx, [edi+eax+0]
imul edx, DRAWVERT_SIZE
movss xmm4, [esi+edx+DRAWVERT_XYZ_OFFSET+8]
movhps xmm4, [esi+edx+DRAWVERT_XYZ_OFFSET+0]
minps xmm0, xmm4
maxps xmm1, xmm4
*/
edx = *((int*)(indexes_p+count_l+0));
edx = edx * DRAWVERT_SIZE;
xmm4 = _mm_load_ss((float *) (src_p+edx+DRAWVERT_XYZ_OFFSET+8));
xmm4 = _mm_loadh_pi(xmm4, (__m64 *) (src_p+edx+DRAWVERT_XYZ_OFFSET+0) );
xmm0 = _mm_min_ps(xmm0, xmm4);
xmm1 = _mm_max_ps(xmm1, xmm4);
/*
mov edx, [edi+eax+4]
imul edx, DRAWVERT_SIZE
movss xmm5, [esi+edx+DRAWVERT_XYZ_OFFSET+0]
movhps xmm5, [esi+edx+DRAWVERT_XYZ_OFFSET+4]
minps xmm2, xmm5
maxps xmm3, xmm5
*/
edx = *((int*)(indexes_p+count_l+4));
edx = edx * DRAWVERT_SIZE;
xmm5 = _mm_load_ss((float *) (src_p+edx+DRAWVERT_XYZ_OFFSET+0));
xmm5 = _mm_loadh_pi(xmm5, (__m64 *) (src_p+edx+DRAWVERT_XYZ_OFFSET+4) );
xmm2 = _mm_min_ps(xmm2, xmm5);
xmm3 = _mm_max_ps(xmm3, xmm5);
/*
mov edx, [edi+eax+8]
imul edx, DRAWVERT_SIZE
movss xmm6, [esi+edx+DRAWVERT_XYZ_OFFSET+8]
movhps xmm6, [esi+edx+DRAWVERT_XYZ_OFFSET+0]
minps xmm0, xmm6
maxps xmm1, xmm6
*/
edx = *((int*)(indexes_p+count_l+8));
edx = edx * DRAWVERT_SIZE;
xmm6 = _mm_load_ss((float *) (src_p+edx+DRAWVERT_XYZ_OFFSET+8));
xmm6 = _mm_loadh_pi(xmm6, (__m64 *) (src_p+edx+DRAWVERT_XYZ_OFFSET+0) );
xmm0 = _mm_min_ps(xmm0, xmm6);
xmm1 = _mm_max_ps(xmm1, xmm6);
/*
mov edx, [edi+eax+12]
imul edx, DRAWVERT_SIZE
movss xmm7, [esi+edx+DRAWVERT_XYZ_OFFSET+0]
movhps xmm7, [esi+edx+DRAWVERT_XYZ_OFFSET+4]
minps xmm2, xmm7
maxps xmm3, xmm7
*/
edx = *((int*)(indexes_p+count_l+12));
edx = edx * DRAWVERT_SIZE;
xmm7 = _mm_load_ss((float *) (src_p+edx+DRAWVERT_XYZ_OFFSET+0));
xmm7 = _mm_loadh_pi(xmm7, (__m64 *) (src_p+edx+DRAWVERT_XYZ_OFFSET+4) );
xmm2 = _mm_min_ps(xmm2, xmm7);
xmm3 = _mm_max_ps(xmm3, xmm7);
/*
add eax, 4*4
jl loop4
*/
count_l = count_l + 4*4;
} while (count_l < 0);
}
/*
done4:
mov eax, count
and eax, 3
jz done1
*/
count_l = count;
count_l = count_l & 3;
if(count_l != 0) {
/*
shl eax, 2
add edi, eax
neg eax
*/
count_l = count_l << 2;
indexes_p = indexes_p + count_l;
count_l = -count_l;
/*
loop1:
*/
do{
/*
mov edx, [edi+eax+0]
imul edx, DRAWVERT_SIZE;
movss xmm4, [esi+edx+DRAWVERT_XYZ_OFFSET+8]
movhps xmm4, [esi+edx+DRAWVERT_XYZ_OFFSET+0]
minps xmm0, xmm4
maxps xmm1, xmm4
*/
edx = *((int*)(indexes_p+count_l+0));
edx = edx * DRAWVERT_SIZE;
xmm4 = _mm_load_ss((float *) (src_p+edx+DRAWVERT_XYZ_OFFSET+8));
xmm4 = _mm_loadh_pi(xmm4, (__m64 *) (src_p+edx+DRAWVERT_XYZ_OFFSET+0) );
xmm0 = _mm_min_ps(xmm0, xmm4);
xmm1 = _mm_max_ps(xmm1, xmm4);
/*
add eax, 4
jl loop1
*/
count_l = count_l + 4;
} while (count_l < 0);
}
/*
done1:
shufps xmm2, xmm2, R_SHUFFLEPS( 3, 1, 0, 2 )
shufps xmm3, xmm3, R_SHUFFLEPS( 3, 1, 0, 2 )
minps xmm0, xmm2
maxps xmm1, xmm3
mov esi, min
movhps [esi], xmm0
movss [esi+8], xmm0
mov edi, max
movhps [edi], xmm1
movss [edi+8], xmm1
*/
xmm2 = _mm_shuffle_ps(xmm2, xmm2, R_SHUFFLEPS( 3, 1, 0, 2 ));
xmm3 = _mm_shuffle_ps(xmm3, xmm3, R_SHUFFLEPS( 3, 1, 0, 2 ));
xmm0 = _mm_min_ps(xmm0, xmm2);
xmm1 = _mm_max_ps(xmm1, xmm3);
min_p = (char *) &min;
_mm_storeh_pi((__m64 *)(min_p), xmm0);
_mm_store_ss((float *)(min_p+8), xmm0);
max_p = (char *) &max;
_mm_storeh_pi((__m64 *)(max_p), xmm1);
_mm_store_ss((float *)(max_p+8), xmm1);
}
/*
============
idSIMD_SSE::Dot
dst[i] = constant * src[i].Normal() + src[i][3];
============
*/
void VPCALL idSIMD_SSE::Dot( float *dst, const idVec3 &constant, const idPlane *src, const int count ) {
int count_l4;
int count_l1;
char *constant_p;
char *src_p;
char *dst_p;
__m128 xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7;
/*
mov eax, count
mov edi, constant
mov edx, eax
mov esi, src
mov ecx, dst
and eax, ~3
*/
count_l4 = count;
constant_p = (char *) &constant;
count_l1 = count_l4;
src_p = (char *) src;
dst_p = (char *) dst;
count_l4 = count_l4 & ~3;
/*
movss xmm5, [edi+0]
shufps xmm5, xmm5, R_SHUFFLEPS( 0, 0, 0, 0 )
movss xmm6, [edi+4]
shufps xmm6, xmm6, R_SHUFFLEPS( 0, 0, 0, 0 )
movss xmm7, [edi+8]
shufps xmm7, xmm7, R_SHUFFLEPS( 0, 0, 0, 0 )
*/
xmm5 = _mm_load_ss((float *) (constant_p+0));
xmm5 = _mm_shuffle_ps(xmm5, xmm5, R_SHUFFLEPS( 0, 0, 0, 0 ));
xmm6 = _mm_load_ss((float *) (constant_p+4));
xmm6 = _mm_shuffle_ps(xmm6, xmm6, R_SHUFFLEPS( 0, 0, 0, 0 ));
xmm7 = _mm_load_ss((float *) (constant_p+8));
xmm7 = _mm_shuffle_ps(xmm7, xmm7, R_SHUFFLEPS( 0, 0, 0, 0 ));
/*
jz startVert1
*/
if (count_l4 != 0) {
/*
imul eax, 16
add esi, eax
neg eax
*/
count_l4 = count_l4 * 16;
src_p = src_p + count_l4;
count_l4 = -count_l4;
/*
loopVert4:
*/
do {
/*
movlps xmm1, [esi+eax+ 0]
movlps xmm3, [esi+eax+ 8]
movhps xmm1, [esi+eax+16]
movhps xmm3, [esi+eax+24]
movlps xmm2, [esi+eax+32]
movlps xmm4, [esi+eax+40]
movhps xmm2, [esi+eax+48]
movhps xmm4, [esi+eax+56]
movaps xmm0, xmm1
shufps xmm0, xmm2, R_SHUFFLEPS( 0, 2, 0, 2 )
shufps xmm1, xmm2, R_SHUFFLEPS( 1, 3, 1, 3 )
movaps xmm2, xmm3
shufps xmm2, xmm4, R_SHUFFLEPS( 0, 2, 0, 2 )
shufps xmm3, xmm4, R_SHUFFLEPS( 1, 3, 1, 3 )
*/
xmm1 = _mm_loadl_pi(xmm1, (__m64 *)(src_p+count_l4+ 0));
xmm3 = _mm_loadl_pi(xmm3, (__m64 *)(src_p+count_l4+ 8));
xmm1 = _mm_loadh_pi(xmm1, (__m64 *)(src_p+count_l4+16));
xmm3 = _mm_loadh_pi(xmm3, (__m64 *)(src_p+count_l4+24));
xmm2 = _mm_loadl_pi(xmm2, (__m64 *)(src_p+count_l4+32));
xmm4 = _mm_loadl_pi(xmm4, (__m64 *)(src_p+count_l4+40));
xmm2 = _mm_loadh_pi(xmm2, (__m64 *)(src_p+count_l4+48));
xmm4 = _mm_loadh_pi(xmm4, (__m64 *)(src_p+count_l4+56));
xmm0 = xmm1;
xmm0 = _mm_shuffle_ps(xmm0, xmm2, R_SHUFFLEPS( 0, 2, 0, 2 ));
xmm1 = _mm_shuffle_ps(xmm1, xmm2, R_SHUFFLEPS( 1, 3, 1, 3 ));
xmm2 = xmm3;
xmm2 = _mm_shuffle_ps(xmm2, xmm4, R_SHUFFLEPS( 0, 2, 0, 2 ));
xmm3 = _mm_shuffle_ps(xmm3, xmm4, R_SHUFFLEPS( 1, 3, 1, 3 ));
/*
add ecx, 16
add eax, 4*16
*/
dst_p = dst_p + 16;
count_l4 = count_l4 + 4*16;
/*
mulps xmm0, xmm5
mulps xmm1, xmm6
mulps xmm2, xmm7
addps xmm0, xmm3
addps xmm0, xmm1
addps xmm0, xmm2
*/
xmm0 = _mm_mul_ps(xmm0, xmm5);
xmm1 = _mm_mul_ps(xmm1, xmm6);
xmm2 = _mm_mul_ps(xmm2, xmm7);
xmm0 = _mm_add_ps(xmm0, xmm3);
xmm0 = _mm_add_ps(xmm0, xmm1);
xmm0 = _mm_add_ps(xmm0, xmm2);
/*
movlps [ecx-16+0], xmm0
movhps [ecx-16+8], xmm0
jl loopVert4
*/
_mm_storel_pi((__m64 *) (dst_p-16+0), xmm0);
_mm_storeh_pi((__m64 *) (dst_p-16+8), xmm0);
} while (count_l4 < 0);
}
/*
startVert1:
and edx, 3
jz done
*/
count_l1 = count_l1 & 3;
if(count_l1 != 0) {
/*
loopVert1:
*/
do {
/*
movss xmm0, [esi+eax+0]
movss xmm1, [esi+eax+4]
movss xmm2, [esi+eax+8]
mulss xmm0, xmm5
mulss xmm1, xmm6
mulss xmm2, xmm7
addss xmm0, [esi+eax+12]
add ecx, 4
addss xmm0, xmm1
add eax, 16
addss xmm0, xmm2
dec edx
movss [ecx-4], xmm0
jnz loopVert1
*/
xmm0 = _mm_load_ss((float *) (src_p+count_l4+ 0));
xmm1 = _mm_load_ss((float *) (src_p+count_l4+ 4));
xmm2 = _mm_load_ss((float *) (src_p+count_l4+ 8));
xmm3 = _mm_load_ss((float *) (src_p+count_l4+12));
xmm0 = _mm_mul_ss(xmm0, xmm5);
xmm1 = _mm_mul_ss(xmm1, xmm6);
xmm2 = _mm_mul_ss(xmm2, xmm7);
xmm0 = _mm_add_ss(xmm0, xmm3);
dst_p = dst_p + 4;
xmm0 = _mm_add_ss(xmm0, xmm1);
count_l4 = count_l4 + 16;
xmm0 = _mm_add_ss(xmm0, xmm2);
count_l1 = count_l1 - 1;
_mm_store_ss((float *) (dst_p-4), xmm0);
} while (count_l1 != 0);
}
/*
done:
*/
}
#elif defined(_MSC_VER) && defined(_M_IX86)
#include <xmmintrin.h>
#include "idlib/geometry/JointTransform.h"
#include "idlib/math/Vector.h"
#include "idlib/math/Matrix.h"
#include "idlib/math/Quat.h"
#include "idlib/math/Plane.h"
#include "renderer/Model.h"
#define SHUFFLEPS( x, y, z, w ) (( (x) & 3 ) << 6 | ( (y) & 3 ) << 4 | ( (z) & 3 ) << 2 | ( (w) & 3 ))
#define R_SHUFFLEPS( x, y, z, w ) (( (w) & 3 ) << 6 | ( (z) & 3 ) << 4 | ( (y) & 3 ) << 2 | ( (x) & 3 ))
// transpose a 4x4 matrix loaded into 4 xmm registers (reg4 is temporary)
#define TRANSPOSE_4x4( reg0, reg1, reg2, reg3, reg4 ) \
__asm movaps reg4, reg2 /* reg4 = 8, 9, 10, 11 */ \
__asm unpcklps reg2, reg3 /* reg2 = 8, 12, 9, 13 */ \
__asm unpckhps reg4, reg3 /* reg4 = 10, 14, 11, 15 */ \
__asm movaps reg3, reg0 /* reg3 = 0, 1, 2, 3 */ \
__asm unpcklps reg0, reg1 /* reg0 = 0, 4, 1, 5 */ \
__asm unpckhps reg3, reg1 /* reg3 = 2, 6, 3, 7 */ \
__asm movaps reg1, reg0 /* reg1 = 0, 4, 1, 5 */ \
__asm shufps reg0, reg2, R_SHUFFLEPS( 0, 1, 0, 1 ) /* reg0 = 0, 4, 8, 12 */ \
__asm shufps reg1, reg2, R_SHUFFLEPS( 2, 3, 2, 3 ) /* reg1 = 1, 5, 9, 13 */ \
__asm movaps reg2, reg3 /* reg2 = 2, 6, 3, 7 */ \
__asm shufps reg2, reg4, R_SHUFFLEPS( 0, 1, 0, 1 ) /* reg2 = 2, 6, 10, 14 */ \
__asm shufps reg3, reg4, R_SHUFFLEPS( 2, 3, 2, 3 ) /* reg3 = 3, 7, 11, 15 */
// transpose a 4x4 matrix from memory into 4 xmm registers (reg4 is temporary)
#define TRANPOSE_4x4_FROM_MEMORY( address, reg0, reg1, reg2, reg3, reg4 ) \
__asm movlps reg1, [address+ 0] /* reg1 = 0, 1, X, X */ \
__asm movlps reg3, [address+ 8] /* reg3 = 2, 3, X, X */ \
__asm movhps reg1, [address+16] /* reg1 = 0, 1, 4, 5 */ \
__asm movhps reg3, [address+24] /* reg3 = 2, 3, 6, 7 */ \
__asm movlps reg2, [address+32] /* reg2 = 8, 9, X, X */ \
__asm movlps reg4, [address+40] /* reg4 = 10, 11, X, X */ \
__asm movhps reg2, [address+48] /* reg2 = 8, 9, 12, 13 */ \
__asm movhps reg4, [address+56] /* reg4 = 10, 11, 14, 15 */ \
__asm movaps reg0, reg1 /* reg0 = 0, 1, 4, 5 */ \
__asm shufps reg0, reg2, R_SHUFFLEPS( 0, 2, 0, 2 ) /* reg0 = 0, 4, 8, 12 */ \
__asm shufps reg1, reg2, R_SHUFFLEPS( 1, 3, 1, 3 ) /* reg1 = 1, 5, 9, 13 */ \
__asm movaps reg2, reg3 /* reg2 = 2, 3, 6, 7 */ \
__asm shufps reg2, reg4, R_SHUFFLEPS( 0, 2, 0, 2 ) /* reg2 = 2, 6, 10, 14 */ \
__asm shufps reg3, reg4, R_SHUFFLEPS( 1, 3, 1, 3 ) /* reg3 = 3, 7, 11, 15 */
// transpose a 4x4 matrix to memory from 4 xmm registers (reg4 is temporary)
#define TRANPOSE_4x4_TO_MEMORY( address, reg0, reg1, reg2, reg3, reg4 ) \
__asm movaps reg4, reg0 /* reg4 = 0, 4, 8, 12 */ \
__asm unpcklps reg0, reg1 /* reg0 = 0, 1, 4, 5 */ \
__asm unpckhps reg4, reg1 /* reg4 = 8, 9, 12, 13 */ \
__asm movaps reg1, reg2 /* reg1 = 2, 6, 10, 14 */ \
__asm unpcklps reg2, reg3 /* reg2 = 2, 3, 6, 7 */ \
__asm unpckhps reg1, reg3 /* reg1 = 10, 11, 14, 15 */ \
__asm movlps [address+ 0], reg0 /* mem0 = 0, 1, X, X */ \
__asm movlps [address+ 8], reg2 /* mem0 = 0, 1, 2, 3 */ \
__asm movhps [address+16], reg0 /* mem1 = 4, 5, X, X */ \
__asm movhps [address+24], reg2 /* mem1 = 4, 5, 6, 7 */ \
__asm movlps [address+32], reg4 /* mem2 = 8, 9, X, X */ \
__asm movlps [address+40], reg1 /* mem2 = 8, 9, 10, 11 */ \
__asm movhps [address+48], reg4 /* mem3 = 12, 13, X, X */ \
__asm movhps [address+56], reg1 /* mem3 = 12, 13, 14, 15 */
// transpose a 4x3 matrix loaded into 3 xmm registers (reg3 is temporary)
#define TRANSPOSE_4x3( reg0, reg1, reg2, reg3 ) \
__asm movaps reg3, reg2 /* reg3 = 8, 9, 10, 11 */ \
__asm shufps reg3, reg1, R_SHUFFLEPS( 2, 3, 0, 1 ) /* reg3 = 10, 11, 4, 5 */ \
__asm shufps reg2, reg0, R_SHUFFLEPS( 0, 1, 2, 3 ) /* reg2 = 8, 9, 2, 3 */ \
__asm shufps reg1, reg0, R_SHUFFLEPS( 2, 3, 0, 1 ) /* reg1 = 6, 7, 0, 1 */ \
__asm movaps reg0, reg1 /* reg0 = 6, 7, 0, 1 */ \
__asm shufps reg0, reg2, R_SHUFFLEPS( 2, 0, 3, 1 ) /* reg0 = 0, 6, 3, 9 */ \
__asm shufps reg1, reg3, R_SHUFFLEPS( 3, 1, 2, 0 ) /* reg1 = 1, 7, 4, 10 */ \
__asm shufps reg2, reg3, R_SHUFFLEPS( 2, 0, 3, 1 ) /* reg2 = 2, 8, 5, 11 */
// transpose a 4x3 matrix from memory into 3 xmm registers (reg3 is temporary)
#define TRANSPOSE_4x3_FROM_MEMORY( address, reg0, reg1, reg2, reg3 ) \
__asm movlps reg1, [address+ 0] /* reg1 = 0, 1, X, X */ \
__asm movlps reg2, [address+ 8] /* reg2 = 2, 3, X, X */ \
__asm movlps reg3, [address+16] /* reg3 = 4, 5, X, X */ \
__asm movhps reg1, [address+24] /* reg1 = 0, 1, 6, 7 */ \
__asm movhps reg2, [address+32] /* reg2 = 2, 3, 8, 9 */ \
__asm movhps reg3, [address+40] /* reg3 = 4, 5, 10, 11 */ \
__asm movaps reg0, reg1 /* reg0 = 0, 1, 6, 7 */ \
__asm shufps reg0, reg2, R_SHUFFLEPS( 0, 2, 1, 3 ) /* reg0 = 0, 6, 3, 9 */ \
__asm shufps reg1, reg3, R_SHUFFLEPS( 1, 3, 0, 2 ) /* reg1 = 1, 7, 4, 10 */ \
__asm shufps reg2, reg3, R_SHUFFLEPS( 0, 2, 1, 3 ) /* reg2 = 2, 8, 5, 11 */
// transpose a 4x3 matrix to memory from 3 xmm registers (reg3 is temporary)
#define TRANSPOSE_4x3_TO_MEMORY( address, reg0, reg1, reg2, reg3 ) \
__asm movhlps reg3, reg0 /* reg3 = 3, 9, X, X */ \
__asm unpcklps reg0, reg1 /* reg0 = 0, 1, 6, 7 */ \
__asm unpckhps reg1, reg2 /* reg1 = 4, 5, 10, 11 */ \
__asm unpcklps reg2, reg3 /* reg2 = 2, 3, 8, 9 */ \
__asm movlps [address+ 0], reg0 /* mem0 = 0, 1, X, X */ \
__asm movlps [address+ 8], reg2 /* mem0 = 0, 1, 2, 3 */ \
__asm movlps [address+16], reg1 /* mem1 = 4, 5, X, X */ \
__asm movhps [address+24], reg0 /* mem1 = 4, 5, 6, 7 */ \
__asm movhps [address+32], reg2 /* mem2 = 8, 9, X, X */ \
__asm movhps [address+40], reg1 /* mem2 = 8, 9, 10, 11 */
// with alignment
#define KFLOATINITS( SRC0, COUNT, PRE, POST ) KFLOATINITDSS( SRC0,SRC0,SRC0,COUNT,PRE,POST )
#define KFLOATINITD( DST, COUNT, PRE, POST ) KFLOATINITDSS( DST,DST,DST,COUNT,PRE,POST )
#define KFLOATINITDS( DST, SRC0, COUNT, PRE, POST ) KFLOATINITDSS( DST,SRC0,SRC0,COUNT,PRE,POST )
#define KFLOATINITDSS( DST, SRC0, SRC1, COUNT, PRE, POST )\
__asm mov ecx,DST \
__asm shr ecx,2 \
__asm mov ebx,COUNT \
__asm neg ecx \
__asm mov edx,SRC0 \
__asm and ecx,3 \
__asm mov esi,SRC1 \
__asm sub ebx,ecx \
__asm jge noUnderFlow \
__asm xor ebx,ebx \
__asm mov ecx,COUNT \
__asm noUnderFlow: \
__asm mov PRE,ecx \
__asm mov eax,ebx \
__asm mov edi,DST \
__asm and eax,8-1 \
__asm mov POST,eax \
__asm and ebx,0xfffffff8 \
__asm jle done \
__asm shl ebx,2 \
__asm lea ecx,[ecx*4+ebx] \
__asm neg ebx \
__asm add edx,ecx \
__asm add esi,ecx \
__asm add edi,ecx \
__asm mov eax,edx \
__asm or eax,esi
// without alignment (pre==0)
#define KFLOATINITS_NA( SRC0, COUNT, PRE, POST ) KFLOATINITDSS_NA( SRC0,SRC0,SRC0,COUNT,PRE,POST )
#define KFLOATINITD_NA( DST, COUNT, PRE, POST ) KFLOATINITDSS_NA( DST,DST,DST,COUNT,PRE,POST )
#define KFLOATINITDS_NA( DST, SRC0, COUNT, PRE, POST ) KFLOATINITDSS_NA( DST,SRC0,SRC0,COUNT,PRE,POST )
#define KFLOATINITDSS_NA( DST, SRC0, SRC1, COUNT, PRE, POST )\
__asm mov eax,COUNT \
__asm mov PRE,0 \
__asm and eax,8-1 \
__asm mov ebx,COUNT \
__asm mov POST,eax \
__asm and ebx,0xfffffff8 \
__asm je done \
__asm shl ebx,2 \
__asm mov edx,SRC0 \
__asm mov esi,SRC1 \
__asm mov edi,DST \
__asm add edx,ebx \
__asm add esi,ebx \
__asm add edi,ebx \
__asm mov eax,edx \
__asm or eax,esi \
__asm or eax,edi \
__asm neg ebx \
/*
when OPER is called:
edx = s0
esi = s1
edi = d
ebx = index*4
xmm0 & xmm1 must not be trashed
*/
#define KMOVDS1( DST, SRC0 ) \
__asm movss xmm2,SRC0 \
__asm movss DST,xmm2
#define KMOVDS4( DST, SRC0 ) \
__asm movups xmm2,SRC0 \
__asm movups DST,xmm2
#define KMINDS1( DST, SRC0 ) \
__asm movss xmm2,SRC0 \
__asm minss DST,xmm2
#define KMAXDS1( DST, SRC0 ) \
__asm movss xmm2,SRC0 \
__asm maxss DST,xmm2
// general ALU operation
#define KALUDSS1( OP, DST, SRC0, SRC1 ) \
__asm movss xmm2,SRC0 \
__asm OP##ss xmm2,SRC1 \
__asm movss DST,xmm2
#define KALUDSS4( OP, DST, SRC0, SRC1 ) \
__asm movups xmm2,SRC0 \
__asm movups xmm3,SRC1 \
__asm OP##ps xmm2,xmm3 \
__asm movups DST,xmm2
#define KADDDSS1( DST, SRC0, SRC1 ) KALUDSS1( add, DST,SRC0,SRC1 )
#define KADDDSS4( DST, SRC0, SRC1 ) KALUDSS4( add, DST,SRC0,SRC1 )
#define KSUBDSS1( DST, SRC0, SRC1 ) KALUDSS1( sub, DST,SRC0,SRC1 )
#define KSUBDSS4( DST, SRC0, SRC1 ) KALUDSS4( sub, DST,SRC0,SRC1 )
#define KMULDSS1( DST, SRC0, SRC1 ) KALUDSS1( mul, DST,SRC0,SRC1 )
#define KMULDSS4( DST, SRC0, SRC1 ) KALUDSS4( mul, DST,SRC0,SRC1 )
#define KDIVDSS1( DST, SRC0, SRC1 ) \
__asm movss xmm2,SRC1 \
__asm rcpss xmm3,xmm2 \
__asm mulss xmm2,xmm3 \
__asm mulss xmm2,xmm3 \
__asm addss xmm3,xmm3 \
__asm subss xmm3,xmm2 \
__asm mulss xmm3,SRC0 \
__asm movss DST,xmm3
#define KDIVDSS4( DST, SRC0, SRC1 ) \
__asm movups xmm2,SRC1 \
__asm rcpps xmm3,xmm2 \
__asm mulps xmm2,xmm3 \
__asm mulps xmm2,xmm3 \
__asm addps xmm3,xmm3 \
__asm subps xmm3,xmm2 \
__asm movups xmm2,SRC0 \
__asm mulps xmm3,xmm2 \
__asm movups DST,xmm3
#define KF2IDS1( SRC0 ) \
__asm movss xmm2,SRC0 \
__asm cvttps2pi mm2,xmm2 \
__asm movd [edi+ebx],mm2
#define KF2IDS4( SRC0 ) \
__asm movups xmm2,SRC0 \
__asm cvttps2pi mm2,xmm2 \
__asm movq [edi+ebx+0],mm2 \
__asm shufps xmm2,xmm2,SHUFFLEPS(1,0,3,2) \
__asm cvttps2pi mm2,xmm2 \
__asm movq [edi+ebx+8],mm2
#define KISQRTDS1( DST,SRC0 ) \
__asm movss xmm2,SRC0 \
__asm rsqrtss xmm3,xmm2 \
__asm mulss xmm2,xmm3 \
__asm mulss xmm2,xmm3 \
__asm subss xmm2,xmm1 \
__asm mulss xmm3,xmm0 \
__asm mulss xmm3,xmm2 \
__asm movss DST,xmm3
#define KISQRTDS4( DST,SRC0 ) \
__asm movups xmm2,SRC0 \
__asm rsqrtps xmm3,xmm2 \
__asm mulps xmm2,xmm3 \
__asm mulps xmm2,xmm3 \
__asm subps xmm2,xmm1 \
__asm mulps xmm3,xmm0 \
__asm mulps xmm3,xmm2 \
__asm movups DST,xmm3
// this is used in vector4 implementation to shift constant V4
#define KANDREGDSV( DST, SRC0, VALUE ) \
__asm mov DST,SRC0 \
__asm and DST,VALUE
// this is used in vector4 code to operate with float arrays as sources
#define KEXPANDFLOAT( DST, SRC ) \
__asm movss DST,SRC \
__asm shufps DST,DST,0
#define KADDDS1( DST,SRC ) KADDDSS1( DST,DST,SRC )
#define KADDDS4( DST,SRC ) KADDDSS4( DST,DST,SRC )
#define KSUBDS1( DST,SRC ) KSUBDSS1( DST,DST,SRC )
#define KSUBDS4( DST,SRC ) KSUBDSS4( DST,DST,SRC )
#define KMULDS1( DST,SRC ) KMULDSS1( DST,DST,SRC )
#define KMULDS4( DST,SRC ) KMULDSS4( DST,DST,SRC )
#define KDIVDS1( DST,SRC ) KDIVDSS1( DST,DST,SRC )
#define KDIVDS4( DST,SRC ) KDIVDSS4( DST,DST,SRC )
// handles pre & post leftovers
#define KFLOATOPER( OPER, OPER4, COUNT ) \
__asm mov ecx,pre \
__asm mov ebx,COUNT \
__asm cmp ebx,ecx \
__asm cmovl ecx,COUNT \
__asm test ecx,ecx \
__asm je preDone \
__asm xor ebx,ebx \
__asm lpPre: \
OPER \
__asm add ebx,4 \
__asm dec ecx \
__asm jg lpPre \
__asm preDone: \
__asm mov ecx,post \
__asm mov ebx,COUNT \
__asm sub ebx,ecx \
__asm shl ebx,2 \
__asm cmp ecx,4 \
__asm jl post4Done \
OPER4 \
__asm sub ecx,4 \
__asm add ebx,4*4 \
__asm post4Done: \
__asm test ecx,ecx \
__asm je postDone \
__asm lpPost: \
OPER \
__asm add ebx,4 \
__asm dec ecx \
__asm jg lpPost \
__asm postDone:
// operate on a constant and a float array
#define KFLOAT_CA( ALUOP, DST, SRC, CONSTANT, COUNT ) \
int pre,post; \
__asm movss xmm0,CONSTANT \
__asm shufps xmm0,xmm0,0 \
KFLOATINITDS( DST, SRC, COUNT, pre, post ) \
__asm and eax,15 \
__asm jne lpNA \
__asm jmp lpA \
__asm align 16 \
__asm lpA: \
__asm prefetchnta [edx+ebx+64] \
__asm movaps xmm1,xmm0 \
__asm movaps xmm2,xmm0 \
__asm ALUOP##ps xmm1,[edx+ebx] \
__asm ALUOP##ps xmm2,[edx+ebx+16] \
__asm movaps [edi+ebx],xmm1 \
__asm movaps [edi+ebx+16],xmm2 \
__asm add ebx,16*2 \
__asm jl lpA \
__asm jmp done \
__asm align 16 \
__asm lpNA: \
__asm prefetchnta [edx+ebx+64] \
__asm movaps xmm1,xmm0 \
__asm movaps xmm2,xmm0 \
__asm movups xmm3,[edx+ebx] \
__asm movups xmm4,[edx+ebx+16] \
__asm ALUOP##ps xmm1,xmm3 \
__asm ALUOP##ps xmm2,xmm4 \
__asm movaps [edi+ebx],xmm1 \
__asm movaps [edi+ebx+16],xmm2 \
__asm add ebx,16*2 \
__asm jl lpNA \
__asm done: \
__asm mov edx,SRC \
__asm mov edi,DST \
__asm KFLOATOPER( KALUDSS1( ALUOP, [edi+ebx],xmm0,[edx+ebx] ), \
__asm KALUDSS4( ALUOP, [edi+ebx],xmm0,[edx+ebx] ), COUNT )
// operate on two float arrays
#define KFLOAT_AA( ALUOP, DST, SRC0, SRC1, COUNT ) \
int pre,post; \
KFLOATINITDSS( DST, SRC0, SRC1, COUNT, pre, post ) \
__asm and eax,15 \
__asm jne lpNA \
__asm jmp lpA \
__asm align 16 \
__asm lpA: \
__asm movaps xmm1,[edx+ebx] \
__asm movaps xmm2,[edx+ebx+16] \
__asm ALUOP##ps xmm1,[esi+ebx] \
__asm ALUOP##ps xmm2,[esi+ebx+16] \
__asm prefetchnta [edx+ebx+64] \
__asm prefetchnta [esi+ebx+64] \
__asm movaps [edi+ebx],xmm1 \
__asm movaps [edi+ebx+16],xmm2 \
__asm add ebx,16*2 \
__asm jl lpA \
__asm jmp done \
__asm align 16 \
__asm lpNA: \
__asm movups xmm1,[edx+ebx] \
__asm movups xmm2,[edx+ebx+16] \
__asm movups xmm3,[esi+ebx] \
__asm movups xmm4,[esi+ebx+16] \
__asm prefetchnta [edx+ebx+64] \
__asm prefetchnta [esi+ebx+64] \
__asm ALUOP##ps xmm1,xmm3 \
__asm ALUOP##ps xmm2,xmm4 \
__asm movaps [edi+ebx],xmm1 \
__asm movaps [edi+ebx+16],xmm2 \
__asm add ebx,16*2 \
__asm jl lpNA \
__asm done: \
__asm mov edx,SRC0 \
__asm mov esi,SRC1 \
__asm mov edi,DST \
KFLOATOPER( KALUDSS1( ALUOP, [edi+ebx],[edx+ebx],[esi+ebx] ), \
KALUDSS4( ALUOP, [edi+ebx],[edx+ebx],[esi+ebx] ), COUNT )