Skip to content

Commit

Permalink
Force inline of huffman decoding functions
Browse files Browse the repository at this point in the history
It seems the inlining heuristics were tripping up in some places. Force
inlining of all the decode/len/diff functions for nice speedups. In
extremely relevant formats like DNG/NEF/CR2 this is a 30-40% improvement
in decode speed.
  • Loading branch information
pedrocr committed Nov 11, 2020
1 parent 8c4837b commit 6b53bd8
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/decoders/ljpeg/huffman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ impl HuffTable {
Ok(())
}

#[inline(always)]
pub fn huff_decode(&self, pump: &mut dyn BitPump) -> Result<i32,String> {
let code = pump.peek_bits(DECODE_CACHE_BITS) as usize;
if let Some((bits,decode)) = self.decodecache[code] {
Expand All @@ -158,25 +159,29 @@ impl HuffTable {
}
}

#[inline(always)]
pub fn huff_decode_slow(&self, pump: &mut dyn BitPump) -> (u8,i32) {
let len = self.huff_len(pump);
(len.0+len.1, self.huff_diff(pump, len))
}

#[inline(always)]
pub fn huff_len(&self, pump: &mut dyn BitPump) -> (u8,u8,u8) {
let code = pump.peek_bits(self.nbits) as usize;
let (bits, len, shift) = self.hufftable[code];
pump.consume_bits(bits as u32);
(bits, len, shift)
}

#[inline(always)]
pub fn huff_get_bits(&self, pump: &mut dyn BitPump) -> u32 {
let code = pump.peek_bits(self.nbits) as usize;
let (bits, len, _) = self.hufftable[code];
pump.consume_bits(bits as u32);
len as u32
}

#[inline(always)]
pub fn huff_diff(&self, pump: &mut dyn BitPump, input: (u8,u8,u8)) -> i32 {
let (_, len, shift) = input;

Expand Down

0 comments on commit 6b53bd8

Please sign in to comment.