30 static int diff_y_mmx(
unsigned char *
a, 
unsigned char *
b, 
int s)
 
   35         "pxor %%mm4, %%mm4 \n\t" 
   36         "pxor %%mm7, %%mm7 \n\t" 
   40         "movq (%%"REG_S
"), %%mm0 \n\t" 
   41         "movq (%%"REG_S
"), %%mm2 \n\t" 
   42         "add  %%"REG_a
", %%"REG_S
" \n\t" 
   43         "movq (%%"REG_D
"), %%mm1 \n\t" 
   44         "add  %%"REG_a
", %%"REG_D
" \n\t" 
   45         "psubusb %%mm1, %%mm2 \n\t" 
   46         "psubusb %%mm0, %%mm1 \n\t" 
   47         "movq %%mm2, %%mm0 \n\t" 
   48         "movq %%mm1, %%mm3 \n\t" 
   49         "punpcklbw %%mm7, %%mm0 \n\t" 
   50         "punpcklbw %%mm7, %%mm1 \n\t" 
   51         "punpckhbw %%mm7, %%mm2 \n\t" 
   52         "punpckhbw %%mm7, %%mm3 \n\t" 
   53         "paddw %%mm0, %%mm4 \n\t" 
   54         "paddw %%mm1, %%mm4 \n\t" 
   55         "paddw %%mm2, %%mm4 \n\t" 
   56         "paddw %%mm3, %%mm4 \n\t" 
   61         "movq %%mm4, %%mm3 \n\t" 
   62         "punpcklwd %%mm7, %%mm4 \n\t" 
   63         "punpckhwd %%mm7, %%mm3 \n\t" 
   64         "paddd %%mm4, %%mm3 \n\t" 
   65         "movd %%mm3, %%eax \n\t" 
   66         "psrlq $32, %%mm3 \n\t" 
   67         "movd %%mm3, %%edx \n\t" 
   68         "addl %%edx, %%eax \n\t" 
   71         : 
"S" (a), 
"D" (
b), 
"a" (s)
 
   77 static int licomb_y_mmx(
unsigned char *a, 
unsigned char *b, 
int s)
 
   82         "pxor %%mm6, %%mm6 \n\t" 
   83         "pxor %%mm7, %%mm7 \n\t" 
   84         "sub  %%"REG_a
", %%"REG_D
" \n\t" 
   88         "movq (%%"REG_D
"), %%mm0 \n\t" 
   89         "movq (%%"REG_D
"), %%mm1 \n\t" 
   90         "punpcklbw %%mm7, %%mm0 \n\t" 
   91         "movq (%%"REG_D
",%%"REG_a
"), %%mm2 \n\t" 
   92         "punpcklbw %%mm7, %%mm1 \n\t" 
   93         "punpcklbw %%mm7, %%mm2 \n\t" 
   94         "paddw %%mm0, %%mm0 \n\t" 
   95         "paddw %%mm2, %%mm1 \n\t" 
   96         "movq %%mm0, %%mm2 \n\t" 
   97         "psubusw %%mm1, %%mm0 \n\t" 
   98         "psubusw %%mm2, %%mm1 \n\t" 
   99         "paddw %%mm0, %%mm6 \n\t" 
  100         "paddw %%mm1, %%mm6 \n\t" 
  102         "movq (%%"REG_S
"), %%mm0 \n\t" 
  103         "movq (%%"REG_D
"), %%mm1 \n\t" 
  104         "punpckhbw %%mm7, %%mm0 \n\t" 
  105         "movq (%%"REG_D
",%%"REG_a
"), %%mm2 \n\t" 
  106         "punpckhbw %%mm7, %%mm1 \n\t" 
  107         "punpckhbw %%mm7, %%mm2 \n\t" 
  108         "paddw %%mm0, %%mm0 \n\t" 
  109         "paddw %%mm2, %%mm1 \n\t" 
  110         "movq %%mm0, %%mm2 \n\t" 
  111         "psubusw %%mm1, %%mm0 \n\t" 
  112         "psubusw %%mm2, %%mm1 \n\t" 
  113         "paddw %%mm0, %%mm6 \n\t" 
  114         "paddw %%mm1, %%mm6 \n\t" 
  116         "movq (%%"REG_D
",%%"REG_a
"), %%mm0 \n\t" 
  117         "movq (%%"REG_S
"), %%mm1 \n\t" 
  118         "punpcklbw %%mm7, %%mm0 \n\t" 
  119         "movq (%%"REG_S
",%%"REG_a
"), %%mm2 \n\t" 
  120         "punpcklbw %%mm7, %%mm1 \n\t" 
  121         "punpcklbw %%mm7, %%mm2 \n\t" 
  122         "paddw %%mm0, %%mm0 \n\t" 
  123         "paddw %%mm2, %%mm1 \n\t" 
  124         "movq %%mm0, %%mm2 \n\t" 
  125         "psubusw %%mm1, %%mm0 \n\t" 
  126         "psubusw %%mm2, %%mm1 \n\t" 
  127         "paddw %%mm0, %%mm6 \n\t" 
  128         "paddw %%mm1, %%mm6 \n\t" 
  130         "movq (%%"REG_D
",%%"REG_a
"), %%mm0 \n\t" 
  131         "movq (%%"REG_S
"), %%mm1 \n\t" 
  132         "punpckhbw %%mm7, %%mm0 \n\t" 
  133         "movq (%%"REG_S
",%%"REG_a
"), %%mm2 \n\t" 
  134         "punpckhbw %%mm7, %%mm1 \n\t" 
  135         "punpckhbw %%mm7, %%mm2 \n\t" 
  136         "paddw %%mm0, %%mm0 \n\t" 
  137         "paddw %%mm2, %%mm1 \n\t" 
  138         "movq %%mm0, %%mm2 \n\t" 
  139         "psubusw %%mm1, %%mm0 \n\t" 
  140         "psubusw %%mm2, %%mm1 \n\t" 
  141         "paddw %%mm0, %%mm6 \n\t" 
  142         "paddw %%mm1, %%mm6 \n\t" 
  144         "add  %%"REG_a
", %%"REG_S
" \n\t" 
  145         "add  %%"REG_a
", %%"REG_D
" \n\t" 
  149         "movq %%mm6, %%mm5 \n\t" 
  150         "punpcklwd %%mm7, %%mm6 \n\t" 
  151         "punpckhwd %%mm7, %%mm5 \n\t" 
  152         "paddd %%mm6, %%mm5 \n\t" 
  153         "movd %%mm5, %%eax \n\t" 
  154         "psrlq $32, %%mm5 \n\t" 
  155         "movd %%mm5, %%edx \n\t" 
  156         "addl %%edx, %%eax \n\t" 
  160         : 
"S" (a), 
"D" (
b), 
"a" (s)
 
  166 static int var_y_mmx(
unsigned char *a, 
unsigned char *b, 
int s)
 
  170         "movl $3, %%ecx \n\t" 
  171         "pxor %%mm4, %%mm4 \n\t" 
  172         "pxor %%mm7, %%mm7 \n\t" 
  176         "movq (%%"REG_S
"), %%mm0 \n\t" 
  177         "movq (%%"REG_S
"), %%mm2 \n\t" 
  178         "movq (%%"REG_S
",%%"REG_a
"), %%mm1 \n\t" 
  179         "add  %%"REG_a
", %%"REG_S
" \n\t" 
  180         "psubusb %%mm1, %%mm2 \n\t" 
  181         "psubusb %%mm0, %%mm1 \n\t" 
  182         "movq %%mm2, %%mm0 \n\t" 
  183         "movq %%mm1, %%mm3 \n\t" 
  184         "punpcklbw %%mm7, %%mm0 \n\t" 
  185         "punpcklbw %%mm7, %%mm1 \n\t" 
  186         "punpckhbw %%mm7, %%mm2 \n\t" 
  187         "punpckhbw %%mm7, %%mm3 \n\t" 
  188         "paddw %%mm0, %%mm4 \n\t" 
  189         "paddw %%mm1, %%mm4 \n\t" 
  190         "paddw %%mm2, %%mm4 \n\t" 
  191         "paddw %%mm3, %%mm4 \n\t" 
  196         "movq %%mm4, %%mm3 \n\t" 
  197         "punpcklwd %%mm7, %%mm4 \n\t" 
  198         "punpckhwd %%mm7, %%mm3 \n\t" 
  199         "paddd %%mm4, %%mm3 \n\t" 
  200         "movd %%mm3, %%eax \n\t" 
  201         "psrlq $32, %%mm3 \n\t" 
  202         "movd %%mm3, %%edx \n\t" 
  203         "addl %%edx, %%eax \n\t" 
  214 #define ABS(a) (((a)^((a)>>31))-((a)>>31)) 
  216 static int diff_y(
unsigned char *a, 
unsigned char *b, 
int s)
 
  220         for (j=0; j<8; j++) diff += 
ABS(a[j]-b[j]);
 
  226 static int licomb_y(
unsigned char *a, 
unsigned char *b, 
int s)
 
  231             diff += 
ABS((a[j]<<1) - b[j-s] - b[j])
 
  232                 + 
ABS((b[j]<<1) - a[j] - a[j+s]);
 
  239 static int qpcomb_y(
unsigned char *a, 
unsigned char *b, 
int s)
 
  244             diff += 
ABS(a[j] - 3*b[j-s] + 3*a[j+s] - b[j]);
 
  250 static int licomb_y_test(
unsigned char *a, 
unsigned char *b, 
int s)
 
  253     int m = licomb_y_mmx(a,b,s);
 
  254     if (c != m) printf(
"%d != %d\n", c, m);
 
  259 static int var_y(
unsigned char *a, 
unsigned char *b, 
int s)
 
  263         for (j=0; j<8; j++) {
 
  264             var += 
ABS(a[j]-a[j+s]);
 
  284     for (i = 0; i < c->
nplanes; i++) {
 
  294     if ((parity+1) & 1) b->
lock[0]++;
 
  295     if ((parity+1) & 2) b->
lock[1]++;
 
  302     if ((parity+1) & 1) b->
lock[0]--;
 
  303     if ((parity+1) & 2) b->
lock[1]--;
 
  311     if (parity < 2 && c->last && parity != c->
last->
parity 
  325     if (parity == 2) 
return 0;
 
  329         if (((parity+1) & 1) && c->
buffers[i].
lock[0]) 
continue;
 
  330         if (((parity+1) & 2) && c->
buffers[i].
lock[1]) 
continue;
 
  346     int (*
func)(
unsigned char *, 
unsigned char *, 
int), 
int *dest)
 
  348     unsigned char *
a, *
b;
 
  351     int xstep = c->
bpp[mp];
 
  352     int ystep = c->
stride[mp]<<3;
 
  368         for (x = 0; x < w; x += xstep) {
 
  369             *dest++ = 
func(a + x, b + x, s);
 
  371         a += ystep; b += ystep;
 
  392     for (; len > 0; len--) {
 
  460 #define F_HAVE_BREAKS 1 
  461 #define F_HAVE_AFFINITY 2 
  465 #define BREAK_RIGHT 2 
  475     if (!begin || !end) 
return 0;
 
  476     for (f = begin; f != 
end; f = f->
next) count++;
 
  483     for (i = 0; i < max; i++) {
 
  497     int l, max_l=0, max_r=0;
 
  517         if (l > max_l) max_l = l;
 
  518         if (-l > max_r) max_r = -l;
 
  522     if (max_l + max_r < 128) 
return;
 
  530     int max_l=0, max_r=0, l;
 
  546             int lc = f->
comb[i] - (v+lv) + 
ABS(v-lv);
 
  551             if (l > max_l) max_l = l;
 
  552             if (-l > max_r) max_r = -l;
 
  554         if (max_l + max_r < 64) 
return;
 
  555         if (max_r > 6*max_l) f->
affinity = -1;
 
  556         else if (max_l > 6*max_r) f->
affinity = 1;
 
  560             if (l > max_l) max_l = l;
 
  561             if (-l > max_r) max_r = -l;
 
  563         if (max_l + max_r < 64) 
return;
 
  564         if (max_r > 2*max_l) f->
affinity = -1;
 
  565         else if (max_l > 2*max_r) f->
affinity = 1;
 
  573     for (i = 0; i < n-1; i++) {
 
  614         else if (f1->
affinity == -1) 
return 2; 
 
  628     const char aff_l[] = 
"+..", aff_r[] = 
"..+";
 
  629     printf(
"\naffinity: ");
 
  630     for (i = 0; i < 4; i++) {
 
  635     printf(
"\nbreaks:   ");
 
  636     for (i=0; i<4; i++) {
 
  655     if (fr->
lock) 
return 0;
 
  659         printf(
"duration: %d    \n", n);
 
  666     for (i = 0; i < n; i++) {
 
  701     unsigned char *d, *s;
 
  702     for (i = 0; i < c->
nplanes; i++) {
 
  705         for (j = c->
h[i]>>1; j; j--) {
 
  706             memcpy(d, s, c->
stride[i]);
 
  717     if (fr->
length < 2) 
return; 
 
  718     for (i = 0; i < 2; i++)
 
  734     for (i = 0; i < fr->
length; i++)
 
  759     c->
w = calloc(c->
nplanes, 
sizeof(
int));
 
  760     c->
h = calloc(c->
nplanes, 
sizeof(
int));
 
  789             c->
diff = diff_y_mmx;
 
  790             c->
comb = licomb_y_mmx;
 
  802         c->
diff = diff_rgb32;
 
  819     } 
while (f != c->
head);