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

Conversation

Shnatsel
Copy link
Contributor

@Shnatsel Shnatsel commented Oct 3, 2023

Before: https://godbolt.org/z/PTo583Y7o

After: https://godbolt.org/z/qdda8sxsr

No autovectorization, but at least the bounds checks are gone.

@Shnatsel
Copy link
Contributor Author

Shnatsel commented Oct 3, 2023

I don't know how to benchmark this change because the crate is not wired up to image (I think?) so my usual benchmarking harness doesn't work, and the crate doesn't contain any examples (understandably, for such an early stage).

Copy link
Contributor

@fintelia fintelia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know whether the argument is always exactly 16 entries? If so, we should assert the exact length rather than >= 16

src/transform.rs Outdated
@@ -46,6 +49,9 @@ pub(crate) fn idct4x4(block: &mut [i32]) {

// 14.3
pub(crate) fn iwht4x4(block: &mut [i32]) {
// Perform one lenght check up front to avoid subsequent bounds checks in this function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: lenght -> length

@Shnatsel
Copy link
Contributor Author

When I made this function accept [i32; 16] tests broke, and I did not know enough about the format to understand why. So I just put the most lenient assert in place that would get rid of the bounds checks.

@fintelia fintelia merged commit a4d00d0 into image-rs:main Oct 22, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants