* Inline Assembly Error: suffix or operands invalid for 'shr'
@ 2009-03-24 20:18 Rodrigo Dominguez
2009-03-24 20:24 ` H.J. Lu
2009-03-25 10:40 ` Chris Lattner
0 siblings, 2 replies; 6+ messages in thread
From: Rodrigo Dominguez @ 2009-03-24 20:18 UTC (permalink / raw)
To: gcc
Hi,
While debugging a problem with Open64, I ran into a similar problem with
GCC. I created the following unit test program:
#include <stdint.h>
int main(void)
{
uint32_t a = 7;
int8_t s = -1;
__asm__ ("shrl %1, %0\n\t"
: "+r" (a)
: "c" (-s)
);
return a;
}
When assembling this program, 'cc1' emits a 'shrl %ecx, %eax' instruction.
The 'shr' instruction can only take an 8-bit register as the first operand.
The emitted instruction should have been 'shrl %cl, %eax'. Therefore, the
compilation fails with a 'suffix or operands invalid for shr' message.
I have 2 questions:
1. AFAIK, by default, __asm__ chooses a register according to the size of
the operand (int8_t in this case). Is this correct? Where can I find
documentation of this?
2. If #1 is true, why does this fail?
Thank you,
Rodrigo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Inline Assembly Error: suffix or operands invalid for 'shr'
2009-03-24 20:18 Inline Assembly Error: suffix or operands invalid for 'shr' Rodrigo Dominguez
@ 2009-03-24 20:24 ` H.J. Lu
2009-03-25 2:19 ` Rodrigo Dominguez
2009-03-25 10:40 ` Chris Lattner
1 sibling, 1 reply; 6+ messages in thread
From: H.J. Lu @ 2009-03-24 20:24 UTC (permalink / raw)
To: Rodrigo Dominguez; +Cc: gcc
On Tue, Mar 24, 2009 at 11:02 AM, Rodrigo Dominguez <roddomi@hotmail.com> wrote:
> Hi,
>
> While debugging a problem with Open64, I ran into a similar problem with
> GCC. I created the following unit test program:
>
> #include <stdint.h>
>
> int main(void)
> {
> uint32_t a = 7;
> int8_t s = -1;
>
> __asm__ ("shrl %1, %0\n\t"
> : "+r" (a)
> : "c" (-s)
> );
>
> return a;
> }
>
> When assembling this program, 'cc1' emits a 'shrl %ecx, %eax' instruction.
> The 'shr' instruction can only take an 8-bit register as the first operand.
> The emitted instruction should have been 'shrl %cl, %eax'. Therefore, the
> compilation fails with a 'suffix or operands invalid for shr' message.
>
Please use
__asm__ ("shrl %b1, %0\n\t"
: "+r" (a)
: "c" (-s)
);
--
H.J.
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: Inline Assembly Error: suffix or operands invalid for 'shr'
2009-03-24 20:24 ` H.J. Lu
@ 2009-03-25 2:19 ` Rodrigo Dominguez
2009-03-25 7:26 ` Paul Koning
2009-03-25 10:02 ` H.J. Lu
0 siblings, 2 replies; 6+ messages in thread
From: Rodrigo Dominguez @ 2009-03-25 2:19 UTC (permalink / raw)
To: 'H.J. Lu'; +Cc: gcc
H.J,
Thanks for replying but this doesn't answer my question. Shouldn't __asm__
generate the right code without using the %b1 trick? The reason I am asking
is I have a 350 line macro which I can't change.
Is there any documentation about __asm__ default behavior regarding this
issue? Something like an Intel/AMD/AT&T manual explaining this?
Thank you,
Rodrigo
> -----Original Message-----
> From: H.J. Lu [mailto:hjl.tools@gmail.com]
> Sent: Tuesday, March 24, 2009 2:09 PM
> To: Rodrigo Dominguez
> Cc: gcc@gcc.gnu.org
> Subject: Re: Inline Assembly Error: suffix or operands invalid for
> 'shr'
>
> On Tue, Mar 24, 2009 at 11:02 AM, Rodrigo Dominguez
> <roddomi@hotmail.com> wrote:
> > Hi,
> >
> > While debugging a problem with Open64, I ran into a similar problem
> with
> > GCC. I created the following unit test program:
> >
> > #include <stdint.h>
> >
> > int main(void)
> > {
> > uint32_t a = 7;
> > int8_t s = -1;
> >
> > __asm__ ("shrl %1, %0\n\t"
> > : "+r" (a)
> > : "c" (-s)
> > );
> >
> > return a;
> > }
> >
> > When assembling this program, 'cc1' emits a 'shrl %ecx, %eax'
> instruction.
> > The 'shr' instruction can only take an 8-bit register as the first
> operand.
> > The emitted instruction should have been 'shrl %cl, %eax'. Therefore,
> the
> > compilation fails with a 'suffix or operands invalid for shr'
> message.
> >
>
> Please use
>
> __asm__ ("shrl %b1, %0\n\t"
> : "+r" (a)
> : "c" (-s)
> );
>
> --
> H.J.
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: Inline Assembly Error: suffix or operands invalid for 'shr'
2009-03-25 2:19 ` Rodrigo Dominguez
@ 2009-03-25 7:26 ` Paul Koning
2009-03-25 10:02 ` H.J. Lu
1 sibling, 0 replies; 6+ messages in thread
From: Paul Koning @ 2009-03-25 7:26 UTC (permalink / raw)
To: roddomi; +Cc: hjl.tools, gcc
>>>>> "Rodrigo" == Rodrigo Dominguez <roddomi@hotmail.com> writes:
Rodrigo> H.J, Thanks for replying but this doesn't answer my
Rodrigo> question. Shouldn't __asm__ generate the right code without
Rodrigo> using the %b1 trick? The reason I am asking is I have a 350
Rodrigo> line macro which I can't change.
GCC doesn't look at the instructions. You have to tell it what form
of argument the instruction expects, and the %b1 does that. So the
macro has a bug and you'll have to fix it...
paul
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Inline Assembly Error: suffix or operands invalid for 'shr'
2009-03-25 2:19 ` Rodrigo Dominguez
2009-03-25 7:26 ` Paul Koning
@ 2009-03-25 10:02 ` H.J. Lu
1 sibling, 0 replies; 6+ messages in thread
From: H.J. Lu @ 2009-03-25 10:02 UTC (permalink / raw)
To: Rodrigo Dominguez; +Cc: gcc
On Tue, Mar 24, 2009 at 1:18 PM, Rodrigo Dominguez <roddomi@hotmail.com> wrote:
> H.J,
>
> Thanks for replying but this doesn't answer my question. Shouldn't __asm__
> generate the right code without using the %b1 trick? The reason I am asking
> is I have a 350 line macro which I can't change.
Those macros are wrong.
> Is there any documentation about __asm__ default behavior regarding this
> issue? Something like an Intel/AMD/AT&T manual explaining this?
asm statement is compiler specific. It is documented in gcc manual. You
can take a look at *.md in i386 to see how asm statement may be used:
[hjl@gnu-13 i386]$ grep shr i386.md | grep %b
shr{q}\t{%b2, %0|%0, %b2}"
shr{l}\t{%b2, %0|%0, %b2}"
shr{l}\t{%b2, %k0|%k0, %b2}"
shr{w}\t{%b2, %0|%0, %b2}"
shr{b}\t{%b2, %0|%0, %b2}"
shr{b}\t{%b1, %0|%0, %b1}"
[hjl@gnu-13 i386]$
H.J.
---
> Thank you,
>
> Rodrigo
>
>> -----Original Message-----
>> From: H.J. Lu [mailto:hjl.tools@gmail.com]
>> Sent: Tuesday, March 24, 2009 2:09 PM
>> To: Rodrigo Dominguez
>> Cc: gcc@gcc.gnu.org
>> Subject: Re: Inline Assembly Error: suffix or operands invalid for
>> 'shr'
>>
>> On Tue, Mar 24, 2009 at 11:02 AM, Rodrigo Dominguez
>> <roddomi@hotmail.com> wrote:
>> > Hi,
>> >
>> > While debugging a problem with Open64, I ran into a similar problem
>> with
>> > GCC. I created the following unit test program:
>> >
>> > #include <stdint.h>
>> >
>> > int main(void)
>> > {
>> > uint32_t a = 7;
>> > int8_t s = -1;
>> >
>> > __asm__ ("shrl %1, %0\n\t"
>> > : "+r" (a)
>> > : "c" (-s)
>> > );
>> >
>> > return a;
>> > }
>> >
>> > When assembling this program, 'cc1' emits a 'shrl %ecx, %eax'
>> instruction.
>> > The 'shr' instruction can only take an 8-bit register as the first
>> operand.
>> > The emitted instruction should have been 'shrl %cl, %eax'. Therefore,
>> the
>> > compilation fails with a 'suffix or operands invalid for shr'
>> message.
>> >
>>
>> Please use
>>
>> __asm__ ("shrl %b1, %0\n\t"
>> : "+r" (a)
>> : "c" (-s)
>> );
>>
>> --
>> H.J.
>
>
--
H.J.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Inline Assembly Error: suffix or operands invalid for 'shr'
2009-03-24 20:18 Inline Assembly Error: suffix or operands invalid for 'shr' Rodrigo Dominguez
2009-03-24 20:24 ` H.J. Lu
@ 2009-03-25 10:40 ` Chris Lattner
1 sibling, 0 replies; 6+ messages in thread
From: Chris Lattner @ 2009-03-25 10:40 UTC (permalink / raw)
To: Rodrigo Dominguez; +Cc: gcc
On Mar 24, 2009, at 11:02 AM, Rodrigo Dominguez wrote:
> When assembling this program, 'cc1' emits a 'shrl %ecx, %eax'
> instruction.
> The 'shr' instruction can only take an 8-bit register as the first
> operand.
> The emitted instruction should have been 'shrl %cl, %eax'.
> Therefore, the
> compilation fails with a 'suffix or operands invalid for shr' message.
>
> I have 2 questions:
>
> 1. AFAIK, by default, __asm__ chooses a register according to the
> size of
> the operand (int8_t in this case). Is this correct? Where can I find
> documentation of this?
Though several people responded with useful information, no one has
answered the question. The issue here is that "-s" has int type, not
int8_t because of C promotion rules. Try using (int8_t)(-s).
-Chris
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-03-25 2:19 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-24 20:18 Inline Assembly Error: suffix or operands invalid for 'shr' Rodrigo Dominguez
2009-03-24 20:24 ` H.J. Lu
2009-03-25 2:19 ` Rodrigo Dominguez
2009-03-25 7:26 ` Paul Koning
2009-03-25 10:02 ` H.J. Lu
2009-03-25 10:40 ` Chris Lattner
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).