public
Description: Open source GPS receiver based on USRP and GN3S
Homepage: http://www.gps-sdr.com
Clone URL: git://github.com/gps-sdr/gps-sdr.git
gps-sdr / simd / sse_new.cpp
100644 1119 lines (1008 sloc) 38.304 kb
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
/*! \file SSE.cpp
SIMD functionality, mainly for 32 bit interleaved complex integer type (CPX)
*/
 
/************************************************************************************************
Copyright 2008 Gregory W Heckler
 
This file is part of the GPS Software Defined Radio (GPS-SDR)
 
The GPS-SDR 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 2 of the
License, or (at your option) any later version.
 
The GPS-SDR 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 GPS-SDR; if not,
write to the:
 
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
************************************************************************************************/
 
 
// __asm
// (
// "mov eax, 0x1 \n\t"
//
// "mov eax, edx \n\t"
// "leave \n\t"
// "ret \n\t"
// ".att_syntax \n\t"
// );
#include "includes.h"
 
 
void sse_add(int16 *A, int16 *B, int32 cnt)
{
 
int32 cnt1;
int32 cnt2;
 
cnt1 = cnt / 8;
cnt2 = (cnt - (8*cnt1));
 
if(((int)A%16) || ((int)B%16)) // unaligned version
{
 
__asm
(
".intel_syntax noprefix \n\t" //Set up for loop
"mov edi, [ebp+8] \n\t" //Address of A
"mov esi, [ebp+12] \n\t" //Address of B
"mov ecx, [ebp-12] \n\t" //Counter 1
"jecxz Z%= \n\t"
"L%=: \n\t"
"movupd xmm0, [edi] \n\t" //Load from A
"movupd xmm1, [esi] \n\t" //Load from B
"paddw xmm0, xmm1 \n\t" //Multiply A*B
"movupd [edi], xmm0 \n\t" //Move into A
"add edi, 16 \n\t"
"add esi, 16 \n\t"
".att_syntax \n\t"
"loop L%= \n\t" //Loop if not donefi
".intel_syntax noprefix \n\t"
"Z%=: \n\t"
"mov ecx, [ebp-16] \n\t" //Counter 2
"mov eax, 0 \n\t"
"LL%=: \n\t" //Really finish off loop with non SIMD instructions
"mov ax, [edi] \n\t"
"add ax, [esi] \n\t"
"mov [edi], ax \n\t"
"add esi, 2 \n\t"
"add edi, 2 \n\t"
".att_syntax \n\t"
".att_syntax \n\t"
"loop LL%= \n\t"
".intel_syntax noprefix \n\t"
 
".intel_syntax noprefix \n\t"
"ZZ%=: \n\t"
"EMMS \n\t"
".att_syntax \n\t"
:
: "m" (A), "m" (B), "m" (cnt), "m" (cnt1), "m" (cnt2)
: "%eax", "%ecx", "%edi", "%esi"
);
 
}
else
{
__asm
(
".intel_syntax noprefix \n\t" //Set up for loop
"mov edi, [ebp+8] \n\t" //Address of A
"mov esi, [ebp+12] \n\t" //Address of B
"mov ecx, [ebp-12] \n\t" //Counter 1
"jecxz Z%= \n\t"
"L%=: \n\t"
"movapd xmm0, [edi] \n\t" //Load from A
"paddw xmm0, [esi] \n\t" //Multiply A*B
"movapd [edi], xmm0 \n\t" //Move into A
"add edi, 16 \n\t"
"add esi, 16 \n\t"
".att_syntax \n\t"
"loop L%= \n\t"
".intel_syntax noprefix \n\t"
"Z%=: \n\t"
"mov ecx, [ebp-16] \n\t" //Counter 2
"jecxz ZZ%= \n\t"
"mov eax, 0 \n\t"
"LL%=: \n\t" //Really finish off loop with non SIMD instructions
"mov ax, [edi] \n\t"
"add ax, [esi] \n\t"
"mov [edi], ax \n\t"
"add esi, 2 \n\t"
"add edi, 2 \n\t"
".att_syntax \n\t"
"loop LL%= \n\t"
".intel_syntax noprefix \n\t"
 
"ZZ%=: \n\t"
"EMMS \n\t"
".att_syntax \n\t"
:
: "m" (A), "m" (B), "m" (cnt), "m" (cnt1), "m" (cnt2)
: "%eax", "%ecx", "%edi", "%esi"
);//end __asm
 
}//end if
 
}
 
 
void sse_sub(int16 *A, int16 *B, int32 cnt)
{
 
int32 cnt1;
int32 cnt2;
 
cnt1 = cnt / 8;
cnt2 = (cnt - (8*cnt1));
 
if(((int)A%16) || ((int)B%16)) // unaligned version
{
 
__asm
(
".intel_syntax noprefix \n\t" //Set up for loop
"mov edi, [ebp+8] \n\t" //Address of A
"mov esi, [ebp+12] \n\t" //Address of B
"mov ecx, [ebp-12] \n\t" //Counter 1
"jecxz Z%= \n\t"
"L%=: \n\t"
"movupd xmm0, [edi] \n\t" //Load from A
"movupd xmm1, [esi] \n\t" //Load from B
"psubw xmm0, xmm1 \n\t" //Multiply A*B
"movupd [edi], xmm0 \n\t" //Move into A
"add edi, 16 \n\t"
"add esi, 16 \n\t"
".att_syntax \n\t"
"loop L%= \n\t"
".intel_syntax noprefix \n\t"
 //Loop if not done
"Z%=: \n\t"
"mov ecx, [ebp-16] \n\t" //Counter 2
"jecxz ZZ%= \n\t"
"mov eax, 0 \n\t"
"LL%=: \n\t" //Really finish off loop with non SIMD instructions
"mov ax, [edi] \n\t"
"sub ax, [esi] \n\t"
"mov [edi], ax \n\t"
"add esi, 2 \n\t"
"add edi, 2 \n\t"
".att_syntax \n\t"
"loop LL%= \n\t"
".intel_syntax noprefix \n\t"
 
"ZZ%=: \n\t"
"EMMS \n\t"
".att_syntax \n\t"
:
: "m" (A), "m" (B), "m" (cnt), "m" (cnt1), "m" (cnt2)
: "%eax", "%ecx", "%edi", "%esi"
);
 
}
else
{
__asm
(
".intel_syntax noprefix \n\t" //Set up for loop
"mov edi, [ebp+8] \n\t" //Address of A
"mov esi, [ebp+12] \n\t" //Address of B
"mov ecx, [ebp-12] \n\t" //Counter 1
"jecxz Z%= \n\t"
"L%=: \n\t"
"movapd xmm0, [edi] \n\t" //Load from A
"psubw xmm0, [esi] \n\t" //Multiply A*B
"movapd [edi], xmm0 \n\t" //Move into A
"add edi, 16 \n\t"
"add esi, 16 \n\t"
".att_syntax \n\t"
"loop L%= \n\t"
".intel_syntax noprefix \n\t"
 //Loop if not done
"Z%=: \n\t"
"mov ecx, [ebp-16] \n\t" //Counter 2
"jecxz ZZ%= \n\t"
"mov eax, 0 \n\t"
"LL%=: \n\t" //Really finish off loop with non SIMD instructions
"mov ax, [edi] \n\t"
"sub ax, [esi] \n\t"
"mov [edi], ax \n\t"
"add esi, 2 \n\t"
"add edi, 2 \n\t"
".att_syntax \n\t"
"loop LL%= \n\t"
".intel_syntax noprefix \n\t"
 
"ZZ%=: \n\t"
"EMMS \n\t"
".att_syntax \n\t"
:
: "m" (A), "m" (B), "m" (cnt), "m" (cnt1), "m" (cnt2)
: "%eax", "%ecx", "%edi", "%esi"
);//end __asm
 
}//end if
 
}
 
void sse_mul(int16 *A, int16 *B, int32 cnt)
{
 
int32 cnt1;
int32 cnt2;
 
cnt1 = cnt / 8;
cnt2 = (cnt - (8*cnt1));
 
if(((int)A%16) || ((int)B%16)) // unaligned version
{
 
__asm
(
".intel_syntax noprefix \n\t" //Set up for loop
"mov edi, [ebp+8] \n\t" //Address of A
"mov esi, [ebp+12] \n\t" //Address of B
"mov ecx, [ebp-12] \n\t" //Counter 1
"jecxz Z%= \n\t"
"L%=: \n\t"
"movupd xmm0, [edi] \n\t" //Load from A
"movupd xmm1, [esi] \n\t" //Load from B
"pmullw xmm0, xmm1 \n\t" //Multiply A*B
"movupd [edi], xmm0 \n\t" //Move into A
"add edi, 16 \n\t"
"add esi, 16 \n\t"
".att_syntax \n\t"
"loop L%= \n\t"
".intel_syntax noprefix \n\t"
 //Loop if not done
"Z%=: \n\t"
"mov ecx, [ebp-16] \n\t" //Counter 2
"jecxz ZZ%= \n\t"
"mov eax, 0 \n\t"
"LL%=: \n\t" //Really finish off loop with non SIMD instructions
"mov ax, [edi] \n\t"
"imul ax, [esi] \n\t"
"mov [edi], ax \n\t"
"add esi, 2 \n\t"
"add edi, 2 \n\t"
".att_syntax \n\t"
"loop LL%= \n\t"
".intel_syntax noprefix \n\t"
 
"ZZ%=: \n\t"
"EMMS \n\t"
".att_syntax \n\t"
:
: "m" (A), "m" (B), "m" (cnt), "m" (cnt1), "m" (cnt2)
: "%eax", "%ecx", "%edi", "%esi"
);
 
}
else
{
__asm
(
".intel_syntax noprefix \n\t" //Set up for loop
"mov edi, [ebp+8] \n\t" //Address of A
"mov esi, [ebp+12] \n\t" //Address of B
"mov ecx, [ebp-12] \n\t" //Counter 1
"jecxz Z%= \n\t"
"L%=: \n\t"
"movapd xmm0, [edi] \n\t" //Load from A
"pmullw xmm0, [esi] \n\t" //Multiply A*B
"movapd [edi], xmm0 \n\t" //Move into A
"add edi, 16 \n\t"
"add esi, 16 \n\t"
".att_syntax \n\t"
"loop L%= \n\t"
".intel_syntax noprefix \n\t"
//Loop if not done
"Z%=: \n\t"
"mov ecx, [ebp-16] \n\t" //Counter 2
"jecxz ZZ%= \n\t"
"mov eax, 0 \n\t"
"LL%=: \n\t" //Really finish off loop with non SIMD instructions
"mov ax, [edi] \n\t"
"imul ax, [esi] \n\t"
"mov [edi], ax \n\t"
"add esi, 2 \n\t"
"add edi, 2 \n\t"
".att_syntax \n\t"
"loop LL%= \n\t"
".intel_syntax noprefix \n\t"
 
"ZZ%=: \n\t"
"EMMS \n\t"
".att_syntax \n\t"
:
: "m" (A), "m" (B), "m" (cnt), "m" (cnt1), "m" (cnt2)
: "%eax", "%ecx", "%edi", "%esi"
);//end __asm
 
}//end if
 
}
 
 
int32 sse_dot(int16 *A, int16 *B, int32 cnt)
{
 
int32 cnt1;
int32 cnt2;
int32 temp;
 
if(((int32)A%16) || ((int32)B%16)) //If the memory locations are not 16 byte aligned use slower movupd instruction
{
 
cnt1 = cnt / 24;
cnt2 = (cnt - (24*cnt1));
 
__asm
(
".intel_syntax noprefix \n\t" //Set up for loop
"mov edi, [ebp+8] \n\t" //Address of A
"mov esi, [ebp+12] \n\t" //Address of B
"mov ecx, [ebp-16] \n\t" //Counter 1
"pxor xmm0, xmm0 \n\t" //Clear the running sum (accumulator)
"jecxz Z%= \n\t"
"L%=: \n\t"
"movupd xmm1, [esi] \n\t" //Load from A
"movupd xmm2, [esi+16] \n\t" //Load from A
"movupd xmm3, [esi+32] \n\t" //Load from A
"movupd xmm4, [edi] \n\t" //Load from B
"movupd xmm5, [edi+16] \n\t" //Load from B
"movupd xmm6, [edi+32] \n\t" //Load from B
"pmaddwd xmm1, xmm4 \n\t" //Multiply and accumulate
"pmaddwd xmm2, xmm5 \n\t" //Multiply and accumulate
"pmaddwd xmm3, xmm6 \n\t" //Multiply and accumulate
"paddd xmm1, xmm3 \n\t" //Add into accumulator (efficiently)
"paddd xmm0, xmm2 \n\t"
"paddd xmm0, xmm1 \n\t"
"add esi, 48 \n\t"
"add edi, 48 \n\t"
".att_syntax \n\t"
"loop L%= \n\t"
".intel_syntax noprefix \n\t"
 //Loop if not done
"Z%=: \n\t"
"movd ebx, xmm0 \n\t" //right-hand word to ebx
"psrldq xmm0, 4 \n\t" //left-hand word to right side of xmm0
"movd eax, xmm0 \n\t" //left-hand word into eax
"add eax, ebx \n\t" //running sum now in eax
"mov edx, eax \n\t" //move into edx
"psrldq xmm0, 4 \n\t" //left-hand word to right side of xmm0
"movd ebx, xmm0 \n\t" //right-hand word to ebx
"psrldq xmm0, 4 \n\t" //left-hand word to right side of xmm0
"movd eax, xmm0 \n\t" //left-hand word into eax
"add eax, ebx \n\t" //running sum now in eax
"add edx, eax \n\t" //add to edx
"mov ecx, [ebp-20] \n\t"
"jecxz ZZ%= \n\t"
"LL%=: \n\t" //Really finish off loop with non SIMD instructions
"mov bx, [edi] \n\t" //Move 16 bits into bx
"movsx ebx, bx \n\t" //Sign extend to 32 bits
"mov ax, [esi] \n\t" //Move 16 bits into ax
"movsx eax, ax \n\t" //Sign extend to 32 bits
"imul ebx, eax \n\t" //Multiply
"add edx, ebx \n\t" //Add into accumulator
"add esi, 2 \n\t"
"add edi, 2 \n\t"
".att_syntax \n\t"
"loop LL%= \n\t"
".intel_syntax noprefix \n\t"
 
"ZZ%=: \n\t"
"EMMS \n\t"
"mov [ebp-24], edx \n\t"
".att_syntax \n\t"
: "=m"(temp)
: "m" (A), "m" (B), "m" (cnt), "m" (cnt1), "m" (cnt2)
: "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi"
);//end __asm
}
else //use faster movapd instruction
{
 
cnt1 = cnt / 56;
cnt2 = (cnt - (56*cnt1));
 
__asm
(
//Set up for loop
".intel_syntax noprefix \n\t" //Set up for loop
"mov edi, [ebp+8] \n\t" //Address of A
"mov esi, [ebp+12] \n\t" //Address of B
"mov ecx, [ebp-16] \n\t" //Counter 1
"pxor xmm0, xmm0 \n\t" //Clear the running sum (accumulator)
"jecxz Z%= \n\t"
"L%=: \n\t"
"movapd xmm1, [esi] \n\t" //Load from A
"movapd xmm2, [esi+16] \n\t" //Load from A
"movapd xmm3, [esi+32] \n\t" //Load from A
"movapd xmm4, [esi+48] \n\t" //Load from A
"movapd xmm5, [esi+64] \n\t" //Load from A
"movapd xmm6, [esi+80] \n\t" //Load from A
"movapd xmm7, [esi+96] \n\t" //Load from A
"pmaddwd xmm1, [edi] \n\t"
"pmaddwd xmm2, [edi+16] \n\t"
"pmaddwd xmm3, [edi+32] \n\t"
"pmaddwd xmm4, [edi+48] \n\t"
"pmaddwd xmm5, [edi+64] \n\t"
"pmaddwd xmm6, [edi+80] \n\t"
"pmaddwd xmm7, [edi+96] \n\t"
"paddd xmm0, xmm7 \n\t"
"paddd xmm1, xmm2 \n\t"
"paddd xmm3, xmm4 \n\t"
"paddd xmm5, xmm6 \n\t"
"paddd xmm1, xmm3 \n\t"
"paddd xmm0, xmm5 \n\t"
"paddd xmm0, xmm1 \n\t"
"add esi, 112 \n\t"
"add edi, 112 \n\t"
".att_syntax \n\t"
"loop L%= \n\t"
".intel_syntax noprefix \n\t"
// Loop if not done
"Z%=: \n\t"
"movd ebx, xmm0 \n\t" // right-hand word to ebx
"psrldq xmm0, 4 \n\t" // left-hand word to right side of xmm0
"movd eax, xmm0 \n\t" // left-hand word into eax
"add eax, ebx \n\t" // running sum now in eax
"mov edx, eax \n\t" // move into temp
"psrldq xmm0, 4 \n\t"
"movd ebx, xmm0 \n\t" // right-hand word to ebx
"psrldq xmm0, 4 \n\t" // left-hand word to right side of xmm0
"movd eax, xmm0 \n\t" // left-hand word into eax
"add eax, ebx \n\t" // running sum now in eax
"add edx, eax \n\t" // add into temp
"mov ecx, [ebp-20] \n\t"
"jecxz ZZ%= \n\t"
"LL%=: \n\t" //Really finish off loop with non SIMD instructions
"mov bx, [edi] \n\t" //Move 16 bits into bx
"movsx ebx, bx \n\t" //Sign extend to 32 bits
"mov ax, [esi] \n\t" //Move 16 bits into ax
"movsx eax, ax \n\t" //Sign extend to 32 bits
"imul ebx, eax \n\t" //Multiply
"add edx, ebx \n\t" //Add into accumulator
"add esi, 2 \n\t"
"add edi, 2 \n\t"
".att_syntax \n\t"
"loop LL%= \n\t"
".intel_syntax noprefix \n\t"
 
"ZZ%=: \n\t"
"EMMS \n\t"
"mov [ebp-24], edx \n\t"
".att_syntax \n\t"
: "=m"(temp)
: "m" (A), "m" (B), "m" (cnt), "m" (cnt1), "m" (cnt2)
: "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi"
);
}
 
return(temp);
 
}
 
void sse_conj(CPX *A, int32 cnt)
{
 
int32 cnt1;
int32 cnt2;
int32 temp = 0xffff0001; //[1, -1]
 
cnt1 = cnt/4;
cnt2 = cnt-4*cnt1;
 
__asm
(
".intel_syntax noprefix \n\t" //Set up for loop
"mov edi, [ebp+8] \n\t" //Address of A source1
"mov ecx, [ebp-8] \n\t" //Counter
"movd mm7, [ebp-16] \n\t"
"punpckldq mm7, mm7 \n\t"
"movd xmm7, [ebp-16] \n\t"
"punpckldq xmm7, xmm7 \n\t"
"punpckldq xmm7, xmm7 \n\t"
"jecxz Z%= \n\t"
"L%=: \n\t"
" movupd xmm0, [edi] \n\t" //Load from A
" pmullw xmm0, xmm7 \n\t" //Multiply to get [Re -Im Re -Im]
" movupd [edi], xmm0 \n\t" //Move into A
" add edi, 16 \n\t" //Move in array
".att_syntax \n\t"
"loop L%= \n\t" //Loop if not done
".intel_syntax noprefix \n\t"
"Z%=: \n\t"
"mov ecx, [ebp-12] \n\t"
"jecxz ZZ%= \n\t"
"LL%=: \n\t"
" movd mm0, [edi] \n\t" //Load from A
" pmullw mm0, mm7 \n\t" //Multiply to get [Re -Im Re -Im]
" movd [edi], mm0 \n\t" //Move into A
" add edi, 4 \n\t"
".att_syntax \n\t"
"loop LL%= \n\t" //Loop if not done
".intel_syntax noprefix \n\t"
 
"ZZ%=: \n\t"
"EMMS \n\t"
".att_syntax \n\t"
:
: "m" (A), "m" (cnt), "m" (cnt1), "m" (cnt2), "m" (temp)
: "%ecx", "%edx", "%edi"
);
 
}
 
void sse_cmul(CPX *A, CPX *B, int32 cnt)
{
 
int32 cnt1;
int32 cnt2;
 
volatile int32 M[4] = {0xffff0001, 0x00010001, 0xffff0001, 0x00010001}; //{1,-1,1,1,1,-1,1,1};
 
cnt1 = cnt/4;
cnt2 = cnt-4*cnt1;
 
cnt1 = 0;
cnt2 = cnt;
 
__asm
(
".intel_syntax noprefix \n\t" //Set up for loop
"mov edi, [ebp+8] \n\t" //Address of A
"mov esi, [ebp+12] \n\t" //Address of B
"mov ecx, [ebp-12] \n\t" //Counter 1
"movupd xmm7,[ebp-32] \n\t" // Move the multiply thingie
"jecxz Z%= \n\t"
"L%=: \n\t"
"movlpd xmm0, [edi] \n\t" //Copy from A
"movlpd xmm1, [edi+8] \n\t" //Copy from A
"movlpd xmm3, [esi] \n\t" //Copy from B
"movlpd xmm4, [esi+8] \n\t" //Copy from B
"punpckldq xmm0, xmm0 \n\t" //Copy low 32 bits to high 32 bits
"punpckldq xmm1, xmm1 \n\t" //Copy low 32 bits to high 32 bits
"punpckldq xmm3, xmm3 \n\t" //Copy low 32 bits to high 32 bits
"punpckldq xmm4, xmm4 \n\t" //Copy low 32 bits to high 32 bits
"pshuflw xmm3, xmm3, 0x14 \n\t" //Shuffle Low 64 bits to get [Re Im Im Re]
"pshuflw xmm4, xmm4, 0x14 \n\t" //Shuffle Low 64 bits to get [Re Im Im Re]
"pshufhw xmm3, xmm3, 0x14 \n\t" //Shuffle High 64 bits to get [Re Im Im Re]
"pshufhw xmm4, xmm4, 0x14 \n\t" //Shuffle High 64 bits to get [Re Im Im Re]
"pmullw xmm3, xmm7 \n\t" //Multiply to get [Re Im -Im Re]
"pmullw xmm4, xmm7 \n\t" //Multiply to get [Re Im -Im Re]
"pmaddwd xmm0, xmm3 \n\t" //Complex multiply and add
"pmaddwd xmm1, xmm4 \n\t" //Complex multiply and add
"packssdw xmm0, xmm0 \n\t" //Get into low 64 bits
"packssdw xmm1, xmm1 \n\t" //Get into low 64 bits
"movsd [edi], xmm0 \n\t" //Move into A
"movsd [edi+8], xmm1 \n\t" //Move into A
"add edi, 16 \n\t" //Move in array
"add esi, 16 \n\t" //Move in array
".att_syntax \n\t"
"loop L%= \n\t"
".intel_syntax noprefix \n\t"
"Z%=: \n\t"
"mov ecx, [ebp-16] \n\t"
"jecxz ZZ%= \n\t"
"LL%=: \n\t"
"movlpd xmm0, [edi] \n\t" //Copy from A
"movlpd xmm1, [esi] \n\t" //Copy from B
"punpckldq xmm0, xmm0 \n\t" //Copy low 32 bits to high 32 bits
"punpckldq xmm1, xmm1 \n\t" //Copy low 32 bits to high 32 bits
"pshuflw xmm1, xmm1, 0x14\n\t" //Shuffle Low 64 bits to get [Re Im Im Re]
"pmullw xmm1, xmm7 \n\t" //Multiply to get [Re Im -Im Re]
"pmaddwd xmm0, xmm1 \n\t" //Complex multiply and add
"packssdw xmm0, xmm0 \n\t" //Get into low 32 bits
"movd [edi], xmm0 \n\t" //Move into A
"add edi, 4 \n\t"
"add esi, 4 \n\t"
".att_syntax \n\t"
"loop LL%= \n\t"
".intel_syntax noprefix \n\t"
 
"ZZ%=: \n\t"
"EMMS \n\t"
".att_syntax \n\t"
:
: "m" (A), "m" (B), "m" (cnt), "m" (cnt1), "m" (cnt2)
: "%ecx", "%edi", "%esi"
);
 
}
 
 
void sse_cmuls(CPX *A, CPX *B, int32 cnt, int32 shift)
{
 
int32 cnt1;
int32 cnt2;
int32 round;
 
volatile int32 M[4] = {0xffff0001, 0x00010001, 0xffff0001, 0x00010001}; //{1,-1,1,1,1,-1,1,1};
 
cnt1 = cnt/4;
cnt2 = cnt-4*cnt1;
 
round = 1 << (shift-1);
 
__asm
(
".intel_syntax noprefix \n\t" //Set up for loop
"mov edi, [ebp+8] \n\t" //Address of A
"mov esi, [ebp+12] \n\t" //Address of B
"mov ecx, [ebp-12] \n\t" //Counter 1
"movupd xmm7,[ebp-36] \n\t" //Move the multiply thingie
"movss xmm6, [ebp+20] \n\t" //Move the round thingie
"movss xmm5, [ebp-20] \n\t" //Move the round thingie
"punpckldq xmm5, xmm5 \n\t"
"punpcklqdq xmm5, xmm5 \n\t"
"jecxz Z%= \n\t"
"L%=: \n\t"
"movlpd xmm0, [edi] \n\t" //Copy from A
"movlpd xmm1, [edi+8] \n\t" //Copy from A
"movlpd xmm3, [esi] \n\t" //Copy from B
"movlpd xmm4, [esi+8] \n\t" //Copy from B
"punpckldq xmm0, xmm0 \n\t" //Copy low 32 bits to high 32 bits
"punpckldq xmm1, xmm1 \n\t" //Copy low 32 bits to high 32 bits
"punpckldq xmm3, xmm3 \n\t" //Copy low 32 bits to high 32 bits
"punpckldq xmm4, xmm4 \n\t" //Copy low 32 bits to high 32 bits
"pshuflw xmm3, xmm3, 0x14 \n\t" //Shuffle Low 64 bits to get [Re Im Im Re]
"pshuflw xmm4, xmm4, 0x14 \n\t" //Shuffle Low 64 bits to get [Re Im Im Re]
"pshufhw xmm3, xmm3, 0x14 \n\t" //Shuffle High 64 bits to get [Re Im Im Re]
"pshufhw xmm4, xmm4, 0x14 \n\t" //Shuffle High 64 bits to get [Re Im Im Re]
"pmullw xmm3, xmm7 \n\t" //Multiply to get [Re Im -Im Re]
"pmullw xmm4, xmm7 \n\t" //Multiply to get [Re Im -Im Re]
"pmaddwd xmm0, xmm3 \n\t" //Complex multiply and add
"pmaddwd xmm1, xmm4 \n\t" //Complex multiply and add
"paddd xmm0, xmm5 \n\t" //Add in 2^(shift-1)
"paddd xmm1, xmm5 \n\t" //Add in 2^(shift-1)
"psrad xmm0, xmm6 \n\t" //Shift by X bits
"psrad xmm1, xmm6 \n\t" //Shift by X bits
"packssdw xmm0, xmm0 \n\t" //Get into low 64 bits
"packssdw xmm1, xmm1 \n\t" //Get into low 64 bits
"movlpd [edi], xmm0 \n\t" //Move into A
"movlpd [edi+8], xmm1 \n\t" //Move into A
"add edi, 16 \n\t" //Move in array
"add esi, 16 \n\t" //Move in array
".att_syntax \n\t"
"loop L%= \n\t"
".intel_syntax noprefix \n\t"
 
"Z%=: \n\t"
"mov ecx, [ebp-16] \n\t"
"jecxz ZZ%= \n\t"
"LL%=: \n\t"
"movlpd xmm0, [edi] \n\t" //Copy from A
"movlpd xmm1, [esi] \n\t" //Copy from B
"punpckldq xmm0, xmm0 \n\t" //Copy low 32 bits to high 32 bits
"punpckldq xmm1, xmm1 \n\t" //Copy low 32 bits to high 32 bits
"pshuflw xmm1, xmm1, 0x14\n\t" //Shuffle Low 64 bits to get [Re Im Im Re]
"pmullw xmm1, xmm7 \n\t" //Multiply to get [Re Im -Im Re]
"pmaddwd xmm0, xmm1 \n\t" //Complex multiply and add
"paddd xmm0, xmm5 \n\t" //Add in 2^(shift-1)
"psrad xmm0, xmm6 \n\t" //Shift by X bits
"packssdw xmm0, xmm0 \n\t" //Get into low 32 bits
"movd [edi], xmm0 \n\t" //Move into A
"add edi, 4 \n\t"
"add esi, 4 \n\t"
".att_syntax \n\t"
"loop LL%= \n\t"
".intel_syntax noprefix \n\t"
 
"ZZ%=: \n\t"
"EMMS \n\t"
".att_syntax \n\t"
:
: "m" (A), "m" (B), "m" (cnt), "m" (cnt1), "m" (cnt2), "m" (shift), "m" (round)
: "%ecx", "%edi", "%esi"
);
 
}
 
void sse_cmulsc(CPX *A, CPX *B, CPX *C, int32 cnt, int32 shift)
{
 
int32 cnt1;
int32 cnt2;
int32 round;
 
volatile int32 M[4] = {0xffff0001, 0x00010001, 0xffff0001, 0x00010001}; //{1,-1,1,1,1,-1,1,1};
 
cnt1 = cnt/4;
cnt2 = cnt-4*cnt1;
 
round = 1 << (shift-1);
 
__asm
(
".intel_syntax noprefix \n\t" //Set up for loop
"mov edi, [ebp+8] \n\t" //Address of A
"mov esi, [ebp+12] \n\t" //Address of B
"mov eax, [ebp+16] \n\t" //Address of C
"mov ecx, [ebp-12] \n\t" //Counter 1
"movupd xmm7,[ebp-36] \n\t" //Move the multiply thingie
"movss xmm6, [ebp+24] \n\t" //Move the round thingie
"movss xmm5, [ebp-20] \n\t" //Move the round thingie
"punpckldq xmm5, xmm5 \n\t"
"punpcklqdq xmm5, xmm5 \n\t"
"jecxz Z%= \n\t"
"L%=: \n\t"
"movlpd xmm0, [edi] \n\t" //Copy from A
"movlpd xmm1, [edi+8] \n\t" //Copy from A
"movlpd xmm3, [esi] \n\t" //Copy from B
"movlpd xmm4, [esi+8] \n\t" //Copy from B
"punpckldq xmm0, xmm0 \n\t" //Copy low 32 bits to high 32 bits
"punpckldq xmm1, xmm1 \n\t" //Copy low 32 bits to high 32 bits
"punpckldq xmm3, xmm3 \n\t" //Copy low 32 bits to high 32 bits
"punpckldq xmm4, xmm4 \n\t" //Copy low 32 bits to high 32 bits
"pshuflw xmm3, xmm3, 0x14 \n\t" //Shuffle Low 64 bits to get [Re Im Im Re]
"pshuflw xmm4, xmm4, 0x14 \n\t" //Shuffle Low 64 bits to get [Re Im Im Re]
"pshufhw xmm3, xmm3, 0x14 \n\t" //Shuffle High 64 bits to get [Re Im Im Re]
"pshufhw xmm4, xmm4, 0x14 \n\t" //Shuffle High 64 bits to get [Re Im Im Re]
"pmullw xmm3, xmm7 \n\t" //Multiply to get [Re Im -Im Re]
"pmullw xmm4, xmm7 \n\t" //Multiply to get [Re Im -Im Re]
"pmaddwd xmm0, xmm3 \n\t" //Complex multiply and add
"pmaddwd xmm1, xmm4 \n\t" //Complex multiply and add
"paddd xmm0, xmm5 \n\t" //Add in 2^(shift-1)
"paddd xmm1, xmm5 \n\t" //Add in 2^(shift-1)
"psrad xmm0, xmm6 \n\t" //Shift by X bits
"psrad xmm1, xmm6 \n\t" //Shift by X bits
"packssdw xmm0, xmm0 \n\t" //Get into low 64 bits
"packssdw xmm1, xmm1 \n\t" //Get into low 64 bits
"movlpd [eax], xmm0 \n\t" //Move into A
"movlpd [eax+8], xmm1 \n\t" //Move into A
"add edi, 16 \n\t" //Move in array
"add esi, 16 \n\t" //Move in array
"add eax, 16 \n\t"
".att_syntax \n\t"
"loop L%= \n\t"
".intel_syntax noprefix \n\t"
 
"Z%=: \n\t"
"mov ecx, [ebp-16] \n\t"
"jecxz ZZ%= \n\t"
"LL%=: \n\t"
"movlpd xmm0, [edi] \n\t" //Copy from A
"movlpd xmm1, [esi] \n\t" //Copy from B
"punpckldq xmm0, xmm0 \n\t" //Copy low 32 bits to high 32 bits
"punpckldq xmm1, xmm1 \n\t" //Copy low 32 bits to high 32 bits
"pshuflw xmm1, xmm1, 0x14\n\t" //Shuffle Low 64 bits to get [Re Im Im Re]
"pmullw xmm1, xmm7 \n\t" //Multiply to get [Re Im -Im Re]
"pmaddwd xmm0, xmm1 \n\t" //Complex multiply and add
"paddd xmm0, xmm5 \n\t" //Add in 2^(shift-1)
"psrad xmm0, xmm6 \n\t" //Shift by X bits
"packssdw xmm0, xmm0 \n\t" //Get into low 32 bits
"movd [eax], xmm0 \n\t" //Move into A
"add edi, 4 \n\t"
"add esi, 4 \n\t"
"add eax, 4 \n\t"
".att_syntax \n\t"
"loop LL%= \n\t"
".intel_syntax noprefix \n\t"
 
"ZZ%=: \n\t"
"EMMS \n\t"
".att_syntax \n\t"
:
: "m" (A), "m" (B), "m" (C), "m" (cnt), "m" (cnt1), "m" (cnt2), "m" (shift), "m" (round)
: "%eax", "%ecx", "%edi", "%esi"
);
 
}
 
 
void sse_cacc(CPX *A, MIX *B, int32 cnt, int32 *iaccum, int32 *baccum)
{
 
int32 cnt1;
int32 cnt2;
 
if(((int)A%16) || ((int)B%16))
{
 
cnt1 = cnt / 6;
cnt2 = (cnt - (6*cnt1));
 
__asm
(
".intel_syntax noprefix \n\t" //Set up for loop
"mov edi, [ebp+8] \n\t" //Address of A
"mov esi, [ebp+12] \n\t" //Address of B
"mov ecx, [ebp-12] \n\t" //Counter 1
"pxor xmm0, xmm0 \n\t" //Clear the running sum
"pxor mm0, mm0 \n\t" //Clear the running sum
"jecxz Z%= \n\t"
"L%=: \n\t"
" movlpd xmm1, [edi] \n\t" //load IF data
" movlpd xmm2, [edi+8] \n\t" //load IF data
" movlpd xmm3, [edi+16] \n\t" //load IF data
" movupd xmm4, [esi] \n\t" //load Sine data
" movupd xmm5, [esi+16] \n\t" //load Sine data
" movupd xmm6, [esi+32] \n\t" //load Sine data
" punpckldq xmm1, xmm1 \n\t" //copies bits 0..31 to 32..63 and bits 32..63 to 64..95 and 65..127
" punpckldq xmm2, xmm2 \n\t" //copies bits 0..63 to 64..127
" punpckldq xmm3, xmm3 \n\t" //copies bits 0..63 to 64..127
" pmaddwd xmm1, xmm4 \n\t" //multiply and add, result in xmm1
" pmaddwd xmm2, xmm5 \n\t" //multiply and add, result in xmm2
" pmaddwd xmm3, xmm6 \n\t" //multiply and add, result in xmm3
" paddd xmm0, xmm3 \n\t" //Add into accumulator (efficiently)
" paddd xmm1, xmm2 \n\t"
" paddd xmm0, xmm1 \n\t"
" add edi, 24 \n\t" //move in complex sine by 24 bytes
" add esi, 48 \n\t" //move in IF array by 48 bytes
".att_syntax \n\t"
"loop L%= \n\t"
".intel_syntax noprefix \n\t"
 
"Z%=: \n\t"
"mov ecx, [ebp-16] \n\t"
"jecxz ZZ%= \n\t"
"LL%=: \n\t"
" movd mm1, [edi] \n\t" //load IF data
" movq mm2, [esi] \n\t"
" punpckldq mm1, mm1 \n\t" //copy bottom 32 bits of IF data into high 32 bits
" pmaddwd mm1, mm2 \n\t" //perform mmx complex multiply
" paddd mm0, mm1 \n\t" //add into accumulator
" add edi, 4 \n\t" //move in complex sine by 4 bytes
" add esi, 8 \n\t" //move in IF array by 8 bytes
".att_syntax \n\t"
"loop LL%= \n\t" //Loop if not done
".intel_syntax noprefix \n\t"
 
"ZZ%=: \n\t"
"movdq2q mm1, xmm0 \n\t"
"punpckhqdq xmm0, xmm0 \n\t" //move bits 64..127 of xmm0 into 0..63 of xmm0
"movdq2q mm2, xmm0 \n\t"
"paddd mm0, mm1 \n\t" //add together
"paddd mm0, mm2 \n\t" //add" punpckldq xmm1, xmm1 \n\t" //copies bits 0..31 to 32..63 and bits 32..63 to 64..95 and 65..127 together
"mov eax, [ebp+20] \n\t"
"movd [eax], mm0 \n\t"
"punpckhdq mm0, mm0 \n\t"
"mov eax, [ebp+24] \n\t"
"movd [eax], mm0 \n\t"
"EMMS \n\t"
".att_syntax \n\t"
:
: "m" (A), "m" (B), "m" (cnt), "m" (iaccum), "m" (baccum), "m" (cnt1), "m" (cnt2)
: "%eax", "%ecx", "%edi", "%esi"
);//end __asm
}
else
{
 
cnt1 = cnt / 12;
cnt2 = (cnt - (12*cnt1));
 
__asm
(
".intel_syntax noprefix \n\t" //Set up for loop
"mov edi, [ebp+8] \n\t" //Address of A
"mov esi, [ebp+12] \n\t" //Address of B
"mov ecx, [ebp-12] \n\t" //Counter 1
"pxor xmm0, xmm0 \n\t" //Clear the running sum
"pxor mm0, mm0 \n\t" //Clear the running sum
"jecxz AZ%= \n\t"
"AL%=: \n\t"
" movlpd xmm1, [edi] \n\t" //load IF data
" movlpd xmm2, [edi+8] \n\t" //load IF data
" movlpd xmm3, [edi+16] \n\t" //load IF data
" movlpd xmm4, [edi+24] \n\t" //load IF data
" movlpd xmm5, [edi+32] \n\t" //load IF data
" movlpd xmm6, [edi+40] \n\t" //load IF data
" punpckldq xmm1, xmm1 \n\t" //copies bits 0..31 to 32..63 and bits 32..63 to 64..95 and 65..127
" punpckldq xmm2, xmm2 \n\t" //copies bits 0..63 to 64..127
" punpckldq xmm3, xmm3 \n\t" //copies bits 0..63 to 64..127
" punpckldq xmm4, xmm4 \n\t" //copies bits 0..63 to 64..127
" punpckldq xmm5, xmm5 \n\t" //copies bits 0..63 to 64..127
" punpckldq xmm6, xmm6 \n\t" //copies bits 0..63 to 64..127
" pmaddwd xmm1, [esi] \n\t" //multiply and add, result in xmm1
" pmaddwd xmm2, [esi+16] \n\t" //multiply and add, result in xmm2
" pmaddwd xmm3, [esi+32] \n\t" //multiply and add, result in xmm3
" pmaddwd xmm4, [esi+48] \n\t" //multiply and add, result in xmm4
" pmaddwd xmm5, [esi+64] \n\t" //multiply and add, result in xmm5
" pmaddwd xmm6, [esi+80] \n\t" //multiply and add, result in xmm6
" paddd xmm1, xmm2 \n\t" //Add into accumulator (efficiently)
" paddd xmm3, xmm4 \n\t"
" paddd xmm5, xmm6 \n\t"
" paddd xmm1, xmm3 \n\t"
" paddd xmm0, xmm5 \n\t"
" paddd xmm0, xmm1 \n\t"
" add edi, 48 \n\t" //move in complex sine by 56 bytes
" add esi, 96 \n\t" //move in IF array by 112 bytes
".att_syntax \n\t"
"loop AL%= \n\t" // Loop if not done
".intel_syntax noprefix \n\t"
"AZ%=: \n\t"
"mov ecx, [ebp-16] \n\t"
"jecxz AZZ%= \n\t"
"ALL%=: \n\t"
" movq mm1, [edi] \n\t" //load IF data
" punpckldq mm1, mm1 \n\t" //copy bottom 32 bits of IF data into high 32 bits
" pmaddwd mm1, [esi] \n\t" //perform mmx complex multiply
" paddd mm0, mm1 \n\t" //add into accumulator
" add edi, 4 \n\t" //move in complex sine by 4 bytes
" add esi, 8 \n\t" //move in IF array by 8 bytes
".att_syntax \n\t"
"loop ALL%= \n\t"
".intel_syntax noprefix \n\t"
"AZZ%=: \n\t"
"movdq2q mm1, xmm0 \n\t"
"punpckhqdq xmm0, xmm0 \n\t" //move bits 64..127 of xmm0 into 0..63 of xmm0
"movdq2q mm2, xmm0 \n\t"
"paddd mm0, mm1 \n\t" //add together
"paddd mm0, mm2 \n\t" //add together
"mov eax, [ebp+20] \n\t"
"movd [eax], mm0 \n\t"
"punpckhdq mm0, mm0 \n\t"
"mov eax, [ebp+24] \n\t"
"movd [eax], mm0 \n\t"
"EMMS \n\t"
".att_syntax \n\t"
:
: "m" (A), "m" (B), "m" (cnt), "m" (iaccum), "m" (baccum), "m" (cnt1), "m" (cnt2)
: "%eax", "%ecx", "%edi", "%esi"
);//end __asm
 
}//end if
 
 
}
 
//!< A must hold baseband data, E,P,L must hold PRN data
void sse_prn_accum(CPX *A, CPX *E, CPX *P, CPX *L, int32 cnt, CPX *accum)
{
 
int32 cnt1;
int32 cnt2;
 
cnt1 = cnt / 2;
cnt2 = (cnt - (2*cnt1));
cnt1 = 0;
cnt2 = cnt;
 
__asm
(
".intel_syntax noprefix \n\t" //Set up for loop
"mov esi, [ebp+8] \n\t" //Address of A
"mov eax, [ebp+12] \n\t" //Address of E
"mov ebx, [ebp+16] \n\t" //Address of P
"mov edx, [ebp+20] \n\t" //Address of L
"mov ecx, [ebp-12] \n\t" //Counter 1
"pxor mm5, mm5 \n\t" //Clear the running sum for E
"pxor mm6, mm6 \n\t" //Clear the running sum for P
"pxor mm7, mm7 \n\t" //Clear the running sum for L
"jecxz Z%= \n\t"
"L%=: \n\t"
" movq mm0, [esi] \n\t" //load IF data
" movq mm1, [eax] \n\t" //load E data
" movq mm2, [ebx] \n\t" //load P data
" movq mm3, [edx] \n\t" //load L data
" movq mm4, mm0 \n\t" //load IF data
" pand mm0, mm1 \n\t" //mask it
" pandn mm1, mm4 \n\t" //mask it
" paddsw mm5, mm1 \n\t" //add
" psubsw mm5, mm0 \n\t" //subtract
" movq mm0, mm4 \n\t" //load IF data
" pand mm0, mm2 \n\t" //mask it
" pandn mm2, mm4 \n\t" //mask it
" paddsw mm6, mm2 \n\t" //add
" psubsw mm6, mm0 \n\t" //subtract
" movq mm0, mm4 \n\t" //load IF data
" pand mm0, mm3 \n\t" //mask it
" pandn mm3, mm4 \n\t" //mask it
" paddsw mm7, mm3 \n\t" //add
" psubsw mm7, mm0 \n\t" //subtract
" add esi, 8 \n\t" //move in complex sine by 24 bytes
" add eax, 8 \n\t" //move in IF array by 48 bytes
" add ebx, 8 \n\t" //move in IF array by 48 bytes
" add edx, 8 \n\t" //move in IF array by 48 bytes
".att_syntax \n\t"
"loop L%= \n\t"
".intel_syntax noprefix \n\t"
 
"Z%=: \n\t"
"mov ecx, [ebp-16] \n\t"
"jecxz ZZ%= \n\t"
"LL%=: \n\t"
" movd mm0, [esi] \n\t" //load IF data
" movd mm1, [eax] \n\t" //load E data
" movd mm2, [ebx] \n\t" //load P data
" movd mm3, [edx] \n\t" //load L data
" movq mm4, mm0 \n\t" //load IF data
" pand mm0, mm1 \n\t" //mask it
" pandn mm1, mm4 \n\t" //mask it
" paddsw mm5, mm1 \n\t" //add
" psubsw mm5, mm0 \n\t" //subtract
" movq mm0, mm4 \n\t" //load IF data
" pand mm0, mm2 \n\t" //mask it
" pandn mm2, mm4 \n\t" //mask it
" paddsw mm6, mm2 \n\t" //add
" psubsw mm6, mm0 \n\t" //subtract
" movq mm0, mm4 \n\t" //load IF data
" pand mm0, mm3 \n\t" //mask it
" pandn mm3, mm4 \n\t" //mask it
" paddsw mm7, mm3 \n\t" //add
" psubsw mm7, mm0 \n\t" //subtract
" add esi, 4 \n\t" //move in complex sine by 24 bytes
" add eax, 4 \n\t" //move in IF array by 48 bytes
" add ebx, 4 \n\t" //move in IF array by 48 bytes
" add edx, 4 \n\t" //move in IF array by 48 bytes
".att_syntax \n\t"
"loop LL%= \n\t" //Loop if not done
".intel_syntax noprefix \n\t"
 //Loop if not done
"ZZ%=: \n\t"
"mov esi, [ebp+28] \n\t"
"movq mm0, mm5 \n\t"
"punpckhdq mm0, mm0 \n\t"
"paddsw mm5, mm0 \n\t"
"movd [esi], mm5 \n\t"
"add esi, 4 \n\t"
"movq mm0, mm6 \n\t"
"punpckhdq mm0, mm0 \n\t"
"paddsw mm6, mm0 \n\t"
"movd [esi], mm6 \n\t"
"add esi, 4 \n\t"
"movq mm0, mm7 \n\t"
"punpckhdq mm0, mm0 \n\t"
"paddsw mm7, mm0 \n\t"
"movd [esi], mm7 \n\t"
"EMMS \n\t"
".att_syntax \n\t"
:
: "m" (A), "m" (E), "m" (P), "m" (L), "m" (cnt), "m" (accum), "m" (cnt1), "m" (cnt2)
: "%eax", "%ebx", "%ecx", "%edx", "%esi"
);//end __asm
 
}
 
 
 
//!< A must hold baseband data, E,P,L must hold PRN data
void sse_prn_accum_new(CPX *A, MIX *E, MIX *P, MIX *L, int32 cnt, CPX_ACCUM *accum)
{
 
__asm
(
".intel_syntax noprefix \n\t" //Set up for loop
"mov esi, [ebp+8] \n\t" //Address of A
"mov eax, [ebp+12] \n\t" //Address of E
"mov ebx, [ebp+16] \n\t" //Address of P
"mov edx, [ebp+20] \n\t" //Address of L
"mov ecx, [ebp+24] \n\t" //Value of cnt
"pxor mm5, mm5 \n\t" //Clear the running sum for E
"pxor mm6, mm6 \n\t" //Clear the running sum for P
"pxor mm7, mm7 \n\t" //Clear the running sum for L
"jecxz Z%= \n\t"
"L%=: \n\t"
" movd mm0, [esi] \n\t" //load IF data
" movq mm1, [eax] \n\t" //load E data
" movq mm2, [ebx] \n\t" //load P data
" movq mm3, [edx] \n\t" //load L data
" punpckldq mm0, mm0 \n\t" //copy low 32 bits to high 32 pits
" pmaddwd mm1, mm0 \n\t" //complex multiply E by IF
" pmaddwd mm2, mm0 \n\t" //complex multiply P by IF
" pmaddwd mm3, mm0 \n\t" //complex multiply L by IF
" paddd mm5, mm1 \n\t" //add into E accumulator
" paddd mm6, mm2 \n\t" //add into E accumulator
" paddd mm7, mm3 \n\t" //add into E accumulator
" add esi, 4 \n\t" //move in baseband data by one sample (4 bytes)
" add eax, 8 \n\t" //move in PRN-E array by one sample (8 bytes)
" add ebx, 8 \n\t" //move in PRN-P array by one sample (8 bytes)
" add edx, 8 \n\t" //move in PRN-L array by one sample (8 bytes)
".att_syntax \n\t"
"loop L%= \n\t"
".intel_syntax noprefix \n\t"
 
"Z%=: \n\t"
"mov esi, [ebp+28] \n\t"
"movq [esi], mm5 \n\t"
"add esi, 8 \n\t"
"movq [esi], mm6 \n\t"
"add esi, 8 \n\t"
"movq [esi], mm7 \n\t"
"EMMS \n\t"
".att_syntax \n\t"
:
: "m" (A), "m" (E), "m" (P), "m" (L), "m" (cnt), "m" (accum)
: "%eax", "%ebx", "%ecx", "%edx", "%esi"
);//end __asm
 
}