Skip to content

Commit

Permalink
Merge pull request #4054 from Feoramund/zlib-reverse-bits
Browse files Browse the repository at this point in the history
Use `intrinsics.reverse_bits` in `core:compress/zlib`
  • Loading branch information
laytan authored Aug 11, 2024
2 parents 26fa3ac + cf8f6af commit b9e68ee
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions core/compress/zlib/zlib.odin
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package compress_zlib

import "core:compress"

import "base:intrinsics"
import "core:mem"
import "core:io"
import "core:hash"
Expand Down Expand Up @@ -123,13 +124,7 @@ Huffman_Table :: struct {
@(optimization_mode="favor_size")
z_bit_reverse :: #force_inline proc(n: u16, bits: u8) -> (r: u16) {
assert(bits <= 16)
// NOTE: Can optimize with llvm.bitreverse.i64 or some bit twiddling
// by reversing all of the bits and masking out the unneeded ones.
r = n
r = ((r & 0xAAAA) >> 1) | ((r & 0x5555) << 1)
r = ((r & 0xCCCC) >> 2) | ((r & 0x3333) << 2)
r = ((r & 0xF0F0) >> 4) | ((r & 0x0F0F) << 4)
r = ((r & 0xFF00) >> 8) | ((r & 0x00FF) << 8)
r = intrinsics.reverse_bits(n)

r >>= (16 - bits)
return
Expand Down

0 comments on commit b9e68ee

Please sign in to comment.