1.28. 64-BIT VALUES IN 32-BIT ENVIRONMENT
Listing 1.384: Optimizing Keil 6/2013 (ARM mode)
||f|| PROC
LSR r0,r0,#7
ORR r0,r0,r1,LSL #25
LSR r1,r1,#7
BX lr
ENDP
Listing 1.385: Optimizing Keil 6/2013 (Thumb mode)
||f|| PROC
LSLS r2,r1,#25
LSRS r0,r0,#7
ORRS r0,r0,r2
LSRS r1,r1,#7
BX lr
ENDP
MIPS
GCC for MIPS follows the same algorithm as Keil does for Thumb mode:
Listing 1.386: Optimizing GCC 4.4.5 (IDA)
f:
sll $v0, $a0, 25
srl $v1, $a1, 7
or $v1, $v0, $v1
jr $ra
srl $v0, $a0, 7
1.28.5 Converting 32-bit value into 64-bit one
#include <stdint.h>
int64_t f (int32_t a)
{
return a;
};
x86
Listing 1.387: Optimizing MSVC 2012
_a$ = 8
_f PROC
mov eax, DWORD PTR _a$[esp-4]
cdq
ret 0
_f ENDP
Here we also run into necessity to extend a 32-bit signed value into a 64-bit signed one. Unsigned values
are converted straightforwardly: all bits in the higher part must be set to 0. But this is not appropriate for
signed data types: the sign has to be copied into the higher part of the resulting number.
TheCDQinstruction does that here, it takes its input value inEAX, extends it to 64-bit and leaves it in the
EDX:EAXregister pair. In other words,CDQgets the number sign fromEAX(by getting the most significant
bit inEAX), and depending of it, sets all 32 bits inEDXto 0 or 1. Its operation is somewhat similar to the
MOVSXinstruction.