Re: __builtin_constant_p and inline assembly constraints

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Simon Kagstrom writes:
 > At Wed, 23 Aug 2006 12:51:33 +0100,
 > Andrew Haley wrote:
 > >  > But I cannot quite understand where the difference comes from. What I
 > >  > would like the original macro to generate is:
 > >  > 
 > >  > .set push
 > >  > .set noreorder
 > >  > 	.long	0xfffe0009
 > >  > 	.short	0xffff
 > >  > 	.short	9
 > >  > .set pop
 > > 
 > > So why not do that, then?  In a single asm.  
 > 
 > I would love to, but I can't. That's what my original problem with
 > __builtin_constant_p was. My original syscall macro indeed looked like
 > this:
 > 
 >   #define _syscall1(type,name,atype,a) \
 >   type name(atype a) { \
 > 	  register unsigned long __v0 asm("$2"); \
 > 	  \
 > 	  __asm__ volatile ( \
 > 	  ".set  push" \
 > 	  ".set  noreorder  " \
 > 	  ".long %1" \
 > 	  ".long %2" \
 > 	  ".short 0xffff  #" #name "  " \
 > 	  ".short %3" \
 > 	  ".set  pop" \
 > 	  : "=&r" (__v0) \
 > 	  :"r?i" (__builtin_constant_p(a) ? 0xfffd : 0xfffe), "r?i" (a), \
 > 	   "i" (__NR_##name) ); \
 > 	  \
 > 	  return (type) __v0; \
 >   }
 > 
 > and it didn't work because of the
 > 
 > 	:"r?i" (__builtin_constant_p(a) ? 0xfffd : 0xfffe), "r?i" (a), \
 > 
 > part.

But that __builtin_constant_p problem was because you put the call to
it in a function, not because of any other issues.  Why not put the
*whole lot* in a macro?  There's no need to break it into separate
functions.  Why was the function you had before not something like

#define puts(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");					\
  (int) __v0;								\
 })

Surely that would work.

Andrew.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux