Skip to content

Commit 0504761

Browse files
FreezyLemonshssoichiro
authored andcommitted
Make apply_ssim_boost a const fn
1 parent 1412bed commit 0504761

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/activity.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ struct RsqrtOutput {
106106
}
107107

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

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

143-
debug_assert!((16384..32768).contains(&rsqrt));
143+
debug_assert!(16384 <= rsqrt && rsqrt < 32768);
144144
RsqrtOutput { norm: rsqrt as u16, shift: rsqrt_shift }
145145
}
146146

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

157157
/// Apply ssim boost to a given input
158158
#[inline(always)]
159-
pub fn apply_ssim_boost(
159+
pub const fn apply_ssim_boost(
160160
input: u32, svar: u32, dvar: u32, bit_depth: usize,
161161
) -> u32 {
162162
let coeff_shift = bit_depth - 8;

0 commit comments

Comments
 (0)