src/slz.c
/* This function compares buffers <a> and <b> and reads 32 or 64 bits at a time
 * during the approach. It makes us of unaligned little endian memory accesses
 * on capable architectures. <max> is the maximum number of bytes that can be
 * read, so both <a> and <b> must have at least <max> bytes ahead. <max> may
 * safely be null or negative if that simplifies computations in the caller.
 */
This function compares buffers  and  and reads 32 or 64 bits at a time
during the approach. It makes us of unaligned little endian memory accesses
on capable architectures.  is the maximum number of bytes that can be
read, so both  and  must have at least  bytes ahead.  may
safely be null or negative if that simplifies computations in the caller.
This function compares buffers and and reads 32 or 64 bits at a time during the approach . It makes us of unaligned little endian memory accesses on capable architectures . is the maximum number of bytes that can be read so both and must have at least bytes ahead . may safely be null or negative if that simplifies computations in the caller .
static inline long memmatch(const unsigned char *a, const unsigned char *b, long max)
{
	long len = 0;
#ifdef UNALIGNED_LE_OK
	unsigned long xor;
	while (1) {
		if (len + 2 * sizeof(long) > (unsigned long)max) {
			while (len < max) {
				if (a[len] != b[len])
					break;
				len++;
			}
			return len;
		}
		xor = *(long *)&a[len] ^ *(long *)&b[len];
		if (xor)
			break;
		len += sizeof(long);
		xor = *(long *)&a[len] ^ *(long *)&b[len];
		if (xor)
			break;
		len += sizeof(long);
	}
	if (sizeof(long) > 4 && !(xor & 0xffffffff)) {
		xor >>= 16; xor >>= 16;
		if (xor & 0xffff) {
			if (xor & 0xff)
				return len + 4;
			return len + 5;
		}
		if (xor & 0xffffff)
			return len + 6;
		return len + 7;
	}
	if (xor & 0xffff) {
		if (xor & 0xff)
			return len;
		return len + 1;
	}
	if (xor & 0xffffff)
		return len + 2;
	return len + 3;
#else 
	while (len < max) {
		if (a[len] != b[len])
			break;
		len++;
	}
	return len;
#endif
}
static inline long memmatch ( const unsigned char * a , const unsigned char * b , long max ) { long len = 0 ; #ifdef UNALIGNED_LE_OK unsigned long xor ; while ( 1 ) { if ( len + 2 * sizeof ( long ) > ( unsigned long ) max ) { while ( len < max ) { if ( a [ len ] != b [ len ] ) break ; len ++ ; } return len ; } xor = * ( long * ) & a [ len ] ^ * ( long * ) & b [ len ] ; if ( xor ) break ; len += sizeof ( long ) ; xor = * ( long * ) & a [ len ] ^ * ( long * ) & b [ len ] ; if ( xor ) break ; len += sizeof ( long ) ; } if ( sizeof ( long ) > 4 && ! ( xor & 0xffffffff ) ) { xor >>= 16 ; xor >>= 16 ; if ( xor & 0xffff ) { if ( xor & 0xff ) return len + 4 ; return len + 5 ; } if ( xor & 0xffffff ) return len + 6 ; return len + 7 ; } if ( xor & 0xffff ) { if ( xor & 0xff ) return len ; return len + 1 ; } if ( xor & 0xffffff ) return len + 2 ; return len + 3 ; #else while ( len < max ) { if ( a [ len ] != b [ len ] ) break ; len ++ ; } return len ; #endif }
This function compares buffers <a> and <b> and reads 32 or 64 bits at a time
 during the approach.
This function compares buffers <a > and <b > and reads 32 or 64 bits at a time during the approach .
/* This code is optimized out on 32-bit archs, but we still
		 * need to shift in two passes to avoid a warning. It is
		 * properly optimized out as a single shift.
		 */ // UNALIGNED_LE_OK /* This is the generic version for big endian or unaligned-incompatible
	 * architectures.
	 */