3 ms·
He's actually wrong on the ABI requiring the top bits to be 0. It only requires that the bottom 32 bits match the parameter, but the top bits of a 32-bit parame
by 201984 10mo ago
He's actually wrong on the ABI requiring the top bits to be 0. It only requires that the bottom 32 bits match the parameter, but the top bits of a 32-bit parameter passed in a 64-bit register can be anything (at least on Linux).
You can see that in this godbolt example: https://godbolt.org/z/M1ze74Gh6 https://godbolt.org/z/M1ze74Gh6
The reason the code in his post works is because the upper 32 bits of the parameters going into an addition can't affect the low 32 bits of the result, and he's only storing the low 32 bits.
- fweimer 10mo agoThe LLVM x86-64 ABI requires the top bits to be zero. GCC treats them as undefined. Until a recent clarification, the x86-64 psABI made the upper bits undefined by omission only, which is why I think most people followed the GCC interpretation. https://github.com/llvm/llvm-project/issues/12579 https://github.com/llvm/llvm-project/issues/12579 https://groups.google.com/g/x86-64-abi/c/h7FFh30oS3s/m/Gksanh3WAAAJ https://groups.google.com/g/x86-64-abi/c/h7FFh30oS3s/m/Gksan... https://gitlab.com/x86-psABIs/x86-64-ABI/-/merge_requests/61 https://gitlab.com/x86-psABIs/x86-64-ABI/-/merge_requests/61
- account42 10mo agoGCC is the one defining the effective ABI here so LLVM was always buggy no matter what the spec said / didn't say.
- gpderetta 10mo agoActually not, the ABI is a cross vendor initiative.
- account42 10mo agoIn theory. In practice the vast majority of Linux userland programs are compiled with GCC so unless GCC did something particularly braindead they are unlikely to break compatibility with that and so it's the ABI everyone needs to target. Which is also what happened in this case: The standard was updated to mandate the GCC behavior.
- mattgodbolt 10mo agoAhhh! Thanks: that helps me understand where I picked up my misinformation!
- jfindper 10mo agoThere is something fun about using godbolt.org to say that Matt Godbolt is wrong.