summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xxdelta3/examples/Makefile5
-rw-r--r--xdelta3/xdelta3-decode.h5
-rw-r--r--xdelta3/xdelta3.c24
-rw-r--r--xdelta3/xdelta3.h21
4 files changed, 35 insertions, 20 deletions
diff --git a/xdelta3/examples/Makefile b/xdelta3/examples/Makefile
index d171a80..d6d9cc9 100755
--- a/xdelta3/examples/Makefile
+++ b/xdelta3/examples/Makefile
@@ -1,6 +1,5 @@
1#CFLAGS = -g -Wall -I.. 1#CFLAGS = -g -Wall -I.. -DXD3_DEBUG=1
2# -DXD3_DEBUG=1 2CFLAGS = -O3 -Wall -I.. -DXD3_DEBUG=0
3CFLAGS = -O3 -pg -Wall -I.. -DXD3_DEBUG=0
4# -pg 3# -pg
5 4
6SOURCES = small_page_test.c encode_decode_test.c speed_test.c 5SOURCES = small_page_test.c encode_decode_test.c speed_test.c
diff --git a/xdelta3/xdelta3-decode.h b/xdelta3/xdelta3-decode.h
index 5ddf823..0b49fb9 100644
--- a/xdelta3/xdelta3-decode.h
+++ b/xdelta3/xdelta3-decode.h
@@ -1021,8 +1021,9 @@ xd3_decode_input (xd3_stream *stream)
1021 return XD3_INVALID_INPUT; 1021 return XD3_INVALID_INPUT;
1022 } 1022 }
1023 1023
1024 src->cpyoff_blocks = stream->dec_cpyoff / src->blksize; 1024 xd3_blksize_div(stream->dec_cpyoff, src,
1025 src->cpyoff_blkoff = stream->dec_cpyoff % src->blksize; 1025 &src->cpyoff_blocks,
1026 &src->cpyoff_blkoff);
1026 } 1027 }
1027 1028
1028 /* xd3_decode_emit returns XD3_OUTPUT on every success. */ 1029 /* xd3_decode_emit returns XD3_OUTPUT on every success. */
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c
index 58fb8b5..88de13a 100644
--- a/xdelta3/xdelta3.c
+++ b/xdelta3/xdelta3.c
@@ -2629,15 +2629,14 @@ xd3_set_source (xd3_stream *stream,
2629 xd3_source *src) 2629 xd3_source *src)
2630{ 2630{
2631 xoff_t blk_num; 2631 xoff_t blk_num;
2632 xoff_t tail_size; 2632 usize_t tail_size;
2633 2633
2634 IF_DEBUG1 (DP(RINT "[set source] size %"Q"u\n", src->size)); 2634 IF_DEBUG1 (DP(RINT "[set source] size %"Q"u\n", src->size));
2635 2635
2636 if (src == NULL || src->size < stream->smatcher.large_look) { return 0; } 2636 if (src == NULL || src->size < stream->smatcher.large_look) { return 0; }
2637 2637
2638 stream->src = src; 2638 stream->src = src;
2639 blk_num = src->size / src->blksize; 2639 xd3_blksize_div (src->size, src, &blk_num, &tail_size);
2640 tail_size = src->size - (blk_num * src->blksize);
2641 src->blocks = blk_num + (tail_size > 0); 2640 src->blocks = blk_num + (tail_size > 0);
2642 src->onlastblk = xd3_bytes_on_srcblk (src, src->blocks - 1); 2641 src->onlastblk = xd3_bytes_on_srcblk (src, src->blocks - 1);
2643 src->srclen = 0; 2642 src->srclen = 0;
@@ -4416,8 +4415,7 @@ xd3_source_extend_match (xd3_stream *stream)
4416 * match_fwd/match_back and direction. Consolidate? */ 4415 * match_fwd/match_back and direction. Consolidate? */
4417 matchoff = stream->match_srcpos - stream->match_back; 4416 matchoff = stream->match_srcpos - stream->match_back;
4418 streamoff = stream->input_position - stream->match_back; 4417 streamoff = stream->input_position - stream->match_back;
4419 tryblk = matchoff / src->blksize; 4418 xd3_blksize_div (matchoff, src, &tryblk, &tryoff);
4420 tryoff = matchoff - (tryblk * src->blksize);
4421 4419
4422 /* this loops backward over source blocks */ 4420 /* this loops backward over source blocks */
4423 while (stream->match_back < stream->match_maxback) 4421 while (stream->match_back < stream->match_maxback)
@@ -4465,8 +4463,7 @@ xd3_source_extend_match (xd3_stream *stream)
4465 4463
4466 matchoff = stream->match_srcpos + stream->match_fwd; 4464 matchoff = stream->match_srcpos + stream->match_fwd;
4467 streamoff = stream->input_position + stream->match_fwd; 4465 streamoff = stream->input_position + stream->match_fwd;
4468 tryblk = matchoff / src->blksize; 4466 xd3_blksize_div (matchoff, src, & tryblk, & tryoff);
4469 tryoff = matchoff - (tryblk * src->blksize);
4470 4467
4471 /* Note: practically the same code as backwards case above: same comments */ 4468 /* Note: practically the same code as backwards case above: same comments */
4472 while (stream->match_fwd < stream->match_maxfwd) 4469 while (stream->match_fwd < stream->match_maxfwd)
@@ -4839,11 +4836,16 @@ xd3_srcwin_move_point (xd3_stream *stream, usize_t *next_move_point)
4839 while (stream->srcwin_cksum_pos < logical_input_cksum_pos && 4836 while (stream->srcwin_cksum_pos < logical_input_cksum_pos &&
4840 stream->srcwin_cksum_pos < stream->src->size) 4837 stream->srcwin_cksum_pos < stream->src->size)
4841 { 4838 {
4842 xoff_t blkno = stream->srcwin_cksum_pos / stream->src->blksize; 4839 xoff_t blkno;
4843 xoff_t blkbaseoffset = blkno * stream->src->blksize; 4840 xoff_t blkbaseoffset;
4844 ssize_t oldpos = stream->srcwin_cksum_pos - blkbaseoffset; 4841 usize_t blkrem;
4845 ssize_t blkpos = xd3_bytes_on_srcblk_fast (stream->src, blkno); 4842 ssize_t oldpos;
4843 ssize_t blkpos;
4846 int ret; 4844 int ret;
4845 xd3_blksize_div (stream->srcwin_cksum_pos,
4846 stream->src, &blkno, &blkrem);
4847 oldpos = blkrem;
4848 blkpos = xd3_bytes_on_srcblk_fast (stream->src, blkno);
4847 4849
4848 if (oldpos + stream->smatcher.large_look > blkpos) 4850 if (oldpos + stream->smatcher.large_look > blkpos)
4849 { 4851 {
diff --git a/xdelta3/xdelta3.h b/xdelta3/xdelta3.h
index af79839..9abddbf 100644
--- a/xdelta3/xdelta3.h
+++ b/xdelta3/xdelta3.h
@@ -677,8 +677,7 @@ struct _xd3_source
677 xoff_t blocks; /* the total number of blocks in 677 xoff_t blocks; /* the total number of blocks in
678 this source */ 678 this source */
679 usize_t onlastblk; /* cached size info, avoid __udivdi3 */ 679 usize_t onlastblk; /* cached size info, avoid __udivdi3 */
680 usize_t cpyoff_blocks; /* offset of copy window in 680 xoff_t cpyoff_blocks; /* offset of dec_cpyoff in blocks */
681 blocks */
682 usize_t cpyoff_blkoff; /* offset of copy window in 681 usize_t cpyoff_blkoff; /* offset of copy window in
683 blocks, remainder */ 682 blocks, remainder */
684 xoff_t getblkno; /* request block number: xd3 sets 683 xoff_t getblkno; /* request block number: xd3 sets
@@ -1164,6 +1163,18 @@ const char* xd3_errstring (xd3_stream *stream)
1164 return stream->msg ? stream->msg : ""; 1163 return stream->msg ? stream->msg : "";
1165} 1164}
1166 1165
1166
1167/* 64-bit divisions are expensive. on a 32bit platform, these show in
1168 * a profile as __udivdi3(). these are all the xoff_t divisions: */
1169static inline
1170void xd3_blksize_div (const xoff_t offset,
1171 const xd3_source *source,
1172 xoff_t *blkno,
1173 usize_t *blkoff) {
1174 *blkno = offset / source->blksize;
1175 *blkoff = offset - (*blkno * source->blksize);
1176}
1177
1167/* This function tells the number of bytes expected to be set in 1178/* This function tells the number of bytes expected to be set in
1168 * source->onblk after a getblk request. This is for convenience of 1179 * source->onblk after a getblk request. This is for convenience of
1169 * handling a partial last block. Note that this is a relatively 1180 * handling a partial last block. Note that this is a relatively
@@ -1173,14 +1184,16 @@ const char* xd3_errstring (xd3_stream *stream)
1173static inline 1184static inline
1174usize_t xd3_bytes_on_srcblk (xd3_source *source, xoff_t blkno) 1185usize_t xd3_bytes_on_srcblk (xd3_source *source, xoff_t blkno)
1175{ 1186{
1187 xoff_t s_1_div;
1188 usize_t s_1_rem;
1176 XD3_ASSERT (blkno < source->blocks); 1189 XD3_ASSERT (blkno < source->blocks);
1177 1190
1178 if (blkno != source->blocks - 1) 1191 if (blkno != source->blocks - 1)
1179 { 1192 {
1180 return source->blksize; 1193 return source->blksize;
1181 } 1194 }
1182 1195 xd3_blksize_div(source->size - 1, source, &s_1_div, &s_1_rem);
1183 return (usize_t)((source->size - 1) % source->blksize) + 1; 1196 return s_1_rem + 1;
1184} 1197}
1185 1198
1186static inline 1199static inline