Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Difference between EMMS and FNINIT?

144 views
Skip to first unread message

axelbrz

unread,
Oct 13, 2009, 2:34:34 AM10/13/09
to

Hi,

I've read the documentation about EMMS and FNINIT instructions, and
they both seem to be the same.

Manual of Intel IA32 says:

FNINIT:
Sets the FPU control, status, tag, instruction pointer, and data
pointer registers to their default states. The FPU control word is set
to 037FH (round to nearest, all exceptions masked, 64-bit precision).
The status word is cleared (no exception flags set, TOP is set to 0).
The data registers in the register stack are left unchanged, but they
are all tagged as empty (11B). Both the instruction and data pointers
are cleared.
The FINIT instruction checks for and handles any pending unmasked
floating-point exceptions before performing the initialization; the
FNINIT instruction does not.

EMMS:
Sets the values of all the tags in the x87 FPU tag word to empty (all
1s). This operation marks the x87 FPU data registers (which are
aliased to the MMX technology registers) as available for use by x87
FPU floating-point instructions.

The difference between the descriptions seems to be that FNINIT
restores the instruction and data pointers to their default states,
but it's not clear if EMMS does it too, and although if it's the only
difference, the only thing you want when you start using FPU
instructions is to have all tag words empty, and both of them seem to
do it.

1) So, can anyone tell me the difference between them?

2) And if that's the difference and I only want to use FPU
instructions after MMX instructions, I could use both of them, right?

3) And if I use MMX instructions, and then I do FNINIT, should I use
EMMS too before?

Thank you,

Axel.

BGB / cr88192

unread,
Oct 13, 2009, 7:13:33 PM10/13/09
to

"axelbrz" <axe...@MUNGED.microcosmotalk.com> wrote in message
news:4ad41f7a$0$5084$9a6e...@unlimited.newshosting.com...

EMMS does less...


> 2) And if that's the difference and I only want to use FPU
> instructions after MMX instructions, I could use both of them, right?
>

yep, except that FINIT resets the FPU to default values, which "could"
matter if a compiler is doing anything non-default with the FPU.

EMMS then could then potentially preserve the pre-existing FPU state.

> 3) And if I use MMX instructions, and then I do FNINIT, should I use
> EMMS too before?
>

just from these descriptions, it should not make too much difference...


the bigger question is, then, why to use MMX rather than equivalent SSE2
operations?...


> Thank you,
>
> Axel.


axelbrz

unread,
Oct 13, 2009, 8:19:35 PM10/13/09
to

:)

Because I'm studing computer science, and I have to know how to use
both MMX and XMM registers!

Thank you for your answer!


On Oct 13, 8:13=A0pm, "BGB / cr88192"
<cr88...@MUNGED.microcosmotalk.com> wrote:
> "axelbrz" <axel...@MUNGED.microcosmotalk.com> wrote in message

Rod Pemberton

unread,
Oct 14, 2009, 4:20:20 AM10/14/09
to

"axelbrz" <axe...@MUNGED.microcosmotalk.com> wrote in message
news:4ad41f7a$0$5084$9a6e...@unlimited.newshosting.com...
>

> I've read the documentation about EMMS and FNINIT instructions, and
> they both seem to be the same.
>
> [...]

> 1) So, can anyone tell me the difference between them?
>

Just a warning: I've not used them... My comments are based on a skim of
the manuals.

The Intel and AMD manuals in a number of places indicate the EMMS (and/or
FEMMS for AMD cpu's) is used between 1) x87 FPU instructions and XMM
instructions or 2) between XMM instructions and x87 FPU instructions.
Apparently, this is because they both use the same "registers" but modify
different bits in the in x87 FPU tag word. AFAICT, these bits are
(apparently) automatically set/reset upon use of XMM instructions, but are
not automatically set/reset when using x87 FPU instructions... Therefore,
problem when switching between them. If these bits are incorrect for x87
instructions, they will cause "floating point exceptions or incorrect
results" according to the Intel manuals.

The Intel manuals show their operations on the same pages you quoted:

EMMS:
x87FPUTagWord<--FFFFH;

FNINIT/FINIT:
FPUControlWord<--037FH;
FPUStatusWord<--0;
FPUTagWord<--FFFFH;
FPUDataPointer<--0;
FPUInstructionPointer<--0;
FPULastInstructionOpcode<--0;

You might check the other (e.g., Vol 1, Vol 3) Intel manuals for these
sections or similar for more information:
"EMMS Instruction"
"Transitions Between x87 FPU and MMX Code"
"Using the EMMS Instruction"
"The MMX State and MMX Registers"
"Effect of MMX, x87 FPU, FXSAVE, and FXRSTOR Instructions on the x87 FPU
Tag Word"

> 2) And if that's the difference and I only want to use FPU
> instructions after MMX instructions,

Use EMMS between.

> I could use both of them, right?

Yes. But, not needed, AFAICT. FNINIT or FINIT is probably only needed
once, and then you can use EMMS between all other transitions.

> 3) And if I use MMX instructions, and then I do FNINIT, should I use
> EMMS too before?

I don't think the EMMS is needed since FNINIT or FINIT does what EMMS does
and more. It'd be very odd if EMMS were required prior to FNINIT/FINIT when
transitioning from XMM to x87 FPU...


Rod Pemberton


0 new messages