Supponiamo che io sono:Moltiplicare per 0 ottimizzazione
double f(const double *r) {
return 0*(r[0]*r[1]);
}
dovrebbe compilatore in grado di ottimizzare il segmento, o ha ancora per eseguire l'operazione, nel caso in cui i valori potrebbero essere inf o nan?
gcc -O3 -S test.c:
.file "test.c"
.text
.p2align 4,,15
.globl f
.type f, @function
f:
.LFB0:
.cfi_startproc
movsd (%rdi), %xmm0
mulsd 8(%rdi), %xmm0
mulsd .LC0(%rip), %xmm0
ret
.cfi_endproc
.LFE0:
.size f, .-f
.section .rodata.cst8,"aM",@progbits,8
.align 8
.LC0:
.long 0
.long 0
.ident "GCC: (Ubuntu 4.4.3-4ubuntu5) 4.4.3"
.section .note.GNU-stack,"",@progbits
sembra nessuna eliminazione?
aha:
gcc -O3 -ffast-math -S test.c
.file "test.c"
.text
.p2align 4,,15
.globl f
.type f, @function
f:
.LFB0:
.cfi_startproc
xorpd %xmm0, %xmm0
ret
.cfi_endproc
.LFE0:
.size f, .-f
.ident "GCC: (Ubuntu 4.4.3-4ubuntu5) 4.4.3"
.section .note.GNU-stack,"",@progbits
ok, ha dovuto forzare la matematica funky con '-ffast-math' – Anycorn
Non è solo' NaN'. In IEEE 754, il risultato di '0.0 * x' dipende dal segno di' x'. –
@R .. grazie. questa è un'informazione veramente importante per me. – Anycorn