> I wonder if using *shift_table.unsafe_ref(i) here will be faster. (This will always be safe, since val is 32 bits and rightshifting by 28 leaves 4 non-zero.)

LLVM manages to find out this itself and optimizes away the bounds check. Should I use unsafe_ref() anyway?

> static SHIFT_TABLE_PTR: *uint = &SHIFT_TABLE[0] as *uint;
> static MASK_TABLE_PTR: *uint = &MASK_TABLE[0] as *uint;
> 
> // ...
> 
> let shift = *SHIFT_TABLE_PTR.offset(i);
> let mask = *MASK_TABLE_PTR.offset(i);

This caused the test cases to fail, I don't really know why but it didn't give any performance benefit anyway.

> static SHIFT_MASK_TABLE: [(uint, uint), .. 16] = [
>     (0, 0x0), (0, 0x0fff_ffff),
>     (8, 0x1f_fff), (8, 0x1f_ffff),
>     // ... 
> ];
> 
> // ...
> let (shift, mask) = SHIFT_MASK_TABLE[i];

Right, this is better. I've changed it to use a tuple of (u32, u32) which on x68_64 occupies a single cache line which is really good. This gave a speedup of approx 15ns.

> Lastly, maybe using a smaller type than uint for the tables might be better? shift_table could be u8, and mask_table could be u32.

Using u8 in shift_table worsened the performance. Also using a tuple (u8, u32) worsened the performance. (Does rust pad structures to the alignment of the biggest member like C?)