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

Avoid bounds checks in IDCD and IWHT #9

Merged
merged 2 commits into from
Oct 22, 2023
Merged
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: 6 additions & 0 deletions src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ pub(crate) fn idct4x4(block: &mut [i32]) {
i64::from(block[idx])
}

// Perform one lenght check up front to avoid subsequent bounds checks in this function
assert!(block.len() >= 16);

for i in 0usize..4 {
let a1 = fetch(block, i) + fetch(block, 8 + i);
let b1 = fetch(block, i) - fetch(block, 8 + i);
Expand Down Expand Up @@ -46,6 +49,9 @@ pub(crate) fn idct4x4(block: &mut [i32]) {

// 14.3
pub(crate) fn iwht4x4(block: &mut [i32]) {
// Perform one length check up front to avoid subsequent bounds checks in this function
assert!(block.len() >= 16);

for i in 0usize..4 {
let a1 = block[i] + block[12 + i];
let b1 = block[4 + i] + block[8 + i];
Expand Down