wok-current diff busybox/stuff/busybox-1.12.0-unlzma.u @ rev 4057
Up: pidgin (2.6.2)
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Wed Sep 09 23:23:01 2009 +0200 (2009-09-09) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/busybox/stuff/busybox-1.12.0-unlzma.u Wed Sep 09 23:23:01 2009 +0200 1.3 @@ -0,0 +1,302 @@ 1.4 +--- busybox-1.12.0/archival/libunarchive/decompress_unlzma.c 1.5 ++++ busybox-1.12.0/archival/libunarchive/decompress_unlzma.c 1.6 +@@ -14,8 +14,10 @@ 1.7 + 1.8 + #if ENABLE_FEATURE_LZMA_FAST 1.9 + # define speed_inline ALWAYS_INLINE 1.10 ++# define size_inline 1.11 + #else 1.12 + # define speed_inline 1.13 ++# define size_inline ALWAYS_INLINE 1.14 + #endif 1.15 + 1.16 + 1.17 +@@ -44,8 +46,8 @@ 1.18 + #define RC_MODEL_TOTAL_BITS 11 1.19 + 1.20 + 1.21 +-/* Called twice: once at startup and once in rc_normalize() */ 1.22 +-static void rc_read(rc_t *rc) 1.23 ++/* Called twice: once at startup (LZMA_FAST only) and once in rc_normalize() */ 1.24 ++static size_inline void rc_read(rc_t *rc) 1.25 + { 1.26 + int buffer_size = safe_read(rc->fd, RC_BUFFER, RC_BUFFER_SIZE); 1.27 + if (buffer_size <= 0) 1.28 +@@ -54,8 +56,17 @@ 1.29 + rc->buffer_end = RC_BUFFER + buffer_size; 1.30 + } 1.31 + 1.32 ++/* Called twice, but one callsite is in speed_inline'd rc_is_bit_1() */ 1.33 ++static void rc_do_normalize(rc_t *rc) 1.34 ++{ 1.35 ++ if (rc->ptr >= rc->buffer_end) 1.36 ++ rc_read(rc); 1.37 ++ rc->range <<= 8; 1.38 ++ rc->code = (rc->code << 8) | *rc->ptr++; 1.39 ++} 1.40 ++ 1.41 + /* Called once */ 1.42 +-static rc_t* rc_init(int fd) /*, int buffer_size) */ 1.43 ++static ALWAYS_INLINE rc_t* rc_init(int fd) /*, int buffer_size) */ 1.44 + { 1.45 + int i; 1.46 + rc_t *rc; 1.47 +@@ -63,17 +74,18 @@ 1.48 + rc = xmalloc(sizeof(*rc) + RC_BUFFER_SIZE); 1.49 + 1.50 + rc->fd = fd; 1.51 +- /* rc->buffer_size = buffer_size; */ 1.52 +- rc->buffer_end = RC_BUFFER + RC_BUFFER_SIZE; 1.53 + rc->ptr = rc->buffer_end; 1.54 + 1.55 +- rc->code = 0; 1.56 +- rc->range = 0xFFFFFFFF; 1.57 + for (i = 0; i < 5; i++) { 1.58 ++#if ENABLE_FEATURE_LZMA_FAST 1.59 + if (rc->ptr >= rc->buffer_end) 1.60 + rc_read(rc); 1.61 + rc->code = (rc->code << 8) | *rc->ptr++; 1.62 ++#else 1.63 ++ rc_do_normalize(rc); 1.64 ++#endif 1.65 + } 1.66 ++ rc->range = 0xFFFFFFFF; 1.67 + return rc; 1.68 + } 1.69 + 1.70 +@@ -83,14 +95,6 @@ 1.71 + free(rc); 1.72 + } 1.73 + 1.74 +-/* Called twice, but one callsite is in speed_inline'd rc_is_bit_0_helper() */ 1.75 +-static void rc_do_normalize(rc_t *rc) 1.76 +-{ 1.77 +- if (rc->ptr >= rc->buffer_end) 1.78 +- rc_read(rc); 1.79 +- rc->range <<= 8; 1.80 +- rc->code = (rc->code << 8) | *rc->ptr++; 1.81 +-} 1.82 + static ALWAYS_INLINE void rc_normalize(rc_t *rc) 1.83 + { 1.84 + if (rc->range < (1 << RC_TOP_BITS)) { 1.85 +@@ -98,49 +102,30 @@ 1.86 + } 1.87 + } 1.88 + 1.89 +-/* rc_is_bit_0 is called 9 times */ 1.90 +-/* Why rc_is_bit_0_helper exists? 1.91 +- * Because we want to always expose (rc->code < rc->bound) to optimizer. 1.92 +- * Thus rc_is_bit_0 is always inlined, and rc_is_bit_0_helper is inlined 1.93 +- * only if we compile for speed. 1.94 +- */ 1.95 +-static speed_inline uint32_t rc_is_bit_0_helper(rc_t *rc, uint16_t *p) 1.96 ++/* rc_is_bit_1 is called 9 times */ 1.97 ++static speed_inline int rc_is_bit_1(rc_t *rc, uint16_t *p) 1.98 + { 1.99 + rc_normalize(rc); 1.100 + rc->bound = *p * (rc->range >> RC_MODEL_TOTAL_BITS); 1.101 +- return rc->bound; 1.102 ++ if (rc->code < rc->bound) { 1.103 ++ rc->range = rc->bound; 1.104 ++ *p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS; 1.105 ++ return 0; 1.106 ++ } 1.107 ++ else { 1.108 ++ rc->range -= rc->bound; 1.109 ++ rc->code -= rc->bound; 1.110 ++ *p -= *p >> RC_MOVE_BITS; 1.111 ++ return 1; 1.112 ++ } 1.113 + } 1.114 +-static ALWAYS_INLINE int rc_is_bit_0(rc_t *rc, uint16_t *p) 1.115 +-{ 1.116 +- uint32_t t = rc_is_bit_0_helper(rc, p); 1.117 +- return rc->code < t; 1.118 +-} 1.119 + 1.120 +-/* Called ~10 times, but very small, thus inlined */ 1.121 +-static speed_inline void rc_update_bit_0(rc_t *rc, uint16_t *p) 1.122 +-{ 1.123 +- rc->range = rc->bound; 1.124 +- *p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS; 1.125 +-} 1.126 +-static speed_inline void rc_update_bit_1(rc_t *rc, uint16_t *p) 1.127 +-{ 1.128 +- rc->range -= rc->bound; 1.129 +- rc->code -= rc->bound; 1.130 +- *p -= *p >> RC_MOVE_BITS; 1.131 +-} 1.132 +- 1.133 + /* Called 4 times in unlzma loop */ 1.134 +-static int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol) 1.135 ++static speed_inline int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol) 1.136 + { 1.137 +- if (rc_is_bit_0(rc, p)) { 1.138 +- rc_update_bit_0(rc, p); 1.139 +- *symbol *= 2; 1.140 +- return 0; 1.141 +- } else { 1.142 +- rc_update_bit_1(rc, p); 1.143 +- *symbol = *symbol * 2 + 1; 1.144 +- return 1; 1.145 +- } 1.146 ++ int ret = rc_is_bit_1(rc, p); 1.147 ++ *symbol = *symbol * 2 + ret; 1.148 ++ return ret; 1.149 + } 1.150 + 1.151 + /* Called once */ 1.152 +@@ -266,13 +251,13 @@ 1.153 + header.dst_size = SWAP_LE64(header.dst_size); 1.154 + 1.155 + if (header.dict_size == 0) 1.156 +- header.dict_size = 1; 1.157 ++ header.dict_size++; 1.158 + 1.159 + buffer = xmalloc(MIN(header.dst_size, header.dict_size)); 1.160 + 1.161 + num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)); 1.162 + p = xmalloc(num_probs * sizeof(*p)); 1.163 +- num_probs = LZMA_LITERAL + (LZMA_LIT_SIZE << (lc + lp)); 1.164 ++ num_probs += LZMA_LITERAL - LZMA_BASE_SIZE; 1.165 + for (i = 0; i < num_probs; i++) 1.166 + p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1; 1.167 + 1.168 +@@ -282,9 +267,8 @@ 1.169 + int pos_state = (buffer_pos + global_pos) & pos_state_mask; 1.170 + 1.171 + prob = p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state; 1.172 +- if (rc_is_bit_0(rc, prob)) { 1.173 ++ if (!rc_is_bit_1(rc, prob)) { 1.174 + mi = 1; 1.175 +- rc_update_bit_0(rc, prob); 1.176 + prob = (p + LZMA_LITERAL 1.177 + + (LZMA_LIT_SIZE * ((((buffer_pos + global_pos) & literal_pos_mask) << lc) 1.178 + + (previous_byte >> (8 - lc)) 1.179 +@@ -340,26 +324,21 @@ 1.180 + int offset; 1.181 + uint16_t *prob_len; 1.182 + 1.183 +- rc_update_bit_1(rc, prob); 1.184 + prob = p + LZMA_IS_REP + state; 1.185 +- if (rc_is_bit_0(rc, prob)) { 1.186 +- rc_update_bit_0(rc, prob); 1.187 ++ if (!rc_is_bit_1(rc, prob)) { 1.188 + rep3 = rep2; 1.189 + rep2 = rep1; 1.190 + rep1 = rep0; 1.191 + state = state < LZMA_NUM_LIT_STATES ? 0 : 3; 1.192 + prob = p + LZMA_LEN_CODER; 1.193 + } else { 1.194 +- rc_update_bit_1(rc, prob); 1.195 +- prob = p + LZMA_IS_REP_G0 + state; 1.196 +- if (rc_is_bit_0(rc, prob)) { 1.197 +- rc_update_bit_0(rc, prob); 1.198 ++ prob += LZMA_IS_REP_G0 - LZMA_IS_REP; 1.199 ++ if (!rc_is_bit_1(rc, prob)) { 1.200 + prob = (p + LZMA_IS_REP_0_LONG 1.201 + + (state << LZMA_NUM_POS_BITS_MAX) 1.202 + + pos_state 1.203 + ); 1.204 +- if (rc_is_bit_0(rc, prob)) { 1.205 +- rc_update_bit_0(rc, prob); 1.206 ++ if (!rc_is_bit_1(rc, prob)) { 1.207 + 1.208 + state = state < LZMA_NUM_LIT_STATES ? 9 : 11; 1.209 + #if ENABLE_FEATURE_LZMA_FAST 1.210 +@@ -372,25 +351,16 @@ 1.211 + len = 1; 1.212 + goto string; 1.213 + #endif 1.214 +- } else { 1.215 +- rc_update_bit_1(rc, prob); 1.216 + } 1.217 + } else { 1.218 + uint32_t distance; 1.219 + 1.220 +- rc_update_bit_1(rc, prob); 1.221 +- prob = p + LZMA_IS_REP_G1 + state; 1.222 +- if (rc_is_bit_0(rc, prob)) { 1.223 +- rc_update_bit_0(rc, prob); 1.224 +- distance = rep1; 1.225 +- } else { 1.226 +- rc_update_bit_1(rc, prob); 1.227 +- prob = p + LZMA_IS_REP_G2 + state; 1.228 +- if (rc_is_bit_0(rc, prob)) { 1.229 +- rc_update_bit_0(rc, prob); 1.230 +- distance = rep2; 1.231 +- } else { 1.232 +- rc_update_bit_1(rc, prob); 1.233 ++ prob += LZMA_IS_REP_G1 - LZMA_IS_REP_G0; 1.234 ++ distance = rep1; 1.235 ++ if (rc_is_bit_1(rc, prob)) { 1.236 ++ prob += LZMA_IS_REP_G2 - LZMA_IS_REP_G1; 1.237 ++ distance = rep2; 1.238 ++ if (rc_is_bit_1(rc, prob)) { 1.239 + distance = rep3; 1.240 + rep3 = rep2; 1.241 + } 1.242 +@@ -404,24 +374,20 @@ 1.243 + } 1.244 + 1.245 + prob_len = prob + LZMA_LEN_CHOICE; 1.246 +- if (rc_is_bit_0(rc, prob_len)) { 1.247 +- rc_update_bit_0(rc, prob_len); 1.248 +- prob_len = (prob + LZMA_LEN_LOW 1.249 +- + (pos_state << LZMA_LEN_NUM_LOW_BITS)); 1.250 ++ if (!rc_is_bit_1(rc, prob_len)) { 1.251 ++ prob_len += LZMA_LEN_LOW - LZMA_LEN_CHOICE 1.252 ++ + (pos_state << LZMA_LEN_NUM_LOW_BITS); 1.253 + offset = 0; 1.254 + num_bits = LZMA_LEN_NUM_LOW_BITS; 1.255 + } else { 1.256 +- rc_update_bit_1(rc, prob_len); 1.257 +- prob_len = prob + LZMA_LEN_CHOICE_2; 1.258 +- if (rc_is_bit_0(rc, prob_len)) { 1.259 +- rc_update_bit_0(rc, prob_len); 1.260 +- prob_len = (prob + LZMA_LEN_MID 1.261 +- + (pos_state << LZMA_LEN_NUM_MID_BITS)); 1.262 ++ prob_len += LZMA_LEN_CHOICE_2 - LZMA_LEN_CHOICE; 1.263 ++ if (!rc_is_bit_1(rc, prob_len)) { 1.264 ++ prob_len += LZMA_LEN_MID - LZMA_LEN_CHOICE_2 1.265 ++ + (pos_state << LZMA_LEN_NUM_MID_BITS); 1.266 + offset = 1 << LZMA_LEN_NUM_LOW_BITS; 1.267 + num_bits = LZMA_LEN_NUM_MID_BITS; 1.268 + } else { 1.269 +- rc_update_bit_1(rc, prob_len); 1.270 +- prob_len = prob + LZMA_LEN_HIGH; 1.271 ++ prob_len += LZMA_LEN_HIGH - LZMA_LEN_CHOICE_2; 1.272 + offset = ((1 << LZMA_LEN_NUM_LOW_BITS) 1.273 + + (1 << LZMA_LEN_NUM_MID_BITS)); 1.274 + num_bits = LZMA_LEN_NUM_HIGH_BITS; 1.275 +@@ -440,17 +406,18 @@ 1.276 + << LZMA_NUM_POS_SLOT_BITS); 1.277 + rc_bit_tree_decode(rc, prob, LZMA_NUM_POS_SLOT_BITS, 1.278 + &pos_slot); 1.279 ++ rep0 = pos_slot; 1.280 + if (pos_slot >= LZMA_START_POS_MODEL_INDEX) { 1.281 + num_bits = (pos_slot >> 1) - 1; 1.282 + rep0 = 2 | (pos_slot & 1); 1.283 ++ prob = p + LZMA_ALIGN; 1.284 + if (pos_slot < LZMA_END_POS_MODEL_INDEX) { 1.285 + rep0 <<= num_bits; 1.286 +- prob = p + LZMA_SPEC_POS + rep0 - pos_slot - 1; 1.287 ++ prob += LZMA_SPEC_POS - LZMA_ALIGN - 1 + rep0 - pos_slot ; 1.288 + } else { 1.289 + num_bits -= LZMA_NUM_ALIGN_BITS; 1.290 + while (num_bits--) 1.291 + rep0 = (rep0 << 1) | rc_direct_bit(rc); 1.292 +- prob = p + LZMA_ALIGN; 1.293 + rep0 <<= LZMA_NUM_ALIGN_BITS; 1.294 + num_bits = LZMA_NUM_ALIGN_BITS; 1.295 + } 1.296 +@@ -461,8 +428,7 @@ 1.297 + rep0 |= i; 1.298 + i <<= 1; 1.299 + } 1.300 +- } else 1.301 +- rep0 = pos_slot; 1.302 ++ } 1.303 + if (++rep0 == 0) 1.304 + break; 1.305 + }