aboutsummaryrefslogtreecommitdiff
path: root/linux/lib/xz
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2009-05-26 17:42:16 +0300
committerLasse Collin <lasse.collin@tukaani.org>2009-05-26 17:42:16 +0300
commit2da995969e5385db150bd51ac8ba03a463e7186d (patch)
tree7e6140f08ff963c09008700e60c55d5dbafc835f /linux/lib/xz
parent28892358dcf724b13bf0c49b1e3fa5b29e2d4f09 (diff)
downloadxz-embedded-2da995969e5385db150bd51ac8ba03a463e7186d.tar.gz
Avoid integer division, since it's not necessarily available
in early boot code in the Linux kernel. Thanks to Alain Knaff for pointing this out. It's possible that the compiler already avoided divide instructions, but since there wasn't much to change, it was simplest to change the code to be sure.
Diffstat (limited to 'linux/lib/xz')
-rw-r--r--linux/lib/xz/xz_dec_lzma2.c19
-rw-r--r--linux/lib/xz/xz_dec_stream.c2
2 files changed, 15 insertions, 6 deletions
diff --git a/linux/lib/xz/xz_dec_lzma2.c b/linux/lib/xz/xz_dec_lzma2.c
index d0d5d0c..3710390 100644
--- a/linux/lib/xz/xz_dec_lzma2.c
+++ b/linux/lib/xz/xz_dec_lzma2.c
@@ -788,12 +788,21 @@ static bool XZ_FUNC lzma_props(struct xz_dec_lzma2 *s, uint8_t props)
if (props > (4 * 5 + 4) * 9 + 8)
return false;
- s->lzma.pos_mask = props / (9 * 5);
- props -= s->lzma.pos_mask * 9 * 5;
+ s->lzma.pos_mask = 0;
+ while (props >= 9 * 5) {
+ props -= 9 * 5;
+ ++s->lzma.pos_mask;
+ }
+
s->lzma.pos_mask = (1 << s->lzma.pos_mask) - 1;
- s->lzma.literal_pos_mask = props / 9;
- s->lzma.lc = props - s->lzma.literal_pos_mask * 9;
+ s->lzma.literal_pos_mask = 0;
+ while (props >= 9) {
+ props -= 9;
+ ++s->lzma.literal_pos_mask;
+ }
+
+ s->lzma.lc = props;
if (s->lzma.lc + s->lzma.literal_pos_mask > 4)
return false;
@@ -1112,7 +1121,7 @@ XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_lzma2_reset(
return XZ_OPTIONS_ERROR;
s->dict.size = 2 + (props & 1);
- s->dict.size <<= props / 2 + 11;
+ s->dict.size <<= (props >> 1) + 11;
if (s->dict.allocated > 0 && s->dict.allocated < s->dict.size)
return XZ_MEMLIMIT_ERROR;
diff --git a/linux/lib/xz/xz_dec_stream.c b/linux/lib/xz/xz_dec_stream.c
index c8387b4..9b9dfc0 100644
--- a/linux/lib/xz/xz_dec_stream.c
+++ b/linux/lib/xz/xz_dec_stream.c
@@ -382,7 +382,7 @@ static enum xz_ret XZ_FUNC dec_stream_footer(struct xz_dec *s)
* Index CRC32 field to s->index.size, thus we use s->index.size / 4
* instead of s->index.size / 4 - 1.
*/
- if (s->index.size / 4 != get_le32(s->temp.buf + 4))
+ if ((s->index.size >> 2) != get_le32(s->temp.buf + 4))
return XZ_DATA_ERROR;
if (s->temp.buf[8] != 0 || s->temp.buf[9] != s->has_crc32)