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]
Other format: [Raw text]

ppc: generalize simple builtins


i have some code adding some non-altivec builtins to the PPC port, and
noticed what a mess i've made in the builtins.  we wrongly assume that the 
altivec builtins are the only binop, unop, and ternary builtins.

this patch generalizes the simple builtins, so we can add other simple 
binop, unop, and ternary builtins by just plugging into the existing 
framework (adding them to the bdesc* tables).

ok?

2002-05-29  Aldy Hernandez  <aldyh@redhat.com>

	* rs6000.c: (altivec_expand_builtin): Only expand altivec builtins
	when TARGET_ALTIVEC.  Move handling of generic unary, binary, and
	ternary operations from here...
	(rs6000_expand_builtin): ...to here.
	New argument expandedp.
	Change all instances of altivec_expand_binop_builtin to
	rs6000_expand_binop_builtin.
	(altivec_expand_unop_builtin): Rename to
	rs6000_expand_unop_builtin.
	(altivec_expand_binop_builtin): Rename to
	rs6000_expand_binop_builtin.
	(altivec_expand_ternop_builtin): Rename to
	rs6000_expand_ternop_builtin.


Index: config/rs6000/rs6000.c
===================================================================
RCS file: /cvs/uberbaum/gcc/config/rs6000/rs6000.c,v
retrieving revision 1.323
diff -c -p -r1.323 rs6000.c
*** config/rs6000/rs6000.c	20 May 2002 02:31:24 -0000	1.323
--- config/rs6000/rs6000.c	29 May 2002 08:50:16 -0000
*************** static int rs6000_adjust_priority PARAMS
*** 187,200 ****
  static int rs6000_issue_rate PARAMS ((void));
  
  static void rs6000_init_builtins PARAMS ((void));
! static void altivec_init_builtins PARAMS ((void));
  static rtx rs6000_expand_builtin PARAMS ((tree, rtx, rtx, enum machine_mode, int));
! static rtx altivec_expand_builtin PARAMS ((tree, rtx));
! static rtx altivec_expand_unop_builtin PARAMS ((enum insn_code, tree, rtx));
! static rtx altivec_expand_binop_builtin PARAMS ((enum insn_code, tree, rtx));
  static rtx altivec_expand_abs_builtin PARAMS ((enum insn_code, tree, rtx));
  static rtx altivec_expand_predicate_builtin PARAMS ((enum insn_code, const char *, tree, rtx));
- static rtx altivec_expand_ternop_builtin PARAMS ((enum insn_code, tree, rtx));
  static rtx altivec_expand_stv_builtin PARAMS ((enum insn_code, tree));
  static void rs6000_parse_abi_options PARAMS ((void));
  static void rs6000_parse_vrsave_option PARAMS ((void));
--- 187,200 ----
  static int rs6000_issue_rate PARAMS ((void));
  
  static void rs6000_init_builtins PARAMS ((void));
! static rtx rs6000_expand_unop_builtin PARAMS ((enum insn_code, tree, rtx));
! static rtx rs6000_expand_binop_builtin PARAMS ((enum insn_code, tree, rtx));
! static rtx rs6000_expand_ternop_builtin PARAMS ((enum insn_code, tree, rtx));
  static rtx rs6000_expand_builtin PARAMS ((tree, rtx, rtx, enum machine_mode, int));
! static void altivec_init_builtins PARAMS ((void));
! static rtx altivec_expand_builtin PARAMS ((tree, rtx, bool *));
  static rtx altivec_expand_abs_builtin PARAMS ((enum insn_code, tree, rtx));
  static rtx altivec_expand_predicate_builtin PARAMS ((enum insn_code, const char *, tree, rtx));
  static rtx altivec_expand_stv_builtin PARAMS ((enum insn_code, tree));
  static void rs6000_parse_abi_options PARAMS ((void));
  static void rs6000_parse_vrsave_option PARAMS ((void));
*************** static const struct builtin_description 
*** 3567,3573 ****
  };
  
  static rtx
! altivec_expand_unop_builtin (icode, arglist, target)
       enum insn_code icode;
       tree arglist;
       rtx target;
--- 3567,3573 ----
  };
  
  static rtx
! rs6000_expand_unop_builtin (icode, arglist, target)
       enum insn_code icode;
       tree arglist;
       rtx target;
*************** altivec_expand_abs_builtin (icode, argli
*** 3652,3658 ****
  }
  
  static rtx
! altivec_expand_binop_builtin (icode, arglist, target)
       enum insn_code icode;
       tree arglist;
       rtx target;
--- 3652,3658 ----
  }
  
  static rtx
! rs6000_expand_binop_builtin (icode, arglist, target)
       enum insn_code icode;
       tree arglist;
       rtx target;
*************** altivec_expand_stv_builtin (icode, argli
*** 3826,3832 ****
  }
  
  static rtx
! altivec_expand_ternop_builtin (icode, arglist, target)
       enum insn_code icode;
       tree arglist;
       rtx target;
--- 3826,3832 ----
  }
  
  static rtx
! rs6000_expand_ternop_builtin (icode, arglist, target)
       enum insn_code icode;
       tree arglist;
       rtx target;
*************** altivec_expand_ternop_builtin (icode, ar
*** 3886,3895 ****
  
    return target;
  }
  static rtx
! altivec_expand_builtin (exp, target)
       tree exp;
       rtx target;
  {
    struct builtin_description *d;
    struct builtin_description_predicates *dp;
--- 3886,3899 ----
  
    return target;
  }
+ 
+ /* Expand the builtin in EXP and store the result in TARGET.  Store
+    true in *EXPANDEDP if we found a builtin to expand.  */
  static rtx
! altivec_expand_builtin (exp, target, expandedp)
       tree exp;
       rtx target;
+      bool *expandedp;
  {
    struct builtin_description *d;
    struct builtin_description_predicates *dp;
*************** altivec_expand_builtin (exp, target)
*** 3901,3907 ****
    rtx op0, op1, op2, pat;
    enum machine_mode tmode, mode0, mode1, mode2;
    unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
!   
    switch (fcode)
      {
      case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
--- 3905,3913 ----
    rtx op0, op1, op2, pat;
    enum machine_mode tmode, mode0, mode1, mode2;
    unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
! 
!   *expandedp = true;
! 
    switch (fcode)
      {
      case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
*************** altivec_expand_builtin (exp, target)
*** 4182,4199 ****
      if (d->code == fcode)
        return altivec_expand_abs_builtin (d->icode, arglist, target);
  
-   /* Handle simple unary operations.  */
-   d = (struct builtin_description *) bdesc_1arg;
-   for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
-     if (d->code == fcode)
-       return altivec_expand_unop_builtin (d->icode, arglist, target);
- 
-   /* Handle simple binary operations.  */
-   d = (struct builtin_description *) bdesc_2arg;
-   for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
-     if (d->code == fcode)
-       return altivec_expand_binop_builtin (d->icode, arglist, target);
- 
    /* Expand the AltiVec predicates.  */
    dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
    for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
--- 4188,4193 ----
*************** altivec_expand_builtin (exp, target)
*** 4204,4241 ****
    switch (fcode)
      {
      case ALTIVEC_BUILTIN_LVSL:
!       return altivec_expand_binop_builtin (CODE_FOR_altivec_lvsl,
  					   arglist, target);
      case ALTIVEC_BUILTIN_LVSR:
!       return altivec_expand_binop_builtin (CODE_FOR_altivec_lvsr,
! 					   arglist, target);
      case ALTIVEC_BUILTIN_LVEBX:
!       return altivec_expand_binop_builtin (CODE_FOR_altivec_lvebx,
! 					   arglist, target);
      case ALTIVEC_BUILTIN_LVEHX:
!       return altivec_expand_binop_builtin (CODE_FOR_altivec_lvehx,
! 					   arglist, target);
      case ALTIVEC_BUILTIN_LVEWX:
!       return altivec_expand_binop_builtin (CODE_FOR_altivec_lvewx,
! 					   arglist, target);
      case ALTIVEC_BUILTIN_LVXL:
!       return altivec_expand_binop_builtin (CODE_FOR_altivec_lvxl,
! 					   arglist, target);
      case ALTIVEC_BUILTIN_LVX:
!       return altivec_expand_binop_builtin (CODE_FOR_altivec_lvx,
! 					   arglist, target);
      default:
        break;
        /* Fall through.  */
      }
  
!   /* Handle simple ternary operations.  */
!   d = (struct builtin_description *) bdesc_3arg;
!   for (i = 0; i < ARRAY_SIZE  (bdesc_3arg); i++, d++)
!     if (d->code == fcode)
!       return altivec_expand_ternop_builtin (d->icode, arglist, target);
! 
!   abort ();
    return NULL_RTX;
  }
  
--- 4198,4229 ----
    switch (fcode)
      {
      case ALTIVEC_BUILTIN_LVSL:
!       return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvsl,
  					   arglist, target);
      case ALTIVEC_BUILTIN_LVSR:
!       return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvsr,
! 					  arglist, target);
      case ALTIVEC_BUILTIN_LVEBX:
!       return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvebx,
! 					  arglist, target);
      case ALTIVEC_BUILTIN_LVEHX:
!       return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvehx,
! 					  arglist, target);
      case ALTIVEC_BUILTIN_LVEWX:
!       return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvewx,
! 					  arglist, target);
      case ALTIVEC_BUILTIN_LVXL:
!       return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvxl,
! 					  arglist, target);
      case ALTIVEC_BUILTIN_LVX:
!       return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvx,
! 					  arglist, target);
      default:
        break;
        /* Fall through.  */
      }
  
!   *expandedp = false;
    return NULL_RTX;
  }
  
*************** rs6000_expand_builtin (exp, target, subt
*** 4253,4262 ****
       enum machine_mode mode ATTRIBUTE_UNUSED;
       int ignore ATTRIBUTE_UNUSED;
  {
    if (TARGET_ALTIVEC)
!     return altivec_expand_builtin (exp, target);
  
    abort ();
  }
  
  static void
--- 4241,4282 ----
       enum machine_mode mode ATTRIBUTE_UNUSED;
       int ignore ATTRIBUTE_UNUSED;
  {
+   tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
+   tree arglist = TREE_OPERAND (exp, 1);
+   unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
+   struct builtin_description *d;
+   size_t i;
+   rtx ret;
+   bool success;
+   
    if (TARGET_ALTIVEC)
!     {
!       ret = altivec_expand_builtin (exp, target, &success);
! 
!       if (success)
! 	return ret;
!     }
! 
!   /* Handle simple unary operations.  */
!   d = (struct builtin_description *) bdesc_1arg;
!   for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
!     if (d->code == fcode)
!       return rs6000_expand_unop_builtin (d->icode, arglist, target);
! 
!   /* Handle simple binary operations.  */
!   d = (struct builtin_description *) bdesc_2arg;
!   for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
!     if (d->code == fcode)
!       return rs6000_expand_binop_builtin (d->icode, arglist, target);
! 
!   /* Handle simple ternary operations.  */
!   d = (struct builtin_description *) bdesc_3arg;
!   for (i = 0; i < ARRAY_SIZE  (bdesc_3arg); i++, d++)
!     if (d->code == fcode)
!       return rs6000_expand_ternop_builtin (d->icode, arglist, target);
  
    abort ();
+   return NULL_RTX;
  }
  
  static void


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