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

Make apply_ssim_boost a const fn #3352

Merged
merged 1 commit into from
Feb 20, 2024
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
8 changes: 4 additions & 4 deletions src/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ struct RsqrtOutput {
}

/// Fixed point `rsqrt` for `ssim_boost`
fn ssim_boost_rsqrt(x: u64) -> RsqrtOutput {
const fn ssim_boost_rsqrt(x: u64) -> RsqrtOutput {
const INSHIFT: u8 = 16;
const OUTSHIFT: u8 = 14;

let k = ((ILog::ilog(x) - 1) >> 1) as i16;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just making sure, is the removal of the - 1 intentional here? My guess is yes given the docs in v_frame: floor(log2(self)) + 1, or 0 if self == 0, but want to be certain this is bit-identical to the prior output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's intentional and I did make sure they're equivalent for x != 0: https://rust.godbolt.org/z/Gh5TxbEYK

let k = (x.ilog2() >> 1) as i16;
/*t is x in the range [0.25, 1) in QINSHIFT, or x*2^(-s).
Shift by log2(x) - log2(0.25*(1 << INSHIFT)) to ensure 0.25 lower bound.*/
let s: i16 = 2 * k - (INSHIFT as i16 - 2);
Expand Down Expand Up @@ -140,7 +140,7 @@ fn ssim_boost_rsqrt(x: u64) -> RsqrtOutput {
Coefficients here, and the final result r, are Q14. */
let rsqrt: i32 = 23557 + mult16_16_q15(n, -13490 + mult16_16_q15(n, 6711));

debug_assert!((16384..32768).contains(&rsqrt));
debug_assert!(16384 <= rsqrt && rsqrt < 32768);
RsqrtOutput { norm: rsqrt as u16, shift: rsqrt_shift }
}

Expand All @@ -156,7 +156,7 @@ pub fn ssim_boost(svar: u32, dvar: u32, bit_depth: usize) -> DistortionScale {

/// Apply ssim boost to a given input
#[inline(always)]
pub fn apply_ssim_boost(
pub const fn apply_ssim_boost(
input: u32, svar: u32, dvar: u32, bit_depth: usize,
) -> u32 {
let coeff_shift = bit_depth - 8;
Expand Down
Loading