1 /* lzo_mchw.ch -- matching functions using a window
3 This file is part of the LZO real-time data compression library.
5 Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer
6 Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer
7 Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer
8 Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
9 Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
10 Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
11 Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
12 Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
13 Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
14 Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
15 Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
16 Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
17 Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
18 Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
19 Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
20 Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
23 The LZO library is free software; you can redistribute it and/or
24 modify it under the terms of the GNU General Public License as
25 published by the Free Software Foundation; either version 2 of
26 the License, or (at your option) any later version.
28 The LZO library is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU General Public License for more details.
33 You should have received a copy of the GNU General Public License
34 along with the LZO library; see the file COPYING.
35 If not, write to the Free Software Foundation, Inc.,
36 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
38 Markus F.X.J. Oberhumer
39 <markus@oberhumer.com>
40 http://www.oberhumer.com/opensource/lzo/
44 /***********************************************************************
46 ************************************************************************/
52 lzo_uint look; /* bytes in lookahead buffer */
63 const lzo_bytep in_end;
68 lzo_uint textsize; /* text size counter */
69 lzo_uint codesize; /* code size counter */
70 lzo_uint printcount; /* counter for reporting progress every 1K bytes */
73 unsigned long lit_bytes;
74 unsigned long match_bytes;
75 unsigned long rep_bytes;
82 unsigned long r1_r, m3_r, m2_m, m3_m;
90 unsigned long r1_r, m3_r, m2_m, m3_m;
98 unsigned long r1_r, m2_m, m3_m;
101 #if defined(LZO1X) || defined(LZO1Y) || defined(LZO1Z)
106 unsigned long m1a_m, m1b_m, m2_m, m3_m, m4_m;
107 unsigned long lit1_r, lit2_r, lit3_r;
112 unsigned long m1, m2, m3, m4;
118 #if (LZO_CC_BORLANDC && LZO_ARCH_I086) && (__BORLANDC__ < 0x0450)
119 /* work around a Borland C 3.1 bug */
120 # define getbyte(c) ((c).ip < (c).in_end ? (c).ip +=1, (c).ip[-1] : (-1))
121 #elif (LZO_OS_TOS && (LZO_CC_PUREC || LZO_CC_TURBOC))
122 /* work around a code generation bug in Turbo C / Pure C (Atari ST) */
123 # define getbyte(c) ((c).ip < (c).in_end ? (int) (unsigned) *((c).ip)++ : (-1))
125 # define getbyte(c) ((c).ip < (c).in_end ? *((c).ip)++ : (-1))
128 #include "lzo_swd.ch"
131 /***********************************************************************
133 ************************************************************************/
136 init_match ( LZO_COMPRESS_T *c, lzo_swd_p s,
137 const lzo_bytep dict, lzo_uint dict_len,
147 c->last_m_len = c->last_m_off = 0;
149 c->textsize = c->codesize = c->printcount = 0;
150 c->lit_bytes = c->match_bytes = c->rep_bytes = 0;
153 r = swd_init(s,dict,dict_len);
160 s->use_best_off = (flags & 1) ? 1 : 0;
165 /***********************************************************************
167 ************************************************************************/
170 find_match ( LZO_COMPRESS_T *c, lzo_swd_p s,
171 lzo_uint this_len, lzo_uint skip )
177 assert(this_len >= skip);
178 swd_accept(s, this_len - skip);
179 c->textsize += this_len - skip + 1;
183 assert(this_len <= 1);
184 c->textsize += this_len - skip;
187 s->m_len = SWD_THRESHOLD;
191 lzo_memset(s->best_pos,0,sizeof(s->best_pos));
207 c->look = s->look + 1;
209 c->bp = c->ip - c->look;
212 /* brute force match search */
213 if (c->m_len > SWD_THRESHOLD && c->m_len + 1 <= c->look)
215 const lzo_bytep ip = c->bp;
216 const lzo_bytep m = c->bp - c->m_off;
217 const lzo_bytep in = c->in;
219 if (ip - in > s->swd_n)
228 if (lzo_memcmp(in,ip,c->m_len+1) == 0)
229 printf("%p %p %p %5d\n",in,ip,m,c->m_len);
235 if (c->cb && c->cb->nprogress && c->textsize > c->printcount)
237 (*c->cb->nprogress)(c->cb, c->textsize, c->codesize, 0);
238 c->printcount += 1024;