Skip to content

Commit ea1b709

Browse files
committed
IMPORT: slz: avoid multiple shifts on 64-bits
On 64-bit platforms, disassembling the code shows that send_huff() performs a left shift followed by a right one, which are the result of integer truncation and zero-extension caused solely by using different types at different levels in the call chain. By making encode24() take a 64-bit int on input and send_huff() take one optionally, we can remove one shift in the hot path and gain 1% performance without affecting other platforms. This is slz upstream commit fd165b36c4621579c5305cf3bb3a7f5410d3720b.
1 parent 0a91c6d commit ea1b709

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/slz.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ union ref {
166166
* 32-bit words into output buffer. X must not contain non-zero bits above
167167
* xbits.
168168
*/
169-
static inline void enqueue24(struct slz_stream *strm, uint32_t x, uint32_t xbits)
169+
static inline void enqueue24(struct slz_stream *strm, uint64_t x, uint32_t xbits)
170170
{
171-
uint64_t queue = strm->queue + ((uint64_t)x << strm->qbits);
171+
uint64_t queue = strm->queue + (x << strm->qbits);
172172
uint32_t qbits = strm->qbits + xbits;
173173

174174
if (__builtin_expect(qbits >= 32, 1)) {
@@ -293,7 +293,8 @@ static inline void copy_32b(struct slz_stream *strm, uint32_t x)
293293
strm->outbuf += 4;
294294
}
295295

296-
static inline void send_huff(struct slz_stream *strm, uint32_t code)
296+
/* Using long because faster on 64-bit (can save one shift) */
297+
static inline void send_huff(struct slz_stream *strm, unsigned long code)
297298
{
298299
uint32_t bits;
299300

0 commit comments

Comments
 (0)