This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: problems with read-write "asm" operands


Sorry to reply to my own posting, but here's a slightly simpler version of the same code with nearly the same problem:

unsigned counters[3];

int bump(int left, int right)
{
int slot = 0;
int le = 0;

asm
("cmp %2,%3\n"
"setl %b0\n"
"setle %b1\n"
"add %k1,%k0\n"
: "+&q,&q" (slot), "+&q,&q" (le)
: "r,g" (left), "g,r" (right)
: "cc");

++counters[slot];
}

The job of the inline assembly code is now just to set "slot" to either 0, 1, or 2 depending on whether left is <, ==, or > right. Manipulation of the counters array is done in C code, which makes things somewhat more readable and more clearly expresses what kinds of side effects can occur.

Both "slot" and "le" are zero initialized in the C code, and both are declared as read-write ("+") operands. However....

- If I compile with "-O9", the register selected for "slot" is
correctly zero initialized. The register selected for "le",
however, is not. It simply inherits whatever leftover value
might previously have been in that register.

- If I compile with "-g", neither register is zero initialized.
Each simply inherits whatever leftover value might previously have
been in its selected register.

This is getting mighty strange. Anybody got a clue?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]