inline-asm/9637: arguments passed/return to asm block via mmx registers trigger failure

Philip Graham Willoughby pgw99@doc.ic.ac.uk
Mon May 12 12:32:00 GMT 2003


http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9637

On 2003-05-10 14:07:50 +0000, Dara Hazeghi wrote:
> 
> It seems that the crash has been solved, and we now exit gracefully.  
> Can the submitter verify if the code in question is in fact faulty?  

I now have a somewhat better understanding of inline asm than when I submitted
this bug.

Here is an explanation of what the operative (well, problematic) lines of this
code:

: "=y" (c), "=y" (a), "=y" (b)
: "0" (c)

are actually supposed to do.

The first line means "Pick three MMX registers.  These will contain the values
of c, a and b at the end of the ASM instructions.  I've called them $y0, %y1
and %y2 inside the asm block, and I need you to substitute those names with the
names of the registers you picked."

The second line means "Remember the first register you picked?  Well, I want
you to put the value of c into it before running the ASM block."

So far this matches what the documentation says.

Now, on to the reasons I think that this code might have failed:

* Reason 1:

The function tries to use a FP value and the MMX registes in the same function,
and you can't mix FP calls and MMX calls indiscriminately.

- Good Solution:
Fix gcc to add the appropriate calls to save/restore the FP stack before/after
asm blocks which use MMX registers

- Bad Solution:
Change the documentation so it says "You cannot mix FP and MMX calls in the
same function."

* Reason 2:

GCC doesn't actually understand how to pass things to/from MMX registers.

- Good Solution:
Fix gcc to bring it in line with what the docs say.

- Bad Solution:
Change the docs to remove references to MMX register constraints to asm.

* Reason 3:

GCC doesn't know how to move a "long long" value into or out of an MMX
register.

- Good Solution:
Teach it how - they are the same length, so it ought not to be a problem.
Alignment _may_ be an issue however.

- Bad Solution:
Change the docs to say it doesn't work.  That would raise the question of what
in fact gcc can move into an MMX register...

Hope all this helps.  The bottom line is that the code as written should work
if gcc behaves as documented.  I can't assure you that the asm actually works
when compiled because I have never persuaded gcc to compile it ;-), plus of
course there are better instructions to do the same from the SSE instruction
set.  I'd still like to resolve this as a fallback path for k6 and pre-xp
athlon processors.

Regards,

Philip Willoughby

Systems Programmer, Department of Computing, Imperial College, London, UK
-- 
echo bzidd@nfo.ho.co.se | tr "bizndfohces" "pwgd9ociaku"

Why reinvent the wheel?
Because we can make it rounder...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20030512/d3b54461/attachment.sig>


More information about the Gcc-bugs mailing list