summaryrefslogtreecommitdiff
path: root/xdelta3/xdelta3.c
diff options
context:
space:
mode:
authorjosh.macdonald <jmacd@users.noreply.github.com>2013-01-21 08:35:44 +0000
committerjosh.macdonald <jmacd@users.noreply.github.com>2013-01-21 08:35:44 +0000
commitac17b222cb4294dfeabf1aeed74dfe1a24991412 (patch)
tree77e5ac5174b47377cddf0cbb20c8c56c5663cbd3 /xdelta3/xdelta3.c
parent2fa2807516df9afb29fbff9ffb18232260c66ec4 (diff)
Revert to r386; prepare 3.0.6 release
Diffstat (limited to 'xdelta3/xdelta3.c')
-rw-r--r--xdelta3/xdelta3.c79
1 files changed, 39 insertions, 40 deletions
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c
index 23a6622..608622a 100644
--- a/xdelta3/xdelta3.c
+++ b/xdelta3/xdelta3.c
@@ -533,7 +533,7 @@ static int xd3_srcwin_move_point (xd3_stream *stream,
533static int xd3_emit_run (xd3_stream *stream, usize_t pos, 533static int xd3_emit_run (xd3_stream *stream, usize_t pos,
534 usize_t size, uint8_t *run_c); 534 usize_t size, uint8_t *run_c);
535static usize_t xd3_checksum_hash (const xd3_hash_cfg *cfg, 535static usize_t xd3_checksum_hash (const xd3_hash_cfg *cfg,
536 const usize_t cksum); 536 const usize_t cksum);
537static xoff_t xd3_source_cksum_offset(xd3_stream *stream, usize_t low); 537static xoff_t xd3_source_cksum_offset(xd3_stream *stream, usize_t low);
538static void xd3_scksum_insert (xd3_stream *stream, 538static void xd3_scksum_insert (xd3_stream *stream,
539 usize_t inx, 539 usize_t inx,
@@ -999,7 +999,7 @@ static void
999xd3_build_code_table (const xd3_code_table_desc *desc, xd3_dinst *tbl) 999xd3_build_code_table (const xd3_code_table_desc *desc, xd3_dinst *tbl)
1000{ 1000{
1001 usize_t size1, size2, mode; 1001 usize_t size1, size2, mode;
1002 usize_t cpy_modes = 2U + desc->near_modes + desc->same_modes; 1002 usize_t cpy_modes = 2 + desc->near_modes + desc->same_modes;
1003 xd3_dinst *d = tbl; 1003 xd3_dinst *d = tbl;
1004 1004
1005 (d++)->type1 = XD3_RUN; 1005 (d++)->type1 = XD3_RUN;
@@ -1015,8 +1015,7 @@ xd3_build_code_table (const xd3_code_table_desc *desc, xd3_dinst *tbl)
1015 { 1015 {
1016 (d++)->type1 = XD3_CPY + mode; 1016 (d++)->type1 = XD3_CPY + mode;
1017 1017
1018 for (size1 = MIN_MATCH; size1 < MIN_MATCH + desc->cpy_sizes; 1018 for (size1 = MIN_MATCH; size1 < MIN_MATCH + desc->cpy_sizes; size1 += 1, d += 1)
1019 size1 += 1, d += 1)
1020 { 1019 {
1021 d->type1 = XD3_CPY + mode; 1020 d->type1 = XD3_CPY + mode;
1022 d->size1 = size1; 1021 d->size1 = size1;
@@ -1530,10 +1529,10 @@ xd3_swap_usize_t (usize_t* p1, usize_t* p2)
1530 1529
1531/* It's not constant time, but it computes the log. */ 1530/* It's not constant time, but it computes the log. */
1532static int 1531static int
1533xd3_check_pow2 (xoff_t value, int *logof) 1532xd3_check_pow2 (xoff_t value, usize_t *logof)
1534{ 1533{
1535 xoff_t x = 1; 1534 xoff_t x = 1;
1536 int nolog; 1535 usize_t nolog;
1537 if (logof == NULL) { 1536 if (logof == NULL) {
1538 logof = &nolog; 1537 logof = &nolog;
1539 } 1538 }
@@ -1594,16 +1593,17 @@ xd3_round_blksize (usize_t sz, usize_t blksz)
1594#define A32_DO8(buf,i) A32_DO4(buf,i); A32_DO4(buf,i+4); 1593#define A32_DO8(buf,i) A32_DO4(buf,i); A32_DO4(buf,i+4);
1595#define A32_DO16(buf) A32_DO8(buf,0); A32_DO8(buf,8); 1594#define A32_DO16(buf) A32_DO8(buf,0); A32_DO8(buf,8);
1596 1595
1597static uint32_t adler32 (uint32_t adler, const uint8_t *buf, size_t len) 1596static unsigned long adler32 (unsigned long adler, const uint8_t *buf,
1597 usize_t len)
1598{ 1598{
1599 uint32_t s1 = adler & 0xffff; 1599 unsigned long s1 = adler & 0xffff;
1600 uint32_t s2 = (adler >> 16) & 0xffff; 1600 unsigned long s2 = (adler >> 16) & 0xffff;
1601 int k; 1601 int k;
1602 1602
1603 while (len > 0) 1603 while (len > 0)
1604 { 1604 {
1605 k = (len < A32_NMAX) ? (int) len : A32_NMAX; 1605 k = (len < A32_NMAX) ? len : A32_NMAX;
1606 len -= (size_t) k; 1606 len -= k;
1607 1607
1608 while (k >= 16) 1608 while (k >= 16)
1609 { 1609 {
@@ -2560,9 +2560,9 @@ xoff_t xd3_source_eof(const xd3_source *src)
2560} 2560}
2561 2561
2562inline 2562inline
2563xoff_t xd3_bytes_on_srcblk (xd3_source *src, xoff_t blkno) 2563usize_t xd3_bytes_on_srcblk (xd3_source *src, xoff_t blkno)
2564{ 2564{
2565 xoff_t r = (blkno == src->max_blkno ? 2565 usize_t r = (blkno == src->max_blkno ?
2566 src->onlastblk : 2566 src->onlastblk :
2567 src->blksize); 2567 src->blksize);
2568 return r; 2568 return r;
@@ -2653,7 +2653,7 @@ int
2653xd3_set_source (xd3_stream *stream, 2653xd3_set_source (xd3_stream *stream,
2654 xd3_source *src) 2654 xd3_source *src)
2655{ 2655{
2656 int shiftby; 2656 usize_t shiftby;
2657 2657
2658 stream->src = src; 2658 stream->src = src;
2659 src->srclen = 0; 2659 src->srclen = 0;
@@ -2665,16 +2665,16 @@ xd3_set_source (xd3_stream *stream,
2665 { 2665 {
2666 src->blksize = xd3_pow2_roundup(src->blksize); 2666 src->blksize = xd3_pow2_roundup(src->blksize);
2667 xd3_check_pow2 (src->blksize, &shiftby); 2667 xd3_check_pow2 (src->blksize, &shiftby);
2668 IF_DEBUG1 (DP(RINT "raising src_blksz to %"Q"u\n", src->blksize)); 2668 IF_DEBUG1 (DP(RINT "raising src_blksz to %u\n", src->blksize));
2669 } 2669 }
2670 2670
2671 src->shiftby = shiftby; 2671 src->shiftby = shiftby;
2672 src->maskby = (1U << shiftby) - 1; 2672 src->maskby = (1 << shiftby) - 1;
2673 2673
2674 if (xd3_check_pow2 (src->max_winsize, NULL) != 0) 2674 if (xd3_check_pow2 (src->max_winsize, NULL) != 0)
2675 { 2675 {
2676 src->max_winsize = xd3_xoff_roundup(src->max_winsize); 2676 src->max_winsize = xd3_xoff_roundup(src->max_winsize);
2677 IF_DEBUG1 (DP(RINT "raising src_maxsize to %"Q"u\n", src->blksize)); 2677 IF_DEBUG1 (DP(RINT "raising src_maxsize to %u\n", src->blksize));
2678 } 2678 }
2679 src->max_winsize = max(src->max_winsize, XD3_ALLOCSIZE); 2679 src->max_winsize = max(src->max_winsize, XD3_ALLOCSIZE);
2680 2680
@@ -3696,8 +3696,8 @@ xd3_encode_init (xd3_stream *stream, int full_init)
3696 * identical or short inputs require no table allocation. */ 3696 * identical or short inputs require no table allocation. */
3697 if (large_comp) 3697 if (large_comp)
3698 { 3698 {
3699 usize_t hash_values = (usize_t) (stream->src->max_winsize / 3699 usize_t hash_values = (stream->src->max_winsize /
3700 (xoff_t) stream->smatcher.large_step); 3700 stream->smatcher.large_step);
3701 3701
3702 xd3_size_hashtable (stream, 3702 xd3_size_hashtable (stream,
3703 hash_values, 3703 hash_values,
@@ -4138,7 +4138,7 @@ xd3_process_memory (int is_encode,
4138 config.winsize = min(input_size, (usize_t) XD3_DEFAULT_WINSIZE); 4138 config.winsize = min(input_size, (usize_t) XD3_DEFAULT_WINSIZE);
4139 config.iopt_size = min(input_size / 32, XD3_DEFAULT_IOPT_SIZE); 4139 config.iopt_size = min(input_size / 32, XD3_DEFAULT_IOPT_SIZE);
4140 config.iopt_size = max(config.iopt_size, 128U); 4140 config.iopt_size = max(config.iopt_size, 128U);
4141 config.sprevsz = (usize_t) xd3_pow2_roundup (config.winsize); 4141 config.sprevsz = xd3_pow2_roundup (config.winsize);
4142 } 4142 }
4143 4143
4144 if ((ret = xd3_config_stream (&stream, &config)) != 0) 4144 if ((ret = xd3_config_stream (&stream, &config)) != 0)
@@ -4560,21 +4560,19 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos)
4560 return 1; 4560 return 1;
4561} 4561}
4562 4562
4563static inline xoff_t 4563static inline int
4564xd3_forward_match(const uint8_t *s1c, const uint8_t *s2c, size_t n) 4564xd3_forward_match(const uint8_t *s1c, const uint8_t *s2c, int n)
4565{ 4565{
4566 size_t i = 0; 4566 int i = 0;
4567#if UNALIGNED_OK 4567#if UNALIGNED_OK
4568 const size_t ssize = sizeof(size_t); 4568 int nint = n / sizeof(int);
4569 const size_t nint = n / ssize;
4570 4569
4571 /* If there are at least 8 elements */
4572 if (nint >> 3) 4570 if (nint >> 3)
4573 { 4571 {
4574 usize_t j = 0; 4572 int j = 0;
4575 const size_t *s1 = (const size_t*)s1c; 4573 const int *s1 = (const int*)s1c;
4576 const size_t *s2 = (const size_t*)s2c; 4574 const int *s2 = (const int*)s2c;
4577 const size_t nint_8 = nint - 8; 4575 int nint_8 = nint - 8;
4578 4576
4579 while (i <= nint_8 && 4577 while (i <= nint_8 &&
4580 s1[i++] == s2[j++] && 4578 s1[i++] == s2[j++] &&
@@ -4586,7 +4584,7 @@ xd3_forward_match(const uint8_t *s1c, const uint8_t *s2c, size_t n)
4586 s1[i++] == s2[j++] && 4584 s1[i++] == s2[j++] &&
4587 s1[i++] == s2[j++]) { } 4585 s1[i++] == s2[j++]) { }
4588 4586
4589 i = (i - 1) * ssize; 4587 i = (i - 1) * sizeof(int);
4590 } 4588 }
4591#endif 4589#endif
4592 4590
@@ -4617,9 +4615,9 @@ xd3_source_extend_match (xd3_stream *stream)
4617 of the input match being tested. */ 4615 of the input match being tested. */
4618 xoff_t tryblk; /* tryblk, tryoff are the block, offset position 4616 xoff_t tryblk; /* tryblk, tryoff are the block, offset position
4619 of matchoff */ 4617 of matchoff */
4620 xoff_t tryoff; 4618 usize_t tryoff;
4621 xoff_t tryrem; /* tryrem is the number of matchable bytes */ 4619 usize_t tryrem; /* tryrem is the number of matchable bytes */
4622 xoff_t matched; 4620 usize_t matched;
4623 4621
4624 IF_DEBUG2(DP(RINT "[extend match] srcpos %"Q"u\n", 4622 IF_DEBUG2(DP(RINT "[extend match] srcpos %"Q"u\n",
4625 stream->match_srcpos)); 4623 stream->match_srcpos));
@@ -4722,8 +4720,8 @@ xd3_source_extend_match (xd3_stream *stream)
4722 stream->next_in + streamoff, 4720 stream->next_in + streamoff,
4723 tryrem); 4721 tryrem);
4724 tryoff += matched; 4722 tryoff += matched;
4725 streamoff += (xoff_t) matched; 4723 streamoff += matched;
4726 stream->match_fwd += (xoff_t) matched; 4724 stream->match_fwd += matched;
4727 4725
4728 if (tryrem != matched) 4726 if (tryrem != matched)
4729 { 4727 {
@@ -5096,7 +5094,7 @@ xd3_srcwin_move_point (xd3_stream *stream, usize_t *next_move_point)
5096 { 5094 {
5097 xoff_t blkno; 5095 xoff_t blkno;
5098 xoff_t blkbaseoffset; 5096 xoff_t blkbaseoffset;
5099 xoff_t blkrem; 5097 usize_t blkrem;
5100 ssize_t oldpos; /* Using ssize_t because of a */ 5098 ssize_t oldpos; /* Using ssize_t because of a */
5101 ssize_t blkpos; /* do { blkpos-- } 5099 ssize_t blkpos; /* do { blkpos-- }
5102 while (blkpos >= oldpos); */ 5100 while (blkpos >= oldpos); */
@@ -5154,11 +5152,12 @@ xd3_srcwin_move_point (xd3_stream *stream, usize_t *next_move_point)
5154 usize_t hval = xd3_checksum_hash (& stream->large_hash, cksum); 5152 usize_t hval = xd3_checksum_hash (& stream->large_hash, cksum);
5155 5153
5156 stream->large_table[hval] = 5154 stream->large_table[hval] =
5157 (uint32_t) (blkbaseoffset + (xoff_t)(blkpos + HASH_CKOFFSET)); 5155 (usize_t) (blkbaseoffset +
5156 (xoff_t)(blkpos + HASH_CKOFFSET));
5158 5157
5159 IF_DEBUG (stream->large_ckcnt += 1); 5158 IF_DEBUG (stream->large_ckcnt += 1);
5160 5159
5161 blkpos -= (ssize_t) stream->smatcher.large_step; 5160 blkpos -= stream->smatcher.large_step;
5162 } 5161 }
5163 while (blkpos >= oldpos); 5162 while (blkpos >= oldpos);
5164 5163