summaryrefslogtreecommitdiff
path: root/lzo/src/lzo1x_9x.c
diff options
context:
space:
mode:
Diffstat (limited to 'lzo/src/lzo1x_9x.c')
-rw-r--r--lzo/src/lzo1x_9x.c138
1 files changed, 62 insertions, 76 deletions
diff --git a/lzo/src/lzo1x_9x.c b/lzo/src/lzo1x_9x.c
index b108bf8e..4432e48d 100644
--- a/lzo/src/lzo1x_9x.c
+++ b/lzo/src/lzo1x_9x.c
@@ -2,19 +2,7 @@
This file is part of the LZO real-time data compression library.
- Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
- Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
+ Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
The LZO library is free software; you can redistribute it and/or
@@ -39,7 +27,7 @@
#if !defined(LZO1X) && !defined(LZO1Y) && !defined(LZO1Z)
-# define LZO1X
+# define LZO1X 1
#endif
#if defined(LZO1X)
@@ -57,9 +45,9 @@
//
************************************************************************/
-#define N M4_MAX_OFFSET /* size of ring buffer */
-#define THRESHOLD 1 /* lower limit for match length */
-#define F 2048 /* upper limit for match length */
+#define SWD_N M4_MAX_OFFSET /* size of ring buffer */
+#define SWD_THRESHOLD 1 /* lower limit for match length */
+#define SWD_F 2048 /* upper limit for match length */
#define SWD_BEST_OFF (LZO_MAX3( M2_MAX_LEN, M3_MAX_LEN, M4_MAX_LEN ) + 1)
@@ -88,9 +76,9 @@
# define HEAD3(b,p) \
((((((lzo_xint)b[p]<<3)^b[p+1])<<3)^b[p+2]) & (SWD_HSIZE-1))
#endif
-#if 0 && defined(LZO_UNALIGNED_OK_4) && defined(LZO_ABI_LITTLE_ENDIAN)
+#if 0 && (LZO_OPT_UNALIGNED32) && (LZO_ABI_LITTLE_ENDIAN)
# define HEAD3(b,p) \
- (((* (lzo_uint32p) &b[p]) ^ ((* (lzo_uint32p) &b[p])>>10)) & (SWD_HSIZE-1))
+ (((* (lzo_uint32_tp) &b[p]) ^ ((* (lzo_uint32_tp) &b[p])>>10)) & (SWD_HSIZE-1))
#endif
#include "lzo_mchw.ch"
@@ -103,12 +91,12 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
lzo_voidp wrkmem,
const lzo_bytep dict, lzo_uint dict_len,
lzo_callback_p cb,
- int try_lazy,
+ int try_lazy_parm,
lzo_uint good_length,
lzo_uint max_lazy,
lzo_uint nice_length,
lzo_uint max_chain,
- lzo_uint32 flags );
+ lzo_uint32_t flags );
/***********************************************************************
@@ -121,14 +109,14 @@ code_match ( LZO_COMPRESS_T *c, lzo_bytep op, lzo_uint m_len, lzo_uint m_off )
lzo_uint x_len = m_len;
lzo_uint x_off = m_off;
- c->match_bytes += (unsigned long) m_len;
+ c->match_bytes += m_len;
#if 0
/*
static lzo_uint last_m_len = 0, last_m_off = 0;
static lzo_uint prev_m_off[4];
- static int prev_m_off_ptr = 0;
- int i;
+ static unsigned prev_m_off_ptr = 0;
+ unsigned i;
//if (m_len >= 3 && m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
if (m_len >= 3 && m_len <= M2_MAX_LEN)
@@ -142,7 +130,7 @@ code_match ( LZO_COMPRESS_T *c, lzo_bytep op, lzo_uint m_len, lzo_uint m_off )
{
for (i = 0; i < 4; i++)
if (m_off == prev_m_off[i])
- printf("prev_m_off %d: %5ld\n",i,(long)m_off);
+ printf("prev_m_off %u: %5ld\n",i,(long)m_off);
}
}
last_m_len = m_len;
@@ -277,7 +265,7 @@ code_match ( LZO_COMPRESS_T *c, lzo_bytep op, lzo_uint m_len, lzo_uint m_off )
static lzo_bytep
STORE_RUN ( LZO_COMPRESS_T *c, lzo_bytep op, const lzo_bytep ii, lzo_uint t )
{
- c->lit_bytes += (unsigned long) t;
+ c->lit_bytes += t;
if (op == c->out && t <= 238)
{
@@ -286,9 +274,9 @@ STORE_RUN ( LZO_COMPRESS_T *c, lzo_bytep op, const lzo_bytep ii, lzo_uint t )
else if (t <= 3)
{
#if defined(LZO1Z)
- op[-1] |= LZO_BYTE(t);
+ op[-1] = LZO_BYTE(op[-1] | t);
#else
- op[-2] |= LZO_BYTE(t);
+ op[-2] = LZO_BYTE(op[-2] | t);
#endif
c->lit1_r++;
}
@@ -343,15 +331,15 @@ code_run ( LZO_COMPRESS_T *c, lzo_bytep op, const lzo_bytep ii,
//
************************************************************************/
-static int
+static lzo_uint
len_of_coded_match ( lzo_uint m_len, lzo_uint m_off, lzo_uint lit )
{
- int n = 4;
+ lzo_uint n = 4;
if (m_len < 2)
- return -1;
+ return 0;
if (m_len == 2)
- return (m_off <= M1_MAX_OFFSET && lit > 0 && lit < 4) ? 2 : -1;
+ return (m_off <= M1_MAX_OFFSET && lit > 0 && lit < 4) ? 2 : 0;
if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
return 2;
if (m_len == M2_MIN_LEN && m_off <= MX_MAX_OFFSET && lit >= 4)
@@ -380,20 +368,20 @@ len_of_coded_match ( lzo_uint m_len, lzo_uint m_off, lzo_uint lit )
}
return n;
}
- return -1;
+ return 0;
}
-static lzo_int
-min_gain(lzo_uint ahead, lzo_uint lit1, lzo_uint lit2, int l1, int l2, int l3)
+static lzo_uint
+min_gain(lzo_uint ahead, lzo_uint lit1, lzo_uint lit2, lzo_uint l1, lzo_uint l2, lzo_uint l3)
{
- lzo_int lazy_match_min_gain = 0;
+ lzo_uint lazy_match_min_gain;
assert (ahead >= 1);
- lazy_match_min_gain += ahead;
+ lazy_match_min_gain = ahead;
#if 0
- if (l3 > 0)
+ if (l3)
lit2 -= ahead;
#endif
@@ -403,10 +391,10 @@ min_gain(lzo_uint ahead, lzo_uint lit1, lzo_uint lit2, int l1, int l2, int l3)
lazy_match_min_gain += (lit2 <= 18) ? 0 : 1;
lazy_match_min_gain += (l2 - l1) * 2;
- if (l3 > 0)
+ if (l3)
lazy_match_min_gain -= (ahead - l3) * 2;
- if (lazy_match_min_gain < 0)
+ if ((lzo_int) lazy_match_min_gain < 0)
lazy_match_min_gain = 0;
#if 0
@@ -535,12 +523,12 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
lzo_voidp wrkmem,
const lzo_bytep dict, lzo_uint dict_len,
lzo_callback_p cb,
- int try_lazy,
+ int try_lazy_parm,
lzo_uint good_length,
lzo_uint max_lazy,
lzo_uint nice_length,
lzo_uint max_chain,
- lzo_uint32 flags )
+ lzo_uint32_t flags )
{
lzo_bytep op;
const lzo_bytep ii;
@@ -549,6 +537,7 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
LZO_COMPRESS_T cc;
LZO_COMPRESS_T * const c = &cc;
lzo_swd_p const swd = (lzo_swd_p) wrkmem;
+ lzo_uint try_lazy;
int r;
/* sanity check */
@@ -564,19 +553,20 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
/* setup parameter defaults */
/* number of lazy match tries */
- if (try_lazy < 0)
+ try_lazy = (lzo_uint) try_lazy_parm;
+ if (try_lazy_parm < 0)
try_lazy = 1;
/* reduce lazy match search if we already have a match with this length */
- if (good_length <= 0)
+ if (good_length == 0)
good_length = 32;
/* do not try a lazy match if we already have a match with this length */
- if (max_lazy <= 0)
+ if (max_lazy == 0)
max_lazy = 32;
/* stop searching for longer matches than this one */
- if (nice_length <= 0)
+ if (nice_length == 0)
nice_length = 0;
/* don't search more positions than this */
- if (max_chain <= 0)
+ if (max_chain == 0)
max_chain = SWD_MAX_CHAIN;
c->init = 0;
@@ -607,7 +597,7 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
{
lzo_uint ahead;
lzo_uint max_ahead;
- int l1, l2, l3;
+ lzo_uint l1, l2, l3;
c->codesize = pd(op, out);
@@ -648,7 +638,7 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
lit++;
swd->max_chain = max_chain;
r = find_match(c,swd,1,0);
- assert(r == 0);
+ assert(r == 0); LZO_UNUSED(r);
continue;
}
@@ -660,10 +650,9 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
assert_match(swd,m_len,m_off);
-
/* shall we try a lazy match ? */
ahead = 0;
- if (try_lazy <= 0 || m_len >= max_lazy)
+ if (try_lazy == 0 || m_len >= max_lazy)
{
/* no */
l1 = 0;
@@ -675,7 +664,7 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
l1 = len_of_coded_match(m_len,m_off,lit);
assert(l1 > 0);
#if 1
- max_ahead = LZO_MIN((lzo_uint)try_lazy, (lzo_uint)l1 - 1);
+ max_ahead = LZO_MIN(try_lazy, l1 - 1);
#else
max_ahead = LZO_MIN3(try_lazy, l1, m_len - 1);
#endif
@@ -684,7 +673,7 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
while (ahead < max_ahead && c->look > m_len)
{
- lzo_int lazy_match_min_gain;
+ lzo_uint lazy_match_min_gain;
if (m_len >= good_length)
swd->max_chain = max_chain >> 2;
@@ -693,7 +682,7 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
r = find_match(c,swd,1,0);
ahead++;
- assert(r == 0);
+ assert(r == 0); LZO_UNUSED(r);
assert(c->look > 0);
assert(ii + lit + ahead == c->bp);
@@ -713,7 +702,7 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
better_match(swd,&c->m_len,&c->m_off);
#endif
l2 = len_of_coded_match(c->m_len,c->m_off,lit+ahead);
- if (l2 < 0)
+ if (l2 == 0)
continue;
#if 0
if (c->m_len == m_len && l2 >= l1)
@@ -723,7 +712,7 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
#if 1
/* compressed-data compatibility [see above] */
- l3 = (op == out) ? -1 : len_of_coded_match(ahead,m_off,lit);
+ l3 = (op == out) ? 0 : len_of_coded_match(ahead,m_off,lit);
#else
l3 = len_of_coded_match(ahead,m_off,lit);
#endif
@@ -734,7 +723,7 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
c->lazy++;
assert_match(swd,c->m_len,c->m_off);
- if (l3 > 0)
+ if (l3)
{
/* code previous run */
op = code_run(c,op,ii,lit,ahead);
@@ -762,7 +751,7 @@ lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len,
op = code_match(c,op,m_len,m_off);
swd->max_chain = max_chain;
r = find_match(c,swd,m_len,1+ahead);
- assert(r == 0);
+ assert(r == 0); LZO_UNUSED(r);
lazy_match_done: ;
}
@@ -812,24 +801,24 @@ lzo1x_999_compress_level ( const lzo_bytep in , lzo_uint in_len,
{
static const struct
{
- int try_lazy;
+ int try_lazy_parm;
lzo_uint good_length;
lzo_uint max_lazy;
lzo_uint nice_length;
lzo_uint max_chain;
- lzo_uint32 flags;
+ lzo_uint32_t flags;
} c[9] = {
- { 0, 0, 0, 8, 4, 0 }, /* faster compression */
- { 0, 0, 0, 16, 8, 0 },
- { 0, 0, 0, 32, 16, 0 },
-
- { 1, 4, 4, 16, 16, 0 },
- { 1, 8, 16, 32, 32, 0 },
- { 1, 8, 16, 128, 128, 0 },
-
- { 2, 8, 32, 128, 256, 0 },
- { 2, 32, 128, F, 2048, 1 },
- { 2, F, F, F, 4096, 1 } /* max. compression */
+ /* faster compression */
+ { 0, 0, 0, 8, 4, 0 },
+ { 0, 0, 0, 16, 8, 0 },
+ { 0, 0, 0, 32, 16, 0 },
+ { 1, 4, 4, 16, 16, 0 },
+ { 1, 8, 16, 32, 32, 0 },
+ { 1, 8, 16, 128, 128, 0 },
+ { 2, 8, 32, 128, 256, 0 },
+ { 2, 32, 128, SWD_F, 2048, 1 },
+ { 2, SWD_F, SWD_F, SWD_F, 4096, 1 }
+ /* max. compression */
};
if (compression_level < 1 || compression_level > 9)
@@ -838,7 +827,7 @@ lzo1x_999_compress_level ( const lzo_bytep in , lzo_uint in_len,
compression_level -= 1;
return lzo1x_999_compress_internal(in, in_len, out, out_len, wrkmem,
dict, dict_len, cb,
- c[compression_level].try_lazy,
+ c[compression_level].try_lazy_parm,
c[compression_level].good_length,
c[compression_level].max_lazy,
#if 0
@@ -875,7 +864,4 @@ lzo1x_999_compress ( const lzo_bytep in , lzo_uint in_len,
}
-/*
-vi:ts=4:et
-*/
-
+/* vim:set ts=4 sw=4 et: */