Implement @depositBits and @extractBits
This PR takes #18680, updates the changes to master, and fixes the outstanding issues which prevented it from being merged.
There currently are outstanding issues related to the COFF linker which are blocking progress in the x86 backend:
- #19498 causes causing calls to the compiler-rt functions for u128 to crash the compiler when using the x86 backend to target Windows.
- All calls to the compiler-rt functions for pext and pdep appear to invoke a bug in the COFF linker, causing these symbols to be linked from a non-existent DLL called
.dll.
I have been told that moving on and just skipping the failing tests is the appropriate course of action here.
The comptime implementation calls into big.int.depositBits/extractBits, which themselves call the corresponding builtins. This allows for significantly better performance at comptime, but obviously requires zig1.wasm to be updated. I understand that a core member will be required to redo this commit for me before this can be merged?
The C backend implementation for integer sizes above u64 is blocked by #19991. I am subscribed to this issue, and once fixed, I have a work-in-progress implementation ready to be completed and included in a follow-up PR. Up-to u64, the C backend implementation works fine, and is sufficent for bootstrapping the compiler.
I've included a number of behaviour tests to ensure that the implementations are correct.
Many thanks to @Rexicon226, @jacobly0 and others for your extensive help :)
Closes #14995
There's currently a copy-paste in compiler-rt waiting for the required functions to be moved to std/Target.zig. Once that change is made, I'll fix that commit up.
There is scope for a follow-up PR to optimise the codegen for u128 and above to compile down to multiple invocations of pdep and pext. I intend to tackle that at a later date :)
I think I've addressed those all now :) I'll take a look at any feedback you've given tomorrow. Thank you for the help so-far! Also it'd probably be a good idea to give the workflows approval in-case any tests aren't passing on platforms I haven't been able to test for :) (Although I imagine you don't want to be running a third-party zig1.wasm on the CI?)
Fixed the faulty assumption that the source and mask would have the same number of limbs in the big.int implementation. Also added a couple more tests to confirm we have the correct behaviour.
Currently away from my computer, will get these changes addressed in a week or two :)
Other reviews have been addressed, will be able to take a proper stab at the reviews of big.int in about 2 weeks once I have some more spare time after exams.
Edit: Got bored and did it ^_^
Just a gentle ping — the 0.15 release is scheduled for August. Is there any chance this PR could make it in time?
Kind of just waiting for another review of things. Fingers crossed that we could get it merged in time, but focus is probably elsewhere for the core team right now. I'll give things another look this weekend. Not the end of the world if we miss 0.15.