The following code (taken from L4Ka::Pistachio) compiles correctly on gcc (3.3.4, 3.3.5, and 3.4.4) when given any optimization level, but fails when you don't use any: $ cat foo.c unsigned char inb (unsigned long port) { unsigned char tmp; if (port < 0x100) __asm__ __volatile__ ("inb %w1, %0":"=al" (tmp):"dN" (port)); else __asm__ __volatile__ ("inb %%dx, %0": "=al" (tmp):"d" (port)); return tmp; } $ gcc -c foo.c foo.c: In function `inb': foo.c:7: error: impossible constraint in `asm' foo.c:9: error: impossible constraint in `asm' $ gcc -c foo.c -O $
Which target triplet?
You don't want the "al" contstraint at all. Read the docs to figure out which constaint you really want. the constraint "al" means pick either the "a" constraint or the "l" constraint
Subject: Re: assembly constraints fail unless optimizing code On Sat, 2005-03-05 at 01:26 +0000, giovannibajo at libero dot it wrote: > Which target triplet? i386-pc-linux-gnu
Subject: Re: assembly constraints fail unless optimizing code On Sat, 2005-03-05 at 01:31 +0000, pinskia at gcc dot gnu dot org wrote: > You don't want the "al" contstraint at all. > > Read the docs to figure out which constaint you really want. the constraint "al" means pick either the > "a" constraint or the "l" constraint The original code's not mine at all, so I don't know what constraint is actually wanted. However, after looking through section 5.36 of the gcc 3.4.3 manual, I can't figure out what the "l" constraint means for the i386 architecture anyways. So maybe the original code *shouldn't* be using the "=al" constraint, but either the manual's missing a description of the "l" constraint for i386 so I can't decide whether it's correct or not, or gcc's not complaining about an illegal constraint when optimizations are enabled (or maybe that's an optimization feature?).