forked from mpc-hc/mpc-hc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeinterlace.cpp
More file actions
1968 lines (1679 loc) · 64.8 KB
/
deinterlace.cpp
File metadata and controls
1968 lines (1679 loc) · 64.8 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
// VirtualDub - Video processing and capture application
// Copyright (C) 1998-2007 Avery Lee
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "stdafx.h"
#include <emmintrin.h>
#include "vd2/system/memory.h"
#include "vd2/system/cpuaccel.h"
#include "vd2/system/vdstl.h"
#pragma warning(disable: 4799) // warning C4799: function has no EMMS instruction
///////////////////////////////////////////////////////////////////////////
#ifdef _M_IX86
static void __declspec(naked) asm_blend_row_clipped(void *dst, const void *src, uint32 w, ptrdiff_t srcpitch) {
__asm {
push ebp
push edi
push esi
push ebx
mov edi,[esp+20]
mov esi,[esp+24]
sub edi,esi
mov ebp,[esp+28]
mov edx,[esp+32]
xloop:
mov ecx,[esi]
mov eax,0fefefefeh
mov ebx,[esi+edx]
and eax,ecx
shr eax,1
and ebx,0fefefefeh
shr ebx,1
add esi,4
add eax,ebx
dec ebp
mov [edi+esi-4],eax
jnz xloop
pop ebx
pop esi
pop edi
pop ebp
ret
};
}
static void __declspec(naked) asm_blend_row(void *dst, const void *src, uint32 w, ptrdiff_t srcpitch) {
__asm {
push ebp
push edi
push esi
push ebx
mov edi,[esp+20]
mov esi,[esp+24]
sub edi,esi
mov ebp,[esp+28]
mov edx,[esp+32]
xloop:
mov ecx,[esi]
mov eax,0fcfcfcfch
mov ebx,[esi+edx]
and eax,ecx
shr ebx,1
mov ecx,[esi+edx*2]
shr ecx,2
and ebx,07f7f7f7fh
shr eax,2
and ecx,03f3f3f3fh
add eax,ebx
add esi,4
add eax,ecx
dec ebp
mov [edi+esi-4],eax
jnz xloop
pop ebx
pop esi
pop edi
pop ebp
ret
};
}
static void __declspec(naked) asm_blend_row_MMX(void *dst, const void *src, uint32 w, ptrdiff_t srcpitch) {
static const __declspec(align(8)) __int64 mask0 = 0xfcfcfcfcfcfcfcfci64;
static const __declspec(align(8)) __int64 mask1 = 0x7f7f7f7f7f7f7f7fi64;
static const __declspec(align(8)) __int64 mask2 = 0x3f3f3f3f3f3f3f3fi64;
__asm {
push ebp
push edi
push esi
push ebx
mov edi,[esp+20]
mov esi,[esp+24]
sub edi,esi
mov ebp,[esp+28]
mov edx,[esp+32]
movq mm5,mask0
movq mm6,mask1
movq mm7,mask2
inc ebp
shr ebp,1
xloop:
movq mm2,[esi]
movq mm0,mm5
movq mm1,[esi+edx]
pand mm0,mm2
psrlq mm1,1
movq mm2,[esi+edx*2]
psrlq mm2,2
pand mm1,mm6
psrlq mm0,2
pand mm2,mm7
paddb mm0,mm1
add esi,8
paddb mm0,mm2
dec ebp
movq [edi+esi-8],mm0
jne xloop
pop ebx
pop esi
pop edi
pop ebp
ret
};
}
static void __declspec(naked) asm_blend_row_ISSE(void *dst, const void *src, uint32 w, ptrdiff_t srcpitch) {
__asm {
push ebp
push edi
push esi
push ebx
mov edi,[esp+20]
mov esi,[esp+24]
sub edi,esi
mov ebp,[esp+28]
mov edx,[esp+32]
inc ebp
shr ebp,1
pcmpeqb mm7, mm7
align 16
xloop:
movq mm0, [esi]
movq mm2, mm7
pxor mm0, mm7
pxor mm2, [esi+edx*2]
pavgb mm0, mm2
pxor mm0, mm7
pavgb mm0, [esi+edx]
add esi,8
movq [edi+esi-8],mm0
dec ebp
jne xloop
pop ebx
pop esi
pop edi
pop ebp
ret
};
}
#else
static void asm_blend_row_clipped(void *dst0, const void *src0, uint32 w, ptrdiff_t srcpitch) {
uint32 *dst = (uint32 *)dst0;
const uint32 *src = (const uint32 *)src0;
const uint32 *src2 = (const uint32 *)((const char *)src + srcpitch);
do {
const uint32 x = *src++;
const uint32 y = *src2++;
*dst++ = (x|y) - (((x^y)&0xfefefefe)>>1);
} while(--w);
}
static void asm_blend_row(void *dst0, const void *src0, uint32 w, ptrdiff_t srcpitch) {
uint32 *dst = (uint32 *)dst0;
const uint32 *src = (const uint32 *)src0;
const uint32 *src2 = (const uint32 *)((const char *)src + srcpitch);
const uint32 *src3 = (const uint32 *)((const char *)src2 + srcpitch);
do {
const uint32 a = *src++;
const uint32 b = *src2++;
const uint32 c = *src3++;
const uint32 hi = (a & 0xfcfcfc) + 2*(b & 0xfcfcfc) + (c & 0xfcfcfc);
const uint32 lo = (a & 0x030303) + 2*(b & 0x030303) + (c & 0x030303) + 0x020202;
*dst++ = (hi + (lo & 0x0c0c0c))>>2;
} while(--w);
}
#endif
#if defined(VD_CPU_X86) || defined(VD_CPU_AMD64)
static void asm_blend_row_SSE2(void *dst, const void *src, uint32 w, ptrdiff_t srcpitch) {
__m128i zero = _mm_setzero_si128();
__m128i inv = _mm_cmpeq_epi8(zero, zero);
w = (w + 3) >> 2;
const __m128i *src1 = (const __m128i *)src;
const __m128i *src2 = (const __m128i *)((const char *)src + srcpitch);
const __m128i *src3 = (const __m128i *)((const char *)src + srcpitch*2);
__m128i *dstrow = (__m128i *)dst;
do {
__m128i a = *src1++;
__m128i b = *src2++;
__m128i c = *src3++;
*dstrow++ = _mm_avg_epu8(_mm_xor_si128(_mm_avg_epu8(_mm_xor_si128(a, inv), _mm_xor_si128(c, inv)), inv), b);
} while(--w);
}
void ela_L8_SSE2(__m128i *dst, const __m128i *srcat, const __m128i *srcab, int w16) {
do {
__m128i top0 = srcat[0];
__m128i top1 = srcat[1];
__m128i top2 = srcat[2];
__m128i bot0 = srcab[0];
__m128i bot1 = srcab[1];
__m128i bot2 = srcab[2];
++srcat;
++srcab;
__m128i topl2 = _mm_or_si128(_mm_srli_si128(top0, 16 - 3), _mm_slli_si128(top1, 3));
__m128i topl1 = _mm_or_si128(_mm_srli_si128(top0, 16 - 2), _mm_slli_si128(top1, 2));
__m128i topc0 = _mm_or_si128(_mm_srli_si128(top0, 16 - 1), _mm_slli_si128(top1, 1));
__m128i topr1 = top1;
__m128i topr2 = _mm_or_si128(_mm_srli_si128(top1, 1), _mm_slli_si128(top2, 16 - 1));
__m128i topr3 = _mm_or_si128(_mm_srli_si128(top1, 2), _mm_slli_si128(top2, 16 - 2));
__m128i botl2 = _mm_or_si128(_mm_srli_si128(bot0, 16 - 3), _mm_slli_si128(bot1, 3));
__m128i botl1 = _mm_or_si128(_mm_srli_si128(bot0, 16 - 2), _mm_slli_si128(bot1, 2));
__m128i botc0 = _mm_or_si128(_mm_srli_si128(bot0, 16 - 1), _mm_slli_si128(bot1, 1));
__m128i botr1 = bot1;
__m128i botr2 = _mm_or_si128(_mm_srli_si128(bot1, 1), _mm_slli_si128(bot2, 16 - 1));
__m128i botr3 = _mm_or_si128(_mm_srli_si128(bot1, 2), _mm_slli_si128(bot2, 16 - 2));
__m128i rawscorec0 = _mm_or_si128(_mm_subs_epu8(topc0, botc0), _mm_subs_epu8(botc0, topc0));
__m128i rawscorel1 = _mm_or_si128(_mm_subs_epu8(topl1, botr1), _mm_subs_epu8(botr1, topl1));
__m128i rawscorel2 = _mm_or_si128(_mm_subs_epu8(topl2, botr2), _mm_subs_epu8(botr2, topl2));
__m128i rawscorer1 = _mm_or_si128(_mm_subs_epu8(topr1, botl1), _mm_subs_epu8(botl1, topr1));
__m128i rawscorer2 = _mm_or_si128(_mm_subs_epu8(topr2, botl2), _mm_subs_epu8(botl2, topr2));
dst[0] = rawscorec0;
dst[1] = rawscorel1;
dst[2] = rawscorel2;
dst[3] = rawscorer1;
dst[4] = rawscorer2;
dst[5] = _mm_avg_epu8(topr1, botr1);
dst[6] = _mm_avg_epu8(topc0, botr2);
dst[7] = _mm_avg_epu8(topl1, botr3);
dst[8] = _mm_avg_epu8(topr2, botc0);
dst[9] = _mm_avg_epu8(topr3, botl1);
dst += 10;
} while(--w16);
}
void nela_L8_SSE2(__m128i *dst, const __m128i *elabuf, int w16) {
__m128i zero = _mm_setzero_si128();
__m128i x80b = _mm_set1_epi8((unsigned char)0x80);
do {
__m128i x0, x1, x2, y;
x0 = elabuf[0];
y = elabuf[10];
x1 = _mm_or_si128(_mm_srli_si128(x0, 1), _mm_slli_si128(y, 15));
x2 = _mm_or_si128(_mm_srli_si128(x0, 2), _mm_slli_si128(y, 14));
__m128i scorec0 = _mm_avg_epu8(_mm_avg_epu8(x0, x2), x1);
x0 = elabuf[1];
y = elabuf[11];
x1 = _mm_or_si128(_mm_srli_si128(x0, 1), _mm_slli_si128(y, 15));
x2 = _mm_or_si128(_mm_srli_si128(x0, 2), _mm_slli_si128(y, 14));
__m128i scorel1 = _mm_avg_epu8(_mm_avg_epu8(x0, x2), x1);
x0 = elabuf[2];
y = elabuf[12];
x1 = _mm_or_si128(_mm_srli_si128(x0, 1), _mm_slli_si128(y, 15));
x2 = _mm_or_si128(_mm_srli_si128(x0, 2), _mm_slli_si128(y, 14));
__m128i scorel2 = _mm_avg_epu8(_mm_avg_epu8(x0, x2), x1);
x0 = elabuf[3];
y = elabuf[13];
x1 = _mm_or_si128(_mm_srli_si128(x0, 1), _mm_slli_si128(y, 15));
x2 = _mm_or_si128(_mm_srli_si128(x0, 2), _mm_slli_si128(y, 14));
__m128i scorer1 = _mm_avg_epu8(_mm_avg_epu8(x0, x2), x1);
x0 = elabuf[4];
y = elabuf[14];
x1 = _mm_or_si128(_mm_srli_si128(x0, 1), _mm_slli_si128(y, 15));
x2 = _mm_or_si128(_mm_srli_si128(x0, 2), _mm_slli_si128(y, 14));
__m128i scorer2 = _mm_avg_epu8(_mm_avg_epu8(x0, x2), x1);
scorec0 = _mm_xor_si128(scorec0, x80b);
scorel1 = _mm_xor_si128(scorel1, x80b);
scorel2 = _mm_xor_si128(scorel2, x80b);
scorer1 = _mm_xor_si128(scorer1, x80b);
scorer2 = _mm_xor_si128(scorer2, x80b);
// result = (scorel1 < scorec0) ? (scorel2 < scorel1 ? l2 : l1) : (scorer1 < scorec0) ? (scorer2 < scorer1 ? r2 : r1) : c0
__m128i cmplt_l1_c0 = _mm_cmplt_epi8(scorel1, scorec0);
__m128i cmplt_r1_c0 = _mm_cmplt_epi8(scorer1, scorec0);
__m128i cmplt_l1_r1 = _mm_cmplt_epi8(scorel1, scorer1);
__m128i is_l1 = _mm_and_si128(cmplt_l1_r1, cmplt_l1_c0);
__m128i is_r1 = _mm_andnot_si128(cmplt_l1_r1, cmplt_r1_c0);
__m128i is_c0_inv = _mm_or_si128(cmplt_l1_c0, cmplt_r1_c0);
__m128i is_c0 = _mm_andnot_si128(is_c0_inv, _mm_cmpeq_epi8(zero, zero));
__m128i is_l2 = _mm_and_si128(is_l1, _mm_cmplt_epi8(scorel2, scorel1));
__m128i is_r2 = _mm_and_si128(is_r1, _mm_cmplt_epi8(scorer2, scorer1));
is_l1 = _mm_andnot_si128(is_l2, is_l1);
is_r1 = _mm_andnot_si128(is_r2, is_r1);
__m128i mask_c0 = is_c0;
__m128i mask_l1 = is_l1;
__m128i mask_l2 = is_l2;
__m128i mask_r1 = is_r1;
__m128i mask_r2 = is_r2;
__m128i result_c0 = _mm_and_si128(elabuf[5], mask_c0);
__m128i result_l1 = _mm_and_si128(elabuf[6], mask_l1);
__m128i result_l2 = _mm_and_si128(elabuf[7], mask_l2);
__m128i result_r1 = _mm_and_si128(elabuf[8], mask_r1);
__m128i result_r2 = _mm_and_si128(elabuf[9], mask_r2);
elabuf += 10;
__m128i pred = _mm_or_si128(_mm_or_si128(_mm_or_si128(result_l1, result_l2), _mm_or_si128(result_r1, result_r2)), result_c0);
*dst++ = pred;
} while(--w16);
}
#endif
#if defined(VD_CPU_X86)
void __declspec(naked) __stdcall ela_L8_MMX(void *dst, const void *srcat, const void *srcab, int w16) {
static const __declspec(align(8)) uint64 xFEb = 0xfefefefefefefefe;
__asm {
push ebx
mov ebx, [esp + 4 + 4]
mov ecx, [esp + 8 + 4]
mov edx, [esp + 12 + 4]
mov eax, [esp + 16 + 4]
movq mm7, xFEb
xloop:
movq mm0, [ecx + 15]
movq mm1, [edx + 15]
movq mm4, mm0
movq mm2, [ecx + 15 + 8]
psubusb mm0, mm1
movq mm3, [edx + 15 + 8]
movq mm5, mm2
psubusb mm2, mm3
psubusb mm1, mm4
psubusb mm3, mm5
por mm0, mm1
movq [ebx], mm0
por mm2, mm3
movq [ebx + 8], mm2
movq mm0, [ecx + 14]
movq mm1, [edx + 16]
movq mm4, mm0
movq mm2, [ecx + 14 + 8]
psubusb mm0, mm1
movq mm3, [edx + 16 + 8]
movq mm5, mm2
psubusb mm2, mm3
psubusb mm1, mm4
psubusb mm3, mm5
por mm0, mm1
movq [ebx + 16], mm0
por mm2, mm3
movq [ebx + 24], mm2
movq mm0, [ecx + 13]
movq mm1, [edx + 17]
movq mm4, mm0
movq mm2, [ecx + 13 + 8]
psubusb mm0, mm1
movq mm3, [edx + 17 + 8]
movq mm5, mm2
psubusb mm2, mm3
psubusb mm1, mm4
psubusb mm3, mm5
por mm0, mm1
movq [ebx + 32], mm0
por mm2, mm3
movq [ebx + 40], mm2
movq mm0, [ecx + 16]
movq mm1, [edx + 14]
movq mm4, mm0
movq mm2, [ecx + 16 + 8]
psubusb mm0, mm1
movq mm3, [edx + 14 + 8]
movq mm5, mm2
psubusb mm2, mm3
psubusb mm1, mm4
psubusb mm3, mm5
por mm0, mm1
movq [ebx + 48], mm0
por mm2, mm3
movq [ebx + 56], mm2
movq mm0, [ecx + 17]
movq mm1, [edx + 13]
movq mm4, mm0
movq mm2, [ecx + 17 + 8]
psubusb mm0, mm1
movq mm3, [edx + 13 + 8]
movq mm5, mm2
psubusb mm2, mm3
psubusb mm1, mm4
psubusb mm3, mm5
por mm0, mm1
movq [ebx + 64], mm0
por mm2, mm3
movq [ebx + 72], mm2
movq mm0, [ecx + 16]
movq mm1, [edx + 16]
movq mm2, [ecx + 16 + 8]
movq mm3, [edx + 16 + 8]
movq mm4, mm0
movq mm5, mm2
pxor mm0, mm1
pxor mm2, mm3
por mm1, mm4
por mm3, mm5
pand mm0, mm7
pand mm2, mm7
psrlw mm0, 1
psrlw mm2, 1
psubb mm1, mm0
psubb mm3, mm2
movq [ebx + 80], mm1
movq [ebx + 88], mm3
movq mm0, [ecx + 15]
movq mm1, [edx + 17]
movq mm2, [ecx + 15 + 8]
movq mm3, [edx + 17 + 8]
movq mm4, mm0
movq mm5, mm2
pxor mm0, mm1
pxor mm2, mm3
por mm1, mm4
por mm3, mm5
pand mm0, mm7
pand mm2, mm7
psrlw mm0, 1
psrlw mm2, 1
psubb mm1, mm0
psubb mm3, mm2
movq [ebx + 96], mm1
movq [ebx + 104], mm3
movq mm0, [ecx + 14]
movq mm1, [edx + 18]
movq mm2, [ecx + 14 + 8]
movq mm3, [edx + 18 + 8]
movq mm4, mm0
movq mm5, mm2
pxor mm0, mm1
pxor mm2, mm3
por mm1, mm4
por mm3, mm5
pand mm0, mm7
pand mm2, mm7
psrlw mm0, 1
psrlw mm2, 1
psubb mm1, mm0
psubb mm3, mm2
movq [ebx + 112], mm1
movq [ebx + 120], mm3
movq mm0, [ecx + 17]
movq mm1, [edx + 15]
movq mm2, [ecx + 17 + 8]
movq mm3, [edx + 15 + 8]
movq mm4, mm0
movq mm5, mm2
pxor mm0, mm1
pxor mm2, mm3
por mm1, mm4
por mm3, mm5
pand mm0, mm7
pand mm2, mm7
psrlw mm0, 1
psrlw mm2, 1
psubb mm1, mm0
psubb mm3, mm2
movq [ebx + 128], mm1
movq [ebx + 136], mm3
movq mm0, [ecx + 18]
movq mm1, [edx + 14]
movq mm2, [ecx + 18 + 8]
movq mm3, [edx + 14 + 8]
movq mm4, mm0
movq mm5, mm2
pxor mm0, mm1
pxor mm2, mm3
por mm1, mm4
por mm3, mm5
pand mm0, mm7
pand mm2, mm7
psrlw mm0, 1
psrlw mm2, 1
psubb mm1, mm0
psubb mm3, mm2
movq [ebx + 144], mm1
movq [ebx + 152], mm3
add ebx, 160
add ecx, 16
add edx, 16
dec eax
jne xloop
emms
pop ebx
ret 16
}
}
void __declspec(naked) __stdcall ela_L8_ISSE(void *dst, const void *srcat, const void *srcab, int w16) {
static const __declspec(align(8)) uint64 xFEb = 0xfefefefefefefefe;
__asm {
push ebx
mov ebx, [esp + 4 + 4]
mov ecx, [esp + 8 + 4]
mov edx, [esp + 12 + 4]
mov eax, [esp + 16 + 4]
movq mm7, xFEb
xloop:
movq mm0, [ecx + 15]
movq mm1, [edx + 15]
movq mm4, mm0
movq mm2, [ecx + 15 + 8]
psubusb mm0, mm1
movq mm3, [edx + 15 + 8]
movq mm5, mm2
psubusb mm2, mm3
psubusb mm1, mm4
psubusb mm3, mm5
por mm0, mm1
movq [ebx], mm0
por mm2, mm3
movq [ebx + 8], mm2
movq mm0, [ecx + 14]
movq mm1, [edx + 16]
movq mm4, mm0
movq mm2, [ecx + 14 + 8]
psubusb mm0, mm1
movq mm3, [edx + 16 + 8]
movq mm5, mm2
psubusb mm2, mm3
psubusb mm1, mm4
psubusb mm3, mm5
por mm0, mm1
movq [ebx + 16], mm0
por mm2, mm3
movq [ebx + 24], mm2
movq mm0, [ecx + 13]
movq mm1, [edx + 17]
movq mm4, mm0
movq mm2, [ecx + 13 + 8]
psubusb mm0, mm1
movq mm3, [edx + 17 + 8]
movq mm5, mm2
psubusb mm2, mm3
psubusb mm1, mm4
psubusb mm3, mm5
por mm0, mm1
movq [ebx + 32], mm0
por mm2, mm3
movq [ebx + 40], mm2
movq mm0, [ecx + 16]
movq mm1, [edx + 14]
movq mm4, mm0
movq mm2, [ecx + 16 + 8]
psubusb mm0, mm1
movq mm3, [edx + 14 + 8]
movq mm5, mm2
psubusb mm2, mm3
psubusb mm1, mm4
psubusb mm3, mm5
por mm0, mm1
movq [ebx + 48], mm0
por mm2, mm3
movq [ebx + 56], mm2
movq mm0, [ecx + 17]
movq mm1, [edx + 13]
movq mm4, mm0
movq mm2, [ecx + 17 + 8]
psubusb mm0, mm1
movq mm3, [edx + 13 + 8]
movq mm5, mm2
psubusb mm2, mm3
psubusb mm1, mm4
psubusb mm3, mm5
por mm0, mm1
movq [ebx + 64], mm0
por mm2, mm3
movq [ebx + 72], mm2
movq mm0, [ecx + 16]
movq mm1, [edx + 16]
movq mm2, [ecx + 16 + 8]
movq mm3, [edx + 16 + 8]
pavgb mm1, mm0
pavgb mm3, mm2
movq [ebx + 80], mm1
movq [ebx + 88], mm3
movq mm0, [ecx + 15]
movq mm1, [edx + 17]
movq mm2, [ecx + 15 + 8]
movq mm3, [edx + 17 + 8]
pavgb mm1, mm0
pavgb mm3, mm2
movq [ebx + 96], mm1
movq [ebx + 104], mm3
movq mm0, [ecx + 14]
movq mm1, [edx + 18]
movq mm2, [ecx + 14 + 8]
movq mm3, [edx + 18 + 8]
pavgb mm1, mm0
pavgb mm3, mm2
movq [ebx + 112], mm1
movq [ebx + 120], mm3
movq mm0, [ecx + 17]
movq mm1, [edx + 15]
movq mm2, [ecx + 17 + 8]
movq mm3, [edx + 15 + 8]
pavgb mm1, mm0
pavgb mm3, mm2
movq [ebx + 128], mm1
movq [ebx + 136], mm3
movq mm0, [ecx + 18]
movq mm1, [edx + 14]
movq mm2, [ecx + 18 + 8]
movq mm3, [edx + 14 + 8]
pavgb mm1, mm0
pavgb mm3, mm2
movq [ebx + 144], mm1
movq [ebx + 152], mm3
add ebx, 160
add ecx, 16
add edx, 16
dec eax
jne xloop
emms
pop ebx
ret 16
}
}
void __declspec(naked) __stdcall nela_L8_ISSE(void *dst, const void *elabuf, int w16) {
static const __declspec(align(8)) uint64 x7fb = 0x7f7f7f7f7f7f7f7f;
__asm {
mov edx, [esp+4]
mov ecx, [esp+8]
mov eax, [esp+12]
xloop:
movq mm0, [ecx+000h]
pavgb mm0, [ecx+002h]
pavgb mm0, [ecx+001h]
movq mm1, [ecx+010h]
pavgb mm1, [ecx+012h]
pavgb mm1, [ecx+011h]
movq mm2, [ecx+020h]
pavgb mm2, [ecx+022h]
pavgb mm2, [ecx+021h]
movq mm3, [ecx+030h]
pavgb mm3, [ecx+032h]
pavgb mm3, [ecx+031h]
movq mm4, [ecx+040h]
pavgb mm4, [ecx+042h]
pavgb mm4, [ecx+041h]
movq mm5, x7fb
pxor mm0, mm5
pxor mm1, mm5
pxor mm2, mm5
pxor mm3, mm5
pxor mm4, mm5
;mm0 = scorec0
;mm1 = scorel1
;mm2 = scorel2
;mm3 = scorer1
;mm4 = scorer2
movq mm5, mm3
pcmpgtb mm5, mm1 ;(scorer1 > scorel1) == (scorel1 < scorer1)
pcmpgtb mm4, mm3 ;scorer2 > scorer1
pcmpgtb mm2, mm1 ;scorel2 > scorel1
pcmpgtb mm1, mm0 ;scorel1 > scorec0
pcmpgtb mm3, mm0 ;scorer1 > scorec0
movq mm6, mm1
pcmpeqb mm0, mm0
por mm6, mm3 ;scorel1 > scorec0 || scorer1 > scorec0
pxor mm0, mm6 ;mask_c0
pand mm3, mm5 ;scorer1 > scorec0 && scorer1 > scorel1
pandn mm5, mm1 ;scorel1 > scorec0 && scorel1 >= scorer1
pand mm4, mm3 ;mask_r2
pand mm2, mm5 ;mask_l2
pxor mm3, mm4 ;mask_r1
pxor mm5, mm2 ;mask_l1
pand mm0, [ecx+050h]
pand mm5, [ecx+060h]
pand mm2, [ecx+070h]
pand mm3, [ecx+080h]
pand mm4, [ecx+090h]
por mm0, mm5
por mm2, mm3
por mm0, mm4
por mm0, mm2
movq [edx], mm0
movq mm0, [ecx+008h]
movq mm5, [ecx+0a0h]
movq mm6, mm0
psrlq mm0, 16
movq mm7, mm5
psllq mm5, 48
por mm0, mm5
psrlq mm6, 8
psllq mm7, 56
por mm6, mm7
pavgb mm0, [ecx+008h]
pavgb mm0, mm6
movq mm1, [ecx+018h]
movq mm5, [ecx+0b0h]
movq mm6, mm1
psrlq mm1, 16
movq mm7, mm5
psllq mm5, 48
por mm1, mm5
psrlq mm6, 8
psllq mm7, 56
por mm6, mm7
pavgb mm1, [ecx+018h]
pavgb mm1, mm6
movq mm2, [ecx+028h]
movq mm5, [ecx+0c0h]
movq mm6, mm2
psrlq mm2, 16
movq mm7, mm5
psllq mm5, 48
por mm2, mm5
psrlq mm6, 8
psllq mm7, 56
por mm6, mm7
pavgb mm2, [ecx+028h]
pavgb mm2, mm6
movq mm3, [ecx+038h]
movq mm5, [ecx+0d0h]
movq mm6, mm3
psrlq mm3, 16
movq mm7, mm5
psllq mm5, 48
por mm3, mm5
psrlq mm6, 8
psllq mm7, 56
por mm6, mm7
pavgb mm3, [ecx+038h]
pavgb mm3, mm6
movq mm4, [ecx+048h]
movq mm5, [ecx+0e0h]
movq mm6, mm4
psrlq mm4, 16
movq mm7, mm5
psllq mm5, 48
por mm4, mm5
psrlq mm6, 8
psllq mm7, 56
por mm6, mm7
pavgb mm4, [ecx+048h]
pavgb mm4, mm6
movq mm5, x7fb
pxor mm0, mm5
pxor mm1, mm5
pxor mm2, mm5
pxor mm3, mm5
pxor mm4, mm5
;mm0 = scorec0
;mm1 = scorel1
;mm2 = scorel2
;mm3 = scorer1
;mm4 = scorer2
movq mm5, mm3
pcmpgtb mm5, mm1 ;(scorer1 > scorel1) == (scorel1 < scorer1)
pcmpgtb mm4, mm3 ;scorer2 > scorer1
pcmpgtb mm2, mm1 ;scorel2 > scorel1
pcmpgtb mm1, mm0 ;scorel1 > scorec0
pcmpgtb mm3, mm0 ;scorer1 > scorec0
movq mm6, mm1
pcmpeqb mm0, mm0
por mm6, mm3 ;scorel1 > scorec0 || scorer1 > scorec0
pxor mm0, mm6 ;mask_c0
pand mm3, mm5 ;scorer1 > scorec0 && scorer1 > scorel1
pandn mm5, mm1 ;scorel1 > scorec0 && scorel1 >= scorer1
pand mm4, mm3 ;mask_r2
pand mm2, mm5 ;mask_l2
pxor mm3, mm4 ;mask_r1
pxor mm5, mm2 ;mask_l1
pand mm0, [ecx+058h]
pand mm5, [ecx+068h]
pand mm2, [ecx+078h]
pand mm3, [ecx+088h]
pand mm4, [ecx+098h]
por mm0, mm5
por mm2, mm3
por mm0, mm4
por mm0, mm2
movq [edx+8], mm0
add ecx, 0a0h
add edx, 16
dec eax
jnz xloop
emms
ret 12
}
}
void __declspec(naked) __stdcall nela_L8_MMX(void *dst, const void *elabuf, int w16) {
static const __declspec(align(8)) uint64 x7fb = 0x7f7f7f7f7f7f7f7f;
__asm {
mov edx, [esp+4]
mov ecx, [esp+8]
mov eax, [esp+12]
xloop:
movq mm0, [ecx+000h]
movq mm5, [ecx+002h]
movq mm6, mm0
pxor mm0, mm5
por mm6, mm5
movq mm7, [ecx+001h]
psrlq mm0, 1
pand mm0, x7fb
psubb mm6, mm0
movq mm0, mm6
pxor mm6, mm7
por mm0, mm7
psrlq mm6, 1
pand mm6, x7fb
psubb mm0, mm6
movq mm1, [ecx+010h]
movq mm5, [ecx+012h]
movq mm6, mm1
pxor mm1, mm5
por mm6, mm5
movq mm7, [ecx+011h]
psrlq mm1, 1
pand mm1, x7fb
psubb mm6, mm1
movq mm1, mm6
pxor mm6, mm7
por mm1, mm7
psrlq mm6, 1
pand mm6, x7fb
psubb mm1, mm6
movq mm2, [ecx+020h]
movq mm5, [ecx+022h]
movq mm6, mm2
pxor mm2, mm5
por mm6, mm5
movq mm7, [ecx+021h]
psrlq mm2, 1
pand mm2, x7fb
psubb mm6, mm2
movq mm2, mm6
pxor mm6, mm7
por mm2, mm7
psrlq mm6, 1
pand mm6, x7fb
psubb mm2, mm6
movq mm3, [ecx+030h]
movq mm5, [ecx+032h]
movq mm6, mm3
pxor mm3, mm5
por mm6, mm5
movq mm7, [ecx+031h]
psrlq mm3, 1
pand mm3, x7fb
psubb mm6, mm3
movq mm3, mm6
pxor mm6, mm7
por mm3, mm7
psrlq mm6, 1
pand mm6, x7fb
psubb mm3, mm6
movq mm4, [ecx+040h]
movq mm5, [ecx+042h]
movq mm6, mm4
pxor mm4, mm5
por mm6, mm5
movq mm7, [ecx+041h]