PATCH: pseudo conditional traps for ix86

Greg McGary greg@mcgary.org
Mon Aug 28 00:04:00 GMT 2000


2000-08-27  Greg McGary  <greg@mcgary.org>

	* config/i386/i386-protos.h (ix86_expand_compare): Add extern decl.
	* config/i386/i386.c (ix86_expand_compare): Remove `static'.
	* config/i386/i386.md (trap, conditional_trap): New insn & expand.

No regressions.

OK?

Index: gcc/config/i386/i386-protos.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/i386-protos.h,v
retrieving revision 1.24
diff -u -p -r1.24 i386-protos.h
--- i386-protos.h	2000/08/25 16:52:24	1.24
+++ i386-protos.h	2000/08/28 07:00:25
@@ -100,6 +100,7 @@ extern int ix86_unary_operator_ok PARAMS
 					 rtx[]));
 extern int ix86_match_ccmode PARAMS ((rtx, enum machine_mode));
 extern rtx ix86_expand_fp_compare PARAMS ((enum rtx_code, rtx, rtx, rtx));
+extern rtx ix86_expand_compare PARAMS ((enum rtx_code));
 extern int ix86_use_fcomi_compare PARAMS ((enum rtx_code));
 extern void ix86_expand_branch PARAMS ((enum rtx_code, rtx));
 extern int ix86_expand_setcc PARAMS ((enum rtx_code, rtx));
Index: gcc/config/i386/i386.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/i386.c,v
retrieving revision 1.173
diff -u -p -r1.173 i386.c
--- i386.c	2000/08/25 16:52:23	1.173
+++ i386.c	2000/08/28 07:00:27
@@ -402,7 +402,6 @@ static rtx ix86_expand_int_compare PARAM
 static enum machine_mode ix86_fp_compare_mode PARAMS ((enum rtx_code));
 static enum rtx_code ix86_prepare_fp_compare_args PARAMS ((enum rtx_code,
 							   rtx *, rtx *));
-static rtx ix86_expand_compare PARAMS ((enum rtx_code));
 static rtx gen_push PARAMS ((rtx));
 static int memory_address_length PARAMS ((rtx addr));
 static int ix86_flags_dependant PARAMS ((rtx, rtx, enum attr_type));
@@ -4897,7 +4896,7 @@ ix86_expand_fp_compare (code, op0, op1, 
 			 const0_rtx);
 }
 
-static rtx
+rtx
 ix86_expand_compare (code)
      enum rtx_code code;
 {
Index: gcc/config/i386/i386.md
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/i386.md,v
retrieving revision 1.172
diff -u -p -r1.172 i386.md
--- i386.md	2000/08/21 15:10:42	1.172
+++ i386.md	2000/08/28 07:00:28
@@ -11129,3 +11129,45 @@
     return \"call\\t%*%1\";
 }"
   [(set_attr "type" "callv")])
+
+(define_insn "trap"
+  [(trap_if (const_int 1) (const_int 5))]
+  ""
+  "int\\t$5")
+
+;;; ix86 doesn't have conditional trap instructions, but we fake them
+;;; for the sake of bounds checking.  By emitting bounds checks as
+;;; conditional traps rather than as conditional jumps around
+;;; unconditional traps we avoid introducing spurious basic-block
+;;; boundaries and facilitate elimination of redundant checks.  In
+;;; honor of the too-inflexible-for-BPs `bound' instruction, we use
+;;; interrupt 5.
+;;; 
+;;; FIXME: Static branch prediction rules for ix86 are such that
+;;; forward conditional branches predict as untaken.  As implemented
+;;; below, pseudo conditional traps violate that rule.  We should use
+;;; .pushsection/.popsection to place all of the `int 5's in a special
+;;; section loaded at the end of the text segment and branch forward
+;;; there on bounds-failure, and then jump back immediately (in case
+;;; the system chooses to ignore bounds violations, or to report
+;;; violations and continue execution).
+
+(define_expand "conditional_trap"
+  [(trap_if (match_operator 0 "comparison_operator"
+	     [(match_dup 2) (const_int 0)])
+	    (match_operand 1 "const_int_operand" ""))]
+  ""
+  "
+{
+  emit_insn (gen_rtx_TRAP_IF (VOIDmode,
+			      ix86_expand_compare (GET_CODE (operands[0])),
+			      operands[1]));
+  DONE;
+}")
+
+(define_insn ""
+  [(trap_if (match_operator 0 "comparison_operator"
+	     [(reg 17) (const_int 0)])
+	    (match_operand 1 "const_int_operand" ""))]
+  ""
+  "j%c0\\t1f\;int\\t%1\\n1:")


More information about the Gcc-patches mailing list