From 3ffbf0cf6fc66bd134043736de61f677f5bb2030 Mon Sep 17 00:00:00 2001 From: David Michael Barr Date: Wed, 10 Feb 2021 15:08:58 +0900 Subject: [PATCH] Use explicit table lookup for ac_q and dc_q Resolves an unusual compiler decision to invoke memmove. --- src/quantize.rs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/quantize.rs b/src/quantize.rs index f02d96eeab..dcea1fab74 100644 --- a/src/quantize.rs +++ b/src/quantize.rs @@ -32,25 +32,17 @@ pub fn get_log_tx_scale(tx_size: TxSize) -> usize { } pub fn dc_q(qindex: u8, delta_q: i8, bit_depth: usize) -> i16 { - let &table = match bit_depth { - 8 => &dc_qlookup_Q3, - 10 => &dc_qlookup_10_Q3, - 12 => &dc_qlookup_12_Q3, - _ => unimplemented!(), - }; - - table[(qindex as isize + delta_q as isize).max(0).min(255) as usize] + static DC_Q: [&[i16; 256]; 3] = + [&dc_qlookup_Q3, &dc_qlookup_10_Q3, &dc_qlookup_12_Q3]; + let bd = ((bit_depth ^ 8) >> 1).min(2); + DC_Q[bd][((qindex as isize + delta_q as isize).max(0) as usize).min(255)] } pub fn ac_q(qindex: u8, delta_q: i8, bit_depth: usize) -> i16 { - let &table = match bit_depth { - 8 => &ac_qlookup_Q3, - 10 => &ac_qlookup_10_Q3, - 12 => &ac_qlookup_12_Q3, - _ => unimplemented!(), - }; - - table[(qindex as isize + delta_q as isize).max(0).min(255) as usize] + static AC_Q: [&[i16; 256]; 3] = + [&ac_qlookup_Q3, &ac_qlookup_10_Q3, &ac_qlookup_12_Q3]; + let bd = ((bit_depth ^ 8) >> 1).min(2); + AC_Q[bd][((qindex as isize + delta_q as isize).max(0) as usize).min(255)] } // TODO: Handle lossless properly.