PB5.1 X64 DLL

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
eriansa
Enthusiast
Enthusiast
Posts: 277
Joined: Wed Mar 17, 2004 12:31 am
Contact:

PB5.1 X64 DLL

Post by eriansa »

I've noticed that when a PB 64Bit DLL is called from a C/C++ program following happens :

- The FPU state is still in MMX mode
(one should call !Emms to make sure all float calculations are correct)

- Returning a Float from the DLL should be stored in MMX0
(instead of ProcedureReturn fFloat.f, one should put the var fFloat.f into MMX0 (!movd xmm0, [p.v_fFloat]))

Couldn't this be done by the compiler?
Thorium
Addict
Addict
Posts: 1305
Joined: Sat Aug 15, 2009 6:59 pm

Re: PB5.1 X64 DLL

Post by Thorium »

PB does not use any instruction set expansion.
So it does not return anything using MMX or XMM registers and it does not set up or reset MMX mode. Executing emms has to be done by the MMX code, not by a dll not using MMX.
eriansa
Enthusiast
Enthusiast
Posts: 277
Joined: Wed Mar 17, 2004 12:31 am
Contact:

Re: PB5.1 X64 DLL

Post by eriansa »

Thorium wrote:PB does not use any instruction set expansion.
So it does not return anything using MMX or XMM registers and it does not set up or reset MMX mode. Executing emms has to be done by the MMX code, not by a dll not using MMX.
Please read x64 cDecl calling conventions.

http://en.wikipedia.org/wiki/X86_calling_conventions

You'll see that XMM0 is used to return floats.
Thorium
Addict
Addict
Posts: 1305
Joined: Sat Aug 15, 2009 6:59 pm

Re: PB5.1 X64 DLL

Post by Thorium »

Ah i see XMM0 to XMM3 are used for passing floats. But i still dont see whats wrong with MMX state. XMM are SSE registers and dont have any reference to the FPU registers. So there is no EMMS needed.
eriansa
Enthusiast
Enthusiast
Posts: 277
Joined: Wed Mar 17, 2004 12:31 am
Contact:

Re: PB5.1 X64 DLL

Post by eriansa »

Thorium wrote:But i still dont see whats wrong with MMX state. XMM are SSE registers and dont have any reference to the FPU registers. So there is no EMMS needed.
Perhaps that part shouldn't be in "Feature Requests and Wishlists",
but there are a lot of DLL-Hosts that do not take responsability to reset the MMX state.
Perhaps a compiler switch "/DLL_preserve MMX state"?

Also, a mention in the docs about float returning, could solve a lot of googling..... ;-)
Post Reply