1.25. UNIONS
mov esi, 100
$LL3@main:
call ?float_rand@@YAMXZ
sub esp, 8
fstp QWORD PTR [esp]
push OFFSET $SG4238
call _printf
add esp, 12
dec esi
jne SHORT $LL3@main
xor eax, eax
pop esi
ret 0
_main ENDP
FunctionnamesaresostrangeherebecausethisexamplewascompiledasC++andthisisnamemangling
in C++, we will talk about it later:3.18.1 on page 542. If we compile this in MSVC 2012, it uses the SIMD
instructions for the FPU, read more about it here:1.31.5 on page 438.
MIPS
Listing 1.356: Optimizing GCC 4.4.5
float_rand:
var_10 = -0x10
var_4 = -4
lui $gp, (gnu_local_gp >> 16)
addiu $sp, -0x20
la $gp, (gnu_local_gp & 0xFFFF)
sw $ra, 0x20+var_4($sp)
sw $gp, 0x20+var_10($sp)
; call my_rand():
jal my_rand
or $at, $zero ; branch delay slot, NOP
; $v0=32-bit pseudorandom value
li $v1, 0x7FFFFF
; $v1=0x7FFFFF
and $v1, $v0, $v1
; $v1=pseudorandom value & 0x7FFFFF
lui $a0, 0x3F80
; $a0=0x3F800000
or $v1, $a0
; $v1=pseudorandom value & 0x7FFFFF | 0x3F800000
; matter of the following instruction is still hard to get:
lui $v0, ($LC0 >> 16)
; load 1.0 into $f0:
lwc1 $f0, $LC0
; move value from $v1 to coprocessor 1 (into register $f2)
; it behaves like bitwise copy, no conversion done:
mtc1 $v1, $f2
lw $ra, 0x20+var_4($sp)
; subtract 1.0. leave result in $f0:
sub.s $f0, $f2, $f0
jr $ra
addiu $sp, 0x20 ; branch delay slot
main:
var_18 = -0x18
var_10 = -0x10
var_C = -0xC
var_8 = -8
var_4 = -4
lui $gp, (__gnu_local_gp >> 16)
addiu $sp, -0x28