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]

[RFC,PATCH] 2 new mode attributes to replace mode(word) uses in libgcc


Hi,

the attached patch introduces two new mode attributes to replace
specific uses of mode(word) in libgcc.  libgcc uses mode(word) to
define efficient types for the return value of libgcc cmp instructions
and for shift count operands.  The two new mode attributes can be
configured using target hooks and default to word_mode in order to
sustain the current behaviour for targets which don't intend to play
around with UNITS_PER_WORD like we and rs6000 like to do.

Bootstrapped on s390x. No testsuite regressions.
Boostraps on s390 and i686 are still running.

Ok for mainline given no testsuite regressions occur?

Bye, 

-Andreas-


Index: gcc/libgcc2.h
===================================================================
*** gcc/libgcc2.h.orig	2007-05-09 16:04:09.000000000 +0200
--- gcc/libgcc2.h	2007-05-09 16:04:37.000000000 +0200
*************** typedef		float TFtype	__attribute__ ((mo
*** 173,179 ****
  typedef _Complex float TCtype	__attribute__ ((mode (TC)));
  #endif
  
! typedef int word_type __attribute__ ((mode (__word__)));
  
  /* Make sure that we don't accidentally use any normal C language built-in
     type names in the first part of this file.  Instead we want to use *only*
--- 173,180 ----
  typedef _Complex float TCtype	__attribute__ ((mode (TC)));
  #endif
  
! typedef int cmp_return_type __attribute__((mode (__libgcc_cmp_return__)));
! typedef int shift_count_type __attribute__((mode (__libgcc_shift_count__)));
  
  /* Make sure that we don't accidentally use any normal C language built-in
     type names in the first part of this file.  Instead we want to use *only*
*************** extern UDWtype __udivmoddi4 (UDWtype, UD
*** 329,337 ****
  extern DWtype __negdi2 (DWtype);
  #endif
  
! extern DWtype __lshrdi3 (DWtype, word_type);
! extern DWtype __ashldi3 (DWtype, word_type);
! extern DWtype __ashrdi3 (DWtype, word_type);
  
  /* __udiv_w_sdiv is static inline when building other libgcc2 portions.  */
  #if (!defined(L_udivdi3) && !defined(L_divdi3) && \
--- 330,338 ----
  extern DWtype __negdi2 (DWtype);
  #endif
  
! extern DWtype __lshrdi3 (DWtype, shift_count_type);
! extern DWtype __ashldi3 (DWtype, shift_count_type);
! extern DWtype __ashrdi3 (DWtype, shift_count_type);
  
  /* __udiv_w_sdiv is static inline when building other libgcc2 portions.  */
  #if (!defined(L_udivdi3) && !defined(L_divdi3) && \
*************** extern DWtype __ashrdi3 (DWtype, word_ty
*** 339,346 ****
  extern UWtype __udiv_w_sdiv (UWtype *, UWtype, UWtype, UWtype);
  #endif
  
! extern word_type __cmpdi2 (DWtype, DWtype);
! extern word_type __ucmpdi2 (DWtype, DWtype);
  
  extern Wtype __absvSI2 (Wtype);
  extern Wtype __addvSI3 (Wtype, Wtype);
--- 340,347 ----
  extern UWtype __udiv_w_sdiv (UWtype *, UWtype, UWtype, UWtype);
  #endif
  
! extern cmp_return_type __cmpdi2 (DWtype, DWtype);
! extern cmp_return_type __ucmpdi2 (DWtype, DWtype);
  
  extern Wtype __absvSI2 (Wtype);
  extern Wtype __addvSI3 (Wtype, Wtype);
Index: gcc/libgcc2.c
===================================================================
*** gcc/libgcc2.c.orig	2007-05-09 16:04:09.000000000 +0200
--- gcc/libgcc2.c	2007-05-09 16:04:37.000000000 +0200
*************** __mulvDI3 (DWtype u, DWtype v)
*** 406,421 ****
  
  
  /* Unless shift functions are defined with full ANSI prototypes,
!    parameter b will be promoted to int if word_type is smaller than an int.  */
  #ifdef L_lshrdi3
  DWtype
! __lshrdi3 (DWtype u, word_type b)
  {
    if (b == 0)
      return u;
  
    const DWunion uu = {.ll = u};
!   const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
    DWunion w;
  
    if (bm <= 0)
--- 406,421 ----
  
  
  /* Unless shift functions are defined with full ANSI prototypes,
!    parameter b will be promoted to int if shift_count_type is smaller than an int.  */
  #ifdef L_lshrdi3
  DWtype
! __lshrdi3 (DWtype u, shift_count_type b)
  {
    if (b == 0)
      return u;
  
    const DWunion uu = {.ll = u};
!   const shift_count_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
    DWunion w;
  
    if (bm <= 0)
*************** __lshrdi3 (DWtype u, word_type b)
*** 437,449 ****
  
  #ifdef L_ashldi3
  DWtype
! __ashldi3 (DWtype u, word_type b)
  {
    if (b == 0)
      return u;
  
    const DWunion uu = {.ll = u};
!   const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
    DWunion w;
  
    if (bm <= 0)
--- 437,449 ----
  
  #ifdef L_ashldi3
  DWtype
! __ashldi3 (DWtype u, shift_count_type b)
  {
    if (b == 0)
      return u;
  
    const DWunion uu = {.ll = u};
!   const shift_count_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
    DWunion w;
  
    if (bm <= 0)
*************** __ashldi3 (DWtype u, word_type b)
*** 465,477 ****
  
  #ifdef L_ashrdi3
  DWtype
! __ashrdi3 (DWtype u, word_type b)
  {
    if (b == 0)
      return u;
  
    const DWunion uu = {.ll = u};
!   const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
    DWunion w;
  
    if (bm <= 0)
--- 465,477 ----
  
  #ifdef L_ashrdi3
  DWtype
! __ashrdi3 (DWtype u, shift_count_type b)
  {
    if (b == 0)
      return u;
  
    const DWunion uu = {.ll = u};
!   const shift_count_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
    DWunion w;
  
    if (bm <= 0)
*************** __udivmoddi4 (UDWtype n, UDWtype d, UDWt
*** 1082,1088 ****
  DWtype
  __divdi3 (DWtype u, DWtype v)
  {
!   word_type c = 0;
    DWunion uu = {.ll = u};
    DWunion vv = {.ll = v};
    DWtype w;
--- 1082,1088 ----
  DWtype
  __divdi3 (DWtype u, DWtype v)
  {
!   Wtype c = 0;
    DWunion uu = {.ll = u};
    DWunion vv = {.ll = v};
    DWtype w;
*************** __divdi3 (DWtype u, DWtype v)
*** 1106,1112 ****
  DWtype
  __moddi3 (DWtype u, DWtype v)
  {
!   word_type c = 0;
    DWunion uu = {.ll = u};
    DWunion vv = {.ll = v};
    DWtype w;
--- 1106,1112 ----
  DWtype
  __moddi3 (DWtype u, DWtype v)
  {
!   Wtype c = 0;
    DWunion uu = {.ll = u};
    DWunion vv = {.ll = v};
    DWtype w;
*************** __udivdi3 (UDWtype n, UDWtype d)
*** 1146,1152 ****
  #endif
  
  #ifdef L_cmpdi2
! word_type
  __cmpdi2 (DWtype a, DWtype b)
  {
    const DWunion au = {.ll = a};
--- 1146,1152 ----
  #endif
  
  #ifdef L_cmpdi2
! cmp_return_type
  __cmpdi2 (DWtype a, DWtype b)
  {
    const DWunion au = {.ll = a};
*************** __cmpdi2 (DWtype a, DWtype b)
*** 1165,1171 ****
  #endif
  
  #ifdef L_ucmpdi2
! word_type
  __ucmpdi2 (DWtype a, DWtype b)
  {
    const DWunion au = {.ll = a};
--- 1165,1171 ----
  #endif
  
  #ifdef L_ucmpdi2
! cmp_return_type
  __ucmpdi2 (DWtype a, DWtype b)
  {
    const DWunion au = {.ll = a};
Index: gcc/c-common.c
===================================================================
*** gcc/c-common.c.orig	2007-05-09 16:04:09.000000000 +0200
--- gcc/c-common.c	2007-05-09 16:04:37.000000000 +0200
*************** handle_mode_attribute (tree *node, tree 
*** 4943,4948 ****
--- 4943,4952 ----
  	mode = word_mode;
        else if (!strcmp (p, "pointer"))
  	mode = ptr_mode;
+       else if (!strcmp (p, "libgcc_cmp_return"))
+ 	mode = targetm.libgcc_cmp_return_mode ();
+       else if (!strcmp (p, "libgcc_shift_count"))
+ 	mode = targetm.libgcc_shift_count_mode ();
        else
  	for (j = 0; j < NUM_MACHINE_MODES; j++)
  	  if (!strcmp (p, GET_MODE_NAME (j)))
Index: gcc/target-def.h
===================================================================
*** gcc/target-def.h.orig	2007-05-09 16:04:09.000000000 +0200
--- gcc/target-def.h	2007-05-09 16:47:28.000000000 +0200
*************** Foundation, 51 Franklin Street, Fifth Fl
*** 371,376 ****
--- 371,380 ----
  /* In except.c */
  #define TARGET_EH_RETURN_FILTER_MODE  default_eh_return_filter_mode
  
+ /* In libgcc2.c */
+ #define TARGET_LIBGCC_CMP_RETURN_MODE  default_libgcc_cmp_return_mode
+ #define TARGET_LIBGCC_SHIFT_COUNT_MODE default_libgcc_shift_count_mode
+ 
  /* In tree.c.  */
  #define TARGET_MERGE_DECL_ATTRIBUTES merge_decl_attributes
  #define TARGET_MERGE_TYPE_ATTRIBUTES merge_type_attributes
*************** Foundation, 51 Franklin Street, Fifth Fl
*** 649,654 ****
--- 653,660 ----
    TARGET_DEFAULT_TARGET_FLAGS,			\
    TARGET_HANDLE_OPTION,				\
    TARGET_EH_RETURN_FILTER_MODE,			\
+   TARGET_LIBGCC_CMP_RETURN_MODE,                \
+   TARGET_LIBGCC_SHIFT_COUNT_MODE,               \
    TARGET_MERGE_DECL_ATTRIBUTES,			\
    TARGET_MERGE_TYPE_ATTRIBUTES,			\
    TARGET_ATTRIBUTE_TABLE,			\
Index: gcc/targhooks.c
===================================================================
*** gcc/targhooks.c.orig	2007-05-09 16:04:09.000000000 +0200
--- gcc/targhooks.c	2007-05-09 16:04:37.000000000 +0200
*************** default_eh_return_filter_mode (void)
*** 140,145 ****
--- 140,157 ----
    return word_mode;
  }
  
+ enum machine_mode
+ default_libgcc_cmp_return_mode (void)
+ {
+   return word_mode;
+ }
+ 
+ enum machine_mode
+ default_libgcc_shift_count_mode (void)
+ {
+   return word_mode;
+ }
+ 
  /* The default implementation of TARGET_SHIFT_TRUNCATION_MASK.  */
  
  unsigned HOST_WIDE_INT
Index: gcc/targhooks.h
===================================================================
*** gcc/targhooks.h.orig	2007-05-09 16:04:09.000000000 +0200
--- gcc/targhooks.h	2007-05-09 16:04:37.000000000 +0200
*************** extern rtx default_builtin_setjmp_frame_
*** 31,36 ****
--- 31,38 ----
  extern bool default_pretend_outgoing_varargs_named (CUMULATIVE_ARGS *);
  
  extern enum machine_mode default_eh_return_filter_mode (void);
+ extern enum machine_mode default_libgcc_cmp_return_mode (void);
+ extern enum machine_mode default_libgcc_shift_count_mode (void);
  extern unsigned HOST_WIDE_INT default_shift_truncation_mask
    (enum machine_mode);
  extern unsigned int default_min_divisions_for_recip_mul (enum machine_mode);
Index: gcc/doc/tm.texi
===================================================================
*** gcc/doc/tm.texi.orig	2007-05-09 16:04:09.000000000 +0200
--- gcc/doc/tm.texi	2007-05-09 16:12:00.000000000 +0200
*************** You would most commonly define this macr
*** 1327,1332 ****
--- 1327,1346 ----
  pattern needs to support both a 32- and a 64-bit mode.
  @end defmac
  
+ @deftypefn {Target Hook} {enum machine_mode} TARGET_LIBGCC_CMP_RETURN_MODE ()
+ This target hook should return the mode to be used for the return value
+ of compare instructions expanded to libgcc calls.  If not defined
+ @code{word_mode} is returned which is the right choice for a majority of
+ targets.
+ @end deftypefn
+ 
+ @deftypefn {Target Hook} {enum machine_mode} TARGET_LIBGCC_SHIFT_COUNT_MODE ()
+ This target hook should return the mode to be used for the shift count operand
+ of shift instructions expanded to libgcc calls.  If not defined
+ @code{word_mode} is returned which is the right choice for a majority of
+ targets.
+ @end deftypefn
+ 
  @defmac TARGET_FLOAT_FORMAT
  A code distinguishing the floating point format of the target machine.
  There are four defined values:
Index: gcc/config/s390/s390.c
===================================================================
*** gcc/config/s390/s390.c.orig	2007-05-09 16:04:09.000000000 +0200
--- gcc/config/s390/s390.c	2007-05-10 10:19:58.000000000 +0200
*************** struct machine_function GTY(())
*** 322,327 ****
--- 322,339 ----
  #define REGNO_PAIR_OK(REGNO, MODE)                               \
    (HARD_REGNO_NREGS ((REGNO), (MODE)) == 1 || !((REGNO) & 1))
  
+ static enum machine_mode
+ s390_libgcc_cmp_return_mode (void)
+ {
+   return TARGET_64BIT ? DImode : SImode;
+ }
+ 
+ static enum machine_mode
+ s390_libgcc_shift_count_mode (void)
+ {
+   return TARGET_64BIT ? DImode : SImode;
+ }
+ 
  /* Return true if the back end supports mode MODE.  */
  static bool
  s390_scalar_mode_supported_p (enum machine_mode mode)
*************** s390_reorg (void)
*** 9339,9344 ****
--- 9351,9362 ----
  #undef TARGET_SECONDARY_RELOAD
  #define TARGET_SECONDARY_RELOAD s390_secondary_reload
  
+ #undef TARGET_LIBGCC_CMP_RETURN_MODE
+ #define TARGET_LIBGCC_CMP_RETURN_MODE s390_libgcc_cmp_return_mode
+ 
+ #undef TARGET_LIBGCC_SHIFT_COUNT_MODE
+ #define TARGET_LIBGCC_SHIFT_COUNT_MODE s390_libgcc_shift_count_mode
+ 
  struct gcc_target targetm = TARGET_INITIALIZER;
  
  #include "gt-s390.h"
Index: gcc/target.h
===================================================================
*** gcc/target.h.orig	2007-03-12 10:02:04.000000000 +0100
--- gcc/target.h	2007-05-09 16:24:13.000000000 +0200
*************** struct gcc_target
*** 428,433 ****
--- 428,439 ----
    /* Return machine mode for filter value.  */
    enum machine_mode (* eh_return_filter_mode) (void);
  
+   /* Return machine mode for libgcc expanded cmp instructions.  */
+   enum machine_mode (* libgcc_cmp_return_mode) (void);
+ 
+   /* Return machine mode for libgcc expanded shift instructions.  */
+   enum machine_mode (* libgcc_shift_count_mode) (void);
+ 
    /* Given two decls, merge their attributes and return the result.  */
    tree (* merge_decl_attributes) (tree, tree);
  


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