*/
/*
- * Copyright (C) 2012, 2013, 2014, 2015 Eric Biggers
+ * Copyright (C) 2012-2016 Eric Biggers
*
* This file is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
unsigned
lzx_get_window_order(size_t max_bufsize)
{
- unsigned order;
-
if (max_bufsize == 0 || max_bufsize > LZX_MAX_WINDOW_SIZE)
return 0;
- order = fls32(max_bufsize);
-
- if (((u32)1 << order) != max_bufsize)
- order++;
-
- return max(order, LZX_MIN_WINDOW_ORDER);
+ return max(ilog2_ceil(max_bufsize), LZX_MIN_WINDOW_ORDER);
}
/* Given a valid LZX window order, return the number of symbols that will exist
{
s32 abs_offset, rel_offset;
- rel_offset = get_unaligned_u32_le(target);
+ rel_offset = get_unaligned_le32(target);
if (rel_offset >= -input_pos && rel_offset < LZX_WIM_MAGIC_FILESIZE) {
if (rel_offset < LZX_WIM_MAGIC_FILESIZE - input_pos) {
/* "good translation" */
/* "compensating translation" */
abs_offset = rel_offset - LZX_WIM_MAGIC_FILESIZE;
}
- put_unaligned_u32_le(abs_offset, target);
+ put_unaligned_le32(abs_offset, target);
}
}
{
s32 abs_offset, rel_offset;
- abs_offset = get_unaligned_u32_le(target);
+ abs_offset = get_unaligned_le32(target);
if (abs_offset >= 0) {
if (abs_offset < LZX_WIM_MAGIC_FILESIZE) {
/* "good translation" */
rel_offset = abs_offset - input_pos;
- put_unaligned_u32_le(rel_offset, target);
+ put_unaligned_le32(rel_offset, target);
}
} else {
if (abs_offset >= -input_pos) {
/* "compensating translation" */
rel_offset = abs_offset + LZX_WIM_MAGIC_FILESIZE;
- put_unaligned_u32_le(rel_offset, target);
+ put_unaligned_le32(rel_offset, target);
}
}
}