[patch] Add generic __builtin_bswap16 support

Eric Botcazou ebotcazou@adacore.com
Mon Apr 9 21:45:00 GMT 2012


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  <ebotcazou@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  <ebotcazou@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  <ebotcazou@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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr52624.diff
Type: text/x-diff
Size: 15956 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20120409/37f384f1/attachment.bin>


More information about the Gcc-patches mailing list