31 static int diff_y_mmx(
unsigned char *
a,
unsigned char *
b,
int s)
36 "pxor %%mm4, %%mm4 \n\t"
37 "pxor %%mm7, %%mm7 \n\t"
41 "movq (%%"REG_S
"), %%mm0 \n\t"
42 "movq (%%"REG_S
"), %%mm2 \n\t"
43 "add %%"REG_a
", %%"REG_S
" \n\t"
44 "movq (%%"REG_D
"), %%mm1 \n\t"
45 "add %%"REG_a
", %%"REG_D
" \n\t"
46 "psubusb %%mm1, %%mm2 \n\t"
47 "psubusb %%mm0, %%mm1 \n\t"
48 "movq %%mm2, %%mm0 \n\t"
49 "movq %%mm1, %%mm3 \n\t"
50 "punpcklbw %%mm7, %%mm0 \n\t"
51 "punpcklbw %%mm7, %%mm1 \n\t"
52 "punpckhbw %%mm7, %%mm2 \n\t"
53 "punpckhbw %%mm7, %%mm3 \n\t"
54 "paddw %%mm0, %%mm4 \n\t"
55 "paddw %%mm1, %%mm4 \n\t"
56 "paddw %%mm2, %%mm4 \n\t"
57 "paddw %%mm3, %%mm4 \n\t"
62 "movq %%mm4, %%mm3 \n\t"
63 "punpcklwd %%mm7, %%mm4 \n\t"
64 "punpckhwd %%mm7, %%mm3 \n\t"
65 "paddd %%mm4, %%mm3 \n\t"
66 "movd %%mm3, %%eax \n\t"
67 "psrlq $32, %%mm3 \n\t"
68 "movd %%mm3, %%edx \n\t"
69 "addl %%edx, %%eax \n\t"
72 :
"S" (a),
"D" (
b),
"a" (s)
78 static int licomb_y_mmx(
unsigned char *a,
unsigned char *b,
int s)
83 "pxor %%mm6, %%mm6 \n\t"
84 "pxor %%mm7, %%mm7 \n\t"
85 "sub %%"REG_a
", %%"REG_D
" \n\t"
89 "movq (%%"REG_D
"), %%mm0 \n\t"
90 "movq (%%"REG_D
"), %%mm1 \n\t"
91 "punpcklbw %%mm7, %%mm0 \n\t"
92 "movq (%%"REG_D
",%%"REG_a
"), %%mm2 \n\t"
93 "punpcklbw %%mm7, %%mm1 \n\t"
94 "punpcklbw %%mm7, %%mm2 \n\t"
95 "paddw %%mm0, %%mm0 \n\t"
96 "paddw %%mm2, %%mm1 \n\t"
97 "movq %%mm0, %%mm2 \n\t"
98 "psubusw %%mm1, %%mm0 \n\t"
99 "psubusw %%mm2, %%mm1 \n\t"
100 "paddw %%mm0, %%mm6 \n\t"
101 "paddw %%mm1, %%mm6 \n\t"
103 "movq (%%"REG_S
"), %%mm0 \n\t"
104 "movq (%%"REG_D
"), %%mm1 \n\t"
105 "punpckhbw %%mm7, %%mm0 \n\t"
106 "movq (%%"REG_D
",%%"REG_a
"), %%mm2 \n\t"
107 "punpckhbw %%mm7, %%mm1 \n\t"
108 "punpckhbw %%mm7, %%mm2 \n\t"
109 "paddw %%mm0, %%mm0 \n\t"
110 "paddw %%mm2, %%mm1 \n\t"
111 "movq %%mm0, %%mm2 \n\t"
112 "psubusw %%mm1, %%mm0 \n\t"
113 "psubusw %%mm2, %%mm1 \n\t"
114 "paddw %%mm0, %%mm6 \n\t"
115 "paddw %%mm1, %%mm6 \n\t"
117 "movq (%%"REG_D
",%%"REG_a
"), %%mm0 \n\t"
118 "movq (%%"REG_S
"), %%mm1 \n\t"
119 "punpcklbw %%mm7, %%mm0 \n\t"
120 "movq (%%"REG_S
",%%"REG_a
"), %%mm2 \n\t"
121 "punpcklbw %%mm7, %%mm1 \n\t"
122 "punpcklbw %%mm7, %%mm2 \n\t"
123 "paddw %%mm0, %%mm0 \n\t"
124 "paddw %%mm2, %%mm1 \n\t"
125 "movq %%mm0, %%mm2 \n\t"
126 "psubusw %%mm1, %%mm0 \n\t"
127 "psubusw %%mm2, %%mm1 \n\t"
128 "paddw %%mm0, %%mm6 \n\t"
129 "paddw %%mm1, %%mm6 \n\t"
131 "movq (%%"REG_D
",%%"REG_a
"), %%mm0 \n\t"
132 "movq (%%"REG_S
"), %%mm1 \n\t"
133 "punpckhbw %%mm7, %%mm0 \n\t"
134 "movq (%%"REG_S
",%%"REG_a
"), %%mm2 \n\t"
135 "punpckhbw %%mm7, %%mm1 \n\t"
136 "punpckhbw %%mm7, %%mm2 \n\t"
137 "paddw %%mm0, %%mm0 \n\t"
138 "paddw %%mm2, %%mm1 \n\t"
139 "movq %%mm0, %%mm2 \n\t"
140 "psubusw %%mm1, %%mm0 \n\t"
141 "psubusw %%mm2, %%mm1 \n\t"
142 "paddw %%mm0, %%mm6 \n\t"
143 "paddw %%mm1, %%mm6 \n\t"
145 "add %%"REG_a
", %%"REG_S
" \n\t"
146 "add %%"REG_a
", %%"REG_D
" \n\t"
150 "movq %%mm6, %%mm5 \n\t"
151 "punpcklwd %%mm7, %%mm6 \n\t"
152 "punpckhwd %%mm7, %%mm5 \n\t"
153 "paddd %%mm6, %%mm5 \n\t"
154 "movd %%mm5, %%eax \n\t"
155 "psrlq $32, %%mm5 \n\t"
156 "movd %%mm5, %%edx \n\t"
157 "addl %%edx, %%eax \n\t"
161 :
"S" (a),
"D" (
b),
"a" (s)
167 static int var_y_mmx(
unsigned char *a,
unsigned char *b,
int s)
171 "movl $3, %%ecx \n\t"
172 "pxor %%mm4, %%mm4 \n\t"
173 "pxor %%mm7, %%mm7 \n\t"
177 "movq (%%"REG_S
"), %%mm0 \n\t"
178 "movq (%%"REG_S
"), %%mm2 \n\t"
179 "movq (%%"REG_S
",%%"REG_a
"), %%mm1 \n\t"
180 "add %%"REG_a
", %%"REG_S
" \n\t"
181 "psubusb %%mm1, %%mm2 \n\t"
182 "psubusb %%mm0, %%mm1 \n\t"
183 "movq %%mm2, %%mm0 \n\t"
184 "movq %%mm1, %%mm3 \n\t"
185 "punpcklbw %%mm7, %%mm0 \n\t"
186 "punpcklbw %%mm7, %%mm1 \n\t"
187 "punpckhbw %%mm7, %%mm2 \n\t"
188 "punpckhbw %%mm7, %%mm3 \n\t"
189 "paddw %%mm0, %%mm4 \n\t"
190 "paddw %%mm1, %%mm4 \n\t"
191 "paddw %%mm2, %%mm4 \n\t"
192 "paddw %%mm3, %%mm4 \n\t"
197 "movq %%mm4, %%mm3 \n\t"
198 "punpcklwd %%mm7, %%mm4 \n\t"
199 "punpckhwd %%mm7, %%mm3 \n\t"
200 "paddd %%mm4, %%mm3 \n\t"
201 "movd %%mm3, %%eax \n\t"
202 "psrlq $32, %%mm3 \n\t"
203 "movd %%mm3, %%edx \n\t"
204 "addl %%edx, %%eax \n\t"
215 #define ABS(a) (((a)^((a)>>31))-((a)>>31))
217 static int diff_y(
unsigned char *a,
unsigned char *b,
int s)
221 for (j=0; j<8; j++) diff +=
ABS(a[j]-b[j]);
227 static int licomb_y(
unsigned char *a,
unsigned char *b,
int s)
232 diff +=
ABS((a[j]<<1) - b[j-s] - b[j])
233 +
ABS((b[j]<<1) - a[j] - a[j+s]);
240 static int qpcomb_y(
unsigned char *a,
unsigned char *b,
int s)
245 diff +=
ABS(a[j] - 3*b[j-s] + 3*a[j+s] - b[j]);
251 static int licomb_y_test(
unsigned char *a,
unsigned char *b,
int s)
254 int m = licomb_y_mmx(a,b,s);
255 if (c != m) printf(
"%d != %d\n", c, m);
260 static int var_y(
unsigned char *a,
unsigned char *b,
int s)
264 for (j=0; j<8; j++) {
265 var +=
ABS(a[j]-a[j+s]);
285 for (i = 0; i < c->
nplanes; i++) {
295 if ((parity+1) & 1) b->
lock[0]++;
296 if ((parity+1) & 2) b->
lock[1]++;
303 if ((parity+1) & 1) b->
lock[0]--;
304 if ((parity+1) & 2) b->
lock[1]--;
312 if (parity < 2 && c->last && parity != c->
last->
parity
326 if (parity == 2)
return 0;
330 if (((parity+1) & 1) && c->
buffers[i].
lock[0])
continue;
331 if (((parity+1) & 2) && c->
buffers[i].
lock[1])
continue;
347 int (*
func)(
unsigned char *,
unsigned char *,
int),
int *dest)
349 unsigned char *
a, *
b;
352 int xstep = c->
bpp[mp];
353 int ystep = c->
stride[mp]<<3;
369 for (x = 0; x < w; x += xstep) {
370 *dest++ =
func(a + x, b + x, s);
372 a += ystep; b += ystep;
393 for (; len > 0; len--) {
461 #define F_HAVE_BREAKS 1
462 #define F_HAVE_AFFINITY 2
466 #define BREAK_RIGHT 2
476 if (!begin || !end)
return 0;
477 for (f = begin; f !=
end; f = f->
next) count++;
484 for (i = 0; i < max; i++) {
498 int l, max_l=0, max_r=0;
518 if (l > max_l) max_l = l;
519 if (-l > max_r) max_r = -l;
523 if (max_l + max_r < 128)
return;
531 int max_l=0, max_r=0, l;
547 int lc = f->
comb[i] - (v+lv) +
ABS(v-lv);
552 if (l > max_l) max_l = l;
553 if (-l > max_r) max_r = -l;
555 if (max_l + max_r < 64)
return;
556 if (max_r > 6*max_l) f->
affinity = -1;
557 else if (max_l > 6*max_r) f->
affinity = 1;
561 if (l > max_l) max_l = l;
562 if (-l > max_r) max_r = -l;
564 if (max_l + max_r < 64)
return;
565 if (max_r > 2*max_l) f->
affinity = -1;
566 else if (max_l > 2*max_r) f->
affinity = 1;
574 for (i = 0; i < n-1; i++) {
615 else if (f1->
affinity == -1)
return 2;
629 const char aff_l[] =
"+..", aff_r[] =
"..+";
630 printf(
"\naffinity: ");
631 for (i = 0; i < 4; i++) {
636 printf(
"\nbreaks: ");
637 for (i=0; i<4; i++) {
656 if (fr->
lock)
return 0;
660 printf(
"duration: %d \n", n);
667 for (i = 0; i < n; i++) {
702 unsigned char *d, *s;
703 for (i = 0; i < c->
nplanes; i++) {
706 for (j = c->
h[i]>>1; j; j--) {
707 memcpy(d, s, c->
stride[i]);
718 if (fr->
length < 2)
return;
719 for (i = 0; i < 2; i++)
735 for (i = 0; i < fr->
length; i++)
760 c->
w = calloc(c->
nplanes,
sizeof(
int));
761 c->
h = calloc(c->
nplanes,
sizeof(
int));
790 c->
diff = diff_y_mmx;
791 c->
comb = licomb_y_mmx;
803 c->
diff = diff_rgb32;
820 }
while (f != c->
head);