This is the real fragment of SpotRemover's code that does intensity/color locking. So, we have 3 pixel pairs: mm0 - pixel A mm1 - pixel B mm5 - pixel C Locking takes place if |A-C|M if TRUE then unstable pcmpgtb mm2, MaxStableNeg ; A-C>-M-1 if TRUE then stable (means not(A-C<-M)) pandn mm0, mm2 ; FF => stable ; Calculate the differences ; movq mm3, mm5 psubsb mm3, mm1 ; B-C intensity difference between the older and the oldest movq mm2, mm3 ; B-C ; ; Compare to produce the mask ; pcmpgtb mm3, MaxStable ; B-C>M if TRUE then unstable pcmpgtb mm2, MaxStableNeg ; B-C>-M-1 if TRUE then stable (means not(B-C<-M)) pandn mm3, mm2 ; FF => stable pand mm0, mm3 ; final mask FF - stable; 00 - unstable ; ; Copy the bytes with smaller difference ; pxor mm1, mm5 ; C xor B pand mm1, mm0 ; C xor B (<=MaxStable) | 0 (>MaxStable) pxor mm1, mm5 ; C xor B xor B | B psubb mm1, ToSignedByte ; 8-bit unsigned movq Locked_PixelPair, mm1 ; save somewhere