public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Help restricting args of an intrinsic function
@ 2004-01-31  0:53 Syd Polk
  2004-01-31  0:54 ` Ian Lance Taylor
                   ` (3 more replies)
  0 siblings, 4 replies; 32+ messages in thread
From: Syd Polk @ 2004-01-31  0:53 UTC (permalink / raw)
  To: GCC List

I am trying to implement a few PowerPC intrinsics that are supported by 
another PowerPC compiler. It is going pretty well in general (thanks to 
help by Mike Stump), but now, I have hit a road block.

The intrinsic I am trying to implement is rlwimi. The syntax is:

	__rwlimi (rA,rS, SH, MB, ME);

rA is the output register.
rS is the input.
SH is the shift value; MB and ME are mask begin and mask end values.

The problem is that the only valid values SH, MB and ME are constant 
integers from 1 to 31 inclusively. I have an instruction pattern which 
accepts valid calls like:

   r2 = __rlwimi (r, arg, 3, 5, 8);

This is cool. The next step was getting:

   r2 = __rlwimi (r, arg, 789, 5, 8);

to correctly flag that 789 was not a valid value. I did that by calling 
TREE_CODE on the argument, checking to see if it is INTEGER_CST, and 
then using compare_tree_int to see the constant value. This is all 
cool.

The problem is this:

   const int shift = 3;
   r2 = __rlwimi (r, arg, shift, 5, 8);

When I get the tree for the third arg, it is of type NOP_EXPR. I tried 
just calling default_conversion() from c-typeck.c as an experiment, 
knowing that it is C-specific. However, it still came out a NOP_EXPR.

Our competition handles this case just fine.

This is just one example; there are others even worse:

   enum tests {
	t1, t2, t3, t4, t5
   };

   r2 = __rlwimi(r, arg, t3, 5, 8);

or

   const int foo = 5;
   const int *shiftPtr = &foo;
   r2 = __rlwimi (r, arg, *shiftPtr, 5, 8);

etc.

(not to mention Ada or Fortran constructs)

How can I safely:
	- Determine if a value is really a compile-time constant?
	- Get the value of that constant?


Or, alternatively, is there a hook in the front-end parser that I can 
tie into to flag the error at parse time?

Syd Polk
Apple Computer
Technology EPM, Mac OS X Development Tools
+1 408 974-0577

^ permalink raw reply	[flat|nested] 32+ messages in thread
* Re: Help restricting args of an intrinsic function
@ 2004-02-03 14:18 Etienne Lorrain
  0 siblings, 0 replies; 32+ messages in thread
From: Etienne Lorrain @ 2004-02-03 14:18 UTC (permalink / raw)
  To: gcc

On Monday, February 2, 2004, at 04:35 PM, Daniel Jacobowitz wrote: 
>  const int ci = 5;
>  int a1[ci];
> will not compile, because ci is not an integral constant-expression. 

Mike Stump wrote:
> Does anyone know why the above isn't supported in C? Certainly
> the obviousness of it escapes me. My inclination is to fix the
> standard, not the compiler.

  In C, the keyword "const" means "not modifyed by the C", but it has to
 be a real variable - in case it is modifyed by the program loader or
 linker (for instance in assembler) before the C program starts.
  The C standard should have defined the real constant:
inline const int size_of_array = 5;
  but someone forgot.
  I could also have replaced a lot of #define and #if/#ifdef by C
 constructs, like "inline const struct { ...; } configuration;".

  A dreamer...


	

	
		
Yahoo! Mail : votre e-mail personnel et gratuit qui vous suit partout ! 
Créez votre Yahoo! Mail sur http://fr.benefits.yahoo.com/

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2004-02-03 14:18 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-31  0:53 Help restricting args of an intrinsic function Syd Polk
2004-01-31  0:54 ` Ian Lance Taylor
2004-01-31  1:21   ` Syd Polk
2004-01-31  1:38     ` Ian Lance Taylor
2004-01-31  1:52       ` David Edelsohn
2004-01-31  2:00         ` Syd Polk
2004-01-31  2:03           ` David Edelsohn
2004-01-31  2:20       ` Syd Polk
2004-01-31  3:18       ` Syd Polk
2004-01-31  0:55 ` Diego Novillo
2004-01-31  1:07   ` Syd Polk
2004-01-31  1:42     ` Diego Novillo
2004-01-31  4:29       ` Mike Stump
2004-01-31  7:34         ` Diego Novillo
2004-01-31  7:45           ` Mike Stump
2004-01-31 18:24             ` Diego Novillo
2004-02-02 19:58               ` Mike Stump
2004-02-02 23:44                 ` Syd Polk
2004-02-02 23:56                   ` Richard Henderson
2004-02-03  0:29                     ` Syd Polk
2004-02-03  0:39                       ` Richard Henderson
2004-02-02 23:26         ` Joe Buck
2004-02-02 23:37           ` Mike Stump
2004-02-02 23:45             ` Joe Buck
2004-02-03  0:31               ` Mike Stump
2004-02-03  0:35                 ` Daniel Jacobowitz
2004-02-03  1:16                   ` Mike Stump
2004-02-03  1:56                     ` Gabriel Dos Reis
2004-01-31  0:58 ` Ziemowit Laski
2004-01-31  1:38   ` Syd Polk
2004-01-31  8:12 ` Joseph S. Myers
2004-02-03 14:18 Etienne Lorrain

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).