For some reason this couldn’t actually go in Brainstorming, cause it’s read-only.
Anyways I have a working chess engine in C++, I wanted to see how Zig was, I was hearing some really nice things. Everything worked nicely until a certain point, I noticed that the shifting operators on 64-bit unsigned integers require a 6-bit unsigned integer as the shift amount. I thought this was fine, I would just change my square indices all to u6… Little did I know there is a small issue. I disassembled the final binary, on ReleaseFast mind you. I noticed that the function had an and instruction with 63, meaning it was not assuming that the register held something < 64 already (which is really, really weird because the function argument was u6 also, but I’m going to assume thats something with LLVM IR. Also, shift instruction wraps around ( << 190 = << 62) on my machine… again likely something with LLVM)
The simplest way I found to fix this was to just make a leftShift and rightShift function, change everything to u8, and assert that input is less than 64. This seemed to get rid of the unecessary mask.
My suggestion is to just add an operator called unsafe shift, maybe <<! and it just assumes that the value of the shift is already less 64, or N for uN.
Maybe also an operator like <<% that just does like a mod 64 on the shifter. iirc on ARM this requires a few assembly ops extra but on x86 this is less ops (no mask by 63 needed)
Anyways this helps chess programmers write performant code for our engines while maintaining readability.