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

Comparing liblzf/lzf_d.c (file contents):
Revision 1.13 by root, Mon Mar 28 00:10:31 2011 UTC vs.
Revision 1.16 by root, Mon Feb 23 23:46:10 2015 UTC

1/* 1/*
2 * Copyright (c) 2000-2010 Marc Alexander Lehmann <schmorp@schmorp.de> 2 * Copyright (c) 2000-2010 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 * 13 *
14 * 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
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- 15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
16 * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 16 * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
17 * 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-
18 * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
41#else 41#else
42# include <errno.h> 42# include <errno.h>
43# define SET_ERRNO(n) errno = (n) 43# define SET_ERRNO(n) errno = (n)
44#endif 44#endif
45 45
46#define USE_REP_MOVSB 1
47#if USE_REP_MOVSB /* small win on amd, big loss on intel */ 46#if USE_REP_MOVSB /* small win on amd, big loss on intel */
48#if (__i386 || __amd64) && __GNUC__ >= 3 47#if (__i386 || __amd64) && __GNUC__ >= 3
49# define lzf_movsb(dst, src, len) \ 48# define lzf_movsb(dst, src, len) \
50 asm ("rep movsb" \ 49 asm ("rep movsb" \
51 : "=D" (dst), "=S" (src), "=c" (len) \ 50 : "=D" (dst), "=S" (src), "=c" (len) \
52 : "0" (dst), "1" (src), "2" (len)); 51 : "0" (dst), "1" (src), "2" (len));
53#endif 52#endif
54#endif 53#endif
55 54
56unsigned int 55unsigned int
57lzf_decompress (const void *const in_data, unsigned int in_len, 56lzf_decompress (const void *const in_data, unsigned int in_len,
58 void *out_data, unsigned int out_len) 57 void *out_data, unsigned int out_len)
59{ 58{
60 u8 const *ip = (const u8 *)in_data; 59 u8 const *ip = (const u8 *)in_data;
61 u8 *op = (u8 *)out_data; 60 u8 *op = (u8 *)out_data;
84 } 83 }
85#endif 84#endif
86 85
87#ifdef lzf_movsb 86#ifdef lzf_movsb
88 lzf_movsb (op, ip, ctrl); 87 lzf_movsb (op, ip, ctrl);
88#elif OPTIMISE_SIZE
89 while (ctrl--)
90 *op++ = *ip++;
89#else 91#else
90 switch (ctrl) 92 switch (ctrl)
91 { 93 {
92 case 32: *op++ = *ip++; case 31: *op++ = *ip++; case 30: *op++ = *ip++; case 29: *op++ = *ip++; 94 case 32: *op++ = *ip++; case 31: *op++ = *ip++; case 30: *op++ = *ip++; case 29: *op++ = *ip++;
93 case 28: *op++ = *ip++; case 27: *op++ = *ip++; case 26: *op++ = *ip++; case 25: *op++ = *ip++; 95 case 28: *op++ = *ip++; case 27: *op++ = *ip++; case 26: *op++ = *ip++; case 25: *op++ = *ip++;
140 } 142 }
141 143
142#ifdef lzf_movsb 144#ifdef lzf_movsb
143 len += 2; 145 len += 2;
144 lzf_movsb (op, ref, len); 146 lzf_movsb (op, ref, len);
147#elif OPTIMISE_SIZE
148 len += 2;
149
150 do
151 *op++ = *ref++;
152 while (--len);
145#else 153#else
146 switch (len) 154 switch (len)
147 { 155 {
148 default: 156 default:
149 len += 2; 157 len += 2;
154 memcpy (op, ref, len); 162 memcpy (op, ref, len);
155 op += len; 163 op += len;
156 } 164 }
157 else 165 else
158 { 166 {
159 /* overlapping, use octte by octte copying */ 167 /* overlapping, use octet by octet copying */
160 do 168 do
161 *op++ = *ref++; 169 *op++ = *ref++;
162 while (--len); 170 while (--len);
163 } 171 }
164 172

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines