What is the quickest way to reverse the endianness of a 16 bit and 32 bit integer. I usually do something like (this coding was done in Visual Studio in C++):
un
Who says it does too many calculations?
out = changeEndianness16(in);
gcc 4.6.0
movzwl -4(%rsp), %edx
movl %edx, %eax
movsbl %dh, %ecx
movb %cl, %al
movb %dl, %ah
movw %ax, -2(%rsp)
clang++ 2.9
movw -2(%rsp), %ax
rolw $8, %ax
movw %ax, -4(%rsp)
Intel C/C++ 11.1
movzwl 4(%rsp), %ecx
rolw $8, %cx
xorl %eax, %eax
movw %cx, 6(%rsp)
What does your compiler produce?