Closed huonw closed 9 years ago
Sounds good.
I think the weird codegen in the first case is LLVM trying to be too clever. It's interleaving the swap of the bytes (due to the mem::replace
). Why it's doing it in such a weird way is beyond me, though I can only guess it's trying to make sure as many functional units are active as possible and this is what it decided.
For instance, this is the contents of
shl_assign
:And this is its assembly:
(Why are there _movb_s in there?)
The other way to share code is to write the non-
Assign
versions in terms of theAssign
versions, which seems to generate better code and so hence it may be better to try to use this pattern where possible, e.g.