Patchwork [i386] : Introduce FRNDINT_ROUNDING int iterator

login
register
mail settings
Submitter Uros Bizjak
Date June 19, 2012, 4:27 p.m.
Message ID <CAFULd4a-fyquvwBSP9v8t-Zx=GoLubdX1eemMoJMvFREFhe3hw@mail.gmail.com>
Download mbox | patch
Permalink /patch/165810/
State New
Headers show

Comments

Uros Bizjak - June 19, 2012, 4:27 p.m.
Hello!

2012-06-19  Uros Bizjak  <ubizjak@gmail.com>

	* config/i386/i386.md (FRNDINT_ROUNDING): New int iterator.
	(rounding): New int attribute.
	(ROUNDING): Ditto.
	(frndintxf2_<rounding>): Macroize insn from
	frndintxf2_{floor,ceil,trunc} using FRNDINT_ROUNDING int iterator.
	(frndintxf2_<rounding>_i387): Macroize insn from
	frndintxf2_{floor,ceil,trunc}_i387 using FRNDINT_ROUNDING int iterator.

Bootstrapped and regression tested on x86_64-pc-linux-gnu {,-m32}.
Will be committed to mainline SVN.

BTW: A follow-up patch will also macroize fist<mode>2_{floor,ceil} and friends.

Uros.

Patch

Index: i386.md
===================================================================
--- i386.md	(revision 188781)
+++ i386.md	(working copy)
@@ -15099,11 +15099,26 @@ 
   DONE;
 })
 
+(define_int_iterator FRNDINT_ROUNDING
+	[UNSPEC_FRNDINT_FLOOR
+	 UNSPEC_FRNDINT_CEIL
+	 UNSPEC_FRNDINT_TRUNC])
+
+(define_int_attr rounding
+	[(UNSPEC_FRNDINT_FLOOR "floor")
+	 (UNSPEC_FRNDINT_CEIL "ceil")
+	 (UNSPEC_FRNDINT_TRUNC "trunc")])
+
+(define_int_attr ROUNDING
+	[(UNSPEC_FRNDINT_FLOOR "FLOOR")
+	 (UNSPEC_FRNDINT_CEIL "CEIL")
+	 (UNSPEC_FRNDINT_TRUNC "TRUNC")])
+
 ;; Rounding mode control word calculation could clobber FLAGS_REG.
-(define_insn_and_split "frndintxf2_floor"
+(define_insn_and_split "frndintxf2_<rounding>"
   [(set (match_operand:XF 0 "register_operand")
 	(unspec:XF [(match_operand:XF 1 "register_operand")]
-	 UNSPEC_FRNDINT_FLOOR))
+		   FRNDINT_ROUNDING))
    (clobber (reg:CC FLAGS_REG))]
   "TARGET_USE_FANCY_MATH_387
    && flag_unsafe_math_optimizations
@@ -15112,30 +15127,30 @@ 
   "&& 1"
   [(const_int 0)]
 {
-  ix86_optimize_mode_switching[I387_FLOOR] = 1;
+  ix86_optimize_mode_switching[I387_<ROUNDING>] = 1;
 
   operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
-  operands[3] = assign_386_stack_local (HImode, SLOT_CW_FLOOR);
+  operands[3] = assign_386_stack_local (HImode, SLOT_CW_<ROUNDING>);
 
-  emit_insn (gen_frndintxf2_floor_i387 (operands[0], operands[1],
-					operands[2], operands[3]));
+  emit_insn (gen_frndintxf2_<rounding>_i387 (operands[0], operands[1],
+					     operands[2], operands[3]));
   DONE;
 }
   [(set_attr "type" "frndint")
-   (set_attr "i387_cw" "floor")
+   (set_attr "i387_cw" "<rounding>")
    (set_attr "mode" "XF")])
 
-(define_insn "frndintxf2_floor_i387"
+(define_insn "frndintxf2_<rounding>_i387"
   [(set (match_operand:XF 0 "register_operand" "=f")
 	(unspec:XF [(match_operand:XF 1 "register_operand" "0")]
-	 UNSPEC_FRNDINT_FLOOR))
+		   FRNDINT_ROUNDING))
    (use (match_operand:HI 2 "memory_operand" "m"))
    (use (match_operand:HI 3 "memory_operand" "m"))]
   "TARGET_USE_FANCY_MATH_387
    && flag_unsafe_math_optimizations"
   "fldcw\t%3\n\tfrndint\n\tfldcw\t%2"
   [(set_attr "type" "frndint")
-   (set_attr "i387_cw" "floor")
+   (set_attr "i387_cw" "<rounding>")
    (set_attr "mode" "XF")])
 
 (define_expand "floorxf2"
@@ -15357,45 +15372,6 @@ 
   DONE;
 })
 
-;; Rounding mode control word calculation could clobber FLAGS_REG.
-(define_insn_and_split "frndintxf2_ceil"
-  [(set (match_operand:XF 0 "register_operand")
-	(unspec:XF [(match_operand:XF 1 "register_operand")]
-	 UNSPEC_FRNDINT_CEIL))
-   (clobber (reg:CC FLAGS_REG))]
-  "TARGET_USE_FANCY_MATH_387
-   && flag_unsafe_math_optimizations
-   && can_create_pseudo_p ()"
-  "#"
-  "&& 1"
-  [(const_int 0)]
-{
-  ix86_optimize_mode_switching[I387_CEIL] = 1;
-
-  operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
-  operands[3] = assign_386_stack_local (HImode, SLOT_CW_CEIL);
-
-  emit_insn (gen_frndintxf2_ceil_i387 (operands[0], operands[1],
-				       operands[2], operands[3]));
-  DONE;
-}
-  [(set_attr "type" "frndint")
-   (set_attr "i387_cw" "ceil")
-   (set_attr "mode" "XF")])
-
-(define_insn "frndintxf2_ceil_i387"
-  [(set (match_operand:XF 0 "register_operand" "=f")
-	(unspec:XF [(match_operand:XF 1 "register_operand" "0")]
-	 UNSPEC_FRNDINT_CEIL))
-   (use (match_operand:HI 2 "memory_operand" "m"))
-   (use (match_operand:HI 3 "memory_operand" "m"))]
-  "TARGET_USE_FANCY_MATH_387
-   && flag_unsafe_math_optimizations"
-  "fldcw\t%3\n\tfrndint\n\tfldcw\t%2"
-  [(set_attr "type" "frndint")
-   (set_attr "i387_cw" "ceil")
-   (set_attr "mode" "XF")])
-
 (define_expand "ceilxf2"
   [(use (match_operand:XF 0 "register_operand"))
    (use (match_operand:XF 1 "register_operand"))]
@@ -15613,45 +15589,6 @@ 
   DONE;
 })
 
-;; Rounding mode control word calculation could clobber FLAGS_REG.
-(define_insn_and_split "frndintxf2_trunc"
-  [(set (match_operand:XF 0 "register_operand")
-	(unspec:XF [(match_operand:XF 1 "register_operand")]
-	 UNSPEC_FRNDINT_TRUNC))
-   (clobber (reg:CC FLAGS_REG))]
-  "TARGET_USE_FANCY_MATH_387
-   && flag_unsafe_math_optimizations
-   && can_create_pseudo_p ()"
-  "#"
-  "&& 1"
-  [(const_int 0)]
-{
-  ix86_optimize_mode_switching[I387_TRUNC] = 1;
-
-  operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED);
-  operands[3] = assign_386_stack_local (HImode, SLOT_CW_TRUNC);
-
-  emit_insn (gen_frndintxf2_trunc_i387 (operands[0], operands[1],
-					operands[2], operands[3]));
-  DONE;
-}
-  [(set_attr "type" "frndint")
-   (set_attr "i387_cw" "trunc")
-   (set_attr "mode" "XF")])
-
-(define_insn "frndintxf2_trunc_i387"
-  [(set (match_operand:XF 0 "register_operand" "=f")
-	(unspec:XF [(match_operand:XF 1 "register_operand" "0")]
-	 UNSPEC_FRNDINT_TRUNC))
-   (use (match_operand:HI 2 "memory_operand" "m"))
-   (use (match_operand:HI 3 "memory_operand" "m"))]
-  "TARGET_USE_FANCY_MATH_387
-   && flag_unsafe_math_optimizations"
-  "fldcw\t%3\n\tfrndint\n\tfldcw\t%2"
-  [(set_attr "type" "frndint")
-   (set_attr "i387_cw" "trunc")
-   (set_attr "mode" "XF")])
-
 (define_expand "btruncxf2"
   [(use (match_operand:XF 0 "register_operand"))
    (use (match_operand:XF 1 "register_operand"))]
@@ -15708,7 +15645,7 @@ 
 (define_insn_and_split "frndintxf2_mask_pm"
   [(set (match_operand:XF 0 "register_operand")
 	(unspec:XF [(match_operand:XF 1 "register_operand")]
-	 UNSPEC_FRNDINT_MASK_PM))
+		   UNSPEC_FRNDINT_MASK_PM))
    (clobber (reg:CC FLAGS_REG))]
   "TARGET_USE_FANCY_MATH_387
    && flag_unsafe_math_optimizations