-
Notifications
You must be signed in to change notification settings - Fork 0
/
asmfuncsYV12_intel.cpp
950 lines (885 loc) · 21.8 KB
/
asmfuncsYV12_intel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
/*
Telecide plugin for Avisynth -- recovers original progressive
frames from telecined streams. The filter operates by matching
fields and automatically adapts to phase/pattern changes.
Copyright (C) 2003-2008 Donald A. Graft
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.
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 "version.h"
#include "asmfuncsYV12.h"
#ifdef _MSC_VER
#pragma warning(disable:4799)
#endif
#ifdef DEINTERLACE_MMX_BUILD
/*********************
* YV12 Conditional deinterlacer.
*
* (c) 2003, Klaus Post
* - Algorithm by Donald Graft
*
* ISSE, Blend version.
*
* Deinterlaces one line in a planar image based on
* a given deinterlace map.
*********************/
void isse_blend_plane(BYTE* org, BYTE* src_prev, BYTE* src_next, BYTE* dmaskp, int w) {
#if !defined(GCC__)
__asm {
xor eax, eax
mov esi, org
mov ebx, dmaskp
mov ecx, src_prev
mov edx, src_next
pcmpeqb mm7,mm7 // All 1's
jmp loop_test
align 16
loopback:
movq mm0,[esi+eax] // src
movq mm1,[ecx+eax] // next
movq mm2,[edx+eax] // prev
movq mm4,[ebx+eax] // mask
// Blend pixels
pavgb mm1,mm2 // Blend prev & next 50/50
movq mm5,mm4 // copy mask
pavgb mm1,mm0 // Now correctly blended.
pxor mm5,mm7 // Inv mask
pand mm1, mm4
pand mm0, mm5
// movq mm1,mm0 // Enable debug viewing of mask!
por mm1,mm0
movq [esi+eax],mm1
add eax,8
loop_test:
cmp eax,w
jl loopback
emms
}
#else
__asm__ __volatile__
(
" xor eax,eax\n"
" mov esi,%[org]\n"
" mov ebx,%[dmaskp]\n"
" mov ecx,%[src_prev]\n"
" mov edx,%[src_next]\n"
" pcmpeqb mm7,mm7\n"
" jmp isse_blend_plane_loop_test\n"
" .align 16\n"
"isse_blend_plane_loopback:\n"
" movq mm0,[esi+eax]\n"
" movq mm1,[ecx+eax]\n"
" movq mm2,[edx+eax]\n"
" movq mm4,[ebx+eax]\n"
" pavgb mm1,mm2\n"
" movq mm5,mm4\n"
" pavgb mm1,mm0\n"
" pxor mm5,mm7\n"
" pand mm1,mm4\n"
" pand mm0,mm5\n"
" por mm1,mm0\n"
" movq [esi+eax],mm1\n"
" add eax,8\n"
"isse_blend_plane_loop_test:\n"
" cmp eax,%[w]\n"
" jl isse_blend_plane_loopback\n"
" emms\n"
:
: [w] "m" (w),
[src_next] "m" (src_next),
[src_prev] "m" (src_prev),
[dmaskp] "m" (dmaskp),
[org] "m" (org)
: "mm5", "mm0", "mm2", "mm1", "memory", "ebx", "ecx", "esi", "edx", "mm4", "mm7", "eax"
);
#endif
}
/*********************
* YV12 Conditional deinterlacer.
*
* (c) 2003, Klaus Post
* - Algorithm by Donald Graft
*
* ISSE, Interpolate version.
*
* Deinterlaces one line in a planar image based on
* a given deinterlace map.
*********************/
void isse_interpolate_plane(BYTE* org, BYTE* src_prev, BYTE* src_next, BYTE* dmaskp, int w) {
#if !defined(GCC__)
__asm {
xor eax, eax
mov esi, org
mov ebx, dmaskp
mov ecx, src_prev
mov edx, src_next
pcmpeqb mm7,mm7 // All 1's
jmp loop_test
align 16
loopback:
movq mm4,[ebx+eax] // mask
movq mm0,[esi+eax] // src
movq mm1,[ecx+eax] // next
movq mm2,[edx+eax] // prev
movq mm5,mm4 // copy mask
// Blend pixels
pavgb mm1,mm2 // Blend prev & next 50/50
pxor mm5,mm7 // Inv mask
pand mm1, mm4
pand mm0, mm5
// movq mm1,mm0 // Enable debug viewing of mask!
por mm1,mm0
movq [esi+eax],mm1
add eax,8
loop_test:
cmp eax,w
jl loopback
emms
}
#else
__asm__ __volatile__
(
" xor eax,eax\n"
" mov esi,%[org]\n"
" mov ebx,%[dmaskp]\n"
" mov ecx,%[src_prev]\n"
" mov edx,%[src_next]\n"
" pcmpeqb mm7,mm7\n"
" jmp isse_interpolate_plane_loop_test\n"
" .align 16\n"
"isse_interpolate_plane_loopback:\n"
" movq mm4,[ebx+eax]\n"
" movq mm0,[esi+eax]\n"
" movq mm1,[ecx+eax]\n"
" movq mm2,[edx+eax]\n"
" movq mm5,mm4\n"
" pavgb mm1,mm2\n"
" pxor mm5,mm7\n"
" pand mm1,mm4\n"
" pand mm0,mm5\n"
" por mm1,mm0\n"
" movq [esi+eax],mm1\n"
" add eax,8\n"
"isse_interpolate_plane_loop_test:\n"
" cmp eax,%[w]\n"
" jl isse_interpolate_plane_loopback\n"
" emms\n"
:
: [w] "m" (w),
[src_next] "m" (src_next),
[src_prev] "m" (src_prev),
[dmaskp] "m" (dmaskp),
[org] "m" (org)
: "mm5", "mm0", "mm2", "mm1", "memory", "ebx", "ecx", "edx", "esi", "mm4", "mm7", "eax"
);
#endif
}
/*********************
* YV12 Deinterlace mask.
*
* (c) 2003, Klaus Post
* - Algorithm by Donald Graft
*
* MMX version.
*
* Creates two masks based on the interlacing in the image.
* Overwrites both masks.
*********************/
void mmx_createmask_plane(const BYTE* srcp, const BYTE* prev_p, const BYTE* next_p, BYTE* fmaskp, BYTE* dmaskp, int threshold, int dthreshold, int row_size) {
threshold=(threshold+1)/2;
dthreshold=(dthreshold+1)/2;
__int64 dt = dthreshold | (dthreshold<<16);
__int64 t = threshold | (threshold<<16);
#if !defined(GCC__)
__declspec(align(8)) static __int64 mask1 = 0x00ff00ff00ff00ff;
__asm {
xor eax, eax
mov esi, srcp
mov ebx, prev_p
mov ecx, next_p
mov edx, dmaskp
mov edi, fmaskp
movd mm6, [t]
pxor mm7, mm7
punpckldq mm6,mm6
jmp loop_test
align 16
loopback:
movq mm0, [esi+eax] // src
movq mm1, [ebx+eax] // prev
movq mm3,mm0
movq mm4,mm1
movq mm2, [ecx+eax] // next
punpcklbw mm0,mm7 // src low
punpckhbw mm3,mm7 // src high
movq mm5,mm2
punpcklbw mm1,mm7 // prev low
punpckhbw mm4,mm7 // prev high
punpcklbw mm2,mm7 // next low
punpckhbw mm5,mm7 // next high
movd mm7, [dt]
psubsw mm1, mm0 // p-src low
psubsw mm2, mm0 // n-src low
psraw mm1,1 // Avoid multiply signed overflow
psubsw mm4, mm3 // p-src high
pmullw mm1,mm2 // multiply low
psubsw mm5, mm3 // n-src high
psraw mm4,1 // Avoid multiply signed overflow
movq mm0,mm1 // copy low result
pmullw mm4,mm5 // multiply high
punpckldq mm7,mm7 //
movq mm3,[mask1]
movq mm2,mm4 // copy high result
pcmpgtw mm0,mm6 // Threshold low 0 if mult result is less than t
pcmpgtw mm2,mm6 // Threshold high
pcmpgtw mm1,mm7 // D-Threshold low
pcmpgtw mm4,mm7 // D-Threshold high
pand mm0,mm3
pand mm1,mm3
pand mm2,mm3
pand mm4,mm3
packuswb mm0,mm2 // fmask
packuswb mm1,mm4 // dmask
movq [edi+eax],mm0
movq [edx+eax],mm1
pxor mm7, mm7
add eax,8
loop_test:
cmp eax,row_size
jl loopback
emms
}
#else
static __int64 mask1 = 0x00ff00ff00ff00ffLL;
__asm__ __volatile__
(
" xor eax,eax\n"
" mov esi,%[srcp]\n"
" mov ebx,%[prev_p]\n"
" mov ecx,%[next_p]\n"
" mov edx,%[dmaskp]\n"
" mov edi,%[fmaskp]\n"
" movq mm6,[%[t]]\n"
" pxor mm7,mm7\n"
" punpckldq mm6,mm6\n"
" jmp mmx_createmask_plane_loop_test\n"
" .align 16\n"
"mmx_createmask_plane_loopback:\n"
" movq mm0,[esi+eax]\n"
" movq mm1,[ebx+eax]\n"
" movq mm3,mm0\n"
" movq mm4,mm1\n"
" movq mm2,[ecx+eax]\n"
" punpcklbw mm0,mm7\n"
" punpckhbw mm3,mm7\n"
" movq mm5,mm2\n"
" punpcklbw mm1,mm7\n"
" punpckhbw mm4,mm7\n"
" punpcklbw mm2,mm7\n"
" punpckhbw mm5,mm7\n"
" movq mm7,[%[dt]]\n"
" psubsw mm1,mm0\n"
" psubsw mm2,mm0\n"
" psraw mm1,1\n"
" psubsw mm4,mm3\n"
" pmullw mm1,mm2\n"
" psubsw mm5,mm3\n"
" psraw mm4,1\n"
" movq mm0,mm1\n"
" pmullw mm4,mm5\n"
" punpckldq mm7,mm7\n"
" movq mm3,[%[mask1]]\n"
" movq mm2,mm4\n"
" pcmpgtw mm0,mm6\n"
" pcmpgtw mm2,mm6\n"
" pcmpgtw mm1,mm7\n"
" pcmpgtw mm4,mm7\n"
" pand mm0,mm3\n"
" pand mm1,mm3\n"
" pand mm2,mm3\n"
" pand mm4,mm3\n"
" packuswb mm0,mm2\n"
" packuswb mm1,mm4\n"
" movq [edi+eax],mm0\n"
" movq [edx+eax],mm1\n"
" pxor mm7,mm7\n"
" add eax,8\n"
"mmx_createmask_plane_loop_test:\n"
" cmp eax,%[row_size]\n"
" jl mmx_createmask_plane_loopback\n"
" emms\n"
:
: [dt] "m" (dt),
[t] "m" (t),
[fmaskp] "m" (fmaskp),
[srcp] "m" (srcp),
[row_size] "m" (row_size),
[mask1] "m" (mask1),
[dmaskp] "m" (dmaskp),
[next_p] "m" (next_p),
[prev_p] "m" (prev_p)
: "mm5", "mm0", "mm2", "mm1", "mm3", "memory", "ebx", "ecx", "edx", "esi", "mm6", "mm4", "edi", "mm7", "eax"
);
#endif
}
/*********************
* YV12 Deinterlace mask.
*
* (c) 2003, Klaus Post
* - Algorithm by Donald Graft
*
* MMX version. One mask only!
*
* Creates one masks based on the interlacing in the image.
* Overwrites existing mask.
*********************/
void mmx_createmask_plane_single(const BYTE* srcp, const BYTE* prev_p, const BYTE* next_p, BYTE* dmaskp, int dthreshold, int row_size) {
dthreshold=(dthreshold+1)/2;
__int64 dt = dthreshold | (dthreshold<<16);
#if !defined(GCC__)
__declspec(align(8)) static __int64 mask1 = 0x00ff00ff00ff00ff;
__asm {
xor eax, eax
mov esi, srcp
mov ebx, prev_p
mov ecx, next_p
mov edx, dmaskp
lea edi, mask1
movd mm6, [dt]
pxor mm7, mm7
punpckldq mm6,mm6
jmp loop_test
align 16
loopback:
movq mm0, [esi+eax] // src
movq mm1, [ebx+eax] // prev
movq mm3,mm0
movq mm4,mm1
movq mm2, [ecx+eax] // next
punpcklbw mm0,mm7 // src low
punpckhbw mm3,mm7 // src high
movq mm5,mm2
punpcklbw mm1,mm7 // prev low
punpckhbw mm4,mm7 // prev high
punpcklbw mm2,mm7 // next low
punpckhbw mm5,mm7 // next high
psubsw mm1, mm0 // p-src low
psubsw mm2, mm0 // n-src low
psraw mm1,1 // Avoid multiply signed overflow
psubsw mm4, mm3 // p-src high
pmullw mm1,mm2 // multiply low
psubsw mm5, mm3 // n-src high
psraw mm4,1 // Avoid multiply signed overflow
movq mm0,mm1 // copy low result
pmullw mm4,mm5 // multiply high
movq mm3,[edi]
movq mm2,mm4 // copy high result
pcmpgtw mm1,mm6 // D-Threshold low
pcmpgtw mm4,mm6 // D-Threshold high
pand mm0,mm3
pand mm1,mm3
pand mm2,mm3
pand mm4,mm3
packuswb mm1,mm4 // dmask
movq [edx+eax],mm1
add eax,8
loop_test:
cmp eax,row_size
jl loopback
emms
}
#else
static __int64 mask1 = 0x00ff00ff00ff00ffLL;
__asm__ __volatile__
(
" xor eax,eax\n"
" mov esi,%[srcp]\n"
" mov ebx,%[prev_p]\n"
" mov ecx,%[next_p]\n"
" mov edx,%[dmaskp]\n"
" lea edi,%[mask1]\n"
" movq mm6,[%[dt]]\n"
" pxor mm7,mm7\n"
" punpckldq mm6,mm6\n"
" jmp mmx_createmask_plane_single_loop_test\n"
" .align 16\n"
"mmx_createmask_plane_single_loopback:\n"
" movq mm0,[esi+eax]\n"
" movq mm1,[ebx+eax]\n"
" movq mm3,mm0\n"
" movq mm4,mm1\n"
" movq mm2,[ecx+eax]\n"
" punpcklbw mm0,mm7\n"
" punpckhbw mm3,mm7\n"
" movq mm5,mm2\n"
" punpcklbw mm1,mm7\n"
" punpckhbw mm4,mm7\n"
" punpcklbw mm2,mm7\n"
" punpckhbw mm5,mm7\n"
" psubsw mm1,mm0\n"
" psubsw mm2,mm0\n"
" psraw mm1,1\n"
" psubsw mm4,mm3\n"
" pmullw mm1,mm2\n"
" psubsw mm5,mm3\n"
" psraw mm4,1\n"
" movq mm0,mm1\n"
" pmullw mm4,mm5\n"
" movq mm3,[edi]\n"
" movq mm2,mm4\n"
" pcmpgtw mm1,mm6\n"
" pcmpgtw mm4,mm6\n"
" pand mm0,mm3\n"
" pand mm1,mm3\n"
" pand mm2,mm3\n"
" pand mm4,mm3\n"
" packuswb mm1,mm4\n"
" movq [edx+eax],mm1\n"
" add eax,8\n"
"mmx_createmask_plane_single_loop_test:\n"
" cmp eax,%[row_size]\n"
" jl mmx_createmask_plane_single_loopback\n"
" emms\n"
:
: [dt] "m" (dt),
[srcp] "m" (srcp),
[row_size] "m" (row_size),
[mask1] "m" (mask1),
[dmaskp] "m" (dmaskp),
[next_p] "m" (next_p),
[prev_p] "m" (prev_p)
: "mm5", "mm0", "mm2", "mm1", "mm3", "memory", "ebx", "ecx", "edx", "esi", "mm6", "mm4", "edi", "mm7", "eax"
);
#endif
}
#endif
/*******************************
***** DECIMATE HELPERS ******
******************************/
#ifdef DECIMATE_MMX_BUILD
/*********************
* YV12 Plane blender.
*
* (c) 2003, Klaus Post
* - Algorithm by Donald Graft
*
* ISSE, Blend version.
*
* Blends two planes 50/50
* Rowsize of mod8 is required.
* src and dst way very well be the same!
*********************/
void isse_blend_decimate_plane(BYTE* dst, BYTE* src, BYTE* src_next, int w, int h, int dst_pitch, int src_pitch, int src_next_pitch) {
if (!h) return; // Height == 0 - avoid silly crash.
#if !defined(GCC__)
__asm {
mov ebx, h
mov ecx, w
mov esi, src
mov edi, dst
mov edx, src_next
align 16
yloop:
xor eax, eax // Width counter
jmp loop_test
align 16
loopback:
movq mm0,[esi+eax] // src
movq mm1,[edx+eax] // next
// Blend pixels
pavgb mm1,mm0 // Blend prev & src 50 / 50
movq [edi+eax],mm1
add eax,8
loop_test:
cmp eax,ecx
jl loopback
add edi,dst_pitch
add esi,src_pitch
add edx,src_next_pitch
dec ebx
jnz yloop
emms
}
#else
__asm__ __volatile__
(
" mov ebx,%[h]\n"
" mov ecx,%[w]\n"
" mov esi,%[src]\n"
" mov edi,%[dst]\n"
" mov edx,%[src_next]\n"
" .align 16\n"
"isse_blend_decimate_plane_yloop:\n"
" xor eax,eax\n"
" jmp isse_blend_decimate_plane_loop_test\n"
" .align 16\n"
"isse_blend_decimate_plane_loopback:\n"
" movq mm0,[esi+eax]\n"
" movq mm1,[edx+eax]\n"
" pavgb mm1,mm0\n"
" movq [edi+eax],mm1\n"
" add eax,8\n"
"isse_blend_decimate_plane_loop_test:\n"
" cmp eax,ecx\n"
" jl isse_blend_decimate_plane_loopback\n"
" add edi,%[dst_pitch]\n"
" add esi,%[src_pitch]\n"
" add edx,%[src_next_pitch]\n"
" dec ebx\n"
" jnz isse_blend_decimate_plane_yloop\n"
" emms\n"
:
: [w] "m" (w),
[src] "m" (src),
[src_next_pitch] "m" (src_next_pitch),
[dst_pitch] "m" (dst_pitch),
[src_next] "m" (src_next),
[h] "m" (h),
[src_pitch] "m" (src_pitch),
[dst] "m" (dst)
: "mm0", "mm1", "memory", "ebx", "ecx", "edx", "esi", "edi", "eax"
);
#endif
}
/*********************
* YV12 Scenechange detection.
*
* (c) 2003, Klaus Post
*
* ISSE, MOD 32 version.
*
* Returns an int of the accumulated absolute difference
* between two planes.
*
* The absolute difference between two planes are returned as an int.
* This version is optimized for mod32 widths. Others widths are allowed,
* but the remaining pixels are simply skipped.
*********************/
int isse_scenechange_32(const BYTE* c_plane, const BYTE* tplane, int height, int width, int c_pitch, int t_pitch) {
int wp=(width/32)*32;
int hp=height;
int returnvalue=0xbadbad00;
#if !defined(GCC__)
__asm {
xor ebx,ebx // Height
pxor mm5,mm5 // Maximum difference
mov edx, c_pitch //copy pitch
mov ecx, t_pitch //copy pitch
pxor mm6,mm6 // We maintain two sums, for better pairablility
pxor mm7,mm7
mov esi, c_plane
mov edi, tplane
jmp yloopover
align 16
yloop:
inc ebx
add edi,ecx // add pitch to both planes
add esi,edx
yloopover:
cmp ebx,[hp]
jge endframe
xor eax,eax // Width
align 16
xloop:
cmp eax,[wp]
jge yloop
movq mm0,[esi+eax]
movq mm2,[esi+eax+8]
movq mm1,[edi+eax]
movq mm3,[edi+eax+8]
psadbw mm0,mm1 // Sum of absolute difference
psadbw mm2,mm3
paddd mm6,mm0 // Add...
paddd mm7,mm2
movq mm0,[esi+eax+16]
movq mm2,[esi+eax+24]
movq mm1,[edi+eax+16]
movq mm3,[edi+eax+24]
psadbw mm0,mm1
psadbw mm2,mm3
paddd mm6,mm0
paddd mm7,mm2
add eax,32
jmp xloop
endframe:
paddd mm7,mm6
movd returnvalue,mm7
emms
}
#else
__asm__ __volatile__
(
" xor ebx,ebx\n"
" pxor mm5,mm5\n"
" mov edx,%[c_pitch]\n"
" mov ecx,%[t_pitch]\n"
" pxor mm6,mm6\n"
" pxor mm7,mm7\n"
" mov esi,%[c_plane]\n"
" mov edi,%[tplane]\n"
" jmp isse_scenechange_32_yloopover\n"
" .align 16\n"
"isse_scenechange_32_yloop:\n"
" inc ebx\n"
" add edi,ecx\n"
" add esi,edx\n"
"isse_scenechange_32_yloopover:\n"
" cmp ebx,[%[hp]]\n"
" jge isse_scenechange_32_endframe\n"
" xor eax,eax\n"
" .align 16\n"
"isse_scenechange_32_xloop:\n"
" cmp eax,[%[wp]]\n"
" jge isse_scenechange_32_yloop\n"
" movq mm0,[esi+eax]\n"
" movq mm2,[esi+eax+8]\n"
" movq mm1,[edi+eax]\n"
" movq mm3,[edi+eax+8]\n"
" psadbw mm0,mm1\n"
" psadbw mm2,mm3\n"
" paddd mm6,mm0\n"
" paddd mm7,mm2\n"
" movq mm0,[esi+eax+16]\n"
" movq mm2,[esi+eax+24]\n"
" movq mm1,[edi+eax+16]\n"
" movq mm3,[edi+eax+24]\n"
" psadbw mm0,mm1\n"
" psadbw mm2,mm3\n"
" paddd mm6,mm0\n"
" paddd mm7,mm2\n"
" add eax,32\n"
" jmp isse_scenechange_32_xloop\n"
"isse_scenechange_32_endframe:\n"
" paddd mm7,mm6\n"
" movd %[returnvalue],mm7\n"
" emms\n"
: [returnvalue] "=m" (returnvalue)
: [tplane] "m" (tplane),
[c_plane] "m" (c_plane),
[hp] "m" (hp),
[wp] "m" (wp),
[t_pitch] "m" (t_pitch),
[c_pitch] "m" (c_pitch)
: "mm5", "mm0", "mm1", "mm2", "mm3", "ebx", "ecx", "esi", "edx", "mm6", "edi", "mm7", "eax"
);
#endif
return returnvalue;
}
/*********************
* YV12 Scenechange detection.
*
* (c) 2003, Klaus Post
*
* ISSE, MOD 16 version.
*
* Returns an int of the accumulated absolute difference
* between two planes.
*
* The absolute difference between two planes are returned as an int.
* This version is optimized for mod16 widths. Others widths are allowed,
* but the remaining pixels are simply skipped.
*********************/
int isse_scenechange_16(const BYTE* c_plane, const BYTE* tplane, int height, int width, int c_pitch, int t_pitch) {
int wp=(width/16)*16;
int hp=height;
int returnvalue=0xbadbad00;
#if !defined(GCC__)
__asm {
xor ebx,ebx // Height
pxor mm5,mm5 // Maximum difference
mov edx, c_pitch //copy pitch
mov ecx, t_pitch //copy pitch
pxor mm6,mm6 // We maintain two sums, for better pairablility
pxor mm7,mm7
mov esi, c_plane
mov edi, tplane
jmp yloopover
align 16
yloop:
inc ebx
add edi,ecx // add pitch to both planes
add esi,edx
yloopover:
cmp ebx,[hp]
jge endframe
xor eax,eax // Width
align 16
xloop:
cmp eax,[wp]
jge yloop
movq mm0,[esi+eax]
movq mm2,[esi+eax+8]
movq mm1,[edi+eax]
movq mm3,[edi+eax+8]
psadbw mm0,mm1 // Sum of absolute difference
psadbw mm2,mm3
paddd mm6,mm0 // Add...
paddd mm7,mm2
add eax,16
jmp xloop
endframe:
paddd mm7,mm6
movd returnvalue,mm7
emms
}
#else
__asm__ __volatile__
(
" xor ebx,ebx\n"
" pxor mm5,mm5\n"
" mov edx,%[c_pitch]\n"
" mov ecx,%[t_pitch]\n"
" pxor mm6,mm6\n"
" pxor mm7,mm7\n"
" mov esi,%[c_plane]\n"
" mov edi,%[tplane]\n"
" jmp isse_scenechange_16_yloopover\n"
" .align 16\n"
"isse_scenechange_16_yloop:\n"
" inc ebx\n"
" add edi,ecx\n"
" add esi,edx\n"
"isse_scenechange_16_yloopover:\n"
" cmp ebx,[%[hp]]\n"
" jge isse_scenechange_16_endframe\n"
" xor eax,eax\n"
" .align 16\n"
"isse_scenechange_16_xloop:\n"
" cmp eax,[%[wp]]\n"
" jge isse_scenechange_16_yloop\n"
" movq mm0,[esi+eax]\n"
" movq mm2,[esi+eax+8]\n"
" movq mm1,[edi+eax]\n"
" movq mm3,[edi+eax+8]\n"
" psadbw mm0,mm1\n"
" psadbw mm2,mm3\n"
" paddd mm6,mm0\n"
" paddd mm7,mm2\n"
" add eax,16\n"
" jmp isse_scenechange_16_xloop\n"
"isse_scenechange_16_endframe:\n"
" paddd mm7,mm6\n"
" movd %[returnvalue],mm7\n"
" emms\n"
: [returnvalue] "=m" (returnvalue)
: [tplane] "m" (tplane),
[c_plane] "m" (c_plane),
[hp] "m" (hp),
[wp] "m" (wp),
[t_pitch] "m" (t_pitch),
[c_pitch] "m" (c_pitch)
: "mm5", "mm0", "mm1", "mm2", "mm3", "ebx", "ecx", "esi", "edx", "mm6", "edi", "mm7", "eax"
);
#endif
return returnvalue;
}
/*********************
* YV12 Scenechange detection.
*
* (c) 2003, Klaus Post
*
* ISSE, MOD 8 version.
*
* Returns an int of the accumulated absolute difference
* between two planes.
*
* The absolute difference between two planes are returned as an int.
* This version is optimized for mod8 widths. Others widths are allowed,
* but the remaining pixels are simply skipped.
*********************/
int isse_scenechange_8(const BYTE* c_plane, const BYTE* tplane, int height, int width, int c_pitch, int t_pitch) {
int wp=(width/8)*8;
int hp=height;
int returnvalue=0xbadbad00;
#if !defined(GCC__)
__asm {
xor ebx,ebx // Height
pxor mm5,mm5 // Maximum difference
mov edx, c_pitch //copy pitch
mov ecx, t_pitch //copy pitch
pxor mm6,mm6 // We maintain two sums, for better pairablility
pxor mm7,mm7
mov esi, c_plane
mov edi, tplane
jmp yloopover
align 16
yloop:
inc ebx
add edi,ecx // add pitch to both planes
add esi,edx
yloopover:
cmp ebx,[hp]
jge endframe
xor eax,eax // Width
align 16
xloop:
cmp eax,[wp]
jge yloop
movq mm0,[esi+eax]
movq mm1,[edi+eax]
psadbw mm0,mm1 // Sum of absolute difference
paddd mm6,mm0 // Add...
add eax,8
jmp xloop
endframe:
movd returnvalue,mm6
emms
}
#else
__asm__ __volatile__
(
" xor ebx,ebx\n"
" pxor mm5,mm5\n"
" mov edx,%[c_pitch]\n"
" mov ecx,%[t_pitch]\n"
" pxor mm6,mm6\n"
" pxor mm7,mm7\n"
" mov esi,%[c_plane]\n"
" mov edi,%[tplane]\n"
" jmp isse_scenechange_8_yloopover\n"
" .align 16\n"
"isse_scenechange_8_yloop:\n"
" inc ebx\n"
" add edi,ecx\n"
" add esi,edx\n"
"isse_scenechange_8_yloopover:\n"
" cmp ebx,[%[hp]]\n"
" jge isse_scenechange_8_endframe\n"
" xor eax,eax\n"
" .align 16\n"
"isse_scenechange_8_xloop:\n"
" cmp eax,[%[wp]]\n"
" jge isse_scenechange_8_yloop\n"
" movq mm0,[esi+eax]\n"
" movq mm1,[edi+eax]\n"
" psadbw mm0,mm1\n"
" paddd mm6,mm0\n"
" add eax,8\n"
" jmp isse_scenechange_8_xloop\n"
"isse_scenechange_8_endframe:\n"
" movd %[returnvalue],mm6\n"
" emms\n"
: [returnvalue] "=m" (returnvalue)
: [tplane] "m" (tplane),
[c_plane] "m" (c_plane),
[hp] "m" (hp),
[wp] "m" (wp),
[t_pitch] "m" (t_pitch),
[c_pitch] "m" (c_pitch)
: "mm5", "mm0", "mm1", "ebx", "ecx", "esi", "edx", "mm6", "edi", "mm7", "eax"
);
#endif
return returnvalue;
}
#ifdef _MSC_VER
#pragma warning(default:4799)
#endif
#endif