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: __builtin_constant_p and inline assembly constraints


Simon Kagstrom writes:
 > At Tue, 22 Aug 2006 14:44:44 +0100,
 > Andrew Haley wrote:
 > > Simon Kagstrom writes:
 > >  > I'm trying to dyanmically generate different bitpatterns using inline
 > >  > assembly depeding on a value is constant or not. I'm using it to issue
 > >  > system calls (see http://spel.bth.se/index.php/Cibyl) and avoid
 > >  > clobbering registers with constant values. What I'm trying to achieve
 > >  > is this:
 > >  > 
 > >  > 	move    a0,v0	# Normal MIPS instruction
 > >  > 	0000fffd 	# Argument, is a constant
 > >  > 	00000020 	# Constant 32
 > >  > 	ffff0001 	# System call number 1
 > > [...]
 > > Trying something simpler, 
 > > 
 > > #include <stdio.h>
 > > int main() {
 > >   printf("%d\n", __builtin_constant_p("Hello!"));
 > > }
 > > 
 > > returns 1.
 > 
 > Hmm... I tried this example and it seems that this might be a problem
 > with my version of GCC for MIPS. It works fine with Debian/testing GCC
 > 3.3.6, 3.4.6 and 4.1.2 but the MIPS cross compiler (3.4.3) doesn't
 > work. The flags I use to compile are
 > 
 >   -Wall -mips1 -fno-delayed-branch -Os -fno-pic -mno-abicalls
 > 
 > > Can you try expanding your example with gcc -E, and paste the result
 > > here so I can try it?  Then we'll have a test case we can use.
 > 
 > I've attached it below.

I see this:

static inline int
puts (const char *string)
{
  register unsigned long __v0 asm ("$2");
  __asm__ volatile (".set  push\n.set  noreorder\n");
  if (__builtin_constant_p (string))
    {
      __asm__ volatile (".long  0xfffd0000\n" ".long  %0\n"::"i,!r" (string));
    }
  else
    {
      __asm__ volatile (".short  0xfffe\n" ".short  %0\n"::"r" (string));
    };
  __asm__ volatile (".short 0xffff\t#" "puts" "\n\t"
		    ".short %1\n":"=&r" (__v0):"i" (1));
  __asm__ volatile (".set\tpop\n");
  return (int) __v0;
};

and it's pretty clear that string is not a constant in the context of
this function: it's a parameter.

Andrew.


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