owengage / fastnbt

Fast serde serializer and deserializer for Minecraft's NBT and Anvil formats
MIT License
186 stars 34 forks source link

y_to_index_map math #34

Closed lizelive closed 3 years ago

lizelive commented 3 years ago

(y - MIN_Y) >> 4 as u8

does the same thing as

https://github.com/owengage/fastnbt/blob/10e0edf0758916395e1a0de5e62b7c7a42d8465e/fastanvil/src/java/section_tower.rs#L60

i think this is prob fast enough to not use a lookup table.

const fn y_to_index(y: isize) -> u8 {
    ((y - MIN_Y)>> 4) as u8
}

compiles to

example::y_to_index:
        lea     eax, [rdi + 64]
        shr     eax, 4
        ret
owengage commented 3 years ago

Looks right to me. Way simpler. I'll give this a try soon with my benchmark world render. I suspect you're right about performance.

Thanks for the report. :)

owengage commented 3 years ago

Done on master. It's a little bit faster :)