Skip to content

Commit

Permalink
Eliminate some bounds checks in IDCT (#167)
Browse files Browse the repository at this point in the history
Convert a debug assert into an actual bounds check to use as an optimizer hint.

Eliminates a bunch of bounds checks and should speed things up.
Support older rustc, hence no try_from or type changes.
  • Loading branch information
Shnatsel authored Oct 17, 2020
1 parent ea51ee2 commit 97742b3
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/idct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
// One example is tests/crashtest/images/imagetestsuite/b0b8914cc5f7a6eff409f16d8cc236c5.jpg
// That's why wrapping operators are needed.
use crate::parser::Dimensions;
use std::{
convert::TryFrom,
num::Wrapping,
};
use std::{convert::TryFrom, num::Wrapping};

pub(crate) fn choose_idct_size(full_size: Dimensions, requested_size: Dimensions) -> usize {
fn scaled(len: u16, scale: usize) -> u16 { ((len as u32 * scale as u32 - 1) / 8 + 1) as u16 }
Expand Down Expand Up @@ -54,7 +51,6 @@ pub fn dequantize_and_idct_block_8x8(
output_linestride: usize,
output: &mut [u8]
) {
debug_assert_eq!(coefficients.len(), 64);
let output = output
.chunks_mut(output_linestride);
dequantize_and_idct_block_8x8_inner(coefficients, quantization_table, output)
Expand All @@ -76,6 +72,9 @@ fn dequantize_and_idct_block_8x8_inner<'a, I>(
output.len()
);

// optimizer hint to eliminate bounds checks within loops
assert!(coefficients.len() == 64);

let mut temp = [Wrapping(0); 64];

// columns
Expand Down

0 comments on commit 97742b3

Please sign in to comment.