kusano fc6ab3
/*
kusano fc6ab3
 * match.S -- optimized version of longest_match()
kusano fc6ab3
 * based on the similar work by Gilles Vollant, and Brian Raiter, written 1998
kusano fc6ab3
 *
kusano fc6ab3
 * This is free software; you can redistribute it and/or modify it
kusano fc6ab3
 * under the terms of the BSD License. Use by owners of Che Guevarra
kusano fc6ab3
 * parafernalia is prohibited, where possible, and highly discouraged
kusano fc6ab3
 * elsewhere.
kusano fc6ab3
 */
kusano fc6ab3
kusano fc6ab3
#ifndef NO_UNDERLINE
kusano fc6ab3
#	define	match_init	_match_init
kusano fc6ab3
#	define	longest_match	_longest_match
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#define	scanend		ebx
kusano fc6ab3
#define	scanendw	bx
kusano fc6ab3
#define	chainlenwmask	edx /* high word: current chain len low word: s->wmask */
kusano fc6ab3
#define	curmatch	rsi
kusano fc6ab3
#define	curmatchd	esi
kusano fc6ab3
#define	windowbestlen	r8
kusano fc6ab3
#define	scanalign	r9
kusano fc6ab3
#define	scanalignd	r9d
kusano fc6ab3
#define	window		r10
kusano fc6ab3
#define	bestlen		r11
kusano fc6ab3
#define	bestlend	r11d
kusano fc6ab3
#define	scanstart	r12d
kusano fc6ab3
#define	scanstartw	r12w
kusano fc6ab3
#define scan		r13
kusano fc6ab3
#define nicematch	r14d
kusano fc6ab3
#define	limit		r15
kusano fc6ab3
#define	limitd		r15d
kusano fc6ab3
#define prev		rcx
kusano fc6ab3
kusano fc6ab3
/*
kusano fc6ab3
 * The 258 is a "magic number, not a parameter -- changing it
kusano fc6ab3
 * breaks the hell loose
kusano fc6ab3
 */
kusano fc6ab3
#define	MAX_MATCH	(258)
kusano fc6ab3
#define	MIN_MATCH	(3)
kusano fc6ab3
#define	MIN_LOOKAHEAD	(MAX_MATCH + MIN_MATCH + 1)
kusano fc6ab3
#define	MAX_MATCH_8	((MAX_MATCH + 7) & ~7)
kusano fc6ab3
kusano fc6ab3
/* stack frame offsets */
kusano fc6ab3
#define	LocalVarsSize	(112)
kusano fc6ab3
#define _chainlenwmask	( 8-LocalVarsSize)(%rsp)
kusano fc6ab3
#define _windowbestlen	(16-LocalVarsSize)(%rsp)
kusano fc6ab3
#define save_r14        (24-LocalVarsSize)(%rsp)
kusano fc6ab3
#define save_rsi        (32-LocalVarsSize)(%rsp)
kusano fc6ab3
#define save_rbx        (40-LocalVarsSize)(%rsp)
kusano fc6ab3
#define save_r12        (56-LocalVarsSize)(%rsp)
kusano fc6ab3
#define save_r13        (64-LocalVarsSize)(%rsp)
kusano fc6ab3
#define save_r15        (80-LocalVarsSize)(%rsp)
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
.globl	match_init, longest_match
kusano fc6ab3
kusano fc6ab3
/*
kusano fc6ab3
 * On AMD64 the first argument of a function (in our case -- the pointer to
kusano fc6ab3
 * deflate_state structure) is passed in %rdi, hence our offsets below are
kusano fc6ab3
 * all off of that.
kusano fc6ab3
 */
kusano fc6ab3
kusano fc6ab3
/* you can check the structure offset by running
kusano fc6ab3
kusano fc6ab3
#include <stdlib.h></stdlib.h>
kusano fc6ab3
#include <stdio.h></stdio.h>
kusano fc6ab3
#include "deflate.h"
kusano fc6ab3
kusano fc6ab3
void print_depl()
kusano fc6ab3
{
kusano fc6ab3
deflate_state ds;
kusano fc6ab3
deflate_state *s=&ds;
kusano fc6ab3
printf("size pointer=%u\n",(int)sizeof(void*));
kusano fc6ab3
kusano fc6ab3
printf("#define dsWSize         (%3u)(%%rdi)\n",(int)(((char*)&(s->w_size))-((char*)s)));
kusano fc6ab3
printf("#define dsWMask         (%3u)(%%rdi)\n",(int)(((char*)&(s->w_mask))-((char*)s)));
kusano fc6ab3
printf("#define dsWindow        (%3u)(%%rdi)\n",(int)(((char*)&(s->window))-((char*)s)));
kusano fc6ab3
printf("#define dsPrev          (%3u)(%%rdi)\n",(int)(((char*)&(s->prev))-((char*)s)));
kusano fc6ab3
printf("#define dsMatchLen      (%3u)(%%rdi)\n",(int)(((char*)&(s->match_length))-((char*)s)));
kusano fc6ab3
printf("#define dsPrevMatch     (%3u)(%%rdi)\n",(int)(((char*)&(s->prev_match))-((char*)s)));
kusano fc6ab3
printf("#define dsStrStart      (%3u)(%%rdi)\n",(int)(((char*)&(s->strstart))-((char*)s)));
kusano fc6ab3
printf("#define dsMatchStart    (%3u)(%%rdi)\n",(int)(((char*)&(s->match_start))-((char*)s)));
kusano fc6ab3
printf("#define dsLookahead     (%3u)(%%rdi)\n",(int)(((char*)&(s->lookahead))-((char*)s)));
kusano fc6ab3
printf("#define dsPrevLen       (%3u)(%%rdi)\n",(int)(((char*)&(s->prev_length))-((char*)s)));
kusano fc6ab3
printf("#define dsMaxChainLen   (%3u)(%%rdi)\n",(int)(((char*)&(s->max_chain_length))-((char*)s)));
kusano fc6ab3
printf("#define dsGoodMatch     (%3u)(%%rdi)\n",(int)(((char*)&(s->good_match))-((char*)s)));
kusano fc6ab3
printf("#define dsNiceMatch     (%3u)(%%rdi)\n",(int)(((char*)&(s->nice_match))-((char*)s)));
kusano fc6ab3
}
kusano fc6ab3
kusano fc6ab3
*/
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
/*
kusano fc6ab3
  to compile for XCode 3.2 on MacOSX x86_64
kusano fc6ab3
  - run "gcc -g -c -DXCODE_MAC_X64_STRUCTURE amd64-match.S"
kusano fc6ab3
 */
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
#ifndef CURRENT_LINX_XCODE_MAC_X64_STRUCTURE
kusano fc6ab3
#define dsWSize		( 68)(%rdi)
kusano fc6ab3
#define dsWMask		( 76)(%rdi)
kusano fc6ab3
#define dsWindow	( 80)(%rdi)
kusano fc6ab3
#define dsPrev		( 96)(%rdi)
kusano fc6ab3
#define dsMatchLen	(144)(%rdi)
kusano fc6ab3
#define dsPrevMatch	(148)(%rdi)
kusano fc6ab3
#define dsStrStart	(156)(%rdi)
kusano fc6ab3
#define dsMatchStart	(160)(%rdi)
kusano fc6ab3
#define dsLookahead	(164)(%rdi)
kusano fc6ab3
#define dsPrevLen	(168)(%rdi)
kusano fc6ab3
#define dsMaxChainLen	(172)(%rdi)
kusano fc6ab3
#define dsGoodMatch	(188)(%rdi)
kusano fc6ab3
#define dsNiceMatch	(192)(%rdi)
kusano fc6ab3
kusano fc6ab3
#else 
kusano fc6ab3
kusano fc6ab3
#ifndef STRUCT_OFFSET
kusano fc6ab3
#	define STRUCT_OFFSET	(0)
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
#define dsWSize		( 56 + STRUCT_OFFSET)(%rdi)
kusano fc6ab3
#define dsWMask		( 64 + STRUCT_OFFSET)(%rdi)
kusano fc6ab3
#define dsWindow	( 72 + STRUCT_OFFSET)(%rdi)
kusano fc6ab3
#define dsPrev		( 88 + STRUCT_OFFSET)(%rdi)
kusano fc6ab3
#define dsMatchLen	(136 + STRUCT_OFFSET)(%rdi)
kusano fc6ab3
#define dsPrevMatch	(140 + STRUCT_OFFSET)(%rdi)
kusano fc6ab3
#define dsStrStart	(148 + STRUCT_OFFSET)(%rdi)
kusano fc6ab3
#define dsMatchStart	(152 + STRUCT_OFFSET)(%rdi)
kusano fc6ab3
#define dsLookahead	(156 + STRUCT_OFFSET)(%rdi)
kusano fc6ab3
#define dsPrevLen	(160 + STRUCT_OFFSET)(%rdi)
kusano fc6ab3
#define dsMaxChainLen	(164 + STRUCT_OFFSET)(%rdi)
kusano fc6ab3
#define dsGoodMatch	(180 + STRUCT_OFFSET)(%rdi)
kusano fc6ab3
#define dsNiceMatch	(184 + STRUCT_OFFSET)(%rdi)
kusano fc6ab3
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
.text
kusano fc6ab3
kusano fc6ab3
/* uInt longest_match(deflate_state *deflatestate, IPos curmatch) */
kusano fc6ab3
kusano fc6ab3
longest_match:
kusano fc6ab3
/*
kusano fc6ab3
 * Retrieve the function arguments. %curmatch will hold cur_match
kusano fc6ab3
 * throughout the entire function (passed via rsi on amd64).
kusano fc6ab3
 * rdi will hold the pointer to the deflate_state (first arg on amd64)
kusano fc6ab3
 */
kusano fc6ab3
		mov     %rsi, save_rsi
kusano fc6ab3
		mov     %rbx, save_rbx
kusano fc6ab3
		mov	%r12, save_r12
kusano fc6ab3
		mov     %r13, save_r13
kusano fc6ab3
		mov     %r14, save_r14
kusano fc6ab3
		mov     %r15, save_r15
kusano fc6ab3
kusano fc6ab3
/* uInt wmask = s->w_mask;						*/
kusano fc6ab3
/* unsigned chain_length = s->max_chain_length;				*/
kusano fc6ab3
/* if (s->prev_length >= s->good_match) {				*/
kusano fc6ab3
/*     chain_length >>= 2;						*/
kusano fc6ab3
/* }									*/
kusano fc6ab3
kusano fc6ab3
		movl	dsPrevLen, %eax
kusano fc6ab3
		movl	dsGoodMatch, %ebx
kusano fc6ab3
		cmpl	%ebx, %eax
kusano fc6ab3
		movl	dsWMask, %eax
kusano fc6ab3
		movl	dsMaxChainLen, %chainlenwmask
kusano fc6ab3
		jl	LastMatchGood
kusano fc6ab3
		shrl	$2, %chainlenwmask
kusano fc6ab3
LastMatchGood:
kusano fc6ab3
kusano fc6ab3
/* chainlen is decremented once beforehand so that the function can	*/
kusano fc6ab3
/* use the sign flag instead of the zero flag for the exit test.	*/
kusano fc6ab3
/* It is then shifted into the high word, to make room for the wmask	*/
kusano fc6ab3
/* value, which it will always accompany.				*/
kusano fc6ab3
kusano fc6ab3
		decl	%chainlenwmask
kusano fc6ab3
		shll	$16, %chainlenwmask
kusano fc6ab3
		orl	%eax, %chainlenwmask
kusano fc6ab3
kusano fc6ab3
/* if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;	*/
kusano fc6ab3
kusano fc6ab3
		movl	dsNiceMatch, %eax
kusano fc6ab3
		movl	dsLookahead, %ebx
kusano fc6ab3
		cmpl	%eax, %ebx
kusano fc6ab3
		jl	LookaheadLess
kusano fc6ab3
		movl	%eax, %ebx
kusano fc6ab3
LookaheadLess:	movl	%ebx, %nicematch
kusano fc6ab3
kusano fc6ab3
/* register Bytef *scan = s->window + s->strstart;			*/
kusano fc6ab3
kusano fc6ab3
		mov	dsWindow, %window
kusano fc6ab3
		movl	dsStrStart, %limitd
kusano fc6ab3
		lea	(%limit, %window), %scan
kusano fc6ab3
kusano fc6ab3
/* Determine how many bytes the scan ptr is off from being		*/
kusano fc6ab3
/* dword-aligned.							*/
kusano fc6ab3
kusano fc6ab3
		mov	%scan, %scanalign
kusano fc6ab3
		negl	%scanalignd
kusano fc6ab3
		andl	$3, %scanalignd
kusano fc6ab3
kusano fc6ab3
/* IPos limit = s->strstart > (IPos)MAX_DIST(s) ?			*/
kusano fc6ab3
/*     s->strstart - (IPos)MAX_DIST(s) : NIL;				*/
kusano fc6ab3
kusano fc6ab3
		movl	dsWSize, %eax
kusano fc6ab3
		subl	$MIN_LOOKAHEAD, %eax
kusano fc6ab3
		xorl	%ecx, %ecx
kusano fc6ab3
		subl	%eax, %limitd
kusano fc6ab3
		cmovng	%ecx, %limitd
kusano fc6ab3
kusano fc6ab3
/* int best_len = s->prev_length;					*/
kusano fc6ab3
kusano fc6ab3
		movl	dsPrevLen, %bestlend
kusano fc6ab3
kusano fc6ab3
/* Store the sum of s->window + best_len in %windowbestlen locally, and in memory.	*/
kusano fc6ab3
kusano fc6ab3
		lea	(%window, %bestlen), %windowbestlen
kusano fc6ab3
		mov	%windowbestlen, _windowbestlen
kusano fc6ab3
kusano fc6ab3
/* register ush scan_start = *(ushf*)scan;				*/
kusano fc6ab3
/* register ush scan_end   = *(ushf*)(scan+best_len-1);			*/
kusano fc6ab3
/* Posf *prev = s->prev;						*/
kusano fc6ab3
kusano fc6ab3
		movzwl	(%scan), %scanstart
kusano fc6ab3
		movzwl	-1(%scan, %bestlen), %scanend
kusano fc6ab3
		mov	dsPrev, %prev
kusano fc6ab3
kusano fc6ab3
/* Jump into the main loop.						*/
kusano fc6ab3
kusano fc6ab3
		movl	%chainlenwmask, _chainlenwmask
kusano fc6ab3
		jmp	LoopEntry
kusano fc6ab3
kusano fc6ab3
.balign 16
kusano fc6ab3
kusano fc6ab3
/* do {
kusano fc6ab3
 *     match = s->window + cur_match;
kusano fc6ab3
 *     if (*(ushf*)(match+best_len-1) != scan_end ||
kusano fc6ab3
 *         *(ushf*)match != scan_start) continue;
kusano fc6ab3
 *     [...]
kusano fc6ab3
 * } while ((cur_match = prev[cur_match & wmask]) > limit
kusano fc6ab3
 *          && --chain_length != 0);
kusano fc6ab3
 *
kusano fc6ab3
 * Here is the inner loop of the function. The function will spend the
kusano fc6ab3
 * majority of its time in this loop, and majority of that time will
kusano fc6ab3
 * be spent in the first ten instructions.
kusano fc6ab3
 */
kusano fc6ab3
LookupLoop:
kusano fc6ab3
		andl	%chainlenwmask, %curmatchd
kusano fc6ab3
		movzwl	(%prev, %curmatch, 2), %curmatchd
kusano fc6ab3
		cmpl	%limitd, %curmatchd
kusano fc6ab3
		jbe	LeaveNow
kusano fc6ab3
		subl	$0x00010000, %chainlenwmask
kusano fc6ab3
		js	LeaveNow
kusano fc6ab3
LoopEntry:	cmpw	-1(%windowbestlen, %curmatch), %scanendw
kusano fc6ab3
		jne	LookupLoop
kusano fc6ab3
		cmpw	%scanstartw, (%window, %curmatch)
kusano fc6ab3
		jne	LookupLoop
kusano fc6ab3
kusano fc6ab3
/* Store the current value of chainlen.					*/
kusano fc6ab3
		movl	%chainlenwmask, _chainlenwmask
kusano fc6ab3
kusano fc6ab3
/* %scan is the string under scrutiny, and %prev to the string we	*/
kusano fc6ab3
/* are hoping to match it up with. In actuality, %esi and %edi are	*/
kusano fc6ab3
/* both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and %edx is	*/
kusano fc6ab3
/* initialized to -(MAX_MATCH_8 - scanalign).				*/
kusano fc6ab3
kusano fc6ab3
		mov	$(-MAX_MATCH_8), %rdx
kusano fc6ab3
		lea	(%curmatch, %window), %windowbestlen
kusano fc6ab3
		lea	MAX_MATCH_8(%windowbestlen, %scanalign), %windowbestlen
kusano fc6ab3
		lea	MAX_MATCH_8(%scan, %scanalign), %prev
kusano fc6ab3
kusano fc6ab3
/* the prefetching below makes very little difference... */
kusano fc6ab3
		prefetcht1	(%windowbestlen, %rdx)
kusano fc6ab3
		prefetcht1	(%prev, %rdx)
kusano fc6ab3
kusano fc6ab3
/*
kusano fc6ab3
 * Test the strings for equality, 8 bytes at a time. At the end,
kusano fc6ab3
 * adjust %rdx so that it is offset to the exact byte that mismatched.
kusano fc6ab3
 *
kusano fc6ab3
 * It should be confessed that this loop usually does not represent
kusano fc6ab3
 * much of the total running time. Replacing it with a more
kusano fc6ab3
 * straightforward "rep cmpsb" would not drastically degrade
kusano fc6ab3
 * performance -- unrolling it, for example, makes no difference.
kusano fc6ab3
 */
kusano fc6ab3
kusano fc6ab3
#undef USE_SSE	/* works, but is 6-7% slower, than non-SSE... */
kusano fc6ab3
kusano fc6ab3
LoopCmps:
kusano fc6ab3
#ifdef USE_SSE
kusano fc6ab3
		/* Preload the SSE registers */
kusano fc6ab3
		movdqu	  (%windowbestlen, %rdx), %xmm1
kusano fc6ab3
		movdqu	  (%prev, %rdx), %xmm2
kusano fc6ab3
		pcmpeqb	%xmm2, %xmm1
kusano fc6ab3
		movdqu	16(%windowbestlen, %rdx), %xmm3
kusano fc6ab3
		movdqu	16(%prev, %rdx), %xmm4
kusano fc6ab3
		pcmpeqb	%xmm4, %xmm3
kusano fc6ab3
		movdqu	32(%windowbestlen, %rdx), %xmm5
kusano fc6ab3
		movdqu	32(%prev, %rdx), %xmm6
kusano fc6ab3
		pcmpeqb	%xmm6, %xmm5
kusano fc6ab3
		movdqu	48(%windowbestlen, %rdx), %xmm7
kusano fc6ab3
		movdqu	48(%prev, %rdx), %xmm8
kusano fc6ab3
		pcmpeqb	%xmm8, %xmm7
kusano fc6ab3
kusano fc6ab3
		/* Check the comparisions' results */
kusano fc6ab3
		pmovmskb %xmm1, %rax
kusano fc6ab3
		notw	%ax
kusano fc6ab3
		bsfw	%ax, %ax
kusano fc6ab3
		jnz	LeaveLoopCmps
kusano fc6ab3
		
kusano fc6ab3
		/* this is the only iteration of the loop with a possibility of having
kusano fc6ab3
		   incremented rdx by 0x108 (each loop iteration add 16*4 = 0x40 
kusano fc6ab3
		   and (0x40*4)+8=0x108 */
kusano fc6ab3
		add	$8, %rdx
kusano fc6ab3
		jz LenMaximum
kusano fc6ab3
		add	$8, %rdx
kusano fc6ab3
kusano fc6ab3
		
kusano fc6ab3
		pmovmskb %xmm3, %rax
kusano fc6ab3
		notw	%ax
kusano fc6ab3
		bsfw	%ax, %ax
kusano fc6ab3
		jnz	LeaveLoopCmps
kusano fc6ab3
		
kusano fc6ab3
		
kusano fc6ab3
		add	$16, %rdx
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
		pmovmskb %xmm5, %rax
kusano fc6ab3
		notw	%ax
kusano fc6ab3
		bsfw	%ax, %ax
kusano fc6ab3
		jnz	LeaveLoopCmps
kusano fc6ab3
		
kusano fc6ab3
		add	$16, %rdx
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
		pmovmskb %xmm7, %rax
kusano fc6ab3
		notw	%ax
kusano fc6ab3
		bsfw	%ax, %ax
kusano fc6ab3
		jnz	LeaveLoopCmps
kusano fc6ab3
		
kusano fc6ab3
		add	$16, %rdx
kusano fc6ab3
		
kusano fc6ab3
		jmp	LoopCmps
kusano fc6ab3
LeaveLoopCmps:	add	%rax, %rdx
kusano fc6ab3
#else
kusano fc6ab3
		mov	(%windowbestlen, %rdx), %rax
kusano fc6ab3
		xor	(%prev, %rdx), %rax
kusano fc6ab3
		jnz	LeaveLoopCmps
kusano fc6ab3
		
kusano fc6ab3
		mov	8(%windowbestlen, %rdx), %rax
kusano fc6ab3
		xor	8(%prev, %rdx), %rax
kusano fc6ab3
		jnz	LeaveLoopCmps8
kusano fc6ab3
kusano fc6ab3
		mov	16(%windowbestlen, %rdx), %rax
kusano fc6ab3
		xor	16(%prev, %rdx), %rax
kusano fc6ab3
		jnz	LeaveLoopCmps16
kusano fc6ab3
				
kusano fc6ab3
		add	$24, %rdx
kusano fc6ab3
		jnz	LoopCmps
kusano fc6ab3
		jmp	LenMaximum
kusano fc6ab3
#	if 0
kusano fc6ab3
/*
kusano fc6ab3
 * This three-liner is tantalizingly simple, but bsf is a slow instruction,
kusano fc6ab3
 * and the complicated alternative down below is quite a bit faster. Sad...
kusano fc6ab3
 */
kusano fc6ab3
kusano fc6ab3
LeaveLoopCmps:	bsf	%rax, %rax /* find the first non-zero bit */
kusano fc6ab3
		shrl	$3, %eax /* divide by 8 to get the byte */
kusano fc6ab3
		add	%rax, %rdx
kusano fc6ab3
#	else
kusano fc6ab3
LeaveLoopCmps16:
kusano fc6ab3
		add	$8, %rdx
kusano fc6ab3
LeaveLoopCmps8:
kusano fc6ab3
		add	$8, %rdx
kusano fc6ab3
LeaveLoopCmps:	testl   $0xFFFFFFFF, %eax /* Check the first 4 bytes */
kusano fc6ab3
		jnz     Check16
kusano fc6ab3
		add     $4, %rdx
kusano fc6ab3
		shr     $32, %rax
kusano fc6ab3
Check16:        testw   $0xFFFF, %ax
kusano fc6ab3
		jnz     LenLower
kusano fc6ab3
		add	$2, %rdx
kusano fc6ab3
		shrl	$16, %eax
kusano fc6ab3
LenLower:	subb	$1, %al
kusano fc6ab3
		adc	$0, %rdx
kusano fc6ab3
#	endif
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
/* Calculate the length of the match. If it is longer than MAX_MATCH,	*/
kusano fc6ab3
/* then automatically accept it as the best possible match and leave.	*/
kusano fc6ab3
kusano fc6ab3
		lea	(%prev, %rdx), %rax
kusano fc6ab3
		sub	%scan, %rax
kusano fc6ab3
		cmpl	$MAX_MATCH, %eax
kusano fc6ab3
		jge	LenMaximum
kusano fc6ab3
kusano fc6ab3
/* If the length of the match is not longer than the best match we	*/
kusano fc6ab3
/* have so far, then forget it and return to the lookup loop.		*/
kusano fc6ab3
kusano fc6ab3
		cmpl	%bestlend, %eax
kusano fc6ab3
		jg	LongerMatch
kusano fc6ab3
		mov	_windowbestlen, %windowbestlen
kusano fc6ab3
		mov	dsPrev, %prev
kusano fc6ab3
		movl	_chainlenwmask, %edx
kusano fc6ab3
		jmp	LookupLoop
kusano fc6ab3
kusano fc6ab3
/*         s->match_start = cur_match;					*/
kusano fc6ab3
/*         best_len = len;						*/
kusano fc6ab3
/*         if (len >= nice_match) break;				*/
kusano fc6ab3
/*         scan_end = *(ushf*)(scan+best_len-1);			*/
kusano fc6ab3
kusano fc6ab3
LongerMatch:
kusano fc6ab3
		movl	%eax, %bestlend
kusano fc6ab3
		movl	%curmatchd, dsMatchStart
kusano fc6ab3
		cmpl	%nicematch, %eax
kusano fc6ab3
		jge	LeaveNow
kusano fc6ab3
kusano fc6ab3
		lea	(%window, %bestlen), %windowbestlen
kusano fc6ab3
		mov	%windowbestlen, _windowbestlen
kusano fc6ab3
kusano fc6ab3
		movzwl	-1(%scan, %rax), %scanend
kusano fc6ab3
		mov	dsPrev, %prev
kusano fc6ab3
		movl	_chainlenwmask, %chainlenwmask
kusano fc6ab3
		jmp	LookupLoop
kusano fc6ab3
kusano fc6ab3
/* Accept the current string, with the maximum possible length.		*/
kusano fc6ab3
kusano fc6ab3
LenMaximum:
kusano fc6ab3
		movl	$MAX_MATCH, %bestlend
kusano fc6ab3
		movl	%curmatchd, dsMatchStart
kusano fc6ab3
kusano fc6ab3
/* if ((uInt)best_len <= s->lookahead) return (uInt)best_len;		*/
kusano fc6ab3
/* return s->lookahead;							*/
kusano fc6ab3
kusano fc6ab3
LeaveNow:
kusano fc6ab3
		movl	dsLookahead, %eax
kusano fc6ab3
		cmpl	%eax, %bestlend
kusano fc6ab3
		cmovngl	%bestlend, %eax
kusano fc6ab3
LookaheadRet:
kusano fc6ab3
kusano fc6ab3
/* Restore the registers and return from whence we came.			*/
kusano fc6ab3
kusano fc6ab3
	mov	save_rsi, %rsi
kusano fc6ab3
	mov	save_rbx, %rbx
kusano fc6ab3
	mov	save_r12, %r12
kusano fc6ab3
	mov	save_r13, %r13
kusano fc6ab3
	mov	save_r14, %r14
kusano fc6ab3
	mov	save_r15, %r15
kusano fc6ab3
kusano fc6ab3
	ret
kusano fc6ab3
kusano fc6ab3
match_init:	ret