3 ms·
> In fact swapping the byte order is _one_ CPU instruction. That's one machine instruction, I'm pretty sure it's more than one microcode instruction ;)
by masklinn 15y ago
> In fact swapping the byte order is _one_ CPU instruction.
That's one machine instruction, I'm pretty sure it's more than one microcode instruction ;)
- dfox 15y agoSwapping bits around is operation that is essentially free in hardware. It's just wires.
- ableal 15y agoMost hardware is just wires. Especially since transistors shrunk down to nearly nothing. Still, the layout of something like a barrel shifter (e.g. http://www.erc.msstate.edu/mpl/distributions/scmos/images/bshift.gif http://www.erc.msstate.edu/mpl/distributions/scmos/images/bs... , from a casual search) takes its space on die, much like an adder or multiplier. It's all wires and switches.
- pbsd 15y agoYes and no. On modern Intel CPUs, 32-bit bswap is 1 uop, but 64-bit bswap is 2. On AMD it seems to always be just 1 uop.
- mansr 15y agoOn most x86 and ARM CPUs, byte-reversing a register is a single-cycle operation. PowerPC has byte-reversing load and store instructions but lacks an instruction to reverse a register.