Skip to content

Commit 97742b3

Browse files
authored
Eliminate some bounds checks in IDCT (#167)
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.
1 parent ea51ee2 commit 97742b3

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/idct.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
// One example is tests/crashtest/images/imagetestsuite/b0b8914cc5f7a6eff409f16d8cc236c5.jpg
33
// That's why wrapping operators are needed.
44
use crate::parser::Dimensions;
5-
use std::{
6-
convert::TryFrom,
7-
num::Wrapping,
8-
};
5+
use std::{convert::TryFrom, num::Wrapping};
96

107
pub(crate) fn choose_idct_size(full_size: Dimensions, requested_size: Dimensions) -> usize {
118
fn scaled(len: u16, scale: usize) -> u16 { ((len as u32 * scale as u32 - 1) / 8 + 1) as u16 }
@@ -54,7 +51,6 @@ pub fn dequantize_and_idct_block_8x8(
5451
output_linestride: usize,
5552
output: &mut [u8]
5653
) {
57-
debug_assert_eq!(coefficients.len(), 64);
5854
let output = output
5955
.chunks_mut(output_linestride);
6056
dequantize_and_idct_block_8x8_inner(coefficients, quantization_table, output)
@@ -76,6 +72,9 @@ fn dequantize_and_idct_block_8x8_inner<'a, I>(
7672
output.len()
7773
);
7874

75+
// optimizer hint to eliminate bounds checks within loops
76+
assert!(coefficients.len() == 64);
77+
7978
let mut temp = [Wrapping(0); 64];
8079

8180
// columns

0 commit comments

Comments
 (0)