-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlucas.mac
2752 lines (2624 loc) · 96.4 KB
/
lucas.mac
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
; Copyright 1995-2020 - Mersenne Research, Inc. All rights reserved
; Author: George Woltman
; Email: [email protected]
;
; These macros efficiently implement the basic building blocks of the
; fast fourier transform used to quickly multiply numbers.
;
;; The FFT macros multiply by COS + SIN i. The inverse FFT macros
;; multiply by COS - SIN i. The second multiplication "undoes"
;; the first multiplication because (COS + SIN i)(COS - SIN i) equals
;; (COS*COS + SIN*SIN) + (COS*SIN - COS*SIN) i which equals 1!
; *************** dispatch macros ******************
; Take macro name and three distance values and call that
; macro with all eight addresses.
disp MACRO mac, d1, d2, d4
dispc mac, d1, d2, d4, 0
ENDM
; Take macro name and three distance values and call that
; macro with all eight addresses. Add a constant to all
; eight addresses.
dispc MACRO mac, d1, d2, d4, c
dispc1 mac,%(d1),%(d2),%(d4),%(c)
ENDM
dispc1 MACRO mac, d1, d2, d4, c
dispi mac,c,%(d1+c),%(d2+c),%(d2+d1+c),%(d4+c),%(d4+d1+c),%(d4+d2+c),%(d4+d2+d1+c)
ENDM
; Take macro name and eight distance values and call that
; macro with all eight addresses.
dispi MACRO mac, d1, d2, d3, d4, d5, d6, d7, d8
mac <Q[esi+d1]>,<Q[esi+d2]>,<Q[esi+d3]>,<Q[esi+d4]>,<Q[esi+d5]>,<Q[esi+d6]>,<Q[esi+d7]>,<Q[esi+d8]>
ENDM
; Macro to call the cp_ macros
cp_disp MACRO mac, d1, d2, d4, e1, e2, e4
cp1 mac,esi,%(d1),%(d2),%(d4),ecx,%(e1),%(e2),%(e4)
ENDM
cp1 MACRO mac, src, d1, d2, d4, dst, e1, e2, e4
cp_&mac <Q[src]>,<Q[src+d1]>,<Q[src+d2]>,<Q[src+d2+d1]>,<Q[src+d4]>,<Q[src+d4+d1]>,<Q[src+d4+d2]>,<Q[src+d4+d2+d1]>,<Q[dst]>,<Q[dst+e1]>,<Q[dst+e2]>,<Q[dst+e2+e1]>,<Q[dst+e4]>,<Q[dst+e4+e1]>,<Q[dst+e4+e2]>,<Q[dst+e4+e2+e1]>
ENDM
;; The FFT and inverse FFT macros were written for a different memory
;; rearranging scheme. Since macro comments still refer to the old scheme,
;; the comments for fstp are wrong. This table maps the old scheme to
;; the new scheme.
;;
;; fft:
;; Old four complex output numbers are: R1 + R2i, R3 + R4i, R5 + R6i, R7 + R8i
;; New four complex output numbers are: R1 + R5i, R2 + R6i, R3 + R7i, R4 + R8i
;;
;; unfft:
;; Old four complex output numbers are: R1 + R5i, R2 + R6i, R3 + R7i, R4 + R8i
;; New four complex output numbers are: R1 + R2i, R3 + R4i, R5 + R6i, R7 + R8i
; *************** eight-reals-first-fft macro ******************
; This macro takes eight real values and performs the initial three levels
; of the FFT process.
eight_reals_first_fft MACRO R1,R2,R3,R4,R5,R6,R7,R8
eight_reals_fft_cmn <R1>,<R2>,<R3>,<R4>,<R5>,<R6>,<R7>,<R8>,ebx
ENDM
; *************** eight-reals-fft macro ******************
; This macro takes eight real values and performs three levels of the
; FFT process.
eight_reals_fft MACRO R1,R2,R3,R4,R5,R6,R7,R8
eight_reals_fft_cmn <R1>,<R2>,<R3>,<R4>,<R5>,<R6>,<R7>,<R8>,0
ENDM
; *************** eight-reals-fft-cmn macro ******************
; Common macro takes eight real values and performs three levels of the
; FFT process.
; NOTE: Optimal = 52 clocks, Actual = 52 clocks
eight_reals_fft_cmn MACRO R1,R2,R3,R4,R5,R6,R7,R8,off
fld R1[off] ;; R1
fadd R5[off] ;; new R1 = R1 + R5
fld R1[off] ;; R1
fsub R5[off] ;; new R5 = R1 - R5
fld R3[off] ;; R3
fadd R7[off] ;; new R3 = R3 + R7
fld R3[off] ;; R3
fsub R7[off] ;; new R7 = R3 - R7
fld R2[off] ;; R2
fadd R6[off] ;; new R2 = R2 + R6
fld R2[off] ;; R2
fsub R6[off] ;; new R6 = R2 - R6
fld R4[off] ;; R4
fsub R8[off] ;; new R8 = R4 - R8
fxch st(4) ;; R3,R6,R2,R7,R8,R5,R1
fsub st(6), st ;; R1 = R1 - R3 (new R3)
fadd st, st ;; R3 = R3 * 2
fld R4[off] ;; R4
fadd R8[off] ;; new R4 = R4 + R8
;; R4,R3,R6,R2,R7,R8,R5,R1
fxch st(2) ;; R6,R3,R4,R2,R7,R8,R5,R1
fmul SQRTHALF ;; R6 = R6 * square root of 1/2
fxch st(1) ;; R3,R6,R4,R2,R7,R8,R5,R1
fadd st, st(7) ;; R3 = R1 + R3 (new R1)
fxch st(5) ;; R8,R6,R4,R2,R7,R3,R5,R1
fmul SQRTHALF ;; R8 = R8 * square root of 1/2
fxch st(2) ;; R4,R6,R8,R2,R7,R3,R5,R1
fsub st(3), st ;; R2 = R2 - R4 (new and final R4)
fadd st, st ;; R4 = R4 * 2
fxch st(2) ;; R8,R6,R4,R2,R7,R3,R5,R1
fsub st(1), st ;; R6 = R6 - R8 (Real part)
fadd st, st ;; R8 = R8 * 2
fxch st(3) ;; R2,R6,R4,R8,R7,R3,R5,R1
fadd st(2), st ;; R4 = R2 + R4 (new R2)
;; R4,R6,R2,R8,R7,R1,R5,R3
fxch st(1) ;; R6,R4,R2,R8,R7,R1,R5,R3
fsub st(6), st ;; R5 = R5 - R6 (Real part - final R7)
fadd st(3), st ;; R8 = R6 + R8 (Imaginary part)
fadd st, st ;; R6 = R6 * 2
fxch st(2) ;; R2,R4,R6,R8,R7,R1,R5,R3
fsub st(5), st ;; R1 = R1 - R2 (final R2)
fadd st, st ;; R2 = R2 * 2
fxch st(3) ;; R8,R4,R6,R2,R7,R1,R5,R3
fsub st(4), st ;; R7 = R7 - R8 (Imaginary - final R8)
fadd st, st ;; R8 = R8 * 2
fxch st(6) ;; R5,R4,R6,R2,R7,R1,R8,R3
fadd st(2), st ;; R6 = R5 + R6 (Real part - final R5)
fxch st(5) ;; R1,R4,R6,R2,R7,R5,R8,R3
fadd st(3), st ;; R2 = R1 + R2 (final R1)
fxch st(4) ;; R7,R4,R6,R2,R1,R5,R8,R3
fadd st(6), st ;; R8 = R7 + R8 (Imaginary - final R6)
;; Final - R8,R4,R5,R1,R2,R7,R6,R3
fstp R8
fstp R6
fstp R3
fstp R1
fstp R5
fstp R4
fstp R7
fstp R2
ENDM
; *************** eight-reals-last-unfft macro ******************
; This macro takes eight real values and performs the final three levels
; of the inverse FFT process.
; NOTE: input R2 is one-half of what it should be because there is no
; UNFFT macro for the "nop" step.
; NOTE: input R1 is one-half of what it should be because the eight_reals_fft
; macro produces the R1 inputs.
; NOTE: Rather than doing the double for the nop step of R3 through R8 we
; simply produce eight values that are one-half of what you would expect.
eight_reals_last_unfft MACRO R1,R2,R3,R4,R5,R6,R7,R8
eight_reals_unfft R1,R2,R3,R4,R5,R6,R7,R8
ENDM
; *************** eight-reals-unfft macro ******************
; This macro takes eight real values and performs three levels of the
; inverse FFT process.
; NOTE: input R2 is one-half of what it should be because there is no
; UNFFT macro for the "nop" step.
; NOTE: input R1 is one-half of what it should be because the eight_reals_fft
; macro produces the R1 inputs.
; NOTE: Rather than doing the double for the nop step of R3 through R8 we
; simply produce eight values that are one-half of what you would expect.
; NOTE: Optimal = 50 clocks, Actual = 50 clocks
eight_reals_unfft MACRO R1,R2,R3,R4,R5,R6,R7,R8
fld R5 ;; R5
fsub R7 ;; new R6 = R5 - R7
fld R6 ;; R6
fsub R8 ;; new R8 = R6 - R8
fld R6 ;; R6
fadd R8 ;; new R7 = R6 + R8
fld R5 ;; R5
fadd R7 ;; new R5 = R5 + R7
fld R1 ;; R1
fadd R2 ;; new R1 = R1 + R2
fld R1 ;; R1
fsub R2 ;; new R2 = R1 - R2
;; R2,R1,R5,R7,R8,R6
fxch st(5) ;; R6,R1,R5,R7,R8,R2
fsub st(4), st ;; R8 = R8 - R6
fadd st, st ;; R6 = R6 * 2
fld st(1) ;; R1,R6,R1,R5,R7,R8,R2
fsub R3 ;; new R3 = R1 - R3
fxch st(2) ;; R1,R6,R3,R5,R7,R8,R2
fadd R3 ;; new R1 = R1 + R3
fxch st(5) ;; R8,R6,R3,R5,R7,R1,R2
fadd st(1), st ;; R6 = R6 + R8
fmul SQRTHALF ;; R8 = R8 * square root of 1/2
fld st(6) ;; R2,R8,R6,R3,R5,R7,R1,R2
fsub R4 ;; new R4 = R2 - R4
fxch st(7) ;; R2,R8,R6,R3,R5,R7,R1,R4
fadd R4 ;; new R2 = R2 + R4
fxch st(2) ;; R6,R8,R2,R3,R5,R7,R1,R4
fmul SQRTHALF ;; R6 = R6 * square root of 1/2
fxch st(4) ;; R5,R8,R2,R3,R6,R7,R1,R4
fsub st(6), st ;; R1 = R1 - R5 (new R5)
fadd st, st ;; R5 = R5 * 2
fxch st(4) ;; R6,R8,R2,R3,R5,R7,R1,R4
fsub st(2), st ;; R2 = R2 - R6 (new R6)
fadd st, st ;; R6 = R6 * 2
fxch st(5) ;; R7,R8,R2,R3,R5,R6,R1,R4
fsub st(3), st ;; R3 = R3 - R7 (new R7)
fadd st, st ;; R7 = R7 * 2
fxch st(1) ;; R8,R7,R2,R3,R5,R6,R1,R4
fsub st(7), st ;; R4 = R4 - R8 (new R8)
fadd st, st ;; R8 = R8 * 2
fxch st(6) ;; R1,R7,R2,R3,R5,R6,R8,R4
fadd st(4), st ;; R5 = R1 + R5 (new R1)
fxch st(2) ;; R2,R7,R1,R3,R5,R6,R8,R4
fadd st(5), st ;; R6 = R2 + R6 (new R2)
fxch st(1) ;; R7,R2,R1,R3,R5,R6,R8,R4
fadd st, st(3) ;; R7 = R3 + R7 (new R3)
fxch st(7) ;; R4,R2,R1,R3,R5,R6,R8,R7
fadd st(6), st ;; R8 = R4 + R8 (new R4)
;; R8,R6,R5,R7,R1,R2,R4,R3
fstp R8
fstp R4
fstp R2
fstp R6
fstp R1
fstp R3
fstp R7
fstp R5
ENDM
; *************** eight-reals-fft-1 macro ******************
; Take eight real numbers and perform one level of FFT.
eight_reals_fft_1 MACRO R1,R2,R3,R4,R5,R6,R7,R8
fld R1 ;; R1
fadd R5 ;; R1 = R1 + R5
fld R1 ;; R1
fsub R5 ;; R5 = R1 - R5
fld R2 ;; R2
fadd R6 ;; R2 = R2 + R6
fld R2 ;; R2
fsub R6 ;; R6 = R2 - R6
fld R3 ;; R3
fadd R7 ;; R3 = R3 + R7
fld R3 ;; R3
fsub R7 ;; R7 = R3 - R7
fld R4 ;; R4
fadd R8 ;; R4 = R4 + R8
fld R4 ;; R4
fsub R8 ;; R8 = R4 - R8
fxch st(7) ;; R1,R4,R7,R3,R6,R2,R5,R8
fstp R1
fstp R4
fstp R7
fstp R3
fstp R6
fstp R2
fstp R5
fstp R8
ENDM
; *************** eight-reals-unfft-1 macro ******************
; Perform one level of inverse FFT producing eight real numbers
eight_reals_unfft_1 MACRO R1,R2,R3,R4,R5,R6,R7,R8
fld R1 ;; R1
fadd R5 ;; R1 = R1 + R5
fld R1 ;; R1
fsub R5 ;; R5 = R1 - R5
fld R2 ;; R2
fadd R6 ;; R2 = R2 + R6
fld R2 ;; R2
fsub R6 ;; R6 = R2 - R6
fld R3 ;; R3
fadd R7 ;; R3 = R3 + R7
fld R3 ;; R3
fsub R7 ;; R7 = R3 - R7
fld R4 ;; R4
fadd R8 ;; R4 = R4 + R8
fld R4 ;; R4
fsub R8 ;; R8 = R4 - R8
fxch st(7) ;; R1,R4,R7,R3,R6,R2,R5,R8
fstp R1
fstp R4
fstp R7
fstp R3
fstp R6
fstp R2
fstp R5
fstp R8
ENDM
; *************** eight-reals-fft-2 macro ******************
; Take eight real numbers and perform two levels of FFT.
eight_reals_fft_2 MACRO R1,R2,R3,R4,R5,R6,R7,R8
fld R1 ;; R1
fadd R5 ;; R1 = R1 + R5
fld R1 ;; R1
fsub R5 ;; R5 = R1 - R5
fld R2 ;; R2
fadd R6 ;; R2 = R2 + R6
fld R2 ;; R2
fsub R6 ;; R6 = R2 - R6
fld R3 ;; R3
fadd R7 ;; R3 = R3 + R7
fld R3 ;; R3
fsub R7 ;; R7 = R3 - R7
fld R4 ;; R4
fadd R8 ;; R4 = R4 + R8
fld R4 ;; R4
fsub R8 ;; R8 = R4 - R8
fxch st(3) ;; R3,R4,R7,R8,R6,R2,R5,R1
fsub st(7), st ;; R1 = R1 - R3 (final R3)
fadd st, st ;; R3 = R3 * 2
fxch st(1) ;; R4,R3,R7,R8,R6,R2,R5,R1
fsub st(5), st ;; R2 = R2 - R4 (final R4)
fadd st, st ;; R4 = R4 * 2
fxch st(7) ;; R1,R3,R7,R8,R6,R2,R5,R4
fadd st(1), st ;; R3 = R1 + R3 (final R1)
fxch st(5) ;; R2,R3,R7,R8,R6,R1,R5,R4
fadd st(7), st ;; R4 = R2 + R4 (final R2)
;; R4,R1,R7,R8,R6,R3,R5,R2
fstp R6
fstp R1
fstp R7
fstp R8
fstp R4
fstp R5
fstp R3
fstp R2
ENDM
; *************** eight-reals-unfft-2 macro ******************
; Perform two level of inverse FFT producing eight real numbers
eight_reals_unfft_2 MACRO R1,R2,R3,R4,R5,R6,R7,R8
fld R1 ;; R1
fadd R3 ;; R1 = R1 + R3
fld R1 ;; R1
fsub R3 ;; R3 = R1 - R3
fld R2 ;; R2
fadd R4 ;; R2 = R2 + R4
fld R2 ;; R2
fsub R4 ;; R4 = R2 - R4
;; No-op on R5 - R8
fld R5 ;; R5,R4,R2,R3,R1
fadd st, st(4) ;; R5 = R1 + R5 (final R1)
fxch st(4) ;; R1,R4,R2,R3,R5
fsub R5 ;; R1 = R1 - R5 (final R5)
fld R7 ;; R7,R1,R4,R2,R3,R5
fadd st, st(4) ;; R7 = R3 + R7 (final R3)
fxch st(4) ;; R3,R1,R4,R2,R7,R5
fsub R7 ;; R3 = R3 - R7 (final R7)
fld R6 ;; R6,R3,R1,R4,R2,R7,R5
fadd st, st(4) ;; R6 = R2 + R6 (final R2)
fxch st(4) ;; R2,R3,R1,R4,R6,R7,R5
fsub R6 ;; R2 = R2 - R6 (final R6)
fld R8 ;; R8,R2,R3,R1,R4,R6,R7,R5
fadd st, st(4) ;; R8 = R4 + R8 (final R4)
fxch st(4) ;; R4,R2,R3,R1,R8,R6,R7,R5
fsub R8 ;; R4 = R4 - R8 (final R8)
;; R8,R6,R7,R5,R4,R2,R3,R1
fstp R8
fstp R4
fstp R7
fstp R3
fstp R6
fstp R2
fstp R5
fstp R1
ENDM
; *************** four_real_four_semireal_fft macro ******************
; Take four real and semi-real numbers and perform two levels of the FFT.
; NOTE: Optimal = 40 clocks, Actual = 40 clocks
four_real_four_semireal_fft MACRO R1,R2,R3,R4,R5,R6,R7,R8
cp_four_real_four_semireal_fft R1,R2,R3,R4,R5,R6,R7,R8,R1,R2,R3,R4,R5,R6,R7,R8
ENDM
four_real_four_semireal_first_fft MACRO R1,R2,R3,R4,R5,R6,R7,R8
cp_four_real_four_semireal_fft R1[ebx],R2[ebx],R3[ebx],R4[ebx],R5[ebx],R6[ebx],R7[ebx],R8[ebx],R1,R2,R3,R4,R5,R6,R7,R8
ENDM
cp_four_real_four_semireal_fft MACRO R1,R2,R3,R4,R5,R6,R7,R8,D1,D2,D3,D4,D5,D6,D7,D8
fld R6 ;; R6
fmul SQRTHALF ;; R6 = R6 * square root of 1/2
fld R8 ;; R8
fmul SQRTHALF ;; R8 = R8 * square root of 1/2
fld R1 ;; R1
fadd R3 ;; new R1 = R1 + R3
fld R2 ;; R2
fadd R4 ;; new R2 = R2 + R4
fxch st(2) ;; R8,R1,R2,R6
fsub st(3), st ;; R6 = R6 - R8 (Real part)
fadd st, st ;; R8 = R8 * 2
fld R1 ;; R1
fsub R3 ;; new R3 = R1 - R3 (final R3)
fld R2 ;; R2
fsub R4 ;; new R4 = R2 - R4 (final R4)
fxch st(5) ;; R6,R3,R8,R1,R2,R4
fadd st(2), st ;; R8 = R6 + R8 (Imaginary part)
fxch st(4) ;; R2,R3,R8,R1,R6,R4
fsub st(3), st ;; R1 = R1 - R2 (final R2)
fadd st, st ;; R2 = R2 * 2
fld R5 ;; R5,R2,R3,R8,R1,R6,R4
fxch st(5) ;; R6,R2,R3,R8,R1,R5,R4
fsub st(5), st ;; R5 = R5 - R6 (final R7)
fadd R5 ;; R6 = R5 + R6 (final R5)
fld R7 ;; R7,R6,R2,R3,R8,R1,R5,R4
fxch st(4) ;; R8,R6,R2,R3,R7,R1,R5,R4
fsub st(4), st ;; R7 = R7 - R8 (final R8)
fadd R7 ;; R8 = R7 + R8 (final R6)
fxch st(5) ;; R1,R6,R2,R3,R7,R8,R5,R4
fadd st(2), st ;; R2 = R1 + R2 (final R1)
;; R2,R5,R1,R3,R8,R6,R7,R4
fstp D5
fstp D3
fstp D1
fstp D2
fstp D8
fstp D7
fstp D4
fstp D6
ENDM
; *************** four_real_four_semireal with square macro ******************
; Take four real and semi-real numbers and perform two levels of the FFT.
; Then square the FFT results and perform two levels of inverse FFT.
; NOTE: This will be called at most once per squaring so speed is
; pretty much irrelevant.
four_real_four_semireal_square MACRO R1,R2,R3,R4,R5,R6,R7,R8
mult7 esi, esi ;; Do ZPAD multiplies
fld R1 ;; R1
fld R3 ;; R3,R1
fsub st(1), st ;; R1 = R1 - R3 (new R3)
fadd st, st ;; R3 = R3 * 2
fld R6 ;; R6,R3,R1
fmul SQRTHALF ;; R6 = R6 * square root of 1/2
fxch st(1) ;; R3,R6,R1
fadd st, st(2) ;; R3 = R1 + R3 (new R1)
fld R8 ;; R8,R3,R6,R1
fmul SQRTHALF ;; R8 = R8 * square root of 1/2
fld R2 ;; R2,R8,R3,R6,R1
fld R4 ;; R4,R2,R8,R3,R6,R1
fsub st(1), st ;; R2 = R2 - R4 (new and final R4)
fadd st, st ;; R4 = R4 * 2
fxch st(2) ;; R8,R2,R4,R3,R6,R1
fsub st(4), st ;; R6 = R6 - R8 (Real part)
fadd st, st ;; R8 = R8 * 2
fxch st(2) ;; R4,R2,R8,R3,R6,R1
fadd st, st(1) ;; R4 = R2 + R4 (new R2)
;; R2,R4,R8,R1,R6,R3
fld R5 ;; R5,R2,R4,R8,R1,R6,R3
fxch st(5) ;; R6,R2,R4,R8,R1,R5,R3
fadd st(3), st ;; R8 = R6 + R8 (Imaginary part)
fsub st(5), st ;; R5 = R5 - R6 (Real part - final R7)
fadd st, st ;; R6 = R6 * 2
fxch st(1) ;; R2,R6,R4,R8,R1,R5,R3
fsub st(4), st ;; R1 = R1 - R2 (final R2)
fadd st, st ;; R2 = R2 * 2
fld R7 ;; R7,R2,R6,R4,R8,R1,R5,R3
fxch st(4) ;; R8,R2,R6,R4,R7,R1,R5,R3
fsub st(4), st ;; R7 = R7 - R8 (Imaginary - final R8)
fadd st, st ;; R8 = R8 * 2
fxch st(2) ;; R6,R2,R8,R4,R7,R1,R5,R3
fadd st, st(6) ;; R6 = R5 + R6 (Real part - final R5)
fxch st(1) ;; R2,R6,R8,R4,R7,R1,R5,R3
fadd st, st(5) ;; R2 = R1 + R2 (final R1)
fxch st(2) ;; R8,R6,R2,R4,R7,R1,R5,R3
fadd st, st(4) ;; R8 = R7 + R8 (Imaginary - final R6)
;; R6,R5,R1,R4,R8,R2,R7,R3
fxch st(2) ;; R1,R5,R6,R4,R8,R2,R7,R3
fmul st, st ;; R1 = R1 * R1
fst QWORD PTR [esi-16] ;; Save product of sum of FFT values
fmul HALF ;; Mul by HALF (see eight_reals_unfft)
fxch st(5) ;; R2,R5,R6,R4,R8,R1,R7,R3
fmul st, st ;; R2 = R2 * R2
fmul HALF ;; Mul by HALF (see eight_reals_unfft)
fstp R2 ;; R5,R6,R4,R8,R1,R7,R3
fld st(6) ;; TEMP = R3
fxch st(3) ;; R4,R5,R6,TEMP,R8,R1,R7,R3
fsub st(3), st ;; TEMP = TEMP - R4 (R3-R4)
fadd st, st ;; R4 = R4 * 2
fmul st(7), st ;; R3 = R3 * R4 (new R4)
fadd st, st(3) ;; R4 = R4 + TEMP (R3+R4)
fmulp st(3), st ;; TEMP = R4 * TEMP (new R3)
;; R5,R6,R3,R8,R1,R7,R4
fld st ;; TEMP = R5
fxch st(2) ;; R6,R5,TEMP,R3,R8,R1,R7,R4
fsub st(2), st ;; TEMP = TEMP - R6 (R5-R6)
fadd st, st ;; R6 = R6 * 2
fmul st(1), st ;; R5 = R5 * R6 (new R6)
fadd st, st(2) ;; R6 = R6 + TEMP (R5+R6)
fmulp st(2), st ;; TEMP = R6 * TEMP (new R5)
;; R6,R5,R3,R8,R1,R7,R4
fld st(5) ;; TEMP = R7
fxch st(4) ;; R8,R6,R5,R3,TEMP,R1,R7,R4
fsub st(4), st ;; TEMP = TEMP - R8 (R7-R8)
fadd st, st ;; R8 = R8 * 2
fmul st(6), st ;; R7 = R7 * R8 (new R8)
fadd st, st(4) ;; R8 = R8 + TEMP (R7+R8)
fmulp st(4), st ;; TEMP = R8 * TEMP (new R7)
;; R6,R5,R3,R7,R1,R8,R4
fld R2
fsub st(5), st ;; R1 = R1 - R2 (new R2)
fadd st, st ;; R2 = R2 * 2
fadd st, st(5) ;; R2 = R1 + R2 (new R1)
fxch st(3) ;; R3,R6,R5,R2,R7,R1,R8,R4
;; fadd st, st ;; R3 = R3 * 2
fxch st(7) ;; R4,R6,R5,R2,R7,R1,R8,R3
;; fadd st, st ;; R4 = R4 * 2
fxch st(4) ;; R7,R6,R5,R2,R4,R1,R8,R3
fsub st(2), st ;; R5 = R5 - R7 (new R6)
fadd st, st ;; R7 = R7 * 2
fadd st, st(2) ;; R7 = R5 + R7 (new R5)
fxch st(6) ;; R8,R6,R5,R2,R4,R1,R7,R3
fsub st(1), st ;; R6 = R6 - R8 (new R8)
fadd st, st ;; R8 = R8 * 2
fadd st, st(1) ;; R8 = R6 + R8 (new R7)
;; R7,R8,R6,R1,R4,R2,R5,R3
fxch st(2) ;; R6,R8,R7,R1,R4,R2,R5,R3
fsub st(1), st ;; R8 = R8 - R6
fadd st, st ;; R6 = R6 * 2
fadd st, st(1) ;; R6 = R6 + R8
fmul SQRTHALF ;; R6 = R6 * square root of 1/2
fxch st(1) ;; R8,R6,R7,R1,R4,R2,R5,R3
fmul SQRTHALF ;; R8 = R8 * square root of 1/2
fxch st(7) ;; R3,R6,R7,R1,R4,R2,R5,R8
fsub st(3), st ;; R1 = R1 - R3 (new R3)
fadd st, st ;; R3 = R3 * 2
fadd st, st(3) ;; R3 = R1 + R3 (new R1)
fxch st(4) ;; R4,R6,R7,R1,R3,R2,R5,R8
fsub st(5), st ;; R2 = R2 - R4 (new R4)
fadd st, st ;; R4 = R4 * 2
fadd st, st(5) ;; R4 = R2 + R4 (new R2)
;; R2,R6,R7,R3,R1,R4,R5,R8
fstp R2
fstp R6
fstp R7
fstp R3
fstp R1
fstp R4
fstp R5
fstp R8
ENDM
four_real_four_semireal_mult MACRO R1,R2,R3,R4,R5,R6,R7,R8
four_real_four_semireal_fft R1,R2,R3,R4,R5,R6,R7,R8
sub ebx, ebx ;; Required for us to use the _mulf macro
four_real_four_semireal_mulf R1,R2,R3,R4,R5,R6,R7,R8
ENDM
four_real_four_semireal_mulf MACRO R1,R3,R5,R7,R2,R4,R6,R8
mult7 esi+ebx, esi+ebp ;; Do ZPAD multiplies
fld R3[ebx]
fmul R3[ebp] ;; R33
fld R4[ebx]
fmul R4[ebp] ;; R44
fld R3[ebx]
fmul R4[ebp] ;; R34
fld R4[ebx]
fmul R3[ebp] ;; R43
fxch st(2) ;; R44,R34,R43,R33
fsubp st(3), st ;; R34,R43,R3
fld R5[ebx]
fmul R5[ebp] ;; R55,R34,R43,R3
fxch st(1) ;; R34,R55,R43,R3
faddp st(2), st ;; R55,R4,R3
fld R6[ebx]
fmul R6[ebp] ;; R66,R55,R4,R3
fld R5[ebx]
fmul R6[ebp] ;; R56,R66,R55,R4,R3
fld R6[ebx]
fmul R5[ebp] ;; R65,R56,R66,R55,R4,R3
fxch st(2) ;; R66,R56,R65,R55,R4,R3
fsubp st(3), st ;; R56,R65,R5,R4,R3
fld R7[ebx]
fmul R7[ebp] ;; R77,R56,R65,R5,R4,R3
fxch st(1) ;; R56,R77,R65,R5,R4,R3
faddp st(2), st ;; R77,R6,R5,R4,R3
fld R8[ebx]
fmul R8[ebp] ;; R88,R77,R6,R5,R4,R3
fld R7[ebx]
fmul R8[ebp] ;; R78,R88,R77,R6,R5,R4,R3
fld R8[ebx]
fmul R7[ebp] ;; R87,R78,R88,R77,R6,R5,R4,R3
fxch st(2) ;; R88,R78,R87,R77,R6,R5,R4,R3
fsubp st(3), st ;; R78,R87,R7,R6,R5,R4,R3
fld R1[ebx]
fmul R1[ebp] ;; R1,R78,R87,R7,R6,R5,R4,R3
fxch st(1) ;; R78,R1,R87,R7,R6,R5,R4,R3
faddp st(2), st ;; R1,R8,R7,R6,R5,R4,R3
fld R2[ebx]
fmul R2[ebp] ;; R2,R1,R8,R7,R6,R5,R4,R3
fxch st(3) ;; R7,R1,R8,R2,R6,R5,R4,R3
fsub st(5), st ;; R5 = R5 - R7 (new R6)
fadd st, st ;; R7 = R7 * 2
fxch st(1) ;; R1,R7,R8,R2,R6,R5,R4,R3
fst QWORD PTR [esi-16] ;; Save product of sum of FFT values
fsub st, st(3) ;; R1 = R1 - R2 (new R2)
fxch st(2) ;; R8,R7,R1,R2,R6,R5,R4,R3
fsub st(4), st ;; R6 = R6 - R8 (new R8)
fadd st, st ;; R8 = R8 * 2
fxch st(2) ;; R1,R7,R8,R2,R6,R5,R4,R3
fmul HALF ;; Mul R1 by HALF
fxch st(5) ;; R5,R7,R8,R2,R6,R1,R4,R3
fadd st(1), st ;; R7 = R5 + R7 (new R5)
fxch st(4) ;; R6,R7,R8,R2,R5,R1,R4,R3
fadd st(2), st ;; R8 = R6 + R8 (new R7)
fxch st(5) ;; R1,R7,R8,R2,R5,R6,R4,R3
fadd st(3), st ;; R2 = R1 + R2 (new R1)
;; R2,R5,R7,R1,R6,R8,R4,R3
fxch st(4) ;; R6,R5,R7,R1,R2,R8,R4,R3
fsub st(5), st ;; R8 = R8 - R6
fadd st, st ;; R6 = R6 * 2
fxch st(6) ;; R4,R5,R7,R1,R2,R8,R6,R3
fsub st(4), st ;; R2 = R2 - R4 (new R4)
fadd st, st ;; R4 = R4 * 2
fxch st(5) ;; R8,R5,R7,R1,R2,R4,R6,R3
fadd st(6), st ;; R6 = R6 + R8
fmul SQRTHALF ;; R8 = R8 * square root of 1/2
fxch st(7) ;; R3,R5,R7,R1,R2,R4,R6,R8
fsub st(3), st ;; R1 = R1 - R3 (new R3)
fadd st, st ;; R3 = R3 * 2
fxch st(6) ;; R6,R5,R7,R1,R2,R4,R3,R8
fmul SQRTHALF ;; R6 = R6 * square root of 1/2
fxch st(4) ;; R2,R5,R7,R1,R6,R4,R3,R8
fadd st(5), st ;; R4 = R2 + R4 (new R2)
fxch st(3) ;; R1,R5,R7,R2,R6,R4,R3,R8
fadd st(6), st ;; R3 = R1 + R3 (new R1)
;; R3,R5,R7,R4,R6,R2,R1,R8
fstp R5
fstp R2
fstp R6
fstp R7
fstp R4
fstp R3
fstp R1
fstp R8
ENDM
; *************** four_real_four_semireal_unfft macro ******************
; Perform the two levels of inverse FFT generating four real and four
; semi-real numbers
; NOTE: Optimal = 39 clocks, Actual = 39 clocks
four_real_four_semireal_unfft MACRO R1,R2,R3,R4,R5,R6,R7,R8
cp_four_real_four_semireal_unfft R1,R2,R3,R4,R5,R6,R7,R8,R1,R2,R3,R4,R5,R6,R7,R8
ENDM
cp_four_real_four_semireal_unfft MACRO R1,R2,R3,R4,R5,R6,R7,R8,D1,D2,D3,D4,D5,D6,D7,D8
fld R6 ;; R6
fsub R8 ;; new R8 = R6 - R8
fld R6 ;; R6
fadd R8 ;; new R7 = R6 + R8
fld R5 ;; R5
fsub R7 ;; new R6 = R5 - R7
fld R5 ;; R5
fadd R7 ;; new R5 = R5 + R7
fld R1 ;; R1
fsub R2 ;; new R2 = R1 - R2
fld R1 ;; R1
fadd R2 ;; new R1 = R1 + R2
fxch st(3) ;; R6,R2,R5,R1,R7,R8
fsub st(5), st ;; R8 = R8 - R6
fadd st, st ;; R6 = R6 * 2
fld R4 ;; R4
fxch st(2) ;; R2,R6,R4,R5,R1,R7,R8
fadd st(2), st ;; R4 = R2 + R4 (new R2)
fsub R4 ;; R2 = R2 - R4 (new R4)
fxch st(6) ;; R8,R6,R4,R5,R1,R7,R2
fadd st(1), st ;; R6 = R6 + R8
fmul SQRTHALF ;; R8 = R8 * square root of 1/2
fld R3 ;; R3
fxch st(5) ;; R1,R8,R6,R4,R5,R3,R7,R2
fadd st(5), st ;; R3 = R1 + R3 (new R1)
fsub R3 ;; R1 = R1 - R3 (new R3)
fxch st(2) ;; R6,R8,R1,R4,R5,R3,R7,R2
fmul SQRTHALF ;; R6 = R6 * square root of 1/2
fxch st(7) ;; R2,R8,R1,R4,R5,R3,R7,R6
;; R4,R8,R3,R2,R5,R1,R7,R6
fstp D7
fstp D8
fstp D5
fstp D3
fstp D2
fstp D1
fstp D6
fstp D4
ENDM
; *************** four-complex-fft macro ******************
; This macro takes four complex values and performs two levels of the
; FFT process.
; The four complex input numbers are: R1 + R5i, R2 + R6i, R3 + R7i, R4 + R8i
; The four complex output numbers are: R1 + R5i, R2 + R6i, R3 + R7i, R4 + R8i
; edi = array of sin/cos values
; NOTE: Optimal = 64 clocks, Actual = 64 clocks
four_complex_fft MACRO R1,R2,R3,R4,R5,R6,R7,R8
cp_four_complex_fft R1,R2,R3,R4,R5,R6,R7,R8,R1,R2,R3,R4,R5,R6,R7,R8
ENDM
cp_four_complex_fft MACRO R1,R2,R3,R4,R5,R6,R7,R8,D1,D2,D3,D4,D5,D6,D7,D8
four_complex_fft_cmn R1,R2,R3,R4,R5,R6,R7,R8,D1,D2,D3,D4,D5,D6,D7,D8,0,16,32
ENDM
four_complex_fft_cmn MACRO R1,R2,R3,R4,R5,R6,R7,R8,D1,D2,D3,D4,D5,D6,D7,D8,off2,off3,off4
fld R3 ;; R3
fmul QWORD PTR [edi+off3+8] ;; A3 = R3 * cosine/sine
fld R7 ;; I3,A3
fmul QWORD PTR [edi+off3+8] ;; B3 = I3 * cosine/sine
fxch st(1) ;; A3,B3
fsub R7 ;; A3 = A3 - I3
fld R2 ;; R2,A3,B3
fmul QWORD PTR [edi+off2+8] ;; A2 = R2 * cosine/sine
fxch st(2) ;; B3,A3,A2
fadd R3 ;; B3 = B3 + R3
fxch st(1) ;; A3,B3,A2
fmul QWORD PTR [edi+off3] ;; A3 = A3 * sine (new R3)
fxch st(2) ;; A2,B3,A3
fsub R6 ;; A2 = A2 - I2
fxch st(1) ;; B3,A2,A3
fmul QWORD PTR [edi+off3] ;; B3 = B3 * sine (new I3)
fld R6 ;; I2,B3,A2,A3
fmul QWORD PTR [edi+off2+8] ;; B2 = I2 * cosine/sine
fld R4 ;; R4,B2,B3,A2,A3
fmul QWORD PTR [edi+off4+8] ;; A4 = R4 * cosine/sine
fxch st(1) ;; B2,A4,B3,A2,A3
fadd R2 ;; B2 = B2 + R2
fxch st(3) ;; A2,A4,B3,B2,A3
fmul QWORD PTR [edi+off2] ;; A2 = A2 * sine (new R2)
fld R8 ;; I4,A2,A4,B3,B2,A3
fmul QWORD PTR [edi+off4+8] ;; B4 = I4 * cosine/sine
fxch st(2) ;; A4,A2,B4,B3,B2,A3
fsub R8 ;; A4 = A4 - I4
fxch st(4) ;; B2,A2,B4,B3,A4,A3
fmul QWORD PTR [edi+off2] ;; B2 = B2 * sine (new I2)
fxch st(2) ;; B4,A2,B2,B3,A4,A3
fadd R4 ;; B4 = B4 + R4
fxch st(4) ;; A4,A2,B2,B3,B4,A3
fmul QWORD PTR [edi+off4] ;; A4 = A4 * sine (new R4)
fld R1 ;; R1,A4,A2,B2,B3,B4,A3
;; R1,R4,R2,I2,I3,B4,R3
fsub st, st(6) ;; R1 = R1 - R3 (new R3)
fxch st(5) ;; B4,R4,R2,I2,I3,R1,R3
fmul QWORD PTR [edi+off4] ;; B4 = B4 * sine (new I4)
fld R5 ;; I1,I4,R4,R2,I2,I3,R1,R3
fsub st, st(5) ;; I1 = I1 - I3 (new I3)
fxch st(1) ;; I4,I1,R4,R2,I2,I3,R1,R3
fsub st(4), st ;; I2 = I2 - I4 (new I4)
fadd st, st ;; I4 = I4 * 2
fxch st(2) ;; R4,I1,I4,R2,I2,I3,R1,R3
fsub st(3), st ;; R2 = R2 - R4 (new R4)
fadd st, st ;; R4 = R4 * 2
fxch st(7) ;; R3,I1,I4,R2,I2,I3,R1,R4
fadd R1 ;; R3 = R1 + R3 (new R1)
fxch st(5) ;; I3,I1,I4,R2,I2,R3,R1,R4
fadd R5 ;; I3 = I1 + I3 (new I1)
fxch st(4) ;; I2,I1,I4,R2,I3,R3,R1,R4
fadd st(2), st ;; I4 = I2 + I4 (new I2)
fxch st(3) ;; R2,I1,I4,I2,I3,R3,R1,R4
fadd st(7), st ;; R4 = R2 + R4 (new R2)
;; R4,I3,I2,I4,I1,R1,R3,R2
fxch st(3) ;; I4,I3,I2,R4,I1,R1,R3,R2
fsub st(6), st ;; R3 = R3 - I4 (new R3)
fadd st, st ;; I4 = I4 * 2
fxch st(3) ;; R4,I3,I2,I4,I1,R1,R3,R2
fsub st(1), st ;; I3 = I3 - R4 (new I4)
fadd st, st ;; R4 = R4 * 2
fxch st(7) ;; R2,I3,I2,I4,I1,R1,R3,R4
fsub st(5), st ;; R1 = R1 - R2 (new R2)
fadd st, st ;; R2 = R2 * 2
fxch st(2) ;; I2,I3,R2,I4,I1,R1,R3,R4
fsub st(4), st ;; I1 = I1 - I2 (new I2)
fadd st, st ;; I2 = I2 * 2
fxch st(6) ;; R3,I3,R2,I4,I1,R1,I2,R4
fadd st(3), st ;; I4 = R3 + I4 (new R4)
fxch st(1) ;; I3,R3,R2,I4,I1,R1,I2,R4
fadd st(7), st ;; R4 = I3 + R4 (new I3)
fxch st(5) ;; R1,R3,R2,I4,I1,I3,I2,R4
fadd st(2), st ;; R2 = R1 + R2 (new R1)
fxch st(4) ;; I1,R3,R2,I4,R1,I3,I2,R4
fadd st(6), st ;; I2 = I1 + I2 (new I1)
;; I2,R3,R1,R4,R2,I4,I1,I3
fstp D6
fstp D3
fstp D1
fstp D4
fstp D2
fstp D8
fstp D5
fstp D7
ENDM
; *************** four-complex-unfft macro ******************
; This macro takes four complex values and performs two levels of the
; inverse FFT process.
; The four complex input numbers are: R1 + R2i, R3 + R4i, R5 + R6i, R7 + R8i
; The four complex output numbers are: R1 + R2i, R3 + R4i, R5 + R6i, R7 + R8i
; edi = array of sin/cos values
; NOTE: Optimal = 65 clocks, Actual = 65 clocks
four_complex_unfft MACRO R1,R2,R3,R4,R5,R6,R7,R8
cp_four_complex_unfft R1,R2,R3,R4,R5,R6,R7,R8,R1,R2,R3,R4,R5,R6,R7,R8
ENDM
cp_four_complex_unfft MACRO R1,R2,R3,R4,R5,R6,R7,R8,D1,D2,D3,D4,D5,D6,D7,D8
four_complex_unfft_cmn R1,R2,R3,R4,R5,R6,R7,R8,D1,D2,D3,D4,D5,D6,D7,D8,0,16,32
ENDM
four_complex_unfft_cmn MACRO R1,R2,R3,R4,R5,R6,R7,R8,D1,D2,D3,D4,D5,D6,D7,D8,off2,off3,off4
fld R1 ;; R1
fsub R3 ;; new R2 = R1 - R2
fld R2 ;; I1
fadd R4 ;; new I1 = I1 + I2
fld R2 ;; I1
fsub R4 ;; new I2 = I1 - I2
fld R7 ;; R4
fadd R5 ;; new R3 = R3 + R4
fld R7 ;; R4
fsub R5 ;; new I4 = R4 - R3
fld R1 ;; R1
fadd R3 ;; new R1 = R1 + R2
fld R6 ;; I3
fsub R8 ;; new R4 = I3 - I4
fld R6 ;; I3
fadd R8 ;; new I3 = I3 + I4
;; I3,R4,R1,I4,R3,I2,I1,R2
fxch st(4) ;; R3,R4,R1,I4,I3,I2,I1,R2
fsub st(2), st ;; R1 = R1 - R3 (new R3)
fadd st, st ;; R3 = R3 * 2
fxch st(4) ;; I3,R4,R1,I4,R3,I2,I1,R2
fsub st(6), st ;; I1 = I1 - I3 (new I3)
fadd st, st ;; I3 = I3 * 2
fxch st(1) ;; R4,I3,R1,I4,R3,I2,I1,R2
fsub st(7), st ;; R2 = R2 - R4 (new R4)
fadd st, st ;; R4 = R4 * 2
fxch st(3) ;; I4,I3,R1,R4,R3,I2,I1,R2
fsub st(5), st ;; I2 = I2 - I4 (new I4)
fadd st, st ;; I4 = I4 * 2
fxch st(2) ;; R1,I3,I4,R4,R3,I2,I1,R2
fadd st(4), st ;; R3 = R1 + R3 (new R1)
fmul QWORD PTR [edi+off3] ;; A3 = new R3 * sine
fxch st(6) ;; I1,I3,I4,R4,R3,I2,R1,R2
fadd st(1), st ;; I3 = I1 + I3 (new I1)
fmul QWORD PTR [edi+off3] ;; B3 = new I3 * sine
fxch st(7) ;; R2,I3,I4,R4,R3,I2,R1,I1
fadd st(3), st ;; R4 = R2 + R4 (new R2)
fmul QWORD PTR [edi+off4] ;; A4 = new R4 * sine
fxch st(5) ;; I2,I3,I4,R4,R3,R2,R1,I1
fadd st(2), st ;; I4 = I2 + I4 (new I2)
fmul QWORD PTR [edi+off4] ;; B4 = new I4 * sine
;; B4,I1,I2,R2,R1,A4,A3,B3
fxch st(4) ;; R1,I1,I2,R2,B4,A4,A3,B3
fstp D1 ;; I1,I2,R2,B4,A4,A3,B3
fstp D2 ;; I2,R2,B4,A4,A3,B3
fmul QWORD PTR [edi+off2] ;; B2 = I2 * sine
fld st(5) ;; C3 = B3 (C3,B2,R2,B4,A4,A3,B3)
fmul QWORD PTR [edi+off3+8] ;; C3 = C3 * cosine/sine
fld st(3) ;; C4 = B4 (C4,C3,B2,R2,B4,A4,A3,B3)
fmul QWORD PTR [edi+off4+8] ;; C4 = C4 * cosine/sine
fxch st(6) ;; A3,C3,B2,R2,B4,A4,C4,B3
fsub st(1), st ;; C3 = C3 - A3 (new I3)
fmul QWORD PTR [edi+off3+8] ;; A3 = A3 * cosine/sine
fxch st(5) ;; A4,C3,B2,R2,B4,A3,C4,B3
fsub st(6), st ;; C4 = C4 - A4 (new I4)
fmul QWORD PTR [edi+off4+8] ;; A4 = A4 * cosine/sine
fxch st(5) ;; A3,C3,B2,R2,B4,A4,C4,B3
faddp st(7), st ;; B3 = B3 + A3 (new R3)
fxch st(2) ;; R2,B2,C3,B4,A4,C4,B3
fmul QWORD PTR [edi+off2] ;; A2 = R2 * sine
fld st(1) ;; C2 = B2 (C2,A2,B2,C3,B4,A4,C4,B3)
fmul QWORD PTR [edi+off2+8] ;; C2 = C2 * cosine/sine
fxch st(3) ;; C3,A2,B2,C2,B4,A4,C4,B3
fstp D6 ;; A2,B2,C2,B4,A4,C4,B3
fsub st(2), st ;; C2 = C2 - A2 (new I2)
fmul QWORD PTR [edi+off2+8] ;; A2 = A2 * cosine/sine
fxch st(6) ;; B3,B2,C2,B4,A4,C4,A2
fstp D5 ;; B2,C2,B4,A4,C4,A2
faddp st(5), st ;; A2 = B2 + A2 (new R2)
fxch st(2) ;; A4,B4,C2,C4,A2
faddp st(1), st ;; B4 = B4 + A4 (new R4)
fxch st(2) ;; C4,C2,B4,A2
;; I4,I2,R4,R2
fstp D8
fstp D4
fstp D7
fstp D3
ENDM
; *************** four-complex with square macro ******************
; Take four complex numbers and perform the last two levels of FFT.
; Then square the FFT results and perform two levels of inverse FFT.
; The four complex input numbers are: R1 + R5i, R2 + R6i, R3 + R7i, R4 + R8i
; NOTE: Optimal = 144 clocks, Actual = 144 clocks
four_complex_square MACRO R1,R2,R3,R4,R5,R6,R7,R8
fld R2 ;; R2
fmul QWORD PTR [edi] ;; A2 = R2 * sine
fld R6 ;; I2,A2
fmul QWORD PTR [edi] ;; B2 = I2 * sine
fld R3 ;; R3,B2,A2
fmul QWORD PTR [edi+16] ;; A3 = R3 * sine
fld st(1) ;; C2 = B2 (C2,A3,B2,A2)
fmul QWORD PTR [edi+8] ;; C2 = C2 * cosine/sine
fld R7 ;; I3,C2,A3,B2,A2
fmul QWORD PTR [edi+16] ;; B3 = I3 * sine
fxch st(4) ;; A2,C2,A3,B2,B3
fadd st(1), st ;; C2 = C2 + A2 (new I2)
fmul QWORD PTR [edi+8] ;; A2 = A2 * cosine/sine
fld R8 ;; I4,A2,C2,A3,B2,B3
fmul QWORD PTR [edi+32] ;; B4 = I4 * sine
fxch st(4) ;; B2,A2,C2,A3,B4,B3
fsubp st(1), st ;; A2 = A2 - B2 (new R2)
fld R4 ;; R4,A2,C2,A3,B4,B3
fmul QWORD PTR [edi+32] ;; A4 = R4 * sine
fld st(5) ;; C3 = B3 (C3,A4,A2,C2,A3,B4,B3)
fmul QWORD PTR [edi+24] ;; C3 = C3 * cosine/sine
fld st(5) ;; C4 = B4 (C4,C3,A4,A2,C2,A3,B4,B3)
fmul QWORD PTR [edi+40] ;; C4 = C4 * cosine/sine
fxch st(5) ;; A3,C3,A4,A2,C2,C4,B4,B3
fadd st(1), st ;; C3 = C3 + A3 (new I3)
fmul QWORD PTR [edi+24] ;; A3 = A3 * cosine/sine
fxch st(2) ;; A4,C3,A3,A2,C2,C4,B4,B3
fadd st(5), st ;; C4 = C4 + A4 (new I4)
fmul QWORD PTR [edi+40] ;; A4 = A4 * cosine/sine
fxch st(7) ;; B3,C3,A3,A2,C2,C4,B4,A4
fsubp st(2), st ;; A3 = A3 - B3 (new R3)
fld R5 ;; I1,C3,A3,A2,C2,C4,B4,A4
fxch st(6) ;; B4,C3,A3,A2,C2,C4,I1,A4
fsubp st(7), st ;; A4 = A4 - B4 (new R4)
fld R1 ;; R1,I3,R3,R2,I2,I4,I1,R4
fxch st(2) ;; R3,I3,R1,R2,I2,I4,I1,R4
fsub st(2), st ;; R1 = R1 - R3 (new R3)
fadd st, st ;; R3 = R3 * 2
fxch st(1) ;; I3,R3,R1,R2,I2,I4,I1,R4
fsub st(6), st ;; I1 = I1 - I3 (new I3)
fadd st, st ;; I3 = I3 * 2
fxch st(7) ;; R4,R3,R1,R2,I2,I4,I1,I3
fsub st(3), st ;; R2 = R2 - R4 (new R4)
fadd st, st ;; R4 = R4 * 2
fxch st(5) ;; I4,R3,R1,R2,I2,R4,I1,I3
fsub st(4), st ;; I2 = I2 - I4 (new I4)
fadd st, st ;; I4 = I4 * 2
fxch st(2) ;; R1,R3,I4,R2,I2,R4,I1,I3
fadd st(1), st ;; R3 = R1 + R3 (new R1)
fxch st(3) ;; R2,R3,I4,R1,I2,R4,I1,I3
fadd st(5), st ;; R4 = R2 + R4 (new R2)
fxch st(6) ;; I1,R3,I4,R1,I2,R4,R2,I3
fadd st(7), st ;; I3 = I1 + I3 (new I1)
fxch st(4) ;; I2,R3,I4,R1,I1,R4,R2,I3
fadd st(2), st ;; I4 = I2 + I4 (new I2)
;; I4,R1,I2,R3,I3,R2,R4,I1
fxch st(5) ;; R2,R1,I2,R3,I3,I4,R4,I1
fsub st(1), st ;; R1 = R1 - R2 (new R2)
fadd st, st ;; R2 = R2 * 2
fxch st(2) ;; I2,R1,R2,R3,I3,I4,R4,I1
fsub st(7), st ;; I1 = I1 - I2 (new I2)
fadd st, st ;; I2 = I2 * 2
fxch st(1) ;; R1,I2,R2,R3,I3,I4,R4,I1
fst R2 ;; Save new R2
faddp st(2), st ;; R2 = R1 + R2 (new R1)
fadd st, st(6) ;; I2 = I1 + I2 (new I1)
;; I1,R1,R3,I3,I4,R4,I2
fxch st(4) ;; I4,R1,R3,I3,I1,R4,I2
fsub st(2), st ;; R3 = R3 - I4 (new R3)
fadd st, st ;; I4 = I4 * 2
fld st(1) ;; TEMP1 = R1 (T,I4,R1,R3,I3,I1,R4,I2)
fxch st(5) ;; I1,I4,R1,R3,I3,TEMP1,R4,I2
fsub st(5), st ;; TEMP1 = TEMP1 - I1 (R1-I1)
fadd st, st ;; I1 = I1 * 2
fxch st(6) ;; R4,I4,R1,R3,I3,TEMP1,I1,I2
fsub st(4), st ;; I3 = I3 - R4 (new I4)
fadd st, st ;; R4 = R4 * 2
fxch st(6) ;; I1,I4,R1,R3,I3,TEMP1,R4,I2
fmul st(2), st ;; R1 = R1 * I1 (new I1)
fadd st, st(5) ;; I1 = I1 + TEMP1 (R1+I1)
fxch st(1) ;; I4,I1,R1,R3,I3,TEMP1,R4,I2