ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/liblzf/lzf_c.c
(Generate patch)

Comparing liblzf/lzf_c.c (file contents):
Revision 1.9 by root, Tue Mar 8 19:59:52 2005 UTC vs.
Revision 1.14 by root, Thu Jun 21 22:11:34 2007 UTC

44 * don't play with this unless you benchmark! 44 * don't play with this unless you benchmark!
45 * decompression is not dependent on the hash function 45 * decompression is not dependent on the hash function
46 * the hashing function might seem strange, just believe me 46 * the hashing function might seem strange, just believe me
47 * it works ;) 47 * it works ;)
48 */ 48 */
49#ifndef FRST
49#define FRST(p) (((p[0]) << 8) | p[1]) 50# define FRST(p) (((p[0]) << 8) | p[1])
50#define NEXT(v,p) (((v) << 8) | p[2]) 51# define NEXT(v,p) (((v) << 8) | p[2])
51#define IDX(h) ((((h ^ (h << 5)) >> (3*8 - HLOG)) - h*5) & (HSIZE - 1)) 52# define IDX(h) ((((h ^ (h << 5)) >> (3*8 - HLOG)) - h*5) & (HSIZE - 1))
53/*# define IDX(h) ((ip[0] * 121 ^ ip[1] * 33 ^ ip[2] * 1) & (HSIZE-1))*/
54#endif
52/* 55/*
53 * IDX works because it is very similar to a multiplicative hash, e.g. 56 * IDX works because it is very similar to a multiplicative hash, e.g.
54 * ((h * 57321 >> (3*8 - HLOG)) & (HSIZE - 1)) 57 * ((h * 57321 >> (3*8 - HLOG)) & (HSIZE - 1))
55 * the latter is also quite fast on newer CPUs, and sligthly better 58 * the latter is also quite fast on newer CPUs, and compresses similarly.
56 * 59 *
57 * the next one is also quite good, albeit slow ;) 60 * the next one is also quite good, albeit slow ;)
58 * (int)(cos(h & 0xffffff) * 1e6) 61 * (int)(cos(h & 0xffffff) * 1e6)
59 */ 62 */
60 63
65# define IDX(h) ((h) & (HSIZE - 1)) 68# define IDX(h) ((h) & (HSIZE - 1))
66#endif 69#endif
67 70
68#define MAX_LIT (1 << 5) 71#define MAX_LIT (1 << 5)
69#define MAX_OFF (1 << 13) 72#define MAX_OFF (1 << 13)
70#define MAX_REF ((1 << 8) + (1 << 3)) 73#define MAX_REF ((1 << 8) + (1 << 3))
74
75#if (__i386 || __amd64) && __GNUC__ >= 3
76# define lzf_movsb(dst, src, len) \
77 asm ("rep movsb" \
78 : "=D" (dst), "=S" (src), "=c" (len) \
79 : "0" (dst), "1" (src), "2" (len));
80#endif
71 81
72/* 82/*
73 * compressed format 83 * compressed format
74 * 84 *
75 * 000LLLLL <L+1> ; literal 85 * 000LLLLL <L+1> ; literal
76 * LLLOOOOO oooooooo ; backref L 86 * LLLooooo oooooooo ; backref L
77 * 111OOOOO LLLLLLLL oooooooo ; backref L+7 87 * 111ooooo LLLLLLLL oooooooo ; backref L+7
78 * 88 *
79 */ 89 */
80 90
81unsigned int 91unsigned int
82lzf_compress (const void *const in_data, unsigned int in_len, 92lzf_compress (const void *const in_data, unsigned int in_len,
83 void *out_data, unsigned int out_len 93 void *out_data, unsigned int out_len
84#if LZF_STATE_ARG 94#if LZF_STATE_ARG
85 , LZF_STATE *htab 95 , LZF_STATE htab
86#endif 96#endif
87 ) 97 )
88{ 98{
89#if !LZF_STATE_ARG 99#if !LZF_STATE_ARG
90 LZF_STATE htab; 100 LZF_STATE htab;
99 unsigned int hval = FRST (ip); 109 unsigned int hval = FRST (ip);
100 unsigned long off; 110 unsigned long off;
101 int lit = 0; 111 int lit = 0;
102 112
103#if INIT_HTAB 113#if INIT_HTAB
104# if USE_MEMCPY
105 memset (htab, 0, sizeof (htab)); 114 memset (htab, 0, sizeof (htab));
106# else 115# if 0
107 for (hslot = htab; hslot < htab + HSIZE; hslot++) 116 for (hslot = htab; hslot < htab + HSIZE; hslot++)
108 *hslot++ = ip; 117 *hslot++ = ip;
109# endif 118# endif
110#endif 119#endif
111 120
112 for (;;) 121 for (;;)
113 { 122 {
209 { 218 {
210 if (op + 1 + MAX_LIT >= out_end) 219 if (op + 1 + MAX_LIT >= out_end)
211 return 0; 220 return 0;
212 221
213 *op++ = MAX_LIT - 1; 222 *op++ = MAX_LIT - 1;
214#if USE_MEMCPY 223
215 memcpy (op, ip - MAX_LIT, MAX_LIT); 224#ifdef lzf_movsb
216 op += MAX_LIT; 225 ip -= lit;
217 lit = 0; 226 lzf_movsb (op, ip, lit);
218#else 227#else
219 lit = -lit; 228 lit = -lit;
220 do 229 do
221 *op++ = ip[lit]; 230 *op++ = ip[lit];
222 while (++lit); 231 while (++lit);
228 { 237 {
229 if (op + lit + 1 >= out_end) 238 if (op + lit + 1 >= out_end)
230 return 0; 239 return 0;
231 240
232 *op++ = lit - 1; 241 *op++ = lit - 1;
242#ifdef lzf_movsb
243 ip -= lit;
244 lzf_movsb (op, ip, lit);
245#else
233 lit = -lit; 246 lit = -lit;
234 do 247 do
235 *op++ = ip[lit]; 248 *op++ = ip[lit];
236 while (++lit); 249 while (++lit);
250#endif
237 } 251 }
238 252
239 return op - (u8 *) out_data; 253 return op - (u8 *) out_data;
240} 254}
255

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines