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
|
/* Copyright (c) 2003-2004 Various contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "mt32emu.h"
#ifdef MT32EMU_HAVE_X86
namespace MT32Emu {
#ifndef _MSC_VER
#define eflag(value) __asm__ __volatile__("pushfl \n popfl \n" : : "a"(value))
#define cpuid_flag (1 << 21)
static inline bool atti386_DetectCPUID() {
unsigned int result;
// Is there a cpuid?
result = cpuid_flag; // set test
eflag(result);
if (!(result & cpuid_flag))
return false;
result = 0; // clear test
eflag(result);
if (result & cpuid_flag)
return false;
return true;
}
static inline bool atti386_DetectSIMD() {
unsigned int result;
if (atti386_DetectCPUID() == false)
return false;
/* check cpuid */
__asm__ __volatile__(
"movl $1, %%eax \n" \
"cpuid \n" \
"movl %%edx, %0 \n" \
: "=r"(result) : : "eax", "ebx", "ecx", "edx");
if (result & (1 << 25))
return true;
return false;
}
static inline bool atti386_Detect3DNow() {
unsigned int result;
if (atti386_DetectCPUID() == false)
return false;
// get cpuid
__asm__ __volatile__(
"movl $0x80000001, %%eax \n" \
"cpuid \n" \
"movl %%edx, %0 \n" \
: "=r"(result) : : "eax", "ebx", "ecx", "edx");
if (result & 0x80000000)
return true;
return false;
}
static inline float atti386_iir_filter_sse(float *output, float *hist1_ptr, float *coef_ptr) {
__asm__ __volatile__ (
"pushl %1 \n" \
"pushl %2 \n" \
"movss 0(%0), %%xmm1 \n" \
"movups 0(%1), %%xmm2 \n" \
"movlps 0(%2), %%xmm3 \n" \
" \n" \
"shufps $0x44, %%xmm3, %%xmm3 \n" \
" \n" \
"mulps %%xmm3, %%xmm2 \n" \
" \n" \
"subss %%xmm2, %%xmm1 \n" \
"shufps $0x39, %%xmm2, %%xmm2 \n" \
"subss %%xmm2, %%xmm1 \n" \
" \n" \
"movss %%xmm1, 0(%2) \n" \
" \n" \
"shufps $0x39, %%xmm2, %%xmm2 \n" \
"addss %%xmm2, %%xmm1 \n" \
" \n" \
"shufps $0x39, %%xmm2, %%xmm2 \n" \
"addss %%xmm2, %%xmm1 \n" \
" \n" \
"movss %%xmm3, 4(%2) \n" \
" \n" \
"addl $16, %1 \n" \
"addl $8, %2 \n" \
" \n" \
"movups 0(%1), %%xmm2 \n" \
" \n" \
"movlps 0(%2), %%xmm3 \n" \
"shufps $0x44, %%xmm3, %%xmm3 \n" \
" \n" \
"mulps %%xmm3, %%xmm2 \n" \
" \n" \
"subss %%xmm2, %%xmm1 \n" \
"shufps $0x39, %%xmm2, %%xmm2 \n" \
"subss %%xmm2, %%xmm1 \n" \
" \n" \
"movss %%xmm1, 0(%2) \n" \
" \n" \
"shufps $0x39, %%xmm2, %%xmm2 \n" \
"addss %%xmm2, %%xmm1 \n" \
" \n" \
"shufps $0x39, %%xmm2, %%xmm2 \n" \
"addss %%xmm2, %%xmm1 \n" \
" \n" \
"movss %%xmm3, 4(%2) \n" \
"movss %%xmm1, 0(%0) \n" \
"popl %2 \n" \
"popl %1 \n" \
: : "r"(output), "r"(coef_ptr), "r"(hist1_ptr)
: "xmm1", "xmm2", "xmm3", "memory");
return *output;
}
static inline float atti386_iir_filter_3DNow(float output, float *hist1_ptr, float *coef_ptr) {
float tmp;
__asm__ __volatile__ (
"movq %0, %%mm1 \n" \
" \n" \
"movl %1, %%ebx \n" \
"movq 0(%%ebx), %%mm2 \n" \
" \n" \
"movl %2, %%eax; \n" \
"movq 0(%%eax), %%mm3 \n" \
" \n" \
"pfmul %%mm3, %%mm2 \n" \
"pfsub %%mm2, %%mm1 \n" \
" \n" \
"psrlq $32, %%mm2 \n" \
"pfsub %%mm2, %%mm1 \n" \
" \n" \
"movd %%mm1, %3 \n" \
" \n" \
"addl $8, %%ebx \n" \
"movq 0(%%ebx), %%mm2 \n" \
"movq 0(%%eax), %%mm3 \n" \
" \n" \
"pfmul %%mm3, %%mm2 \n" \
"pfadd %%mm2, %%mm1 \n" \
" \n" \
"psrlq $32, %%mm2 \n" \
"pfadd %%mm2, %%mm1 \n" \
" \n" \
"pushl %3 \n" \
"popl 0(%%eax) \n" \
" \n" \
"movd %%mm3, 4(%%eax) \n" \
" \n" \
"addl $8, %%ebx \n" \
"addl $8, %%eax \n" \
" \n" \
"movq 0(%%ebx), %%mm2 \n" \
"movq 0(%%eax), %%mm3 \n" \
" \n" \
"pfmul %%mm3, %%mm2 \n" \
"pfsub %%mm2, %%mm1 \n" \
" \n" \
"psrlq $32, %%mm2 \n" \
"pfsub %%mm2, %%mm1 \n" \
" \n" \
"movd %%mm1, %3 \n" \
" \n" \
"addl $8, %%ebx \n" \
"movq 0(%%ebx), %%mm2 \n" \
"movq 0(%%eax), %%mm3 \n" \
" \n" \
"pfmul %%mm3, %%mm2 \n" \
"pfadd %%mm2, %%mm1 \n" \
" \n" \
"psrlq $32, %%mm2 \n" \
"pfadd %%mm2, %%mm1 \n" \
" \n" \
"pushl %3 \n" \
"popl 0(%%eax) \n" \
"movd %%mm3, 4(%%eax) \n" \
" \n" \
"movd %%mm1, %0 \n" \
"femms \n" \
: "=m"(output) : "g"(coef_ptr), "g"(hist1_ptr), "m"(tmp)
: "eax", "ebx", "mm1", "mm2", "mm3", "memory");
return output;
}
static inline void atti386_produceOutput1(int tmplen, Bit16s myvolume, Bit16s *useBuf, Bit16s *snd) {
__asm__ __volatile__(
"movl %0, %%ecx \n" \
"movw %1, %%ax \n" \
"shll $16, %%eax \n" \
"movw %1, %%ax \n" \
"movd %%eax, %%mm3 \n" \
"movd %%eax, %%mm2 \n" \
"psllq $32, %%mm3 \n" \
"por %%mm2, %%mm3 \n" \
"movl %2, %%esi \n" \
"movl %3, %%edi \n" \
"1: \n" \
"movq 0(%%esi), %%mm1 \n" \
"movq 0(%%edi), %%mm2 \n" \
"pmulhw %%mm3, %%mm1 \n" \
"paddw %%mm2, %%mm1 \n" \
"movq %%mm1, 0(%%edi) \n" \
" \n" \
"addl $8, %%esi \n" \
"addl $8, %%edi \n" \
" \n" \
"decl %%ecx \n" \
"cmpl $0, %%ecx \n" \
"jg 1b \n" \
"emms \n" \
: : "g"(tmplen), "g"(myvolume), "g"(useBuf), "g"(snd)
: "eax", "ecx", "edi", "esi", "mm1", "mm2", "mm3", "memory");
}
static inline void atti386_produceOutput2(Bit32u len, Bit16s *snd, float *sndbufl, float *sndbufr, float *multFactor) {
__asm__ __volatile__(
"movl %4, %%ecx \n" \
"shrl $1, %%ecx \n" \
"addl $4, %%ecx \n" \
"pushl %%ecx \n" \
" \n" \
"movl %0, %%esi \n" \
"movups 0(%%esi), %%xmm1 \n" \
" \n" \
"movl %1, %%esi \n" \
"movl %2, %%edi \n" \
"1: \n" \
"xorl %%eax, %%eax \n" \
"movw 0(%1), %%ax \n" \
"cwde \n" \
"incl %1 \n" \
"incl %1 \n" \
"movd %%eax, %%mm1 \n" \
"psrlq $32, %%mm1 \n" \
"movw 0(%1), %%ax \n" \
"incl %1 \n" \
"incl %1 \n" \
"movd %%eax, %%mm2 \n" \
"por %%mm2, %%mm1 \n" \
" \n" \
"decl %%ecx \n" \
"jnz 1b \n" \
" \n" \
"popl %%ecx \n" \
"movl %1, %%esi \n" \
"movl %3, %%edi \n" \
"incl %%esi \n" \
"2: \n" \
"decl %%ecx \n" \
"jnz 2b \n" \
: : "g"(multFactor), "r"(snd), "g"(sndbufl), "g"(sndbufr), "g"(len)
: "eax", "ecx", "edi", "esi", "mm1", "mm2", "xmm1", "memory");
}
static inline void atti386_mixBuffers(Bit16s * buf1, Bit16s *buf2, int len) {
__asm__ __volatile__(
"movl %0, %%ecx \n" \
"movl %1, %%esi \n" \
"movl %2, %%edi \n" \
"1: \n" \
"movq 0(%%edi), %%mm1 \n" \
"movq 0(%%esi), %%mm2 \n" \
"paddw %%mm2, %%mm1 \n" \
"movq %%mm1, 0(%%esi) \n" \
"addl $8, %%edi \n" \
"addl $8, %%esi \n" \
"decl %%ecx \n" \
"cmpl $0, %%ecx \n" \
"jg 1b \n" \
"emms \n" \
: : "g"(len), "g"(buf1), "g"(buf2)
: "ecx", "edi", "esi", "mm1", "mm2", "memory");
}
static inline void atti386_mixBuffersRingMix(Bit16s * buf1, Bit16s *buf2, int len) {
__asm__ __volatile__(
"movl %0, %%ecx \n" \
"movl %1, %%esi \n" \
"movl %2, %%edi \n" \
"1: \n" \
"movq 0(%%esi), %%mm1 \n" \
"movq 0(%%edi), %%mm2 \n" \
"movq %%mm1, %%mm3 \n" \
"pmulhw %%mm2, %%mm1 \n" \
"paddw %%mm3, %%mm1 \n" \
"movq %%mm1, 0(%%esi) \n" \
"addl $8, %%edi \n" \
"addl $8, %%esi \n" \
"decl %%ecx \n" \
"cmpl $0, %%ecx \n" \
"jg 1b \n" \
"emms \n" \
: : "g"(len), "g"(buf1), "g"(buf2)
: "ecx", "edi", "esi", "mm1", "mm2", "mm3", "memory");
}
static inline void atti386_mixBuffersRing(Bit16s * buf1, Bit16s *buf2, int len) {
__asm__ __volatile__(
"movl %0, %%ecx \n" \
"movl %1, %%esi \n" \
"movl %2, %%edi \n" \
"1: \n" \
"movq 0(%%esi), %%mm1 \n" \
"movq 0(%%edi), %%mm2 \n" \
"pmulhw %%mm2, %%mm1 \n" \
"movq %%mm1, 0(%%esi) \n" \
"addl $8, %%edi \n" \
"addl $8, %%esi \n" \
"decl %%ecx \n" \
"cmpl $0, %%ecx \n" \
"jg 1b \n" \
"emms \n" \
: : "g"(len), "g"(buf1), "g"(buf2)
: "ecx", "edi", "esi", "mm1", "mm2", "memory");
}
static inline void atti386_partialProductOutput(int quadlen, Bit16s leftvol, Bit16s rightvol, Bit16s *partialBuf, Bit16s *p1buf) {
__asm__ __volatile__(
"movl %0, %%ecx \n" \
"movw %1, %%ax \n" \
"shll $16, %%eax \n" \
"movw %2, %%ax \n" \
"movd %%eax, %%mm1 \n" \
"movd %%eax, %%mm2 \n" \
"psllq $32, %%mm1 \n" \
"por %%mm2, %%mm1 \n" \
"movl %3, %%edi \n" \
"movl %4, %%esi \n" \
"1: \n" \
"movw 0(%%esi), %%bx \n" \
"addl $2, %%esi \n" \
"movw 0(%%esi), %%dx \n" \
"addl $2, %%esi \n" \
"" \
"movw %%dx, %%ax \n" \
"shll $16, %%eax \n" \
"movw %%dx, %%ax \n" \
"movd %%eax, %%mm2 \n" \
"psllq $32, %%mm2 \n" \
"movw %%bx, %%ax \n" \
"shll $16, %%eax \n" \
"movw %%bx, %%ax \n" \
"movd %%eax, %%mm3 \n" \
"por %%mm3, %%mm2 \n" \
"" \
"pmulhw %%mm1, %%mm2 \n" \
"movq %%mm2, 0(%%edi) \n" \
"addl $8, %%edi \n" \
"" \
"decl %%ecx \n" \
"cmpl $0, %%ecx \n" \
"jg 1b \n" \
"emms \n" \
: : "g"(quadlen), "g"(leftvol), "g"(rightvol), "g"(partialBuf), "g"(p1buf)
: "eax", "ebx", "ecx", "edx", "edi", "esi", "mm1", "mm2", "mm3", "memory");
}
#endif
bool DetectSIMD() {
#ifdef _MSC_VER
bool found_simd;
__asm {
pushfd
pop eax // get EFLAGS into eax
mov ebx,eax // keep a copy
xor eax,0x200000
// toggle CPUID bit
push eax
popfd // set new EFLAGS
pushfd
pop eax // EFLAGS back into eax
xor eax,ebx
// have we changed the ID bit?
je NO_SIMD
// No, no CPUID instruction
// we could toggle the
// ID bit so CPUID is present
mov eax,1
cpuid // get processor features
test edx,1<<25 // check the SIMD bit
jz NO_SIMD
mov found_simd,1
jmp DONE
NO_SIMD:
mov found_simd,0
DONE:
}
return found_simd;
#else
return atti386_DetectSIMD();
#endif
}
bool Detect3DNow() {
#ifdef _MSC_VER
bool found3D = false;
__asm {
pushfd
pop eax
mov edx, eax
xor eax, 00200000h
push eax
popfd
pushfd
pop eax
xor eax, edx
jz NO_3DNOW
mov eax, 80000000h
cpuid
cmp eax, 80000000h
jbe NO_3DNOW
mov eax, 80000001h
cpuid
test edx, 80000000h
jz NO_3DNOW
mov found3D, 1
NO_3DNOW:
}
return found3D;
#else
return atti386_Detect3DNow();
#endif
}
float iir_filter_sse(float input,float *hist1_ptr, float *coef_ptr, int revLevel) {
float output;
// 1st number of coefficients array is overall input scale factor, or filter gain
output = input * (*coef_ptr++);
#ifdef _MSC_VER
__asm {
movss xmm1, output
mov eax, coef_ptr
movups xmm2, [eax]
mov eax, hist1_ptr
movlps xmm3, [eax]
shufps xmm3, xmm3, 44h
// hist1_ptr+1, hist1_ptr, hist1_ptr+1, hist1_ptr
mulps xmm2, xmm3
subss xmm1, xmm2
// Rotate elements right
shufps xmm2, xmm2, 39h
subss xmm1, xmm2
// Store new_hist
movss DWORD PTR [eax], xmm1
// Rotate elements right
shufps xmm2, xmm2, 39h
addss xmm1, xmm2
// Rotate elements right
shufps xmm2, xmm2, 39h
addss xmm1, xmm2
// Store previous hist
movss DWORD PTR [eax+4], xmm3
add coef_ptr, 16
add hist1_ptr, 8
mov eax, coef_ptr
movups xmm2, [eax]
mov eax, hist1_ptr
movlps xmm3, [eax]
shufps xmm3, xmm3, 44h
// hist1_ptr+1, hist1_ptr, hist1_ptr+1, hist1_ptr
mulps xmm2, xmm3
subss xmm1, xmm2
// Rotate elements right
shufps xmm2, xmm2, 39h
subss xmm1, xmm2
// Store new_hist
movss DWORD PTR [eax], xmm1
// Rotate elements right
shufps xmm2, xmm2, 39h
addss xmm1, xmm2
// Rotate elements right
shufps xmm2, xmm2, 39h
addss xmm1, xmm2
// Store previous hist
movss DWORD PTR [eax+4], xmm3
movss output, xmm1
}
#else
output = atti386_iir_filter_sse(&output, hist1_ptr, coef_ptr);
#endif
output *= ResonInv[revLevel];
return output;
}
float iir_filter_3dnow(float input,float *hist1_ptr, float *coef_ptr, int revLevel) {
float output;
// 1st number of coefficients array is overall input scale factor, or filter gain
output = input * (*coef_ptr++);
// I find it very sad that 3DNow requires twice as many instructions as Intel's SSE
// Intel does have the upper hand here.
#ifdef _MSC_VER
float tmp;
__asm {
movq mm1, output
mov ebx, coef_ptr
movq mm2, [ebx]
mov eax, hist1_ptr;
movq mm3, [eax]
pfmul mm2, mm3
pfsub mm1, mm2
psrlq mm2, 32
pfsub mm1, mm2
// Store new hist
movd tmp, mm1
add ebx, 8
movq mm2, [ebx]
movq mm3, [eax]
pfmul mm2, mm3
pfadd mm1, mm2
psrlq mm2, 32
pfadd mm1, mm2
push tmp
pop DWORD PTR [eax]
movd DWORD PTR [eax+4], mm3
add ebx, 8
add eax, 8
movq mm2, [ebx]
movq mm3, [eax]
pfmul mm2, mm3
pfsub mm1, mm2
psrlq mm2, 32
pfsub mm1, mm2
// Store new hist
movd tmp, mm1
add ebx, 8
movq mm2, [ebx]
movq mm3, [eax]
pfmul mm2, mm3
pfadd mm1, mm2
psrlq mm2, 32
pfadd mm1, mm2
push tmp
pop DWORD PTR [eax]
movd DWORD PTR [eax+4], mm3
movd output, mm1
femms
}
#else
output = atti386_iir_filter_3DNow(output, hist1_ptr, coef_ptr);
#endif
output *= ResonInv[revLevel];
return output;
}
#if MT32EMU_USE_MMX > 0
int i386_partialProductOutput(int len, Bit16s leftvol, Bit16s rightvol, Bit16s *partialBuf, Bit16s *mixedBuf) {
int tmplen = len >> 1;
if (tmplen == 0) {
return 0;
}
#ifdef _MSC_VER
__asm {
mov ecx,tmplen
mov ax, leftvol
shl eax,16
mov ax, rightvol
movd mm1, eax
movd mm2, eax
psllq mm1, 32
por mm1, mm2
mov edi, partialBuf
mov esi, mixedBuf
mmxloop1:
mov bx, [esi]
add esi,2
mov dx, [esi]
add esi,2
mov ax, dx
shl eax, 16
mov ax, dx
movd mm2,eax
psllq mm2, 32
mov ax, bx
shl eax, 16
mov ax, bx
movd mm3,eax
por mm2,mm3
pmulhw mm2, mm1
movq [edi], mm2
add edi, 8
dec ecx
cmp ecx,0
jg mmxloop1
emms
}
#else
atti386_partialProductOutput(tmplen, leftvol, rightvol, partialBuf, mixedBuf);
#endif
return tmplen << 1;
}
int i386_mixBuffers(Bit16s * buf1, Bit16s *buf2, int len) {
int tmplen = len >> 2;
if (tmplen == 0) {
return 0;
}
#ifdef _MSC_VER
__asm {
mov ecx, tmplen
mov esi, buf1
mov edi, buf2
mixloop1:
movq mm1, [edi]
movq mm2, [esi]
paddw mm1,mm2
movq [esi],mm1
add edi,8
add esi,8
dec ecx
cmp ecx,0
jg mixloop1
emms
}
#else
atti386_mixBuffers(buf1, buf2, tmplen);
#endif
return tmplen << 2;
}
int i386_mixBuffersRingMix(Bit16s * buf1, Bit16s *buf2, int len) {
int tmplen = len >> 2;
if (tmplen == 0) {
return 0;
}
#ifdef _MSC_VER
__asm {
mov ecx, tmplen
mov esi, buf1
mov edi, buf2
mixloop2:
movq mm1, [esi]
movq mm2, [edi]
movq mm3, mm1
pmulhw mm1, mm2
paddw mm1,mm3
movq [esi],mm1
add edi,8
add esi,8
dec ecx
cmp ecx,0
jg mixloop2
emms
}
#else
atti386_mixBuffersRingMix(buf1, buf2, tmplen);
#endif
return tmplen << 2;
}
int i386_mixBuffersRing(Bit16s * buf1, Bit16s *buf2, int len) {
int tmplen = len >> 2;
if (tmplen == 0) {
return 0;
}
#ifdef _MSC_VER
__asm {
mov ecx, tmplen
mov esi, buf1
mov edi, buf2
mixloop3:
movq mm1, [esi]
movq mm2, [edi]
pmulhw mm1, mm2
movq [esi],mm1
add edi,8
add esi,8
dec ecx
cmp ecx,0
jg mixloop3
emms
}
#else
atti386_mixBuffersRing(buf1, buf2, tmplen);
#endif
return tmplen << 2;
}
int i386_produceOutput1(Bit16s *useBuf, Bit16s *stream, Bit32u len, Bit16s volume) {
int tmplen = (len >> 1);
if (tmplen == 0) {
return 0;
}
#ifdef _MSC_VER
__asm {
mov ecx, tmplen
mov ax,volume
shl eax,16
mov ax,volume
movd mm3,eax
movd mm2,eax
psllq mm3, 32
por mm3,mm2
mov esi, useBuf
mov edi, stream
mixloop4:
movq mm1, [esi]
movq mm2, [edi]
pmulhw mm1, mm3
paddw mm1,mm2
movq [edi], mm1
add esi,8
add edi,8
dec ecx
cmp ecx,0
jg mixloop4
emms
}
#else
atti386_produceOutput1(tmplen, volume, useBuf, stream);
#endif
return tmplen << 1;
}
#endif
}
#endif
|