--- filter/yuvdenoise/motion.c.orig	2009-02-21 16:34:02.000000000 +0200
+++ filter/yuvdenoise/motion.c	2009-04-06 16:48:50.000000000 +0300
@@ -150,7 +150,6 @@
     " pxor        %%mm0 , %%mm0;           /* clear mm0                                          */\n"
     " pxor        %%mm7 , %%mm7;           /* clear mm7                                          */\n"
     "                                      /*                                                    */\n"
-    ".rept 8                    ;          /* Loop for 8 lines                                   */\n"
     " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
     " movq        (%%edi), %%mm2;          /* 8 Pixels from reference frame to mm2               */\n"
     " movq         %%mm2 , %%mm3;          /* hold a copy of mm2 in mm3                          */\n"
@@ -164,7 +163,98 @@
     " paddusw      %%mm2 , %%mm0;          /* to mm0                                             */\n"
     " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
     " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
-    " .endr                                /* end loop                                           */\n"
+    " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+    " movq        (%%edi), %%mm2;          /* 8 Pixels from reference frame to mm2               */\n"
+    " movq         %%mm2 , %%mm3;          /* hold a copy of mm2 in mm3                          */\n"
+    " psubusb      %%mm1 , %%mm3;          /* positive differences between mm2 and mm1           */\n"
+    " psubusb      %%mm2 , %%mm1;          /* positive differences between mm1 and mm3           */\n"
+    " paddusb      %%mm3 , %%mm1;          /* mm1 now contains abs(mm1-mm2)                      */\n"
+    " movq         %%mm1 , %%mm2;          /* copy mm1 to mm2                                    */\n"
+    " punpcklbw    %%mm7 , %%mm1;          /* unpack mm1 into mm1 and mm2                        */\n"
+    " punpckhbw    %%mm7 , %%mm2;          /*                                                    */\n"
+    " paddusw      %%mm1 , %%mm0;          /* add mm1 (stored in mm1 and mm2...)                 */\n"
+    " paddusw      %%mm2 , %%mm0;          /* to mm0                                             */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+    " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+    " movq        (%%edi), %%mm2;          /* 8 Pixels from reference frame to mm2               */\n"
+    " movq         %%mm2 , %%mm3;          /* hold a copy of mm2 in mm3                          */\n"
+    " psubusb      %%mm1 , %%mm3;          /* positive differences between mm2 and mm1           */\n"
+    " psubusb      %%mm2 , %%mm1;          /* positive differences between mm1 and mm3           */\n"
+    " paddusb      %%mm3 , %%mm1;          /* mm1 now contains abs(mm1-mm2)                      */\n"
+    " movq         %%mm1 , %%mm2;          /* copy mm1 to mm2                                    */\n"
+    " punpcklbw    %%mm7 , %%mm1;          /* unpack mm1 into mm1 and mm2                        */\n"
+    " punpckhbw    %%mm7 , %%mm2;          /*                                                    */\n"
+    " paddusw      %%mm1 , %%mm0;          /* add mm1 (stored in mm1 and mm2...)                 */\n"
+    " paddusw      %%mm2 , %%mm0;          /* to mm0                                             */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+    " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+    " movq        (%%edi), %%mm2;          /* 8 Pixels from reference frame to mm2               */\n"
+    " movq         %%mm2 , %%mm3;          /* hold a copy of mm2 in mm3                          */\n"
+    " psubusb      %%mm1 , %%mm3;          /* positive differences between mm2 and mm1           */\n"
+    " psubusb      %%mm2 , %%mm1;          /* positive differences between mm1 and mm3           */\n"
+    " paddusb      %%mm3 , %%mm1;          /* mm1 now contains abs(mm1-mm2)                      */\n"
+    " movq         %%mm1 , %%mm2;          /* copy mm1 to mm2                                    */\n"
+    " punpcklbw    %%mm7 , %%mm1;          /* unpack mm1 into mm1 and mm2                        */\n"
+    " punpckhbw    %%mm7 , %%mm2;          /*                                                    */\n"
+    " paddusw      %%mm1 , %%mm0;          /* add mm1 (stored in mm1 and mm2...)                 */\n"
+    " paddusw      %%mm2 , %%mm0;          /* to mm0                                             */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+    " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+    " movq        (%%edi), %%mm2;          /* 8 Pixels from reference frame to mm2               */\n"
+    " movq         %%mm2 , %%mm3;          /* hold a copy of mm2 in mm3                          */\n"
+    " psubusb      %%mm1 , %%mm3;          /* positive differences between mm2 and mm1           */\n"
+    " psubusb      %%mm2 , %%mm1;          /* positive differences between mm1 and mm3           */\n"
+    " paddusb      %%mm3 , %%mm1;          /* mm1 now contains abs(mm1-mm2)                      */\n"
+    " movq         %%mm1 , %%mm2;          /* copy mm1 to mm2                                    */\n"
+    " punpcklbw    %%mm7 , %%mm1;          /* unpack mm1 into mm1 and mm2                        */\n"
+    " punpckhbw    %%mm7 , %%mm2;          /*                                                    */\n"
+    " paddusw      %%mm1 , %%mm0;          /* add mm1 (stored in mm1 and mm2...)                 */\n"
+    " paddusw      %%mm2 , %%mm0;          /* to mm0                                             */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+    " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+    " movq        (%%edi), %%mm2;          /* 8 Pixels from reference frame to mm2               */\n"
+    " movq         %%mm2 , %%mm3;          /* hold a copy of mm2 in mm3                          */\n"
+    " psubusb      %%mm1 , %%mm3;          /* positive differences between mm2 and mm1           */\n"
+    " psubusb      %%mm2 , %%mm1;          /* positive differences between mm1 and mm3           */\n"
+    " paddusb      %%mm3 , %%mm1;          /* mm1 now contains abs(mm1-mm2)                      */\n"
+    " movq         %%mm1 , %%mm2;          /* copy mm1 to mm2                                    */\n"
+    " punpcklbw    %%mm7 , %%mm1;          /* unpack mm1 into mm1 and mm2                        */\n"
+    " punpckhbw    %%mm7 , %%mm2;          /*                                                    */\n"
+    " paddusw      %%mm1 , %%mm0;          /* add mm1 (stored in mm1 and mm2...)                 */\n"
+    " paddusw      %%mm2 , %%mm0;          /* to mm0                                             */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+    " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+    " movq        (%%edi), %%mm2;          /* 8 Pixels from reference frame to mm2               */\n"
+    " movq         %%mm2 , %%mm3;          /* hold a copy of mm2 in mm3                          */\n"
+    " psubusb      %%mm1 , %%mm3;          /* positive differences between mm2 and mm1           */\n"
+    " psubusb      %%mm2 , %%mm1;          /* positive differences between mm1 and mm3           */\n"
+    " paddusb      %%mm3 , %%mm1;          /* mm1 now contains abs(mm1-mm2)                      */\n"
+    " movq         %%mm1 , %%mm2;          /* copy mm1 to mm2                                    */\n"
+    " punpcklbw    %%mm7 , %%mm1;          /* unpack mm1 into mm1 and mm2                        */\n"
+    " punpckhbw    %%mm7 , %%mm2;          /*                                                    */\n"
+    " paddusw      %%mm1 , %%mm0;          /* add mm1 (stored in mm1 and mm2...)                 */\n"
+    " paddusw      %%mm2 , %%mm0;          /* to mm0                                             */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+    " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+    " movq        (%%edi), %%mm2;          /* 8 Pixels from reference frame to mm2               */\n"
+    " movq         %%mm2 , %%mm3;          /* hold a copy of mm2 in mm3                          */\n"
+    " psubusb      %%mm1 , %%mm3;          /* positive differences between mm2 and mm1           */\n"
+    " psubusb      %%mm2 , %%mm1;          /* positive differences between mm1 and mm3           */\n"
+    " paddusb      %%mm3 , %%mm1;          /* mm1 now contains abs(mm1-mm2)                      */\n"
+    " movq         %%mm1 , %%mm2;          /* copy mm1 to mm2                                    */\n"
+    " punpcklbw    %%mm7 , %%mm1;          /* unpack mm1 into mm1 and mm2                        */\n"
+    " punpckhbw    %%mm7 , %%mm2;          /*                                                    */\n"
+    " paddusw      %%mm1 , %%mm0;          /* add mm1 (stored in mm1 and mm2...)                 */\n"
+    " paddusw      %%mm2 , %%mm0;          /* to mm0                                             */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+
     "                                      /*                                                    */\n"
     " movq         %%mm0 , %0   ;          /* make mm0 available to gcc ...                      */\n"
     :"=g" (a)
@@ -193,13 +283,48 @@
     (
     " pxor         %%mm0 , %%mm0;          /* clear mm0                                          */\n"
     "                           ;          /*                                                    */\n"
-    " .rept 8                   ;          /*                                                    */\n"
+
+    " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+    " psadbw      (%%edi), %%mm1;          /* 8 Pixels difference to mm1                         */\n"
+    " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
     " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
     " psadbw      (%%edi), %%mm1;          /* 8 Pixels difference to mm1                         */\n"
     " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
     " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
     " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
-    " .endr                     ;          /*                                                    */\n"
+    " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+    " psadbw      (%%edi), %%mm1;          /* 8 Pixels difference to mm1                         */\n"
+    " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+    " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+    " psadbw      (%%edi), %%mm1;          /* 8 Pixels difference to mm1                         */\n"
+    " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+    " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+    " psadbw      (%%edi), %%mm1;          /* 8 Pixels difference to mm1                         */\n"
+    " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+    " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+    " psadbw      (%%edi), %%mm1;          /* 8 Pixels difference to mm1                         */\n"
+    " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+    " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+    " psadbw      (%%edi), %%mm1;          /* 8 Pixels difference to mm1                         */\n"
+    " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+    " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+    " psadbw      (%%edi), %%mm1;          /* 8 Pixels difference to mm1                         */\n"
+    " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+
     "                                      /*                                                    */\n"
     " movq         %%mm0 , %0   ;          /* make mm0 available to gcc ...                      */\n"
     :"=g" (a)
@@ -252,7 +377,20 @@
     " pxor        %%mm0 , %%mm0;           /* clear mm0                                          */\n"
     " pxor        %%mm7 , %%mm7;           /* clear mm7                                          */\n"
     "                                      /*                                                    */\n"
-    ".rept 4                    ;          /* Loop for 4 lines                                   */\n"
+
+    " movd        (%%esi), %%mm1;          /* 4 Pixels from filtered frame to mm1                */\n"
+    " movd        (%%edi), %%mm2;          /* 4 Pixels from reference frame to mm2               */\n"
+    " movq         %%mm2 , %%mm3;          /* hold a copy of mm2 in mm3                          */\n"
+    " psubusb      %%mm1 , %%mm3;          /* positive differences between mm2 and mm1           */\n"
+    " psubusb      %%mm2 , %%mm1;          /* positive differences between mm1 and mm3           */\n"
+    " paddusb      %%mm3 , %%mm1;          /* mm2 now contains abs(mm1-mm2)                      */\n"
+    " movq         %%mm1 , %%mm2;          /* copy mm1 to mm2                                    */\n"
+    " punpcklbw    %%mm7 , %%mm1;          /* unpack mm1 into mm1 and mm2                        */\n"
+    " punpckhbw    %%mm7 , %%mm2;          /*                                                    */\n"
+    " paddusw      %%mm1 , %%mm2;          /* add mm1 (stored in mm1 and mm2...)                 */\n"
+    " paddusw      %%mm2 , %%mm0;          /* to mm0                                             */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
     " movd        (%%esi), %%mm1;          /* 4 Pixels from filtered frame to mm1                */\n"
     " movd        (%%edi), %%mm2;          /* 4 Pixels from reference frame to mm2               */\n"
     " movq         %%mm2 , %%mm3;          /* hold a copy of mm2 in mm3                          */\n"
@@ -266,7 +404,33 @@
     " paddusw      %%mm2 , %%mm0;          /* to mm0                                             */\n"
     " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
     " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
-    " .endr                                /* end loop                                           */\n"
+    " movd        (%%esi), %%mm1;          /* 4 Pixels from filtered frame to mm1                */\n"
+    " movd        (%%edi), %%mm2;          /* 4 Pixels from reference frame to mm2               */\n"
+    " movq         %%mm2 , %%mm3;          /* hold a copy of mm2 in mm3                          */\n"
+    " psubusb      %%mm1 , %%mm3;          /* positive differences between mm2 and mm1           */\n"
+    " psubusb      %%mm2 , %%mm1;          /* positive differences between mm1 and mm3           */\n"
+    " paddusb      %%mm3 , %%mm1;          /* mm2 now contains abs(mm1-mm2)                      */\n"
+    " movq         %%mm1 , %%mm2;          /* copy mm1 to mm2                                    */\n"
+    " punpcklbw    %%mm7 , %%mm1;          /* unpack mm1 into mm1 and mm2                        */\n"
+    " punpckhbw    %%mm7 , %%mm2;          /*                                                    */\n"
+    " paddusw      %%mm1 , %%mm2;          /* add mm1 (stored in mm1 and mm2...)                 */\n"
+    " paddusw      %%mm2 , %%mm0;          /* to mm0                                             */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+    " movd        (%%esi), %%mm1;          /* 4 Pixels from filtered frame to mm1                */\n"
+    " movd        (%%edi), %%mm2;          /* 4 Pixels from reference frame to mm2               */\n"
+    " movq         %%mm2 , %%mm3;          /* hold a copy of mm2 in mm3                          */\n"
+    " psubusb      %%mm1 , %%mm3;          /* positive differences between mm2 and mm1           */\n"
+    " psubusb      %%mm2 , %%mm1;          /* positive differences between mm1 and mm3           */\n"
+    " paddusb      %%mm3 , %%mm1;          /* mm2 now contains abs(mm1-mm2)                      */\n"
+    " movq         %%mm1 , %%mm2;          /* copy mm1 to mm2                                    */\n"
+    " punpcklbw    %%mm7 , %%mm1;          /* unpack mm1 into mm1 and mm2                        */\n"
+    " punpckhbw    %%mm7 , %%mm2;          /*                                                    */\n"
+    " paddusw      %%mm1 , %%mm2;          /* add mm1 (stored in mm1 and mm2...)                 */\n"
+    " paddusw      %%mm2 , %%mm0;          /* to mm0                                             */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+
     "                                      /*                                                    */\n"
     " movq         %%mm0 , %0   ;          /* make mm0 available to gcc ...                      */\n"
     :"=g" (a)
@@ -294,14 +458,32 @@
     (
     " pxor         %%mm0 , %%mm0;          /* clear mm0                                          */\n"
     "                           ;          /*                                                    */\n"
-    " .rept 4                   ;          /*                                                    */\n"
+
     " movd        (%%esi), %%mm1;          /* 4 Pixels from filtered frame to mm1                */\n"
     " movd        (%%edi), %%mm2;          /* 4 Pixels from filtered frame to mm2                */\n"
     " psadbw       %%mm2 , %%mm1;          /* 4 Pixels difference to mm1                         */\n"
     " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
     " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
     " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
-    " .endr                     ;          /*                                                    */\n"
+    " movd        (%%esi), %%mm1;          /* 4 Pixels from filtered frame to mm1                */\n"
+    " movd        (%%edi), %%mm2;          /* 4 Pixels from filtered frame to mm2                */\n"
+    " psadbw       %%mm2 , %%mm1;          /* 4 Pixels difference to mm1                         */\n"
+    " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+    " movd        (%%esi), %%mm1;          /* 4 Pixels from filtered frame to mm1                */\n"
+    " movd        (%%edi), %%mm2;          /* 4 Pixels from filtered frame to mm2                */\n"
+    " psadbw       %%mm2 , %%mm1;          /* 4 Pixels difference to mm1                         */\n"
+    " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+    " movd        (%%esi), %%mm1;          /* 4 Pixels from filtered frame to mm1                */\n"
+    " movd        (%%edi), %%mm2;          /* 4 Pixels from filtered frame to mm2                */\n"
+    " psadbw       %%mm2 , %%mm1;          /* 4 Pixels difference to mm1                         */\n"
+    " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
+    " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+    " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+
     "                                      /*                                                    */\n"
     " movq         %%mm0 , %0   ;          /* make mm0 available to gcc ...                      */\n"
     :"=g" (a)
@@ -355,7 +537,61 @@
 	  " psrlw        $9    , %%mm6;          /*                                                    */"
 	  " packuswb     %%mm6 , %%mm6;          /*                                                    */"
 	  "                           ;          /*                                                    */"
-	  " .rept 8                   ;          /*                                                    */"
+
+	  " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */"
+	  " movq        (%%edi), %%mm2;          /* 8 Pixels from filtered frame to mm2 (displaced)    */"
+	  " movq        (%%eax), %%mm3;          /* reference to mm3                                   */"
+	  " psrlq        $1    , %%mm1;          /* average source pixels                              */"
+	  " psrlq        $1    , %%mm2;          /* shift right by one (divide by two)                 */"
+	  " pand         %%mm6 , %%mm1;          /* kill downshifted bits                              */"
+	  " pand         %%mm6 , %%mm2;          /* kill downshifted bits                              */"
+	  " paddusw      %%mm2 , %%mm1;          /* add up ...                                         */"
+
+	  " movq         %%mm3 , %%mm4;          /* copy reference to mm4                              */"
+	  " psubusb      %%mm1 , %%mm3;          /* positive differences between mm2 and mm1 */"
+	  " psubusb      %%mm4 , %%mm1;          /* positive differences between mm1 and mm3 */"
+	  " paddusb      %%mm3 , %%mm1;          /* mm1 now contains abs(mm1-mm2) */"
+	  " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */"
+	  " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */"
+	  " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */"
+	  " addl         %%ecx , %%ecx;          /* add framewidth to frameaddress                     */"
+
+	  " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */"
+	  " movq        (%%edi), %%mm2;          /* 8 Pixels from filtered frame to mm2 (displaced)    */"
+	  " movq        (%%eax), %%mm3;          /* reference to mm3                                   */"
+	  " psrlq        $1    , %%mm1;          /* average source pixels                              */"
+	  " psrlq        $1    , %%mm2;          /* shift right by one (divide by two)                 */"
+	  " pand         %%mm6 , %%mm1;          /* kill downshifted bits                              */"
+	  " pand         %%mm6 , %%mm2;          /* kill downshifted bits                              */"
+	  " paddusw      %%mm2 , %%mm1;          /* add up ...                                         */"
+
+	  " movq         %%mm3 , %%mm4;          /* copy reference to mm4                              */"
+	  " psubusb      %%mm1 , %%mm3;          /* positive differences between mm2 and mm1 */"
+	  " psubusb      %%mm4 , %%mm1;          /* positive differences between mm1 and mm3 */"
+	  " paddusb      %%mm3 , %%mm1;          /* mm1 now contains abs(mm1-mm2) */"
+	  " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */"
+	  " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */"
+	  " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */"
+	  " addl         %%ecx , %%ecx;          /* add framewidth to frameaddress                     */"
+
+	  " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */"
+	  " movq        (%%edi), %%mm2;          /* 8 Pixels from filtered frame to mm2 (displaced)    */"
+	  " movq        (%%eax), %%mm3;          /* reference to mm3                                   */"
+	  " psrlq        $1    , %%mm1;          /* average source pixels                              */"
+	  " psrlq        $1    , %%mm2;          /* shift right by one (divide by two)                 */"
+	  " pand         %%mm6 , %%mm1;          /* kill downshifted bits                              */"
+	  " pand         %%mm6 , %%mm2;          /* kill downshifted bits                              */"
+	  " paddusw      %%mm2 , %%mm1;          /* add up ...                                         */"
+
+	  " movq         %%mm3 , %%mm4;          /* copy reference to mm4                              */"
+	  " psubusb      %%mm1 , %%mm3;          /* positive differences between mm2 and mm1 */"
+	  " psubusb      %%mm4 , %%mm1;          /* positive differences between mm1 and mm3 */"
+	  " paddusb      %%mm3 , %%mm1;          /* mm1 now contains abs(mm1-mm2) */"
+	  " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */"
+	  " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */"
+	  " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */"
+	  " addl         %%ecx , %%ecx;          /* add framewidth to frameaddress                     */"
+
 	  " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */"
 	  " movq        (%%edi), %%mm2;          /* 8 Pixels from filtered frame to mm2 (displaced)    */"
 	  " movq        (%%eax), %%mm3;          /* reference to mm3                                   */"
@@ -373,7 +609,79 @@
 	  " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */"
 	  " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */"
 	  " addl         %%ecx , %%ecx;          /* add framewidth to frameaddress                     */"
-	  " .endr                     ;          /*                                                    */"
+
+	  " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */"
+	  " movq        (%%edi), %%mm2;          /* 8 Pixels from filtered frame to mm2 (displaced)    */"
+	  " movq        (%%eax), %%mm3;          /* reference to mm3                                   */"
+	  " psrlq        $1    , %%mm1;          /* average source pixels                              */"
+	  " psrlq        $1    , %%mm2;          /* shift right by one (divide by two)                 */"
+	  " pand         %%mm6 , %%mm1;          /* kill downshifted bits                              */"
+	  " pand         %%mm6 , %%mm2;          /* kill downshifted bits                              */"
+	  " paddusw      %%mm2 , %%mm1;          /* add up ...                                         */"
+
+	  " movq         %%mm3 , %%mm4;          /* copy reference to mm4                              */"
+	  " psubusb      %%mm1 , %%mm3;          /* positive differences between mm2 and mm1 */"
+	  " psubusb      %%mm4 , %%mm1;          /* positive differences between mm1 and mm3 */"
+	  " paddusb      %%mm3 , %%mm1;          /* mm1 now contains abs(mm1-mm2) */"
+	  " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */"
+	  " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */"
+	  " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */"
+	  " addl         %%ecx , %%ecx;          /* add framewidth to frameaddress                     */"
+
+	  " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */"
+	  " movq        (%%edi), %%mm2;          /* 8 Pixels from filtered frame to mm2 (displaced)    */"
+	  " movq        (%%eax), %%mm3;          /* reference to mm3                                   */"
+	  " psrlq        $1    , %%mm1;          /* average source pixels                              */"
+	  " psrlq        $1    , %%mm2;          /* shift right by one (divide by two)                 */"
+	  " pand         %%mm6 , %%mm1;          /* kill downshifted bits                              */"
+	  " pand         %%mm6 , %%mm2;          /* kill downshifted bits                              */"
+	  " paddusw      %%mm2 , %%mm1;          /* add up ...                                         */"
+
+	  " movq         %%mm3 , %%mm4;          /* copy reference to mm4                              */"
+	  " psubusb      %%mm1 , %%mm3;          /* positive differences between mm2 and mm1 */"
+	  " psubusb      %%mm4 , %%mm1;          /* positive differences between mm1 and mm3 */"
+	  " paddusb      %%mm3 , %%mm1;          /* mm1 now contains abs(mm1-mm2) */"
+	  " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */"
+	  " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */"
+	  " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */"
+	  " addl         %%ecx , %%ecx;          /* add framewidth to frameaddress                     */"
+
+	  " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */"
+	  " movq        (%%edi), %%mm2;          /* 8 Pixels from filtered frame to mm2 (displaced)    */"
+	  " movq        (%%eax), %%mm3;          /* reference to mm3                                   */"
+	  " psrlq        $1    , %%mm1;          /* average source pixels                              */"
+	  " psrlq        $1    , %%mm2;          /* shift right by one (divide by two)                 */"
+	  " pand         %%mm6 , %%mm1;          /* kill downshifted bits                              */"
+	  " pand         %%mm6 , %%mm2;          /* kill downshifted bits                              */"
+	  " paddusw      %%mm2 , %%mm1;          /* add up ...                                         */"
+
+	  " movq         %%mm3 , %%mm4;          /* copy reference to mm4                              */"
+	  " psubusb      %%mm1 , %%mm3;          /* positive differences between mm2 and mm1 */"
+	  " psubusb      %%mm4 , %%mm1;          /* positive differences between mm1 and mm3 */"
+	  " paddusb      %%mm3 , %%mm1;          /* mm1 now contains abs(mm1-mm2) */"
+	  " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */"
+	  " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */"
+	  " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */"
+	  " addl         %%ecx , %%ecx;          /* add framewidth to frameaddress                     */"
+
+	  " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */"
+	  " movq        (%%edi), %%mm2;          /* 8 Pixels from filtered frame to mm2 (displaced)    */"
+	  " movq        (%%eax), %%mm3;          /* reference to mm3                                   */"
+	  " psrlq        $1    , %%mm1;          /* average source pixels                              */"
+	  " psrlq        $1    , %%mm2;          /* shift right by one (divide by two)                 */"
+	  " pand         %%mm6 , %%mm1;          /* kill downshifted bits                              */"
+	  " pand         %%mm6 , %%mm2;          /* kill downshifted bits                              */"
+	  " paddusw      %%mm2 , %%mm1;          /* add up ...                                         */"
+
+	  " movq         %%mm3 , %%mm4;          /* copy reference to mm4                              */"
+	  " psubusb      %%mm1 , %%mm3;          /* positive differences between mm2 and mm1 */"
+	  " psubusb      %%mm4 , %%mm1;          /* positive differences between mm1 and mm3 */"
+	  " paddusb      %%mm3 , %%mm1;          /* mm1 now contains abs(mm1-mm2) */"
+	  " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */"
+	  " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */"
+	  " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */"
+	  " addl         %%ecx , %%ecx;          /* add framewidth to frameaddress                     */"
+
 	  "                                      /*                                                    */"
 	  " movq         %%mm0 , %0   ;          /* make mm0 available to gcc ...                      */"
 	  :"=g" (a)
@@ -401,7 +709,27 @@
       (
 	  " pxor         %%mm0 , %%mm0;          /* clear mm0                                          */\n"
 	  "                           ;          /*                                                    */\n"
-	  " .rept 8                   ;          /*                                                    */\n"
+
+	  " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+	  " movq        (%%edi), %%mm2;          /* 8 Pixels from filtered frame to mm2 (displaced)    */\n"
+	  " movq        (%%eax), %%mm3;          /* 8 Pixels from reference frame to mm3               */\n"
+	  " pavgb        %%mm2 , %%mm1;          /* average source pixels                              */\n"
+	  " psadbw       %%mm3 , %%mm1;          /* 8 Pixels difference to mm1                         */\n"
+	  " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
+	  " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+	  " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+	  " addl         %%ecx , %%eax;          /* add framewidth to frameaddress                     */\n"
+
+	  " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+	  " movq        (%%edi), %%mm2;          /* 8 Pixels from filtered frame to mm2 (displaced)    */\n"
+	  " movq        (%%eax), %%mm3;          /* 8 Pixels from reference frame to mm3               */\n"
+	  " pavgb        %%mm2 , %%mm1;          /* average source pixels                              */\n"
+	  " psadbw       %%mm3 , %%mm1;          /* 8 Pixels difference to mm1                         */\n"
+	  " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
+	  " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+	  " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+	  " addl         %%ecx , %%eax;          /* add framewidth to frameaddress                     */\n"
+
 	  " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
 	  " movq        (%%edi), %%mm2;          /* 8 Pixels from filtered frame to mm2 (displaced)    */\n"
 	  " movq        (%%eax), %%mm3;          /* 8 Pixels from reference frame to mm3               */\n"
@@ -411,7 +739,57 @@
 	  " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
 	  " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
 	  " addl         %%ecx , %%eax;          /* add framewidth to frameaddress                     */\n"
-	  " .endr                     ;          /*                                                    */\n"
+
+	  " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+	  " movq        (%%edi), %%mm2;          /* 8 Pixels from filtered frame to mm2 (displaced)    */\n"
+	  " movq        (%%eax), %%mm3;          /* 8 Pixels from reference frame to mm3               */\n"
+	  " pavgb        %%mm2 , %%mm1;          /* average source pixels                              */\n"
+	  " psadbw       %%mm3 , %%mm1;          /* 8 Pixels difference to mm1                         */\n"
+	  " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
+	  " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+	  " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+	  " addl         %%ecx , %%eax;          /* add framewidth to frameaddress                     */\n"
+
+	  " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+	  " movq        (%%edi), %%mm2;          /* 8 Pixels from filtered frame to mm2 (displaced)    */\n"
+	  " movq        (%%eax), %%mm3;          /* 8 Pixels from reference frame to mm3               */\n"
+	  " pavgb        %%mm2 , %%mm1;          /* average source pixels                              */\n"
+	  " psadbw       %%mm3 , %%mm1;          /* 8 Pixels difference to mm1                         */\n"
+	  " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
+	  " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+	  " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+	  " addl         %%ecx , %%eax;          /* add framewidth to frameaddress                     */\n"
+
+	  " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+	  " movq        (%%edi), %%mm2;          /* 8 Pixels from filtered frame to mm2 (displaced)    */\n"
+	  " movq        (%%eax), %%mm3;          /* 8 Pixels from reference frame to mm3               */\n"
+	  " pavgb        %%mm2 , %%mm1;          /* average source pixels                              */\n"
+	  " psadbw       %%mm3 , %%mm1;          /* 8 Pixels difference to mm1                         */\n"
+	  " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
+	  " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+	  " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+	  " addl         %%ecx , %%eax;          /* add framewidth to frameaddress                     */\n"
+
+	  " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+	  " movq        (%%edi), %%mm2;          /* 8 Pixels from filtered frame to mm2 (displaced)    */\n"
+	  " movq        (%%eax), %%mm3;          /* 8 Pixels from reference frame to mm3               */\n"
+	  " pavgb        %%mm2 , %%mm1;          /* average source pixels                              */\n"
+	  " psadbw       %%mm3 , %%mm1;          /* 8 Pixels difference to mm1                         */\n"
+	  " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
+	  " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+	  " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+	  " addl         %%ecx , %%eax;          /* add framewidth to frameaddress                     */\n"
+
+	  " movq        (%%esi), %%mm1;          /* 8 Pixels from filtered frame to mm1                */\n"
+	  " movq        (%%edi), %%mm2;          /* 8 Pixels from filtered frame to mm2 (displaced)    */\n"
+	  " movq        (%%eax), %%mm3;          /* 8 Pixels from reference frame to mm3               */\n"
+	  " pavgb        %%mm2 , %%mm1;          /* average source pixels                              */\n"
+	  " psadbw       %%mm3 , %%mm1;          /* 8 Pixels difference to mm1                         */\n"
+	  " paddusw      %%mm1 , %%mm0;          /* add result to mm0                                  */\n"
+	  " addl         %%ecx , %%esi;          /* add framewidth to frameaddress                     */\n"
+	  " addl         %%ecx , %%edi;          /* add framewidth to frameaddress                     */\n"
+	  " addl         %%ecx , %%eax;          /* add framewidth to frameaddress                     */\n"
+
 	  "                                      /*                                                    */\n"
 	  " movq         %%mm0 , %0   ;          /* make mm0 available to gcc ...                      */\n"
 	  :"=g" (a)
