Hi,
this adds generic support for __builtin_bswap16 (only PowerPC has it for now).
It is mapped to the bswap optab in HImode, whose implementation is as follows:
- if a bswaphi2 pattern is present (PowerPC), it is directly used; or else
- if a rotlhi2/rotrhi2 pattern is present (x86), it is directly used, or else
- if ashlxx2 lshrxx2 are present (SPARC), they are used to open-code the
operation, or else,
- if a bswapsi2 pattern is present, it is used (with a final shift), otherwise
- the bswapsi2 libcall is used (with a final shift).
Since it is expected that most architectures will fall into one of the first 3
cases, no __bswaphi2 symbol is added to libgcc. And pass_optimize_bswap isn't
modified to recognize the builtin either, as this seems overkill to me.
Tested on x86, x86-64 and PowerPC Linux, OK for the mainline?
2012-04-09 Eric Botcazou ebotca...@adacore.com
PR target/52624
* doc/extend.texi (Other Builtins): Document __builtin_bswap16.
(PowerPC AltiVec/VSX Built-in Functions): Remove it.
* builtin-types.def (BT_UINT16): New primitive type.
(BT_FN_UINT16_UINT16): New function type.
* builtins.def (BUILT_IN_BSWAP16): New.
* builtins.c (expand_builtin_bswap): Add TARGET_MODE argument.
(expand_builtin) BUILT_IN_BSWAP16: New case. Pass TARGET_MODE to
expand_builtin_bswap.
* optabs.c (expand_unop): Deal with bswap in HImode specially. Add
missing bits for bswap to libcall code.
* tree.c (build_common_tree_nodes): Build uint16_type_node.
* tree.h (enum tree_index): Add TI_UINT16_TYPE.
(uint16_type_node): New define.
* config/rs6000/rs6000-builtin.def (RS6000_BUILTIN_BSWAP_HI): Delete.
* config/rs6000/rs6000.c (rs6000_expand_builtin): Remove handling of
above builtin.
(rs6000_init_builtins): Likewise.
* config/rs6000/rs6000.md (bswaphi2): Add TARGET_POWERPC predicate.
2012-04-09 Eric Botcazou ebotca...@adacore.com
c-family/
* c-common.h (uint16_type_node): Rename into...
(c_uint16_type_node): ...this.
* c-common.c (c_common_nodes_and_builtins): Adjust for above renaming.
* c-cppbuiltin.c (builtin_define_stdint_macros): Likewise.
2012-04-09 Eric Botcazou ebotca...@adacore.com
testsuite/
* gcc.dg/builtin-bswap-1.c: Test __builtin_bswap16 __builtin_bswap64.
* gcc.dg/builtin-bswap-4.c: Test __builtin_bswap16.
* gcc.dg/builtin-bswap-5.c: Likewise.
* gcc.target/i386/builtin-bswap-4.c: New test.
--
Eric Botcazou
Index: doc/extend.texi
===
--- doc/extend.texi (revision 186176)
+++ doc/extend.texi (working copy)
@@ -8535,12 +8535,17 @@ Similar to @code{__builtin_powi}, except
are @code{long double}.
@end deftypefn
-@deftypefn {Built-in Function} int32_t __builtin_bswap32 (int32_t x)
+@deftypefn {Built-in Function} int16_t __builtin_bswap16 (int16_t x)
Returns @var{x} with the order of the bytes reversed; for example,
-@code{0xaabbccdd} becomes @code{0xddccbbaa}. Byte here always means
+@code{0xaabb} becomes @code{0xbbaa}. Byte here always means
exactly 8 bits.
@end deftypefn
+@deftypefn {Built-in Function} int32_t __builtin_bswap32 (int32_t x)
+Similar to @code{__builtin_bswap16}, except the argument and return types
+are 32-bit.
+@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.
@@ -13426,7 +13431,6 @@ float __builtin_rsqrtf (float);
double __builtin_recipdiv (double, double);
double __builtin_rsqrt (double);
long __builtin_bpermd (long, long);
-int __builtin_bswap16 (int);
@end smallexample
The @code{vec_rsqrt}, @code{__builtin_rsqrt}, and
Index: c-family/c-common.c
===
--- c-family/c-common.c (revision 186176)
+++ c-family/c-common.c (working copy)
@@ -4991,7 +4991,7 @@ c_common_nodes_and_builtins (void)
uint8_type_node =
TREE_TYPE (identifier_global_value (c_get_ident (UINT8_TYPE)));
if (UINT16_TYPE)
-uint16_type_node =
+c_uint16_type_node =
TREE_TYPE (identifier_global_value (c_get_ident (UINT16_TYPE)));
if (UINT32_TYPE)
c_uint32_type_node =
Index: c-family/c-common.h
===
--- c-family/c-common.h (revision 186176)
+++ c-family/c-common.h (working copy)
@@ -390,7 +390,7 @@ extern const unsigned int num_c_common_r
#define int32_type_node c_global_trees[CTI_INT32_TYPE]
#define int64_type_node c_global_trees[CTI_INT64_TYPE]
#define uint8_type_node c_global_trees[CTI_UINT8_TYPE]
-#define uint16_type_node c_global_trees[CTI_UINT16_TYPE]
+#define c_uint16_type_node c_global_trees[CTI_UINT16_TYPE]
#define c_uint32_type_node c_global_trees[CTI_UINT32_TYPE]
#define c_uint64_type_node