Remove real type
bearophile
bearophileHUGS at lycos.com
Fri Apr 23 13:09:40 PDT 2010
Walter Bright:
> I agree. The only reason to use float or double is to save on storage.
A little D1 program, that I compile with LDC:
import tango.stdc.stdio: printf;
import tango.stdc.stdlib: atof;
alias real FP;
void main() {
FP x = atof("1.5");
FP y = atof("2.5");
FP xy = x * y;
printf("%lf\n", xy);
}
ldc -O3 -release -inline -output-s temp.d
FP = double:
_Dmain:
subl $36, %esp
movl $.str, (%esp)
call atof
movl $.str1, (%esp)
fstpl 24(%esp)
call atof
fstpl 16(%esp)
movsd 24(%esp), %xmm0
mulsd 16(%esp), %xmm0
movsd %xmm0, 4(%esp)
movl $.str2, (%esp)
call printf
xorl %eax, %eax
addl $36, %esp
ret $8
-------------------------
FP = real:
_Dmain:
subl $28, %esp
movl $.str, (%esp)
call atof
fstpt 16(%esp)
movl $.str1, (%esp)
call atof
fldt 16(%esp)
fmulp %st(1)
fstpt 4(%esp)
movl $.str2, (%esp)
call printf
xorl %eax, %eax
addl $28, %esp
ret $8
If you use the real type you are forced to use X86 FPU, that is very inefficient if used by LDC.
Bye,
bearophile
More information about the Digitalmars-d
mailing list