public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* GCC Inline ASM generates incorrect assembler code (or documentation is unclear, or I am &*&$@$#*&).
@ 2001-12-14 14:27 Armand Liberi
  2001-12-14 15:51 ` Jan Hubicka
  0 siblings, 1 reply; 3+ messages in thread
From: Armand Liberi @ 2001-12-14 14:27 UTC (permalink / raw)
  To: gcc

Hello,

I have a small example of what I think might be a GCC bug involving inline
asm constraints.  I get the same results on three different versions of GCC,
one in RedHat Linux 7.2, one in the newest CygWin distribution for Windows,
and one in a LynxOS distribution that also comes via RedHat as I understand
it and is several years old.

I first submitted it to the PR web site but it was rejected because of the
LynxOS GCC version number.  It was suggested that I send it to you as a more
general question.

So, if you could tell me if it is a bug, a documentation error, or stupidty,
I would appreciate it.

-------------------------------------------------
Problem
-------------------------------------------------
With the variable declarations:

unsigned int singleInt;
unsigned int lotsOfInts[100]={0};

                asm ("FSTPL %0":"=m" (singleInt)); generates "FSTPL
singleInt" as expected, and

                asm ("FSTPL %0":"=m" (lotsOfInts)); generates "FSTPL
lotsOfInts" as expected, and

                asm ("FLDL %0"::"m" (singleInt)); generates "FLDL singleInt"
as expected, BUT

                asm ("FLDL %0"::"m" (lotsOfInts)); generates "FLDL .LC0"
which is NOT expected (by me).

This actually happened using an FSAVE/FRSTOR sequence in a SIGFPE signal
handler.  As the above illustrates, it was not the instruction that caused
the problem - just that an array address is involved rather than a single
variable.  We pay for support from LynuxWorks and they gave me two fixes
shown below.  Those also appear to be bugs to me but, like so many other
people on the net, I'm a little confused about the constraint rules, etc.,
and cannot find any clear statement of those rules.
-------------------------------------------------
Fixes
-------------------------------------------------
 Two have been suggested to me by LynuxWorks support:

1.  Change 'asm ("FLDL %0"::"m" (lotsOfInts));'
    to 'asm ("FLDL %0":"=m" (lotsOfInts));'.  I.E., use an output constraint
to describe an input (???)

2.  Use 'asm ("FLDL lotsOfInts);'.  I.E., don't use constraints."  (I found
a page on the web that said that if the restraints are left off of the
inputs/outputs, then a "clobber" restraint of "memory" should be included
but I can't find any reference to that any where else.

And, I found that:

3.  Using lotsOfInts[0] corrects the code also.
-------------------------------------------------

Thanks for taking the time to look at this.

Regards,
Armand

He who asks is a fool for five minutes, but he who does not ask remains a
fool forever. - Chinese proverb
Life is just one five minute period after another. - Armand Liberi"



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-12-17 15:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-14 14:27 GCC Inline ASM generates incorrect assembler code (or documentation is unclear, or I am &*&$@$#*&) Armand Liberi
2001-12-14 15:51 ` Jan Hubicka
2001-12-17  8:04   ` Armand Liberi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).