Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use macro for wrapping += and -= #158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/enc/block_splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,7 @@ fn ClusterBlocks<
i = 0usize;
while i < length {
{
{
let _rhs = 1;
let _lhs = &mut block_lengths.slice_mut()[block_idx];
*_lhs = (*_lhs).wrapping_add(_rhs as u32);
}
::wrapping_add!(block_lengths.slice_mut()[block_idx], 1);
if i.wrapping_add(1) == length
|| block_ids[i] as i32 != block_ids[i.wrapping_add(1)] as i32
{
Expand Down
9 changes: 4 additions & 5 deletions src/enc/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,10 @@ pub fn BrotliHistogramCombine<
let best_idx2: u32 = (pairs[0]).idx2;
HistogramSelfAddHistogram(out, (best_idx1 as usize), (best_idx2 as usize));
(out[(best_idx1 as usize)]).set_bit_cost((pairs[0]).cost_combo);
{
let _rhs = cluster_size[(best_idx2 as usize)];
let _lhs = &mut cluster_size[(best_idx1 as usize)];
*_lhs = (*_lhs).wrapping_add(_rhs);
}
::wrapping_add!(
cluster_size[(best_idx1 as usize)],
cluster_size[(best_idx2 as usize)]
);
for i in 0usize..symbols_size {
if symbols[i] == best_idx2 {
symbols[i] = best_idx1;
Expand Down
12 changes: 2 additions & 10 deletions src/enc/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1728,16 +1728,8 @@ fn ChooseContextMap(
i = 0usize;
while i < 9usize {
{
{
let _rhs = bigram_histo[i];
let _lhs = &mut monogram_histo[i.wrapping_rem(3)];
*_lhs = (*_lhs).wrapping_add(_rhs);
}
{
let _rhs = bigram_histo[i];
let _lhs = &mut two_prefix_histo[i.wrapping_rem(6)];
*_lhs = (*_lhs).wrapping_add(_rhs);
}
::wrapping_add!(monogram_histo[i.wrapping_rem(3)], bigram_histo[i]);
::wrapping_add!(two_prefix_histo[i.wrapping_rem(6)], bigram_histo[i]);
}
i = i.wrapping_add(1);
}
Expand Down
9 changes: 4 additions & 5 deletions src/enc/metablock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,11 +627,10 @@ fn BlockSplitterFinishBlock<
xself.merge_last_count_ = 0usize;
xself.target_block_size_ = xself.min_block_size_;
} else {
{
let _rhs = xself.block_size_ as u32;
let _lhs = &mut split.lengths.slice_mut()[xself.num_blocks_.wrapping_sub(1)];
*_lhs = (*_lhs).wrapping_add(_rhs);
}
::wrapping_add!(
split.lengths.slice_mut()[xself.num_blocks_.wrapping_sub(1)],
xself.block_size_ as u32
);
histograms[xself.last_histogram_ix_[0]] = combined_histo[0].clone();
xself.last_entropy_[0] = combined_entropy[0];
if split.num_types == 1 {
Expand Down
18 changes: 18 additions & 0 deletions src/enc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,21 @@ where
read_err?;
Ok(total_out.unwrap())
}

#[macro_export]
macro_rules! wrapping_add {
($expr:expr, $increment:expr) => {{
let _rhs = $increment;
let _lhs = &mut $expr;
*_lhs = (*_lhs).wrapping_add(_rhs);
}};
}

#[macro_export]
macro_rules! wrapping_sub {
($expr:expr, $increment:expr) => {{
let _rhs = $increment;
let _lhs = &mut $expr;
*_lhs = (*_lhs).wrapping_sub(_rhs);
}};
}