From a1bd1f7f1f08edfba0207a0e51ab8e45b15969eb Mon Sep 17 00:00:00 2001 From: Fabian Giesen Date: Sun, 14 Dec 2014 00:38:17 -0800 Subject: [PATCH] stb_image: Faster stbi__extend_receive. --- stb_image.h | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/stb_image.h b/stb_image.h index a930bea..db17605 100644 --- a/stb_image.h +++ b/stb_image.h @@ -1155,31 +1155,23 @@ stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg *j, stbi__huffman *h) return h->values[c]; } +// bias[n] = (-1<code_bits < n) stbi__grow_buffer_unsafe(j); - #if 1 + sgn = (stbi__int32)j->code_buffer >> 31; // sign bit is always in MSB k = stbi_lrot(j->code_buffer, n); j->code_buffer = k & ~stbi__bmask[n]; k &= stbi__bmask[n]; j->code_bits -= n; - #else - k = (j->code_buffer >> (32 - n)) & stbi__bmask[n]; - j->code_bits -= n; - j->code_buffer <<= n; - #endif - // the following test is probably a random branch that won't - // predict well. I tried to table accelerate it but failed. - // maybe it's compiling as a conditional move? - if (k < m) - return (-1 << n) + k + 1; - else - return k; + return k + (stbi__jbias[n] & ~sgn); } // given a value that's at position X in the zigzag stream,