Hacker News new | past | comments | ask | show | jobs | submit login

Using 64bit value for the shift solution would allow still more tight scalar code, dunno for vectorization.

    pub fn phf_shift64(x: u32) {
        ((0x714258693u64 >> (x*4)) & 0b1111) as u8
    }



This particular code will have a bounds check for x * 4 and panic if it's too large, thus inhibiting vectorization in most cases.

Just as a tidbit, to dig deeper into Rust.

How can I provide some quick evidence for this? Well there's a method called u64::unchecked_shr that acts as contrasting evidence.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: