This is the mail archive of the gcc-patches@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]

Da Real Patch, was: Re: [g77 testsuite]


I wrote:

> Hmmm, that's not how I read it.  This is the implementation of ISHFT in
> the Fortran frontend (line 4549ff of f/com.c):

[ Snip - as always, the real culprit is in the code you don't quote ]

> In words, this says:  Test the if count against zero.  If it is larger,
> do an LSHIFT_EXPR of the shiftee, else do an RSHIFT_EXPR of (unsigned)
> the shiftee.  According to tree.def, RSHIFT_EXPR on an unsigned quantity
> should do a logical shift, i.e., with zero-fill.  Perhaps the way the
> conversion to unsigned is done doesn't work.

Well, it turns out that the restriction Richard mentioned (no shifts as
large as the type size - or larger) is even in the tree representation.

I go on record here as to say that I'm not impressed.  I feel the tree
representation should be a high level I(ntermediate) L(anguage), free of
C-isms.

The attached patch repairs the Fortran frontend and documents the
{L|R}SHIFT limitations (in two places).

Bootstrapped (C and Fortran), checked (Fortran only), make dvi'd and
make install'd on i686-pc-linux-gnu.

Is this patch OK for the trunk ?

TIA.

"If you can't do it in FORTRAN, do it in assembly language.  If you
 can't do it in assembly language, it isn't worth doing."

-- 
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)
2001-07-19  Toon Moene  <toon@moene.indiv.nluug.nl>

	* tree.def: Document restriction on {L|R}SHIFT_EXPR's second argument.
	* doc/tree.texi: Ditto.
	* f/com.c (ffecom_expr_intrinsic_): Cope with it.

*** tree.def.orig	Sun Jul 15 11:10:13 2001
--- tree.def	Thu Jul 19 10:58:37 2001
*************** DEFTREECODE (FFS_EXPR, "ffs_expr", '1', 
*** 617,623 ****
     Shift means logical shift if done on an
     unsigned type, arithmetic shift if done on a signed type.
     The second operand is the number of bits to
!    shift by; it need not be the same type as the first operand and result.  */
  DEFTREECODE (LSHIFT_EXPR, "lshift_expr", '2', 2)
  DEFTREECODE (RSHIFT_EXPR, "rshift_expr", '2', 2)
  DEFTREECODE (LROTATE_EXPR, "lrotate_expr", '2', 2)
--- 617,625 ----
     Shift means logical shift if done on an
     unsigned type, arithmetic shift if done on a signed type.
     The second operand is the number of bits to
!    shift by; it need not be the same type as the first operand and result.
!    Note that the result is undefined if the second operand is larger
!    than the first operand's type size.  */
  DEFTREECODE (LSHIFT_EXPR, "lshift_expr", '2', 2)
  DEFTREECODE (RSHIFT_EXPR, "rshift_expr", '2', 2)
  DEFTREECODE (LROTATE_EXPR, "lrotate_expr", '2', 2)
*** doc/c-tree.texi.orig	Thu Jul 19 11:46:59 2001
--- doc/c-tree.texi	Thu Jul 19 11:45:49 2001
*************** second operand is an expression for the 
*** 2003,2008 ****
--- 2003,2010 ----
  shift.  Right shift should be treated as arithmetic, i.e., the
  high-order bits should be zero-filled when the expression has unsigned
  type and filled with the sign bit when the expression has signed type.
+ Note that the result is undefined if the second operand is larger
+ than the first operand's type size.
  
  
  @item BIT_IOR_EXPR
*** f/com.c.orig	Mon Jul 16 20:57:37 2001
--- f/com.c	Thu Jul 19 11:28:01 2001
*************** ffecom_expr_intrinsic_ (ffebld expr, tre
*** 4573,4580 ****
  	expr_tree
  	  = ffecom_3 (COND_EXPR, tree_type,
  		      ffecom_truth_value
! 		      (ffecom_2 (NE_EXPR, integer_type_node,
! 				 arg2_tree,
  				 TYPE_SIZE (uns_type))),
  		      expr_tree,
  		      convert (tree_type, integer_zero_node));
--- 4573,4582 ----
  	expr_tree
  	  = ffecom_3 (COND_EXPR, tree_type,
  		      ffecom_truth_value
! 		      (ffecom_2 (LT_EXPR, integer_type_node,
! 				 ffecom_1 (ABS_EXPR,
! 					   integer_type_node,
! 					   arg2_tree),
  				 TYPE_SIZE (uns_type))),
  		      expr_tree,
  		      convert (tree_type, integer_zero_node));

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