DMD2 out parameters
Johann MacDonagh
johann.macdonagh..no at spam..gmail.com
Thu Dec 23 11:19:27 PST 2010
On 12/23/2010 12:19 PM, Pete wrote:
> Ok, i've done some more investigating and it appears that in DMD2 a float NaN is
> 0x7FE00000 (in dword format) but when it initialises a float 'out' parameter it
> initialises it with 0x7FA00000H. This causes an FPU trap which is where the time
> is going. This looks like a bug to me. Can anyone confirm?
>
> Thanks.
I just did a test with DMD 2.051 on Linux
void F1(ref float a)
{
a++;
}
void F2(out float a)
{
a++;
}
void main()
{
float a;
float b;
F1(a);
F2(b);
}
And ASM:
080490e4 <_D3out2F1FKfZv>:
80490e4: 55 push ebp
80490e5: 8b ec mov ebp,esp
80490e7: 83 ec 04 sub esp,0x4
80490ea: d9 e8 fld1
80490ec: d8 00 fadd DWORD PTR [eax]
80490ee: d9 18 fstp DWORD PTR [eax]
80490f0: c9 leave
80490f1: c3 ret
80490f2: 90 nop
80490f3: 90 nop
080490f4 <_D3out2F2FJfZv>:
80490f4: 55 push ebp
80490f5: 8b ec mov ebp,esp
80490f7: 83 ec 04 sub esp,0x4
80490fa: d9 05 00 81 05 08 fld DWORD PTR ds:0x8058100
8049100: d9 18 fstp DWORD PTR [eax]
8049102: d9 e8 fld1
8049104: d8 00 fadd DWORD PTR [eax]
8049106: d9 18 fstp DWORD PTR [eax]
8049108: c9 leave
8049109: c3 ret
804910a: 90 nop
804910b: 90 nop
0804910c <_Dmain>:
804910c: 55 push ebp
804910d: 8b ec mov ebp,esp
804910f: 83 ec 08 sub esp,0x8
8049112: d9 05 00 81 05 08 fld DWORD PTR ds:0x8058100
8049118: d9 5d f8 fstp DWORD PTR [ebp-0x8]
804911b: d9 05 00 81 05 08 fld DWORD PTR ds:0x8058100
8049121: d9 5d fc fstp DWORD PTR [ebp-0x4]
8049124: 8d 45 f8 lea eax,[ebp-0x8]
8049127: e8 b8 ff ff ff call 80490e4 <_D3out2F1FKfZv>
804912c: 8d 45 fc lea eax,[ebp-0x4]
804912f: e8 c0 ff ff ff call 80490f4 <_D3out2F2FJfZv>
8049134: 31 c0 xor eax,eax
8049136: c9 leave
8049137: c3 ret
And 0x8058100 is 0x7FA00000. As you can see out doesn't force the
loading and storing of a different NaN value.
Of course, maybe the compiler should skip initializing a float that gets
passed into a routine as an out parameter as its first use. E.g.
float a;
a = 1.0;
wouldn't generate two separate assignments.
More information about the Digitalmars-d-learn
mailing list