From 525b61fa5e824f7469c861258b476790c2d6980c Mon Sep 17 00:00:00 2001 From: hjl Date: Thu, 21 May 2009 18:42:20 +0000 Subject: [PATCH] gcc/ 2009-05-21 H.J. Lu Uros Bizjak * config/i386/cpuid.h (bit_MOVBE): New. * config/i386/driver-i386.c (host_detect_local_cpu): Check movbe. * config/i386/i386.c (OPTION_MASK_ISA_MOVBE_SET): New. (OPTION_MASK_ISA_MOVBE_UNSET): Likewise. (ix86_handle_option): Handle OPT_mmovbe. (ix86_target_string): Add -mmovbe. (pta_flags): Add PTA_MOVBE. (processor_alias_table): Add PTA_MOVBE to "atom". (override_options): Handle PTA_MOVBE. * config/i386/i386.h (TARGET_MOVBE): New. * config/i386/i386.md (bswapsi2): Check TARGET_MOVBE. (*bswapsi_movbe): New. (*bswapdi_movbe): Likewise. (bswapdi2): Renamed to ... (*bswapdi_1): This. (bswapdi2): New expander. * config/i386/i386.opt (mmovbe): New. * doc/invoke.texi: Document -mmovbe. gcc/testsuite/ 2009-05-21 H.J. Lu * gcc.target/i386/movbe-1.c: New. * gcc.target/i386/movbe-2.c: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@147773 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 31 ++++++++++++++++++++++++- gcc/config/i386/cpuid.h | 1 + gcc/config/i386/driver-i386.c | 4 ++++ gcc/config/i386/i386.c | 25 ++++++++++++++++++-- gcc/config/i386/i386.h | 1 + gcc/config/i386/i386.md | 41 +++++++++++++++++++++++++++++++-- gcc/config/i386/i386.opt | 4 ++++ gcc/doc/invoke.texi | 7 +++++- gcc/testsuite/ChangeLog | 14 +++++++---- gcc/testsuite/gcc.target/i386/movbe-1.c | 18 +++++++++++++++ gcc/testsuite/gcc.target/i386/movbe-2.c | 19 +++++++++++++++ 11 files changed, 155 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/movbe-1.c create mode 100644 gcc/testsuite/gcc.target/i386/movbe-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 646ea22..c15abbe 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,9 +1,38 @@ +2009-05-21 H.J. Lu + Uros Bizjak + + * config/i386/cpuid.h (bit_MOVBE): New. + + * config/i386/driver-i386.c (host_detect_local_cpu): Check movbe. + + * config/i386/i386.c (OPTION_MASK_ISA_MOVBE_SET): New. + (OPTION_MASK_ISA_MOVBE_UNSET): Likewise. + (ix86_handle_option): Handle OPT_mmovbe. + (ix86_target_string): Add -mmovbe. + (pta_flags): Add PTA_MOVBE. + (processor_alias_table): Add PTA_MOVBE to "atom". + (override_options): Handle PTA_MOVBE. + + * config/i386/i386.h (TARGET_MOVBE): New. + + * config/i386/i386.md (bswapsi2): Check TARGET_MOVBE. + (*bswapsi_movbe): New. + (*bswapdi_movbe): Likewise. + (bswapdi2): Renamed to ... + (*bswapdi_1): This. + (bswapdi2): New expander. + + * config/i386/i386.opt (mmovbe): New. + + * doc/invoke.texi: Document -mmovbe. + 2009-05-21 Taras Glek * plugin.c (try_init_one_plugin): Updated to new plugin_init API. * gcc-plugin.h (plugin_init): Updated signature. * gcc-plugin.h (plugin_name_args): Moved to this header. - * doc/plugins.texi (plugin_init): Updated documention to reflect API change. + * doc/plugins.texi (plugin_init): Updated documention to reflect + API change. * doc/plugins.texi (plugin_name_args): Added to documention. 2009-05-21 Mark Mitchell diff --git a/gcc/config/i386/cpuid.h b/gcc/config/i386/cpuid.h index b525865..2d0916f 100644 --- a/gcc/config/i386/cpuid.h +++ b/gcc/config/i386/cpuid.h @@ -29,6 +29,7 @@ #define bit_CMPXCHG16B (1 << 13) #define bit_SSE4_1 (1 << 19) #define bit_SSE4_2 (1 << 20) +#define bit_MOVBE (1 << 22) #define bit_POPCNT (1 << 23) #define bit_AES (1 << 25) #define bit_XSAVE (1 << 26) diff --git a/gcc/config/i386/driver-i386.c b/gcc/config/i386/driver-i386.c index d4ba466..4fc0098 100644 --- a/gcc/config/i386/driver-i386.c +++ b/gcc/config/i386/driver-i386.c @@ -378,6 +378,7 @@ const char *host_detect_local_cpu (int argc, const char **argv) /* Extended features */ unsigned int has_lahf_lm = 0, has_sse4a = 0; unsigned int has_longmode = 0, has_3dnowp = 0, has_3dnow = 0; + unsigned int has_movbe = 0; bool arch; @@ -415,6 +416,7 @@ const char *host_detect_local_cpu (int argc, const char **argv) has_sse3 = ecx & bit_SSE3; has_ssse3 = ecx & bit_SSSE3; has_cmpxchg16b = ecx & bit_CMPXCHG16B; + has_movbe = ecx & bit_MOVBE; has_cmpxchg8b = edx & bit_CMPXCHG8B; has_cmov = edx & bit_CMOV; @@ -601,6 +603,8 @@ const char *host_detect_local_cpu (int argc, const char **argv) options = concat (options, "-mcx16 ", NULL); if (has_lahf_lm) options = concat (options, "-msahf ", NULL); + if (has_movbe) + options = concat (options, "-mmovbe", NULL); } done: diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 8be82f0..205691f 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -1965,9 +1965,11 @@ static int ix86_isa_flags_explicit; #define OPTION_MASK_ISA_ABM_SET \ (OPTION_MASK_ISA_ABM | OPTION_MASK_ISA_POPCNT) + #define OPTION_MASK_ISA_POPCNT_SET OPTION_MASK_ISA_POPCNT #define OPTION_MASK_ISA_CX16_SET OPTION_MASK_ISA_CX16 #define OPTION_MASK_ISA_SAHF_SET OPTION_MASK_ISA_SAHF +#define OPTION_MASK_ISA_MOVBE_SET OPTION_MASK_ISA_MOVBE /* Define a set of ISAs which aren't available when a given ISA is disabled. MMX and SSE ISAs are handled separately. */ @@ -2009,6 +2011,7 @@ static int ix86_isa_flags_explicit; #define OPTION_MASK_ISA_POPCNT_UNSET OPTION_MASK_ISA_POPCNT #define OPTION_MASK_ISA_CX16_UNSET OPTION_MASK_ISA_CX16 #define OPTION_MASK_ISA_SAHF_UNSET OPTION_MASK_ISA_SAHF +#define OPTION_MASK_ISA_MOVBE_UNSET OPTION_MASK_ISA_MOVBE /* Vectorization library interface and handlers. */ tree (*ix86_veclib_handler)(enum built_in_function, tree, tree) = NULL; @@ -2299,6 +2302,19 @@ ix86_handle_option (size_t code, const char *arg ATTRIBUTE_UNUSED, int value) } return true; + case OPT_mmovbe: + if (value) + { + ix86_isa_flags |= OPTION_MASK_ISA_MOVBE_SET; + ix86_isa_flags_explicit |= OPTION_MASK_ISA_MOVBE_SET; + } + else + { + ix86_isa_flags &= ~OPTION_MASK_ISA_MOVBE_UNSET; + ix86_isa_flags_explicit |= OPTION_MASK_ISA_MOVBE_UNSET; + } + return true; + case OPT_maes: if (value) { @@ -2361,6 +2377,7 @@ ix86_target_string (int isa, int flags, const char *arch, const char *tune, { "-mmmx", OPTION_MASK_ISA_MMX }, { "-mabm", OPTION_MASK_ISA_ABM }, { "-mpopcnt", OPTION_MASK_ISA_POPCNT }, + { "-mmovbe", OPTION_MASK_ISA_MOVBE }, { "-maes", OPTION_MASK_ISA_AES }, { "-mpclmul", OPTION_MASK_ISA_PCLMUL }, }; @@ -2577,7 +2594,8 @@ override_options (bool main_args_p) PTA_AES = 1 << 17, PTA_PCLMUL = 1 << 18, PTA_AVX = 1 << 19, - PTA_FMA = 1 << 20 + PTA_FMA = 1 << 20, + PTA_MOVBE = 1 << 21 }; static struct pta @@ -2621,7 +2639,7 @@ override_options (bool main_args_p) | PTA_SSSE3 | PTA_CX16}, {"atom", PROCESSOR_ATOM, CPU_ATOM, PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3 - | PTA_SSSE3 | PTA_CX16}, + | PTA_SSSE3 | PTA_CX16 | PTA_MOVBE}, {"geode", PROCESSOR_GEODE, CPU_GEODE, PTA_MMX | PTA_3DNOW | PTA_3DNOW_A |PTA_PREFETCH_SSE}, {"k6", PROCESSOR_K6, CPU_K6, PTA_MMX}, @@ -2935,6 +2953,9 @@ override_options (bool main_args_p) if (!(TARGET_64BIT && (processor_alias_table[i].flags & PTA_NO_SAHF)) && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SAHF)) ix86_isa_flags |= OPTION_MASK_ISA_SAHF; + if (processor_alias_table[i].flags & PTA_MOVBE + && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_MOVBE)) + ix86_isa_flags |= OPTION_MASK_ISA_MOVBE; if (processor_alias_table[i].flags & PTA_AES && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_AES)) ix86_isa_flags |= OPTION_MASK_ISA_AES; diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h index e42686b..1d7acf6 100644 --- a/gcc/config/i386/i386.h +++ b/gcc/config/i386/i386.h @@ -59,6 +59,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define TARGET_ABM OPTION_ISA_ABM #define TARGET_POPCNT OPTION_ISA_POPCNT #define TARGET_SAHF OPTION_ISA_SAHF +#define TARGET_MOVBE OPTION_ISA_MOVBE #define TARGET_AES OPTION_ISA_AES #define TARGET_PCLMUL OPTION_ISA_PCLMUL #define TARGET_CMPXCHG16B OPTION_ISA_CX16 diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 596f770..dbe781d 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -16105,7 +16105,7 @@ (bswap:SI (match_operand:SI 1 "register_operand" "")))] "" { - if (!TARGET_BSWAP) + if (!(TARGET_BSWAP || TARGET_MOVBE)) { rtx x = operands[0]; @@ -16117,6 +16117,21 @@ } }) +(define_insn "*bswapsi_movbe" + [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,m") + (bswap:SI (match_operand:SI 1 "nonimmediate_operand" "0,m,r")))] + "TARGET_MOVBE && !(MEM_P (operands[0]) && MEM_P (operands[1]))" + "@ + bswap\t%0 + movbe\t{%1, %0|%0, %1} + movbe\t{%1, %0|%0, %1}" + [(set_attr "type" "*,imov,imov") + (set_attr "modrm" "*,1,1") + (set_attr "prefix_0f" "1") + (set_attr "prefix_extra" "*,1,1") + (set_attr "length" "2,*,*") + (set_attr "mode" "SI")]) + (define_insn "*bswapsi_1" [(set (match_operand:SI 0 "register_operand" "=r") (bswap:SI (match_operand:SI 1 "register_operand" "0")))] @@ -16145,7 +16160,29 @@ [(set_attr "length" "4") (set_attr "mode" "HI")]) -(define_insn "bswapdi2" +(define_expand "bswapdi2" + [(set (match_operand:DI 0 "register_operand" "") + (bswap:DI (match_operand:DI 1 "register_operand" "")))] + "TARGET_64BIT" + "") + +(define_insn "*bswapdi_movbe" + [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m") + (bswap:DI (match_operand:DI 1 "nonimmediate_operand" "0,m,r")))] + "TARGET_64BIT && TARGET_MOVBE + && !(MEM_P (operands[0]) && MEM_P (operands[1]))" + "@ + bswap\t%0 + movbe\t{%1, %0|%0, %1} + movbe\t{%1, %0|%0, %1}" + [(set_attr "type" "*,imov,imov") + (set_attr "modrm" "*,1,1") + (set_attr "prefix_0f" "1") + (set_attr "prefix_extra" "*,1,1") + (set_attr "length" "3,*,*") + (set_attr "mode" "DI")]) + +(define_insn "*bswapdi_1" [(set (match_operand:DI 0 "register_operand" "=r") (bswap:DI (match_operand:DI 1 "register_operand" "0")))] "TARGET_64BIT" diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt index 6fd218f..e9be268 100644 --- a/gcc/config/i386/i386.opt +++ b/gcc/config/i386/i386.opt @@ -339,6 +339,10 @@ msahf Target Report Mask(ISA_SAHF) Var(ix86_isa_flags) VarExists Save Support code generation of sahf instruction in 64bit x86-64 code. +mmovbe +Target Report Mask(ISA_MOVBE) Var(ix86_isa_flags) VarExists Save +Support code generation of movbe instruction. + maes Target Report Mask(ISA_AES) Var(ix86_isa_flags) VarExists Save Support AES built-in functions and code generation diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 3dba074..db9df63 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -577,7 +577,7 @@ Objective-C and Objective-C++ Dialects}. -mno-wide-multiply -mrtd -malign-double @gol -mpreferred-stack-boundary=@var{num} -mincoming-stack-boundary=@var{num} --mcld -mcx16 -msahf -mrecip @gol +-mcld -mcx16 -msahf -mmovbe -mrecip @gol -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -msse4 -mavx @gol -maes -mpclmul @gol -msse4a -m3dnow -mpopcnt -mabm -msse5 @gol @@ -11458,6 +11458,11 @@ SAHF are load and store instructions, respectively, for certain status flags. In 64-bit mode, SAHF instruction is used to optimize @code{fmod}, @code{drem} or @code{remainder} built-in functions: see @ref{Other Builtins} for details. +@item -mmovbe +@opindex mmovbe +This option will enable GCC to use movbe instruction to implement +@code{__builtin_bswap32} and @code{__builtin_bswap64}. + @item -mrecip @opindex mrecip This option will enable GCC to use RCPSS and RSQRTSS instructions (and their diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f477d31..3f4f035 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,9 +1,15 @@ +2009-05-21 H.J. Lu + + * gcc.target/i386/movbe-1.c: New. + * gcc.target/i386/movbe-2.c: Likewise. + 2009-05-21 Taras Glek - * gcc.dg/plugin/selfassign.c (plugin_init): Updated to new plugin_init signature. - * g++.dg/plugin/selfassign.c (plugin_init): Updated to new plugin_init signature. - * g++.dg/plugin/dumb_plugin.c (plugin_init): Updated to new plugin_init signature. - * g++.dg/plugin/attribute_plugin.c (plugin_init): Updated to new plugin_init signature. + * gcc.dg/plugin/selfassign.c (plugin_init): Updated to new + plugin_init signature. + * g++.dg/plugin/selfassign.c (plugin_init): Likewise. + * g++.dg/plugin/dumb_plugin.c (plugin_init): Likewise. + * g++.dg/plugin/attribute_plugin.c (plugin_init): Likewise. 2009-05-21 Mark Mitchell diff --git a/gcc/testsuite/gcc.target/i386/movbe-1.c b/gcc/testsuite/gcc.target/i386/movbe-1.c new file mode 100644 index 0000000..391d4ad --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/movbe-1.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mmovbe" } */ + +extern int x; + +void +foo (int i) +{ + x = __builtin_bswap32 (i); +} + +int +bar () +{ + return __builtin_bswap32 (x); +} + +/* { dg-final { scan-assembler-times "movbe\[ \t\]" 2 } } */ diff --git a/gcc/testsuite/gcc.target/i386/movbe-2.c b/gcc/testsuite/gcc.target/i386/movbe-2.c new file mode 100644 index 0000000..d898f20 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/movbe-2.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mmovbe" } */ + +extern long long x; + +void +foo (long long i) +{ + x = __builtin_bswap64 (i); +} + +long long +bar () +{ + return __builtin_bswap64 (x); +} + +/* { dg-final { scan-assembler-times "movbe\[ \t\]" 4 { target ilp32 } } } */ +/* { dg-final { scan-assembler-times "movbe\[ \t\]" 2 { target lp64 } } } */ -- 2.7.4