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:
 > Hello!
 > 
 > 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
 > 
 > I use the first word as encoding of the "argument" type and the second
 > as the constant or register number. My problem is: How can I generate
 > this reliably from inline assembly? It seems to me that
 > __builtin_constant_p doesn't work as I would expect it to.

Looking at the source of fold_builtin_constant_p(), I see this:

  if (TREE_CODE (arglist) == ADDR_EXPR)
    {
       tree op = TREE_OPERAND (arglist, 0);
       if (TREE_CODE (op) == STRING_CST
	   || (TREE_CODE (op) == ARRAY_REF
	       && integer_zerop (TREE_OPERAND (op, 1))
	       && TREE_CODE (TREE_OPERAND (op, 0)) == STRING_CST))
	 return integer_one_node;
    }

which looks like it ought to work.

Trying something simpler, 

#include <stdio.h>
int main() {
  printf("%d\n", __builtin_constant_p("Hello!"));
}

returns 1.

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.

Andrew.


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