… | |
… | |
43 | #else |
43 | #else |
44 | # include <errno.h> |
44 | # include <errno.h> |
45 | # define SET_ERRNO(n) errno = (n) |
45 | # define SET_ERRNO(n) errno = (n) |
46 | #endif |
46 | #endif |
47 | |
47 | |
|
|
48 | #if (__i386 || __amd64) && __GNUC__ >= 3 |
|
|
49 | # define lzf_movsb(dst, src, len) \ |
|
|
50 | asm ("rep movsb" \ |
|
|
51 | : "=D" (dst), "=S" (src), "=c" (len) \ |
|
|
52 | : "0" (dst), "1" (src), "2" (len)); |
|
|
53 | #endif |
|
|
54 | |
48 | unsigned int |
55 | unsigned int |
49 | lzf_decompress (const void *const in_data, unsigned int in_len, |
56 | lzf_decompress (const void *const in_data, unsigned int in_len, |
50 | void *out_data, unsigned int out_len) |
57 | void *out_data, unsigned int out_len) |
51 | { |
58 | { |
52 | u8 const *ip = (const u8 *)in_data; |
59 | u8 const *ip = (const u8 *)in_data; |
… | |
… | |
74 | SET_ERRNO (EINVAL); |
81 | SET_ERRNO (EINVAL); |
75 | return 0; |
82 | return 0; |
76 | } |
83 | } |
77 | #endif |
84 | #endif |
78 | |
85 | |
79 | #if USE_MEMCPY |
86 | #ifdef lzf_movsb |
80 | memcpy (op, ip, ctrl); |
87 | lzf_movsb (op, ip, ctrl); |
81 | op += ctrl; |
|
|
82 | ip += ctrl; |
|
|
83 | #else |
88 | #else |
84 | do |
89 | do |
85 | *op++ = *ip++; |
90 | *op++ = *ip++; |
86 | while (--ctrl); |
91 | while (--ctrl); |
87 | #endif |
92 | #endif |
… | |
… | |
123 | { |
128 | { |
124 | SET_ERRNO (EINVAL); |
129 | SET_ERRNO (EINVAL); |
125 | return 0; |
130 | return 0; |
126 | } |
131 | } |
127 | |
132 | |
|
|
133 | #ifdef lzf_movsb |
|
|
134 | len += 2; |
|
|
135 | lzf_movsb (op, ref, len); |
|
|
136 | #else |
128 | *op++ = *ref++; |
137 | *op++ = *ref++; |
129 | *op++ = *ref++; |
138 | *op++ = *ref++; |
130 | |
139 | |
131 | do |
140 | do |
132 | *op++ = *ref++; |
141 | *op++ = *ref++; |
133 | while (--len); |
142 | while (--len); |
|
|
143 | #endif |
134 | } |
144 | } |
135 | } |
145 | } |
136 | while (ip < in_end); |
146 | while (ip < in_end); |
137 | |
147 | |
138 | return op - (u8 *)out_data; |
148 | return op - (u8 *)out_data; |