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]

[patch] stormy16 varargs tweaks


This patch corrects the failure that was occurring for
gcc.c-torture/execute/920625-1.c.  The implementation
in stormy16_expand_builtin_va_arg did not exactly
follow the algorithm that is documented in stormy-abi.
The published algorithm is correct.  In addition, the
valist structure had its fields reversed.

920625-1.c is special because it's arguments are 16
bytes and do not fit in the stormy16 argument register
set.  last_register_count (in this case) was going
negative and throwing off the first compare.

OK to install?

Catherine

2001-10-19  Catherine Moore  <clm@redhat.com>

	* config/stormy16/stormy-abi:  Updates to varargs descriptions.
	* config/stormy16/stormy16.c (stormy16_build_va_list):  Reverse
	base and count fields.
	(stormy16_expand_builtin_va_start):  last_reg_count changed to
	size_of_reg_args.  Use count + size in first comparison.

Index: stormy-abi
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/stormy16/stormy-abi,v
retrieving revision 1.2
diff -p -r1.2 stormy-abi
*** stormy-abi	2001/10/05 20:33:09	1.2
--- stormy-abi	2001/10/19 14:08:01
*************** Both fields are 16 bits.  An argument of
*** 70,80 ****
  (N will be even) is accessed as if by the following code:
  
  char *result;
! if (count + N > 16)
    {
!     if (count < 16)
!       count = 16;
!     result = base - (count + N - 16 + 4);
    }
  else
    {
--- 70,82 ----
  (N will be even) is accessed as if by the following code:
  
  char *result;
! /* count = #bytes non-variable arguments */
! /* 12 = #bytes for register arguments */
! if (count + N > 12)
    {
!     if (count < 12)
!       count = 12;
!     result = base - (count + N - 12 + 4);
    }
  else
    {
*************** SP ->
*** 98,105 ****
  	r3
  count->	r2
  	Return address (two words)
! 	9th procedure parameter word
! 	10th procedure parameter word
  	...
  	last procedure parameter word
  
--- 100,107 ----
  	r3
  count->	r2
  	Return address (two words)
! 	7th procedure parameter word
! 	8th procedure parameter word
  	...
  	last procedure parameter word
  
Index: stormy16.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/stormy16/stormy16.c,v
retrieving revision 1.6
diff -p -r1.6 stormy16.c
*** stormy16.c	2001/10/19 14:03:29	1.6
--- stormy16.c	2001/10/19 14:08:01
*************** stormy16_build_va_list ()
*** 1131,1139 ****
    record = make_lang_type (RECORD_TYPE);
    type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
  
!   f_2 = build_decl (FIELD_DECL, get_identifier ("base"),
  		      ptr_type_node);
!   f_1 = build_decl (FIELD_DECL, get_identifier ("count"), 
  		      unsigned_type_node);
  
    DECL_FIELD_CONTEXT (f_1) = record;
--- 1131,1139 ----
    record = make_lang_type (RECORD_TYPE);
    type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
  
!   f_1 = build_decl (FIELD_DECL, get_identifier ("base"),
  		      ptr_type_node);
!   f_2 = build_decl (FIELD_DECL, get_identifier ("count"), 
  		      unsigned_type_node);
  
    DECL_FIELD_CONTEXT (f_1) = record;
*************** stormy16_expand_builtin_va_start (stdarg
*** 1186,1192 ****
  }
  
  /* Implement the stdarg/varargs va_arg macro.  VALIST is the variable
!    of type va_list as a tree, TYPE is the type passed to va_arg.  */
  rtx
  stormy16_expand_builtin_va_arg (valist, type)
       tree valist;
--- 1186,1194 ----
  }
  
  /* Implement the stdarg/varargs va_arg macro.  VALIST is the variable
!    of type va_list as a tree, TYPE is the type passed to va_arg.
!    Note:  This algorithm is documented in stormy-abi.  */
!    
  rtx
  stormy16_expand_builtin_va_arg (valist, type)
       tree valist;
*************** stormy16_expand_builtin_va_arg (valist, 
*** 1197,1204 ****
    rtx count_rtx, addr_rtx, r;
    rtx lab_gotaddr, lab_fromstack;
    tree t;
!   int size, last_reg_count;
    tree size_tree, count_plus_size;
    
    f_base = TYPE_FIELDS (va_list_type_node);
    f_count = TREE_CHAIN (f_base);
--- 1199,1207 ----
    rtx count_rtx, addr_rtx, r;
    rtx lab_gotaddr, lab_fromstack;
    tree t;
!   int size, size_of_reg_args;
    tree size_tree, count_plus_size;
+   rtx count_plus_size_rtx;
    
    f_base = TYPE_FIELDS (va_list_type_node);
    f_count = TREE_CHAIN (f_base);
*************** stormy16_expand_builtin_va_arg (valist, 
*** 1209,1222 ****
    size = PUSH_ROUNDING (int_size_in_bytes (type));
    size_tree = round_up (size_in_bytes (type), UNITS_PER_WORD);
    
!   last_reg_count = NUM_ARGUMENT_REGISTERS * UNITS_PER_WORD - size;
  
    count_rtx = expand_expr (count, NULL_RTX, HImode, EXPAND_NORMAL);
    lab_gotaddr = gen_label_rtx ();
    lab_fromstack = gen_label_rtx ();
    addr_rtx = gen_reg_rtx (Pmode);
!   emit_cmp_and_jump_insns (count_rtx, GEN_INT (last_reg_count),
! 			  GTU, const1_rtx, HImode, 1, 1, lab_fromstack);
    
    t = build (PLUS_EXPR, ptr_type_node, base, count);
    r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
--- 1212,1228 ----
    size = PUSH_ROUNDING (int_size_in_bytes (type));
    size_tree = round_up (size_in_bytes (type), UNITS_PER_WORD);
    
!   size_of_reg_args = NUM_ARGUMENT_REGISTERS * UNITS_PER_WORD;
  
    count_rtx = expand_expr (count, NULL_RTX, HImode, EXPAND_NORMAL);
    lab_gotaddr = gen_label_rtx ();
    lab_fromstack = gen_label_rtx ();
    addr_rtx = gen_reg_rtx (Pmode);
! 
!   count_plus_size = build (PLUS_EXPR, TREE_TYPE (count), count, size_tree);
!   count_plus_size_rtx = expand_expr (count_plus_size, NULL_RTX, HImode, EXPAND_NORMAL);
!   emit_cmp_and_jump_insns (count_plus_size_rtx, GEN_INT (size_of_reg_args),
! 			   GTU, const1_rtx, HImode, 1, 1, lab_fromstack);
    
    t = build (PLUS_EXPR, ptr_type_node, base, count);
    r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);


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