target/5381: compiler does not issue emmx
David Kastrup
David.Kastrup@t-online.de
Tue Jan 15 00:16:00 GMT 2002
The following reply was made to PR target/5381; it has been noted by GNATS.
From: David.Kastrup@t-online.de (David Kastrup)
To: Richard Henderson <rth@redhat.com>
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: target/5381: compiler does not issue emmx
Date: 15 Jan 2002 09:07:37 +0100
Richard Henderson <rth@redhat.com> writes:
> Not a bug -- pmulhuw is an SSE instruction, not part of
> the base MMX instruction set.
Oops, sorry. Darn those spec sheets that don't bother mentioning
this. Probably MMX2 or something.
But here to the second problem that I consider real:
> > Anyhow, as you can see from the generated code, the compiler fails to
> > emit an emmx instruction at the end of the routine, leading to possible
> > floating point errors after return.
>
> Again, not a bug. The user is responsible for handling emmx.
>
> If the compiler were deciding to emit MMX code on its own,
> then yes I would agree that it must clean up after itself.
> But this is not the case here.
The problem is that the compiler is allocating the MMX registers used,
might be rearranging expressions including floating point operands in
between, and is possibly doing optimizations that might move the
__builtin_ functions. It is the use of the MMX registers that
necessitates the emmx instruction before the next floating point
instruction. Since the compiler is the one in control that clobbers
the registers, and since it is the one that knows when it will next
need the floating point stack and will have to flush any remaining MMX
registers back to memory, it stands to reason that it should also be
responsible for issuing the emmx instruction. If the user put emmx
instructions in at a place where the compiler decided to leave a
variable in an MMX register for optimization purposes, things get
ugly.
I would even go as far as to claim that the compiler should issue an
emmx instruction if it has assigned mmx registers due to a "y"
contraint on assembly language templates: after all, it is only after
the template finishes that any output operands can be moved into
memory locations or reused for the a possibly coming up MMX
instruction, so putting an emmx instruction into your assembly
template yourself would definitely be impossible. Adding another
assembly template afterwards and hoping that the compiler will have
cleared out registers before its execution is just crossing fingers
and second-guessing.
As long as the compiler is in charge of assigning the registers, it
should also be in charge of telling the CPU when it is done.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
Email: David.Kastrup@t-online.de
More information about the Gcc-prs
mailing list