From d70ff73fc5507168d5103d660034d5bde1f1d2a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Zumer?= Date: Sat, 20 Jul 2019 14:56:10 -0400 Subject: [PATCH] Remove rate::ilog64() --- src/rate.rs | 15 ++------------- src/util.rs | 5 +++++ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/rate.rs b/src/rate.rs index a7fce0f4f5..44f364b952 100644 --- a/src/rate.rs +++ b/src/rate.rs @@ -13,8 +13,7 @@ use crate::quantize::ac_q; use crate::quantize::dc_q; use crate::quantize::select_ac_qi; use crate::quantize::select_dc_qi; -use crate::util::clamp; -use crate::util::Pixel; +use crate::util::{clamp, ILog, Pixel}; // The number of frame sub-types for which we track distinct parameters. // This does not include FRAME_SUBTYPE_SEF, because we don't need to do any @@ -80,16 +79,6 @@ const DQP_Q57: &[i64; FRAME_NSUBTYPES] = &[ (2.0 * (33_810_170.0 / 86_043_287.0) * (1i64 << 57) as f64) as i64 ]; -// Integer binary logarithm of a 64-bit value. -// v: A 64-bit value. -// Returns floor(log2(v)) + 1, or 0 if v == 0. -// This is the number of bits that would be required to represent v in two's -// complement notation with all of the leading zeros stripped. -// TODO: Mark const once leading_zeros() as a constant function stabilizes. -fn ilog64(v: i64) -> i32 { - 64 - (v.leading_zeros() as i32) -} - // Convert an integer into a Q57 fixed-point fraction. // The integer must be in the range -64 to 63, inclusive. pub(crate) const fn q57(v: i32) -> i64 { @@ -218,7 +207,7 @@ fn blog64(w: i64) -> i64 { if w <= 0 { return -1; } - let ipart = ilog64(w) - 1; + let ipart = w.ilog() as i32 - 1; if ipart > 61 { w >>= ipart - 61; } else { diff --git a/src/util.rs b/src/util.rs index 8330fc4af9..0c949ae564 100644 --- a/src/util.rs +++ b/src/util.rs @@ -165,6 +165,11 @@ impl_cast_from_pixel_to_primitive!(i32); impl_cast_from_pixel_to_primitive!(u32); pub trait ILog: PrimInt { + // Integer binary logarithm of an integer value. + // Returns floor(log2(self)) + 1, or 0 if self == 0. + // This is the number of bits that would be required to represent self in two's + // complement notation with all of the leading zeros stripped. + // TODO: Mark const once leading_zeros() as a constant function stabilizes. fn ilog(self) -> Self { Self::from(size_of::() * 8 - self.leading_zeros() as usize).unwrap() }