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.13 by root, Tue Jun 19 21:25:07 2007 UTC vs.
Revision 1.15 by root, Fri Nov 2 12:39:20 2007 UTC

1/* 1/*
2 * Copyright (c) 2000-2005 Marc Alexander Lehmann <schmorp@schmorp.de> 2 * Copyright (c) 2000-2007 Marc Alexander Lehmann <schmorp@schmorp.de>
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without modifica- 4 * Redistribution and use in source and binary forms, with or without modifica-
5 * tion, are permitted provided that the following conditions are met: 5 * tion, are permitted provided that the following conditions are met:
6 * 6 *
7 * 1. Redistributions of source code must retain the above copyright notice, 7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer. 8 * this list of conditions and the following disclaimer.
9 * 9 *
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 *
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 * 13 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- 15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
19 * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 16 * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- 17 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
70 67
71#define MAX_LIT (1 << 5) 68#define MAX_LIT (1 << 5)
72#define MAX_OFF (1 << 13) 69#define MAX_OFF (1 << 13)
73#define MAX_REF ((1 << 8) + (1 << 3)) 70#define MAX_REF ((1 << 8) + (1 << 3))
74 71
72#if (__i386 || __amd64) && __GNUC__ >= 3
73# define lzf_movsb(dst, src, len) \
74 asm ("rep movsb" \
75 : "=D" (dst), "=S" (src), "=c" (len) \
76 : "0" (dst), "1" (src), "2" (len));
77#endif
78
75/* 79/*
76 * compressed format 80 * compressed format
77 * 81 *
78 * 000LLLLL <L+1> ; literal 82 * 000LLLLL <L+1> ; literal
79 * LLLooooo oooooooo ; backref L 83 * LLLooooo oooooooo ; backref L
102 unsigned int hval = FRST (ip); 106 unsigned int hval = FRST (ip);
103 unsigned long off; 107 unsigned long off;
104 int lit = 0; 108 int lit = 0;
105 109
106#if INIT_HTAB 110#if INIT_HTAB
107# if USE_MEMCPY
108 memset (htab, 0, sizeof (htab)); 111 memset (htab, 0, sizeof (htab));
109# else 112# if 0
110 for (hslot = htab; hslot < htab + HSIZE; hslot++) 113 for (hslot = htab; hslot < htab + HSIZE; hslot++)
111 *hslot++ = ip; 114 *hslot++ = ip;
112# endif 115# endif
113#endif 116#endif
114 117
115 for (;;) 118 for (;;)
116 { 119 {
212 { 215 {
213 if (op + 1 + MAX_LIT >= out_end) 216 if (op + 1 + MAX_LIT >= out_end)
214 return 0; 217 return 0;
215 218
216 *op++ = MAX_LIT - 1; 219 *op++ = MAX_LIT - 1;
217#if USE_MEMCPY 220
218 memcpy (op, ip - MAX_LIT, MAX_LIT); 221#ifdef lzf_movsb
219 op += MAX_LIT; 222 ip -= lit;
220 lit = 0; 223 lzf_movsb (op, ip, lit);
221#else 224#else
222 lit = -lit; 225 lit = -lit;
223 do 226 do
224 *op++ = ip[lit]; 227 *op++ = ip[lit];
225 while (++lit); 228 while (++lit);
231 { 234 {
232 if (op + lit + 1 >= out_end) 235 if (op + lit + 1 >= out_end)
233 return 0; 236 return 0;
234 237
235 *op++ = lit - 1; 238 *op++ = lit - 1;
239#ifdef lzf_movsb
240 ip -= lit;
241 lzf_movsb (op, ip, lit);
242#else
236 lit = -lit; 243 lit = -lit;
237 do 244 do
238 *op++ = ip[lit]; 245 *op++ = ip[lit];
239 while (++lit); 246 while (++lit);
247#endif
240 } 248 }
241 249
242 return op - (u8 *) out_data; 250 return op - (u8 *) out_data;
243} 251}
252

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines