]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
2006-09-07 Eric Christopher <echristo@apple.com>
authorgeoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 1 Nov 2006 05:14:40 +0000 (05:14 +0000)
committergeoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 1 Nov 2006 05:14:40 +0000 (05:14 +0000)
    Falk Hueffner  <falk@debian.org>

* doc/extend.texi (__builtin_bswap32): Document.
(__builtin_bswap64): Ditto.
* doc/libgcc.texi (bswapsi2): Document.
(bswapdi2): Ditto.
* doc/rtl.texi (bswap): Document.
* optabs.c (expand_unop): Don't widen a bswap.
(init_optabs): Init bswap. Set libfuncs explicitly
for bswapsi2 and bswapdi2.
* optabs.h (OTI_bswap): New.
(bswap_optab): Ditto.
* genopinit.c (optabs): Handle bswap_optab.
* tree.h (tree_index): Add TI_UINT32_TYPE and
TI_UINT64_TYPE.
(uint32_type_node): New.
(uint64_type_node): Ditto.
* tree.c (build_common_tree_nodes_2): Initialize
uint32_type_node and uint64_type_node.
* builtins.c (expand_builtin_bswap): New.
(expand_builtin): Call.
(fold_builtin_bswap): New.
(fold_builtin_1): Call.
* fold-const.c (tree_expr_nonnegative_p): Return true
for bswap.
* builtin-types.def (BT_UINT32): New.
(BT_UINT64): Ditto.
(BT_FN_UINT32_UINT32): Ditto.
(BT_FN_UINT64_UINT64): Ditto.
* builtins.def (BUILT_IN_BSWAP32): New.
(BUILT_IN_BSWAP64): Ditto.
* rtl.def (BSWAP): New.
* genattrtab.c (check_attr_value): New.
* libgcc2.c (__bswapSI2): New.
(__bswapDI2): Ditto.
* libgcc2.h (__bswapSI2): Declare.
(__bswapDI2): Ditto.
* mklibgcc.in (lib2funcs): Add _bswapsi2 and _bswapdi2.
* simplify-rtx.c (simplify_const_unary_operation): Return
0 for BSWAP.
* libgcc-std.ver (__bwapsi2): Add.
(__bswapdi2): Ditto.
* reload1.c (eliminate_regs_1): Add bswap.
(elimination_effects): Ditto.
* config/i386/i386.h (x86_bswap): New.
(TARGET_BSWAP): Use.
* config/i386/i386.c (x86_bswap): Set.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@118361 138bc75d-0d04-0410-961f-82ee72b054a4

22 files changed:
gcc/ChangeLog
gcc/builtin-types.def
gcc/builtins.c
gcc/builtins.def
gcc/config/i386/i386.c
gcc/config/i386/i386.h
gcc/doc/extend.texi
gcc/doc/libgcc.texi
gcc/doc/rtl.texi
gcc/fold-const.c
gcc/genattrtab.c
gcc/libgcc-std.ver
gcc/libgcc2.c
gcc/libgcc2.h
gcc/mklibgcc.in
gcc/optabs.c
gcc/optabs.h
gcc/reload1.c
gcc/rtl.def
gcc/simplify-rtx.c
gcc/tree.c
gcc/tree.h

index c5cf3b556d983f4b676a0f6e76622d73f49a7b3b..e60fc548fef68512e70108507b044e87889fabb3 100644 (file)
@@ -1,3 +1,52 @@
+2006-09-07  Eric Christopher  <echristo@apple.com>
+           Falk Hueffner  <falk@debian.org>
+
+       * doc/extend.texi (__builtin_bswap32): Document.
+       (__builtin_bswap64): Ditto.
+       * doc/libgcc.texi (bswapsi2): Document.
+       (bswapdi2): Ditto.
+       * doc/rtl.texi (bswap): Document.
+       * optabs.c (expand_unop): Don't widen a bswap.
+       (init_optabs): Init bswap. Set libfuncs explicitly
+       for bswapsi2 and bswapdi2.
+       * optabs.h (OTI_bswap): New.
+       (bswap_optab): Ditto.
+       * genopinit.c (optabs): Handle bswap_optab.
+       * tree.h (tree_index): Add TI_UINT32_TYPE and
+       TI_UINT64_TYPE.
+       (uint32_type_node): New.
+       (uint64_type_node): Ditto.
+       * tree.c (build_common_tree_nodes_2): Initialize
+       uint32_type_node and uint64_type_node.
+       * builtins.c (expand_builtin_bswap): New.
+       (expand_builtin): Call.
+       (fold_builtin_bswap): New.
+       (fold_builtin_1): Call.
+       * fold-const.c (tree_expr_nonnegative_p): Return true
+       for bswap.
+       * builtin-types.def (BT_UINT32): New.
+       (BT_UINT64): Ditto.
+       (BT_FN_UINT32_UINT32): Ditto.
+       (BT_FN_UINT64_UINT64): Ditto.
+       * builtins.def (BUILT_IN_BSWAP32): New.
+       (BUILT_IN_BSWAP64): Ditto.
+       * rtl.def (BSWAP): New.
+       * genattrtab.c (check_attr_value): New.
+       * libgcc2.c (__bswapSI2): New.
+       (__bswapDI2): Ditto.
+       * libgcc2.h (__bswapSI2): Declare.
+       (__bswapDI2): Ditto.
+       * mklibgcc.in (lib2funcs): Add _bswapsi2 and _bswapdi2.
+       * simplify-rtx.c (simplify_const_unary_operation): Return
+       0 for BSWAP.
+       * libgcc-std.ver (__bwapsi2): Add.
+       (__bswapdi2): Ditto.
+       * reload1.c (eliminate_regs_1): Add bswap.
+       (elimination_effects): Ditto.
+       * config/i386/i386.h (x86_bswap): New.
+       (TARGET_BSWAP): Use.
+       * config/i386/i386.c (x86_bswap): Set.
+
 2006-10-31  Geoffrey Keating  <geoffk@apple.com>
 
        * coverage.c (coverage_checksum_string): Update comment.
index d6330b156525f9beea6a6cc2002487102d92ce89..5d42b2ef9aa866df1836c6eb9ae5f66364c48d3e 100644 (file)
@@ -75,6 +75,8 @@ DEF_PRIMITIVE_TYPE (BT_LONGLONG, long_long_integer_type_node)
 DEF_PRIMITIVE_TYPE (BT_ULONGLONG, long_long_unsigned_type_node)
 DEF_PRIMITIVE_TYPE (BT_INTMAX, intmax_type_node)
 DEF_PRIMITIVE_TYPE (BT_UINTMAX, uintmax_type_node)
+DEF_PRIMITIVE_TYPE (BT_UINT32, uint32_type_node)
+DEF_PRIMITIVE_TYPE (BT_UINT64, uint64_type_node)
 DEF_PRIMITIVE_TYPE (BT_WORD, (*lang_hooks.types.type_for_mode) (word_mode, 0))
 DEF_PRIMITIVE_TYPE (BT_FLOAT, float_type_node)
 DEF_PRIMITIVE_TYPE (BT_DOUBLE, double_type_node)
@@ -204,6 +206,10 @@ DEF_FUNCTION_TYPE_1 (BT_FN_DFLOAT128_DFLOAT128, BT_DFLOAT128, BT_DFLOAT128)
 DEF_FUNCTION_TYPE_1 (BT_FN_VOID_VPTR, BT_VOID, BT_VOLATILE_PTR)
 DEF_FUNCTION_TYPE_1 (BT_FN_VOID_PTRPTR, BT_VOID, BT_PTR_PTR)
 DEF_FUNCTION_TYPE_1 (BT_FN_UINT_UINT, BT_UINT, BT_UINT)
+DEF_FUNCTION_TYPE_1 (BT_FN_ULONG_ULONG, BT_ULONG, BT_ULONG)
+DEF_FUNCTION_TYPE_1 (BT_FN_ULONGLONG_ULONGLONG, BT_ULONGLONG, BT_ULONGLONG)
+DEF_FUNCTION_TYPE_1 (BT_FN_UINT32_UINT32, BT_UINT32, BT_UINT32)
+DEF_FUNCTION_TYPE_1 (BT_FN_UINT64_UINT64, BT_UINT64, BT_UINT64)
 
 DEF_POINTER_TYPE (BT_PTR_FN_VOID_PTR, BT_FN_VOID_PTR)
 
@@ -435,4 +441,3 @@ DEF_FUNCTION_TYPE_VAR_5 (BT_FN_INT_STRING_SIZE_INT_SIZE_CONST_STRING_VAR,
 DEF_POINTER_TYPE (BT_PTR_FN_VOID_VAR, BT_FN_VOID_VAR)
 DEF_FUNCTION_TYPE_3 (BT_FN_PTR_PTR_FN_VOID_VAR_PTR_SIZE,
                     BT_PTR, BT_PTR_FN_VOID_VAR, BT_PTR, BT_SIZE)
-
index 2184c714bdbaf7988c19998990a5dd0b65ef9c62..7bbd632c222f553ff9971631fc93c6a0d6618ccc 100644 (file)
@@ -4625,6 +4625,30 @@ expand_builtin_alloca (tree arglist, rtx target)
   return result;
 }
 
+/* Expand a call to a bswap builtin.  The arguments are in ARGLIST.  MODE
+   is the mode to expand with.  */
+
+static rtx
+expand_builtin_bswap (tree arglist, rtx target, rtx subtarget)
+{
+  enum machine_mode mode;
+  tree arg;
+  rtx op0;
+
+  if (!validate_arglist (arglist, INTEGER_TYPE, VOID_TYPE))
+    return 0;
+
+  arg = TREE_VALUE (arglist);
+  mode = TYPE_MODE (TREE_TYPE (arg));
+  op0 = expand_expr (arg, subtarget, VOIDmode, 0);
+
+  target = expand_unop (mode, bswap_optab, op0, target, 1);
+
+  gcc_assert (target);
+
+  return convert_to_mode (mode, target, 0);
+}
+
 /* Expand a call to a unary builtin.  The arguments are in ARGLIST.
    Return 0 if a normal call should be emitted rather than expanding the
    function in-line.  If convenient, the result should be placed in TARGET.
@@ -5903,6 +5927,14 @@ expand_builtin (tree exp, rtx target, rtx subtarget, enum machine_mode mode,
       expand_stack_restore (TREE_VALUE (arglist));
       return const0_rtx;
 
+    case BUILT_IN_BSWAP32:
+    case BUILT_IN_BSWAP64:
+      target = expand_builtin_bswap (arglist, target, subtarget);
+
+      if (target)
+       return target;
+      break;
+
     CASE_INT_FN (BUILT_IN_FFS):
     case BUILT_IN_FFSIMAX:
       target = expand_builtin_unop (target_mode, arglist, target,
@@ -7543,6 +7575,67 @@ fold_builtin_bitop (tree fndecl, tree arglist)
   return NULL_TREE;
 }
 
+/* Fold function call to builtin_bswap and the long and long long
+   variants.  Return NULL_TREE if no simplification can be made.  */
+static tree
+fold_builtin_bswap (tree fndecl, tree arglist)
+{
+  tree arg;
+
+  if (! validate_arglist (arglist, INTEGER_TYPE, VOID_TYPE))
+    return 0;
+
+  /* Optimize constant value.  */
+  arg = TREE_VALUE (arglist);
+  if (TREE_CODE (arg) == INTEGER_CST && ! TREE_CONSTANT_OVERFLOW (arg))
+    {
+      HOST_WIDE_INT hi, width, r_hi = 0;
+      unsigned HOST_WIDE_INT lo, r_lo = 0;
+      tree type;
+
+      type = TREE_TYPE (arg);
+      width = TYPE_PRECISION (type);
+      lo = TREE_INT_CST_LOW (arg);
+      hi = TREE_INT_CST_HIGH (arg);
+
+      switch (DECL_FUNCTION_CODE (fndecl))
+       {
+         case BUILT_IN_BSWAP32:
+         case BUILT_IN_BSWAP64:
+           {
+             int s;
+
+             for (s = 0; s < width; s += 8)
+               {
+                 int d = width - s - 8;
+                 unsigned HOST_WIDE_INT byte;
+
+                 if (s < HOST_BITS_PER_WIDE_INT)
+                   byte = (lo >> s) & 0xff;
+                 else
+                   byte = (hi >> (s - HOST_BITS_PER_WIDE_INT)) & 0xff;
+
+                 if (d < HOST_BITS_PER_WIDE_INT)
+                   r_lo |= byte << d;
+                 else
+                   r_hi |= byte << (d - HOST_BITS_PER_WIDE_INT);
+               }
+           }
+
+           break;
+
+       default:
+         gcc_unreachable ();
+       }
+
+      if (width < HOST_BITS_PER_WIDE_INT)
+       return build_int_cst (TREE_TYPE (TREE_TYPE (fndecl)), r_lo);
+      else
+       return build_int_cst_wide (TREE_TYPE (TREE_TYPE (fndecl)), r_lo, r_hi);
+    }
+
+  return NULL_TREE;
+}
 /* Return true if EXPR is the real constant contained in VALUE.  */
 
 static bool
@@ -9220,6 +9313,10 @@ fold_builtin_1 (tree fndecl, tree arglist, bool ignore)
     CASE_FLT_FN (BUILT_IN_LLRINT):
       return fold_fixed_mathfn (fndecl, arglist);
 
+    case BUILT_IN_BSWAP32:
+    case BUILT_IN_BSWAP64:
+      return fold_builtin_bswap (fndecl, arglist);
+
     CASE_INT_FN (BUILT_IN_FFS):
     CASE_INT_FN (BUILT_IN_CLZ):
     CASE_INT_FN (BUILT_IN_CTZ):
index 0e73cf440a40fb17e8e0f063c13d8624cf3b5022..d565f8cc33821747a03fc8ee80ef8911049fbc02 100644 (file)
@@ -594,6 +594,8 @@ DEF_EXT_LIB_BUILTIN    (BUILT_IN_ALLOCA, "alloca", BT_FN_PTR_SIZE, ATTR_MALLOC_N
 DEF_GCC_BUILTIN        (BUILT_IN_APPLY, "apply", BT_FN_PTR_PTR_FN_VOID_VAR_PTR_SIZE, ATTR_NULL)
 DEF_GCC_BUILTIN        (BUILT_IN_APPLY_ARGS, "apply_args", BT_FN_PTR_VAR, ATTR_NULL)
 DEF_GCC_BUILTIN        (BUILT_IN_ARGS_INFO, "args_info", BT_FN_INT_INT, ATTR_NULL)
+DEF_GCC_BUILTIN        (BUILT_IN_BSWAP32, "bswap32", BT_FN_UINT32_UINT32, ATTR_CONST_NOTHROW_LIST)
+DEF_GCC_BUILTIN        (BUILT_IN_BSWAP64, "bswap64", BT_FN_UINT64_UINT64, ATTR_CONST_NOTHROW_LIST)
 DEF_LIB_BUILTIN        (BUILT_IN_CALLOC, "calloc", BT_FN_PTR_SIZE_SIZE, ATTR_MALLOC_NOTHROW_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_CLASSIFY_TYPE, "classify_type", BT_FN_INT_VAR, ATTR_NULL)
 DEF_GCC_BUILTIN        (BUILT_IN_CLZ, "clz", BT_FN_INT_UINT, ATTR_CONST_NOTHROW_LIST)
index 074ce92e668b6af973dbda09fe704f9c974fa809..a7919dc8d2bc1b318ea5a631835fa400e4ec6be2 100644 (file)
@@ -885,6 +885,8 @@ const int x86_cmpxchg8b = ~(m_386 | m_486);
 const int x86_cmpxchg16b = m_NOCONA;
 /* Exchange and add was added for 80486.  */
 const int x86_xadd = ~m_386;
+/* Byteswap was added for 80486.  */
+const int x86_bswap = ~m_386;
 const int x86_pad_returns = m_ATHLON_K8 | m_GENERIC;
 
 /* In case the average insn count for single function invocation is
index 9fc54505ca882fd59f6a55ce9d570efe4f8db8e8..b40088ade4828792c3db614d8d702f642b74e701 100644 (file)
@@ -165,6 +165,7 @@ extern const int x86_use_bt;
 extern const int x86_cmpxchg, x86_cmpxchg8b, x86_cmpxchg16b, x86_xadd;
 extern const int x86_use_incdec;
 extern const int x86_pad_returns;
+extern const int x86_bswap;
 extern const int x86_partial_flag_reg_stall;
 extern int x86_prefetch_sse;
 
@@ -238,6 +239,7 @@ extern int x86_prefetch_sse;
 #define TARGET_CMPXCHG8B (x86_cmpxchg8b & (1 << ix86_arch))
 #define TARGET_CMPXCHG16B (x86_cmpxchg16b & (1 << ix86_arch))
 #define TARGET_XADD (x86_xadd & (1 << ix86_arch))
+#define TARGET_BSWAP (x86_bswap & (1 << ix86_arch))
 
 #ifndef TARGET_64BIT_DEFAULT
 #define TARGET_64BIT_DEFAULT 0
index 422c4220d56097e9c12b2a0c1ebd93cfa0e8850a..9ec4460bb6ac5cdc2568b0d9c6ef484575df9590 100644 (file)
@@ -6116,6 +6116,16 @@ Similar to @code{__builtin_powi}, except the argument and return types
 are @code{long double}.
 @end deftypefn
 
+@deftypefn {Built-in Function} int32_t __builtin_bswap32 (int32_t x)
+Returns @var{x} with the order of the bytes reversed; for example,
+@code{0xaabbccdd} becomes @code{0xddccbbaa}.  Byte here always means
+exactly 8 bits.
+@end deftypefn
+
+@deftypefn {Built-in Function} int64_t __builtin_bswap64 (int64_t x)
+Similar to @code{__builtin_bswap32}, except the argument and return types
+are 64-bit.
+@end deftypefn
 
 @node Target Builtins
 @section Built-in Functions Specific to Particular Target Machines
index f67b117f06d26bf48b32ffd995310dbddf7c5d66..fcc55d737c3bf4a70d2974f55c41d0eef6d74ba6 100644 (file)
@@ -212,6 +212,11 @@ These functions return the value zero if the number of bits set in
 These functions return the number of bits set in @var{a}.
 @end deftypefn
 
+@deftypefn {Runtime Function} int32_t __bswapsi2 (int32_t @var{a})
+@deftypefnx {Runtime Function} int64_t __bswapdi2 (int64_t @var{a})
+These functions return the @var{a} byteswapped.
+@end deftypefn
+
 @node Soft float library routines
 @section Routines for floating point emulation
 @cindex soft float library
@@ -728,4 +733,3 @@ document me!
 @deftypefn {Runtime Function} void __clear_cache (char *@var{beg}, char *@var{end})
 This function clears the instruction cache between @var{beg} and @var{end}.
 @end deftypefn
-
index 76e8f16face259af64394bdcc88d75c1bb628cf4..d97b2b327efe4b386bdedcd15ca63dec4568acd7 100644 (file)
@@ -2084,6 +2084,11 @@ mode @var{m}.  The mode of @var{x} will usually be an integer mode.
 Represents the number of 1-bits modulo 2 in @var{x}, represented as an
 integer of mode @var{m}.  The mode of @var{x} will usually be an integer
 mode.
+
+@findex bswap
+@item (bswap:@var{m} @var{x})
+Represents the value @var{x} with the order of bytes reversed, carried out
+in mode @var{m}, which must be a fixed-point machine mode.
 @end table
 
 @node Comparisons
index a718f1414dfa41930c9fb97f18ac700cbdfd44bf..0ac3c8656d2afca6dc74155da87926f1ee54d816 100644 (file)
@@ -12302,6 +12302,8 @@ tree_expr_nonnegative_p (tree t)
            CASE_INT_FN (BUILT_IN_FFS):
            CASE_INT_FN (BUILT_IN_PARITY):
            CASE_INT_FN (BUILT_IN_POPCOUNT):
+           case BUILT_IN_BSWAP32:
+           case BUILT_IN_BSWAP64:
              /* Always true.  */
              return true;
 
@@ -13241,4 +13243,3 @@ fold_strip_sign_ops (tree exp)
     }
   return NULL_TREE;
 }
-
index f11532f19beade33a4737bebaae419d98d002371..3e0fd9ed73cda281988fe59593ba147eac312406 100644 (file)
@@ -959,6 +959,7 @@ check_attr_value (rtx exp, struct attr_desc *attr)
     case CTZ:
     case POPCOUNT:
     case PARITY:
+    case BSWAP:
       XEXP (exp, 0) = check_attr_value (XEXP (exp, 0), attr);
       break;
 
index f8e9e52d0820d24ee70cbe6deebeff4dcb757fae..2d0a43df01d37dbd79460f6940a4bee2b6f40bb9 100644 (file)
@@ -274,3 +274,10 @@ GCC_4.2.0 {
   __floatuntitf
   _Unwind_GetIPInfo
 }
+
+%inherit GCC_4.3 GCC_4.2.0
+GCC_4.3.0 {
+  # byte swapping routines
+  __bswapsi2
+  __bswapdi2
+}
index d093616fe50534a9812d716490c05a7adf181db5..f3a0a2429708f1066681291230701992d7da809d 100644 (file)
@@ -492,6 +492,30 @@ __ashrdi3 (DWtype u, word_type b)
 }
 #endif
 \f
+#ifdef L_bswapsi2
+UWtype
+__bswapSI2 (UWtype u)
+{
+  return ((((u) & 0xff000000) >> 24)
+         | (((u) & 0x00ff0000) >>  8)
+         | (((u) & 0x0000ff00) <<  8)
+         | (((u) & 0x000000ff) << 24));
+}
+#endif
+#ifdef L_bswapdi2
+UDWtype
+__bswapDI2 (UDWtype u)
+{
+  return ((((u) & 0xff00000000000000ull) >> 56)
+         | (((u) & 0x00ff000000000000ull) >> 40)
+         | (((u) & 0x0000ff0000000000ull) >> 24)
+         | (((u) & 0x000000ff00000000ull) >>  8)
+         | (((u) & 0x00000000ff000000ull) <<  8)
+         | (((u) & 0x0000000000ff0000ull) << 24)
+         | (((u) & 0x000000000000ff00ull) << 40)
+         | (((u) & 0x00000000000000ffull) << 56));
+}
+#endif
 #ifdef L_ffssi2
 #undef int
 int
index c13f0c76bcceed89bf4776d1f9b55d493cac156a..1182ba3e92d11b97050c5befec4093ccf85b55d9 100644 (file)
@@ -304,11 +304,13 @@ typedef int word_type __attribute__ ((mode (__word__)));
 #define __ctzSI2       __NW(ctz,2)
 #define __popcountSI2  __NW(popcount,2)
 #define __paritySI2    __NW(parity,2)
+#define __bswapSI2     __NW(bswap,2)
 #define __ffsDI2       __NDW(ffs,2)
 #define __clzDI2       __NDW(clz,2)
 #define __ctzDI2       __NDW(ctz,2)
 #define __popcountDI2  __NDW(popcount,2)
 #define __parityDI2    __NDW(parity,2)
+#define __bswapDI2     __NDW(bswap,2)
 
 extern DWtype __muldi3 (DWtype, DWtype);
 extern DWtype __divdi3 (DWtype, DWtype);
@@ -345,11 +347,13 @@ extern Wtype __addvSI3 (Wtype, Wtype);
 extern Wtype __subvSI3 (Wtype, Wtype);
 extern Wtype __mulvSI3 (Wtype, Wtype);
 extern Wtype __negvSI2 (Wtype);
+extern UWtype __bswapSI2 (UWtype);
 extern DWtype __absvDI2 (DWtype);
 extern DWtype __addvDI3 (DWtype, DWtype);
 extern DWtype __subvDI3 (DWtype, DWtype);
 extern DWtype __mulvDI3 (DWtype, DWtype);
 extern DWtype __negvDI2 (DWtype);
+extern UDWtype __bswapDI2 (UDWtype);
 
 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
 extern SItype __absvsi2 (SItype);
index b4a31a6ca04acc768da9b3dbec1c8707e103f22d..60e390500ea03d3d5c30bdfa47409d6808bc28a6 100644 (file)
@@ -91,7 +91,7 @@ lib2funcs='_muldi3 _negdi2 _lshrdi3 _ashldi3 _ashrdi3
        _ffssi2 _ffsdi2 _clz _clzsi2 _clzdi2 _ctzsi2 _ctzdi2 _popcount_tab
        _popcountsi2 _popcountdi2 _paritysi2 _paritydi2 _powisf2 _powidf2
        _powixf2 _powitf2 _mulsc3 _muldc3 _mulxc3 _multc3 _divsc3 _divdc3
-       _divxc3 _divtc3'
+       _divxc3 _divtc3 _bswapsi2 _bswapdi2'
 
 if [ "$LIB2_SIDITI_CONV_FUNCS" ]; then
   for func in $swfloatfuncs; do
index 4f9374aa132ecb1b8550696c62e65979bc19ac3c..92887ab6b8dc221bca27e7c8bf6232015ec54979 100644 (file)
@@ -2590,6 +2590,10 @@ expand_unop (enum machine_mode mode, optab unoptab, rtx op0, rtx target,
        goto try_libcall;
     }
 
+  /* We can't widen a bswap.  */
+  if (unoptab == bswap_optab)
+    goto try_libcall;
+
   if (CLASS_HAS_WIDER_MODES_P (class))
     for (wider_mode = GET_MODE_WIDER_MODE (mode);
         wider_mode != VOIDmode;
@@ -5292,6 +5296,7 @@ init_optabs (void)
   absv_optab = init_optabv (ABS);
   addcc_optab = init_optab (UNKNOWN);
   one_cmpl_optab = init_optab (NOT);
+  bswap_optab = init_optab (BSWAP);
   ffs_optab = init_optab (FFS);
   clz_optab = init_optab (CLZ);
   ctz_optab = init_optab (CTZ);
@@ -5504,6 +5509,11 @@ init_optabs (void)
   init_interclass_conv_libfuncs (trunc_optab, "trunc", MODE_FLOAT, MODE_DECIMAL_FLOAT);
   init_interclass_conv_libfuncs (trunc_optab, "trunc", MODE_DECIMAL_FLOAT, MODE_FLOAT);
 
+  /* Explicitly initialize the bswap libfuncs since we need them to be
+     valid for things other than word_mode.  */
+  set_optab_libfunc (bswap_optab, SImode, "__bswapsi2");
+  set_optab_libfunc (bswap_optab, DImode, "__bswapdi2");
+
   /* Use cabs for double complex abs, since systems generally have cabs.
      Don't define any libcall for float complex, so that cabs will be used.  */
   if (complex_double_type_node)
index 0f84c9828d53efe27a30a419939ac709844b803d..b47e7623a2e6610e16704a3129413f3359ebf297 100644 (file)
@@ -146,6 +146,8 @@ enum optab_index
   /* Abs value */
   OTI_abs,
   OTI_absv,
+  /* Byteswap */
+  OTI_bswap,
   /* Bitwise not */
   OTI_one_cmpl,
   /* Bit scanning and counting */
@@ -312,6 +314,7 @@ extern GTY(()) optab optab_table[OTI_MAX];
 #define abs_optab (optab_table[OTI_abs])
 #define absv_optab (optab_table[OTI_absv])
 #define one_cmpl_optab (optab_table[OTI_one_cmpl])
+#define bswap_optab (optab_table[OTI_bswap])
 #define ffs_optab (optab_table[OTI_ffs])
 #define clz_optab (optab_table[OTI_clz])
 #define ctz_optab (optab_table[OTI_ctz])
index 353eeec825d9b16ef7e809284733858ff57495d1..e6443226e104f472f3d2021d0a6eb16102c1ce74 100644 (file)
@@ -2555,6 +2555,7 @@ eliminate_regs_1 (rtx x, enum machine_mode mem_mode, rtx insn,
     case CTZ:
     case POPCOUNT:
     case PARITY:
+    case BSWAP:
       new = eliminate_regs_1 (XEXP (x, 0), mem_mode, insn, false);
       if (new != XEXP (x, 0))
        return gen_rtx_fmt_e (code, GET_MODE (x), new);
@@ -2775,6 +2776,7 @@ elimination_effects (rtx x, enum machine_mode mem_mode)
     case CTZ:
     case POPCOUNT:
     case PARITY:
+    case BSWAP:
       elimination_effects (XEXP (x, 0), mem_mode);
       return;
 
index 847b51c6321790de91bf095ebc66e31da0f6ea95..cb37f1ab2b2b142d38602dc7af0f7c96d68574b7 100644 (file)
@@ -567,6 +567,9 @@ DEF_RTL_EXPR(ABS, "abs", "e", RTX_UNARY)
 /* Square root */
 DEF_RTL_EXPR(SQRT, "sqrt", "e", RTX_UNARY)
 
+/* Swap bytes.  */
+DEF_RTL_EXPR(BSWAP, "bswap", "e", RTX_UNARY)
+
 /* Find first bit that is set.
    Value is 1 + number of trailing zeros in the arg.,
    or 0 if arg is 0.  */
index fee07f9b5b8d720eb90bfa666e524e79cf6a717c..fe5463a3f27079470d901cf94d00dfa27f4dd47b 100644 (file)
@@ -1042,6 +1042,9 @@ simplify_const_unary_operation (enum rtx_code code, enum machine_mode mode,
          val &= 1;
          break;
 
+       case BSWAP:
+         return 0;
+
        case TRUNCATE:
          val = arg0;
          break;
@@ -4867,4 +4870,3 @@ simplify_rtx (rtx x)
     }
   return NULL;
 }
-
index d5e3f3f9eeca34b64d2c76bf0038b9e6d48eb100..5886e18da0a2ce3b71ba013007d8ab5b33dcccc2 100644 (file)
@@ -6576,6 +6576,10 @@ build_common_tree_nodes_2 (int short_double)
   long_double_ptr_type_node = build_pointer_type (long_double_type_node);
   integer_ptr_type_node = build_pointer_type (integer_type_node);
 
+  /* Fixed size integer types.  */
+  uint32_type_node = build_nonstandard_integer_type (32, true);
+  uint64_type_node = build_nonstandard_integer_type (64, true);
+
   /* Decimal float types. */
   dfloat32_type_node = make_node (REAL_TYPE);
   TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE; 
index 013232bc1b7b5cc66f0405b5a371bf45a2efc9b1..52a04c40eedac261ead662fd0bf5a29f7f3c1f7f 100644 (file)
@@ -3217,6 +3217,9 @@ enum tree_index
   TI_UINTDI_TYPE,
   TI_UINTTI_TYPE,
 
+  TI_UINT32_TYPE,
+  TI_UINT64_TYPE,
+
   TI_INTEGER_ZERO,
   TI_INTEGER_ONE,
   TI_INTEGER_MINUS_ONE,
@@ -3292,6 +3295,9 @@ extern GTY(()) tree global_trees[TI_MAX];
 #define unsigned_intDI_type_node       global_trees[TI_UINTDI_TYPE]
 #define unsigned_intTI_type_node       global_trees[TI_UINTTI_TYPE]
 
+#define uint32_type_node               global_trees[TI_UINT32_TYPE]
+#define uint64_type_node               global_trees[TI_UINT64_TYPE]
+
 #define integer_zero_node              global_trees[TI_INTEGER_ZERO]
 #define integer_one_node               global_trees[TI_INTEGER_ONE]
 #define integer_minus_one_node         global_trees[TI_INTEGER_MINUS_ONE]