patches/gcc/4.3.0/170-x86-emit-cld.patch
changeset 747 d3e603e7c17c
parent 746 b150d6f590fc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/patches/gcc/4.3.0/170-x86-emit-cld.patch	Mon Jul 28 21:32:33 2008 +0000
     1.3 @@ -0,0 +1,156 @@
     1.4 +Original patch from gentoo: gentoo/src/patchsets/gcc/4.3.0/gentoo/20_all_gcc-x86-emit-cld.patch
     1.5 +bandaid for the cld issue.  to be dropped when gcc-4.3 goes stable.
     1.6 +
     1.7 +http://gcc.gnu.org/ml/gcc-patches/2008-03/msg00417.html
     1.8 +
     1.9 +2008-03-06  Uros Bizjak  <ubizjak@gmail.com>
    1.10 +
    1.11 +	* config/i386/i386.h (TARGET_CLD): New define.
    1.12 +	(struct machine_function): Add needs_cld field.
    1.13 +	(ix86_current_function_needs_cld): New define.
    1.14 +	* config/i386/i386.md (UNSPEC_CLD): New unspec volatile constant.
    1.15 +	("cld"): New isns pattern.
    1.16 +	("strmov_singleop"): Set ix86_current_function_needs_cld flag.
    1.17 +	("rep_mov"): Ditto.
    1.18 +	("strset_singleop"): Ditto.
    1.19 +	("rep_stos"): Ditto.
    1.20 +	("cmpstrnqi_nz_1"): Ditto.
    1.21 +	("cmpstrnqi_1"): Ditto.
    1.22 +	("strlenqi_1"): Ditto.
    1.23 +	* config/i386/i386.c (ix86_expand_prologue): Emit cld insn for
    1.24 +	TARGET_CLD when ix86_current_function_needs_cld is set.
    1.25 +
    1.26 +diff -durN gcc-4.3.0.orig/gcc/config/i386/i386.c gcc-4.3.0/gcc/config/i386/i386.c
    1.27 +--- gcc-4.3.0.orig/gcc/config/i386/i386.c	2008-02-21 13:30:00.000000000 +0100
    1.28 ++++ gcc-4.3.0/gcc/config/i386/i386.c	2008-06-10 14:44:37.000000000 +0200
    1.29 +@@ -6448,6 +6448,10 @@
    1.30 + 	emit_insn (gen_prologue_use (pic_offset_table_rtx));
    1.31 +       emit_insn (gen_blockage ());
    1.32 +     }
    1.33 ++
    1.34 ++  /* Emit cld instruction if stringops are used in the function.  */
    1.35 ++  if (TARGET_CLD && ix86_current_function_needs_cld)
    1.36 ++    emit_insn (gen_cld ());
    1.37 + }
    1.38 + 
    1.39 + /* Emit code to restore saved registers using MOV insns.  First register
    1.40 +diff -durN gcc-4.3.0.orig/gcc/config/i386/i386.h gcc-4.3.0/gcc/config/i386/i386.h
    1.41 +--- gcc-4.3.0.orig/gcc/config/i386/i386.h	2008-02-15 09:12:02.000000000 +0100
    1.42 ++++ gcc-4.3.0/gcc/config/i386/i386.h	2008-06-10 14:44:37.000000000 +0200
    1.43 +@@ -388,6 +388,7 @@
    1.44 + 
    1.45 + extern int x86_prefetch_sse;
    1.46 + 
    1.47 ++#define TARGET_CLD		1
    1.48 + #define TARGET_ABM		x86_abm
    1.49 + #define TARGET_CMPXCHG16B	x86_cmpxchg16b
    1.50 + #define TARGET_POPCNT		x86_popcnt
    1.51 +@@ -2443,8 +2444,9 @@
    1.52 +   int save_varrargs_registers;
    1.53 +   int accesses_prev_frame;
    1.54 +   int optimize_mode_switching[MAX_386_ENTITIES];
    1.55 +-  /* Set by ix86_compute_frame_layout and used by prologue/epilogue expander to
    1.56 +-     determine the style used.  */
    1.57 ++  int needs_cld;
    1.58 ++  /* Set by ix86_compute_frame_layout and used by prologue/epilogue
    1.59 ++     expander to determine the style used.  */
    1.60 +   int use_fast_prologue_epilogue;
    1.61 +   /* Number of saved registers USE_FAST_PROLOGUE_EPILOGUE has been computed
    1.62 +      for.  */
    1.63 +@@ -2464,6 +2466,7 @@
    1.64 + #define ix86_stack_locals (cfun->machine->stack_locals)
    1.65 + #define ix86_save_varrargs_registers (cfun->machine->save_varrargs_registers)
    1.66 + #define ix86_optimize_mode_switching (cfun->machine->optimize_mode_switching)
    1.67 ++#define ix86_current_function_needs_cld (cfun->machine->needs_cld)
    1.68 + #define ix86_tls_descriptor_calls_expanded_in_cfun \
    1.69 +   (cfun->machine->tls_descriptor_call_expanded_p)
    1.70 + /* Since tls_descriptor_call_expanded is not cleared, even if all TLS
    1.71 +diff -durN gcc-4.3.0.orig/gcc/config/i386/i386.md gcc-4.3.0/gcc/config/i386/i386.md
    1.72 +--- gcc-4.3.0.orig/gcc/config/i386/i386.md	2008-02-06 12:34:00.000000000 +0100
    1.73 ++++ gcc-4.3.0/gcc/config/i386/i386.md	2008-06-10 14:44:37.000000000 +0200
    1.74 +@@ -205,6 +205,7 @@
    1.75 +    (UNSPECV_XCHG		12)
    1.76 +    (UNSPECV_LOCK		13)
    1.77 +    (UNSPECV_PROLOGUE_USE	14)
    1.78 ++   (UNSPECV_CLD			15)
    1.79 +   ])
    1.80 + 
    1.81 + ;; Constants to represent pcomtrue/pcomfalse variants
    1.82 +@@ -18529,6 +18530,14 @@
    1.83 + 
    1.84 + ;; Block operation instructions
    1.85 + 
    1.86 ++(define_insn "cld"
    1.87 ++  [(unspec_volatile [(const_int 0)] UNSPECV_CLD)]
    1.88 ++  ""
    1.89 ++  "cld"
    1.90 ++  [(set_attr "length" "1")
    1.91 ++   (set_attr "length_immediate" "0")
    1.92 ++   (set_attr "modrm" "0")])
    1.93 ++
    1.94 + (define_expand "movmemsi"
    1.95 +   [(use (match_operand:BLK 0 "memory_operand" ""))
    1.96 +    (use (match_operand:BLK 1 "memory_operand" ""))
    1.97 +@@ -18601,7 +18610,7 @@
    1.98 + 	      (set (match_operand 2 "register_operand" "")
    1.99 + 		   (match_operand 5 "" ""))])]
   1.100 +   "TARGET_SINGLE_STRINGOP || optimize_size"
   1.101 +-  "")
   1.102 ++  "ix86_current_function_needs_cld = 1;")
   1.103 + 
   1.104 + (define_insn "*strmovdi_rex_1"
   1.105 +   [(set (mem:DI (match_operand:DI 2 "register_operand" "0"))
   1.106 +@@ -18718,7 +18727,7 @@
   1.107 + 		   (match_operand 3 "memory_operand" ""))
   1.108 + 	      (use (match_dup 4))])]
   1.109 +   ""
   1.110 +-  "")
   1.111 ++  "ix86_current_function_needs_cld = 1;")
   1.112 + 
   1.113 + (define_insn "*rep_movdi_rex64"
   1.114 +   [(set (match_operand:DI 2 "register_operand" "=c") (const_int 0))
   1.115 +@@ -18878,7 +18887,7 @@
   1.116 + 	      (set (match_operand 0 "register_operand" "")
   1.117 + 		   (match_operand 3 "" ""))])]
   1.118 +   "TARGET_SINGLE_STRINGOP || optimize_size"
   1.119 +-  "")
   1.120 ++  "ix86_current_function_needs_cld = 1;")
   1.121 + 
   1.122 + (define_insn "*strsetdi_rex_1"
   1.123 +   [(set (mem:DI (match_operand:DI 1 "register_operand" "0"))
   1.124 +@@ -18972,7 +18981,7 @@
   1.125 + 	      (use (match_operand 3 "register_operand" ""))
   1.126 + 	      (use (match_dup 1))])]
   1.127 +   ""
   1.128 +-  "")
   1.129 ++  "ix86_current_function_needs_cld = 1;")
   1.130 + 
   1.131 + (define_insn "*rep_stosdi_rex64"
   1.132 +   [(set (match_operand:DI 1 "register_operand" "=c") (const_int 0))
   1.133 +@@ -19148,7 +19157,7 @@
   1.134 + 	      (clobber (match_operand 1 "register_operand" ""))
   1.135 + 	      (clobber (match_dup 2))])]
   1.136 +   ""
   1.137 +-  "")
   1.138 ++  "ix86_current_function_needs_cld = 1;")
   1.139 + 
   1.140 + (define_insn "*cmpstrnqi_nz_1"
   1.141 +   [(set (reg:CC FLAGS_REG)
   1.142 +@@ -19195,7 +19204,7 @@
   1.143 + 	      (clobber (match_operand 1 "register_operand" ""))
   1.144 + 	      (clobber (match_dup 2))])]
   1.145 +   ""
   1.146 +-  "")
   1.147 ++  "ix86_current_function_needs_cld = 1;")
   1.148 + 
   1.149 + (define_insn "*cmpstrnqi_1"
   1.150 +   [(set (reg:CC FLAGS_REG)
   1.151 +@@ -19264,7 +19273,7 @@
   1.152 + 	      (clobber (match_operand 1 "register_operand" ""))
   1.153 + 	      (clobber (reg:CC FLAGS_REG))])]
   1.154 +   ""
   1.155 +-  "")
   1.156 ++  "ix86_current_function_needs_cld = 1;")
   1.157 + 
   1.158 + (define_insn "*strlenqi_1"
   1.159 +   [(set (match_operand:SI 0 "register_operand" "=&c")