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

Comparing Compress-LZF/lzf_c.c (file contents):
Revision 1.6 by root, Fri Feb 16 22:11:17 2007 UTC vs.
Revision 1.7 by root, Fri Nov 2 12:36:14 2007 UTC

48 */ 48 */
49#ifndef FRST 49#ifndef FRST
50# define FRST(p) (((p[0]) << 8) | p[1]) 50# define FRST(p) (((p[0]) << 8) | p[1])
51# define NEXT(v,p) (((v) << 8) | p[2]) 51# define NEXT(v,p) (((v) << 8) | p[2])
52# 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))*/
53#endif 54#endif
54/* 55/*
55 * 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.
56 * ((h * 57321 >> (3*8 - HLOG)) & (HSIZE - 1)) 57 * ((h * 57321 >> (3*8 - HLOG)) & (HSIZE - 1))
57 * 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.
58 * 59 *
59 * the next one is also quite good, albeit slow ;) 60 * the next one is also quite good, albeit slow ;)
60 * (int)(cos(h & 0xffffff) * 1e6) 61 * (int)(cos(h & 0xffffff) * 1e6)
61 */ 62 */
62 63
67# define IDX(h) ((h) & (HSIZE - 1)) 68# define IDX(h) ((h) & (HSIZE - 1))
68#endif 69#endif
69 70
70#define MAX_LIT (1 << 5) 71#define MAX_LIT (1 << 5)
71#define MAX_OFF (1 << 13) 72#define MAX_OFF (1 << 13)
72#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
73 81
74/* 82/*
75 * compressed format 83 * compressed format
76 * 84 *
77 * 000LLLLL <L+1> ; literal 85 * 000LLLLL <L+1> ; literal
101 unsigned int hval = FRST (ip); 109 unsigned int hval = FRST (ip);
102 unsigned long off; 110 unsigned long off;
103 int lit = 0; 111 int lit = 0;
104 112
105#if INIT_HTAB 113#if INIT_HTAB
106# if USE_MEMCPY
107 memset (htab, 0, sizeof (htab)); 114 memset (htab, 0, sizeof (htab));
108# else 115# if 0
109 for (hslot = htab; hslot < htab + HSIZE; hslot++) 116 for (hslot = htab; hslot < htab + HSIZE; hslot++)
110 *hslot++ = ip; 117 *hslot++ = ip;
111# endif 118# endif
112#endif 119#endif
113 120
114 for (;;) 121 for (;;)
115 { 122 {
211 { 218 {
212 if (op + 1 + MAX_LIT >= out_end) 219 if (op + 1 + MAX_LIT >= out_end)
213 return 0; 220 return 0;
214 221
215 *op++ = MAX_LIT - 1; 222 *op++ = MAX_LIT - 1;
216#if USE_MEMCPY 223
217 memcpy (op, ip - MAX_LIT, MAX_LIT); 224#ifdef lzf_movsb
218 op += MAX_LIT; 225 ip -= lit;
219 lit = 0; 226 lzf_movsb (op, ip, lit);
220#else 227#else
221 lit = -lit; 228 lit = -lit;
222 do 229 do
223 *op++ = ip[lit]; 230 *op++ = ip[lit];
224 while (++lit); 231 while (++lit);
230 { 237 {
231 if (op + lit + 1 >= out_end) 238 if (op + lit + 1 >= out_end)
232 return 0; 239 return 0;
233 240
234 *op++ = lit - 1; 241 *op++ = lit - 1;
242#ifdef lzf_movsb
243 ip -= lit;
244 lzf_movsb (op, ip, lit);
245#else
235 lit = -lit; 246 lit = -lit;
236 do 247 do
237 *op++ = ip[lit]; 248 *op++ = ip[lit];
238 while (++lit); 249 while (++lit);
250#endif
239 } 251 }
240 252
241 return op - (u8 *) out_data; 253 return op - (u8 *) out_data;
242} 254}
255

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines