From patchwork Tue Jun 19 18:26:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 165819 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id EF653B7019 for ; Wed, 20 Jun 2012 04:27:33 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1340735254; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:Date:Message-ID:Subject:From:To: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=jxAraG6 03XnI2x7edpHGjTeqbaI=; b=GL3LPa/W/bxFlT7t+kRMLDtf2IhgyfJDHWJRUWo D+P+AXtVHbr/n7HqaRKf8OU/8qFi9a8zwDVowpXnwGj7N+06z1yHly61ieYqMAv1 I6U09DW0EwltE1xN5Uz+G362YOFXqPSH1aA2Fq3VHT91YFhuiJje2YbvvNCvu+Ny XvLc= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:MIME-Version:Received:Received:Date:Message-ID:Subject:From:To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=ji5hxG1AXI6j+MqqM/d9Q//UqOAvG52FZjvohaXfVpGMegzDG5x4DWeqJKMCoL yu9l3Oyxu6OY4t7wuOYD7/feu1zXCgcO6OjwhQSwNRBXW6YAX9tpw6l0BZE6vWTw ZpJvMlVzXjxWCaiUiWtCeKiJaWoQi7Kw4VnElMYK+HBQU=; Received: (qmail 7584 invoked by alias); 19 Jun 2012 18:26:57 -0000 Received: (qmail 6941 invoked by uid 22791); 19 Jun 2012 18:26:38 -0000 X-SWARE-Spam-Status: No, hits=-4.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, TW_ZJ X-Spam-Check-By: sourceware.org Received: from mail-gg0-f175.google.com (HELO mail-gg0-f175.google.com) (209.85.161.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 19 Jun 2012 18:26:12 +0000 Received: by ggnp4 with SMTP id p4so5029788ggn.20 for ; Tue, 19 Jun 2012 11:26:11 -0700 (PDT) MIME-Version: 1.0 Received: by 10.236.46.195 with SMTP id r43mr23708804yhb.86.1340130371217; Tue, 19 Jun 2012 11:26:11 -0700 (PDT) Received: by 10.147.111.19 with HTTP; Tue, 19 Jun 2012 11:26:11 -0700 (PDT) Date: Tue, 19 Jun 2012 20:26:11 +0200 Message-ID: Subject: Re: [PATCH, i386]: Introduce FIST_ROUNDING int iterator From: Uros Bizjak To: gcc-patches@gcc.gnu.org Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hello! 2012-06-19 Uros Bizjak * config/i386/i386.md (FIST_ROUNDING): New int iterator. (rounding): Handle UNSPEC_FIST_{FLOOR,CEIL}. (ROUNDING): Ditto. (*fist2__1): Macroize insn from *fist2_{floor,ceil}_1 using FIST_ROUNDING int iterator. (fistdi2_): Macroize insn from fistdi2_{floor,ceil} using FIST_ROUNDING int iterator. (fistdi2__with_temp and splitters): Macroize insn and corresponding splitters from fistdi2_{floor,ceil} and corresponding splitters using FIST_ROUNDING int iterator. (fist2_): Macroize insn from fist2_{floor,ceil} using FIST_ROUNDING int iterator. (fist2__with_temp and splitters): Macroize insn and corresponding splitters from fist2_{floor,ceil} and corresponding splitters using FIST_ROUNDING int iterator. (lxf2): Macroize expander from l{floor,ceil}xf2 using FIST_ROUNDING int iterator. Bootstrapped and regression tested on x86_64-pc-linux-gnu {,-m32}, committed to mainline SVN. Uros. Index: config/i386/i386.md =================================================================== --- config/i386/i386.md (revision 188783) +++ config/i386/i386.md (working copy) @@ -15104,15 +15104,23 @@ UNSPEC_FRNDINT_CEIL UNSPEC_FRNDINT_TRUNC]) +(define_int_iterator FIST_ROUNDING + [UNSPEC_FIST_FLOOR + UNSPEC_FIST_CEIL]) + (define_int_attr rounding [(UNSPEC_FRNDINT_FLOOR "floor") (UNSPEC_FRNDINT_CEIL "ceil") - (UNSPEC_FRNDINT_TRUNC "trunc")]) + (UNSPEC_FRNDINT_TRUNC "trunc") + (UNSPEC_FIST_FLOOR "floor") + (UNSPEC_FIST_CEIL "ceil")]) (define_int_attr ROUNDING [(UNSPEC_FRNDINT_FLOOR "FLOOR") (UNSPEC_FRNDINT_CEIL "CEIL") - (UNSPEC_FRNDINT_TRUNC "TRUNC")]) + (UNSPEC_FRNDINT_TRUNC "TRUNC") + (UNSPEC_FIST_FLOOR "FLOOR") + (UNSPEC_FIST_CEIL "CEIL")]) ;; Rounding mode control word calculation could clobber FLAGS_REG. (define_insn_and_split "frndintxf2_" @@ -15205,174 +15213,59 @@ DONE; }) -(define_insn_and_split "*fist2_floor_1" - [(set (match_operand:SWI248x 0 "nonimmediate_operand") - (unspec:SWI248x [(match_operand:XF 1 "register_operand")] - UNSPEC_FIST_FLOOR)) - (clobber (reg:CC FLAGS_REG))] +(define_expand "ceilxf2" + [(use (match_operand:XF 0 "register_operand")) + (use (match_operand:XF 1 "register_operand"))] "TARGET_USE_FANCY_MATH_387 - && flag_unsafe_math_optimizations - && can_create_pseudo_p ()" - "#" - "&& 1" - [(const_int 0)] + && flag_unsafe_math_optimizations" { - ix86_optimize_mode_switching[I387_FLOOR] = 1; + if (optimize_insn_for_size_p ()) + FAIL; + emit_insn (gen_frndintxf2_ceil (operands[0], operands[1])); + DONE; +}) - operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED); - operands[3] = assign_386_stack_local (HImode, SLOT_CW_FLOOR); - if (memory_operand (operands[0], VOIDmode)) - emit_insn (gen_fist2_floor (operands[0], operands[1], - operands[2], operands[3])); +(define_expand "ceil2" + [(use (match_operand:MODEF 0 "register_operand")) + (use (match_operand:MODEF 1 "register_operand"))] + "(TARGET_USE_FANCY_MATH_387 + && (!(SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH) + || TARGET_MIX_SSE_I387) + && flag_unsafe_math_optimizations) + || (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH + && !flag_trapping_math)" +{ + if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH + && !flag_trapping_math) + { + if (TARGET_ROUND) + emit_insn (gen_sse4_1_round2 + (operands[0], operands[1], GEN_INT (ROUND_CEIL))); + else if (optimize_insn_for_size_p ()) + FAIL; + else if (TARGET_64BIT || (mode != DFmode)) + ix86_expand_floorceil (operands[0], operands[1], false); + else + ix86_expand_floorceildf_32 (operands[0], operands[1], false); + } else { - operands[4] = assign_386_stack_local (mode, SLOT_TEMP); - emit_insn (gen_fist2_floor_with_temp (operands[0], operands[1], - operands[2], operands[3], - operands[4])); - } - DONE; -} - [(set_attr "type" "fistp") - (set_attr "i387_cw" "floor") - (set_attr "mode" "")]) + rtx op0, op1; -(define_insn "fistdi2_floor" - [(set (match_operand:DI 0 "memory_operand" "=m") - (unspec:DI [(match_operand:XF 1 "register_operand" "f")] - UNSPEC_FIST_FLOOR)) - (use (match_operand:HI 2 "memory_operand" "m")) - (use (match_operand:HI 3 "memory_operand" "m")) - (clobber (match_scratch:XF 4 "=&1f"))] - "TARGET_USE_FANCY_MATH_387 - && flag_unsafe_math_optimizations" - "* return output_fix_trunc (insn, operands, false);" - [(set_attr "type" "fistp") - (set_attr "i387_cw" "floor") - (set_attr "mode" "DI")]) + if (optimize_insn_for_size_p ()) + FAIL; -(define_insn "fistdi2_floor_with_temp" - [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r") - (unspec:DI [(match_operand:XF 1 "register_operand" "f,f")] - UNSPEC_FIST_FLOOR)) - (use (match_operand:HI 2 "memory_operand" "m,m")) - (use (match_operand:HI 3 "memory_operand" "m,m")) - (clobber (match_operand:DI 4 "memory_operand" "=X,m")) - (clobber (match_scratch:XF 5 "=&1f,&1f"))] - "TARGET_USE_FANCY_MATH_387 - && flag_unsafe_math_optimizations" - "#" - [(set_attr "type" "fistp") - (set_attr "i387_cw" "floor") - (set_attr "mode" "DI")]) + op0 = gen_reg_rtx (XFmode); + op1 = gen_reg_rtx (XFmode); + emit_insn (gen_extendxf2 (op1, operands[1])); + emit_insn (gen_frndintxf2_ceil (op0, op1)); -(define_split - [(set (match_operand:DI 0 "register_operand") - (unspec:DI [(match_operand:XF 1 "register_operand")] - UNSPEC_FIST_FLOOR)) - (use (match_operand:HI 2 "memory_operand")) - (use (match_operand:HI 3 "memory_operand")) - (clobber (match_operand:DI 4 "memory_operand")) - (clobber (match_scratch 5))] - "reload_completed" - [(parallel [(set (match_dup 4) - (unspec:DI [(match_dup 1)] UNSPEC_FIST_FLOOR)) - (use (match_dup 2)) - (use (match_dup 3)) - (clobber (match_dup 5))]) - (set (match_dup 0) (match_dup 4))]) - -(define_split - [(set (match_operand:DI 0 "memory_operand") - (unspec:DI [(match_operand:XF 1 "register_operand")] - UNSPEC_FIST_FLOOR)) - (use (match_operand:HI 2 "memory_operand")) - (use (match_operand:HI 3 "memory_operand")) - (clobber (match_operand:DI 4 "memory_operand")) - (clobber (match_scratch 5))] - "reload_completed" - [(parallel [(set (match_dup 0) - (unspec:DI [(match_dup 1)] UNSPEC_FIST_FLOOR)) - (use (match_dup 2)) - (use (match_dup 3)) - (clobber (match_dup 5))])]) - -(define_insn "fist2_floor" - [(set (match_operand:SWI24 0 "memory_operand" "=m") - (unspec:SWI24 [(match_operand:XF 1 "register_operand" "f")] - UNSPEC_FIST_FLOOR)) - (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" - "* return output_fix_trunc (insn, operands, false);" - [(set_attr "type" "fistp") - (set_attr "i387_cw" "floor") - (set_attr "mode" "")]) - -(define_insn "fist2_floor_with_temp" - [(set (match_operand:SWI24 0 "nonimmediate_operand" "=m,?r") - (unspec:SWI24 [(match_operand:XF 1 "register_operand" "f,f")] - UNSPEC_FIST_FLOOR)) - (use (match_operand:HI 2 "memory_operand" "m,m")) - (use (match_operand:HI 3 "memory_operand" "m,m")) - (clobber (match_operand:SWI24 4 "memory_operand" "=X,m"))] - "TARGET_USE_FANCY_MATH_387 - && flag_unsafe_math_optimizations" - "#" - [(set_attr "type" "fistp") - (set_attr "i387_cw" "floor") - (set_attr "mode" "")]) - -(define_split - [(set (match_operand:SWI24 0 "register_operand") - (unspec:SWI24 [(match_operand:XF 1 "register_operand")] - UNSPEC_FIST_FLOOR)) - (use (match_operand:HI 2 "memory_operand")) - (use (match_operand:HI 3 "memory_operand")) - (clobber (match_operand:SWI24 4 "memory_operand"))] - "reload_completed" - [(parallel [(set (match_dup 4) - (unspec:SWI24 [(match_dup 1)] UNSPEC_FIST_FLOOR)) - (use (match_dup 2)) - (use (match_dup 3))]) - (set (match_dup 0) (match_dup 4))]) - -(define_split - [(set (match_operand:SWI24 0 "memory_operand") - (unspec:SWI24 [(match_operand:XF 1 "register_operand")] - UNSPEC_FIST_FLOOR)) - (use (match_operand:HI 2 "memory_operand")) - (use (match_operand:HI 3 "memory_operand")) - (clobber (match_operand:SWI24 4 "memory_operand"))] - "reload_completed" - [(parallel [(set (match_dup 0) - (unspec:SWI24 [(match_dup 1)] UNSPEC_FIST_FLOOR)) - (use (match_dup 2)) - (use (match_dup 3))])]) - -(define_expand "lfloorxf2" - [(parallel [(set (match_operand:SWI248x 0 "nonimmediate_operand") - (unspec:SWI248x [(match_operand:XF 1 "register_operand")] - UNSPEC_FIST_FLOOR)) - (clobber (reg:CC FLAGS_REG))])] - "TARGET_USE_FANCY_MATH_387 - && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387) - && flag_unsafe_math_optimizations") - -(define_expand "lfloor2" - [(match_operand:SWI48 0 "nonimmediate_operand") - (match_operand:MODEF 1 "register_operand")] - "SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH - && !flag_trapping_math" -{ - if (TARGET_64BIT && optimize_insn_for_size_p ()) - FAIL; - ix86_expand_lfloorceil (operands[0], operands[1], true); + emit_insn (gen_truncxf2_i387_noop (operands[0], op0)); + } DONE; }) -(define_expand "ceilxf2" +(define_expand "btruncxf2" [(use (match_operand:XF 0 "register_operand")) (use (match_operand:XF 1 "register_operand"))] "TARGET_USE_FANCY_MATH_387 @@ -15380,11 +15273,11 @@ { if (optimize_insn_for_size_p ()) FAIL; - emit_insn (gen_frndintxf2_ceil (operands[0], operands[1])); + emit_insn (gen_frndintxf2_trunc (operands[0], operands[1])); DONE; }) -(define_expand "ceil2" +(define_expand "btrunc2" [(use (match_operand:MODEF 0 "register_operand")) (use (match_operand:MODEF 1 "register_operand"))] "(TARGET_USE_FANCY_MATH_387 @@ -15399,13 +15292,13 @@ { if (TARGET_ROUND) emit_insn (gen_sse4_1_round2 - (operands[0], operands[1], GEN_INT (ROUND_CEIL))); + (operands[0], operands[1], GEN_INT (ROUND_TRUNC))); else if (optimize_insn_for_size_p ()) FAIL; else if (TARGET_64BIT || (mode != DFmode)) - ix86_expand_floorceil (operands[0], operands[1], false); + ix86_expand_trunc (operands[0], operands[1]); else - ix86_expand_floorceildf_32 (operands[0], operands[1], false); + ix86_expand_truncdf_32 (operands[0], operands[1]); } else { @@ -15417,17 +15310,85 @@ op0 = gen_reg_rtx (XFmode); op1 = gen_reg_rtx (XFmode); emit_insn (gen_extendxf2 (op1, operands[1])); - emit_insn (gen_frndintxf2_ceil (op0, op1)); + emit_insn (gen_frndintxf2_trunc (op0, op1)); emit_insn (gen_truncxf2_i387_noop (operands[0], op0)); } DONE; }) -(define_insn_and_split "*fist2_ceil_1" +;; Rounding mode control word calculation could clobber FLAGS_REG. +(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)) + (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_MASK_PM] = 1; + + operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED); + operands[3] = assign_386_stack_local (HImode, SLOT_CW_MASK_PM); + + emit_insn (gen_frndintxf2_mask_pm_i387 (operands[0], operands[1], + operands[2], operands[3])); + DONE; +} + [(set_attr "type" "frndint") + (set_attr "i387_cw" "mask_pm") + (set_attr "mode" "XF")]) + +(define_insn "frndintxf2_mask_pm_i387" + [(set (match_operand:XF 0 "register_operand" "=f") + (unspec:XF [(match_operand:XF 1 "register_operand" "0")] + UNSPEC_FRNDINT_MASK_PM)) + (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\tfclex\n\tfldcw\t%2" + [(set_attr "type" "frndint") + (set_attr "i387_cw" "mask_pm") + (set_attr "mode" "XF")]) + +(define_expand "nearbyintxf2" + [(use (match_operand:XF 0 "register_operand")) + (use (match_operand:XF 1 "register_operand"))] + "TARGET_USE_FANCY_MATH_387 + && flag_unsafe_math_optimizations" +{ + emit_insn (gen_frndintxf2_mask_pm (operands[0], operands[1])); + DONE; +}) + +(define_expand "nearbyint2" + [(use (match_operand:MODEF 0 "register_operand")) + (use (match_operand:MODEF 1 "register_operand"))] + "TARGET_USE_FANCY_MATH_387 + && (!(SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH) + || TARGET_MIX_SSE_I387) + && flag_unsafe_math_optimizations" +{ + rtx op0 = gen_reg_rtx (XFmode); + rtx op1 = gen_reg_rtx (XFmode); + + emit_insn (gen_extendxf2 (op1, operands[1])); + emit_insn (gen_frndintxf2_mask_pm (op0, op1)); + + emit_insn (gen_truncxf2_i387_noop (operands[0], op0)); + DONE; +}) + +;; Rounding mode control word calculation could clobber FLAGS_REG. +(define_insn_and_split "*fist2__1" [(set (match_operand:SWI248x 0 "nonimmediate_operand") (unspec:SWI248x [(match_operand:XF 1 "register_operand")] - UNSPEC_FIST_CEIL)) + FIST_ROUNDING)) (clobber (reg:CC FLAGS_REG))] "TARGET_USE_FANCY_MATH_387 && flag_unsafe_math_optimizations @@ -15436,30 +15397,30 @@ "&& 1" [(const_int 0)] { - ix86_optimize_mode_switching[I387_CEIL] = 1; + ix86_optimize_mode_switching[I387_] = 1; operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED); - operands[3] = assign_386_stack_local (HImode, SLOT_CW_CEIL); + operands[3] = assign_386_stack_local (HImode, SLOT_CW_); if (memory_operand (operands[0], VOIDmode)) - emit_insn (gen_fist2_ceil (operands[0], operands[1], - operands[2], operands[3])); + emit_insn (gen_fist2_ (operands[0], operands[1], + operands[2], operands[3])); else { operands[4] = assign_386_stack_local (mode, SLOT_TEMP); - emit_insn (gen_fist2_ceil_with_temp (operands[0], operands[1], - operands[2], operands[3], - operands[4])); + emit_insn (gen_fist2__with_temp + (operands[0], operands[1], operands[2], + operands[3], operands[4])); } DONE; } [(set_attr "type" "fistp") - (set_attr "i387_cw" "ceil") + (set_attr "i387_cw" "") (set_attr "mode" "")]) -(define_insn "fistdi2_ceil" +(define_insn "fistdi2_" [(set (match_operand:DI 0 "memory_operand" "=m") (unspec:DI [(match_operand:XF 1 "register_operand" "f")] - UNSPEC_FIST_CEIL)) + FIST_ROUNDING)) (use (match_operand:HI 2 "memory_operand" "m")) (use (match_operand:HI 3 "memory_operand" "m")) (clobber (match_scratch:XF 4 "=&1f"))] @@ -15467,13 +15428,13 @@ && flag_unsafe_math_optimizations" "* return output_fix_trunc (insn, operands, false);" [(set_attr "type" "fistp") - (set_attr "i387_cw" "ceil") + (set_attr "i387_cw" "") (set_attr "mode" "DI")]) -(define_insn "fistdi2_ceil_with_temp" +(define_insn "fistdi2__with_temp" [(set (match_operand:DI 0 "nonimmediate_operand" "=m,?r") (unspec:DI [(match_operand:XF 1 "register_operand" "f,f")] - UNSPEC_FIST_CEIL)) + FIST_ROUNDING)) (use (match_operand:HI 2 "memory_operand" "m,m")) (use (match_operand:HI 3 "memory_operand" "m,m")) (clobber (match_operand:DI 4 "memory_operand" "=X,m")) @@ -15482,20 +15443,20 @@ && flag_unsafe_math_optimizations" "#" [(set_attr "type" "fistp") - (set_attr "i387_cw" "ceil") + (set_attr "i387_cw" "") (set_attr "mode" "DI")]) (define_split [(set (match_operand:DI 0 "register_operand") (unspec:DI [(match_operand:XF 1 "register_operand")] - UNSPEC_FIST_CEIL)) + FIST_ROUNDING)) (use (match_operand:HI 2 "memory_operand")) (use (match_operand:HI 3 "memory_operand")) (clobber (match_operand:DI 4 "memory_operand")) (clobber (match_scratch 5))] "reload_completed" [(parallel [(set (match_dup 4) - (unspec:DI [(match_dup 1)] UNSPEC_FIST_CEIL)) + (unspec:DI [(match_dup 1)] FIST_ROUNDING)) (use (match_dup 2)) (use (match_dup 3)) (clobber (match_dup 5))]) @@ -15504,35 +15465,35 @@ (define_split [(set (match_operand:DI 0 "memory_operand") (unspec:DI [(match_operand:XF 1 "register_operand")] - UNSPEC_FIST_CEIL)) + FIST_ROUNDING)) (use (match_operand:HI 2 "memory_operand")) (use (match_operand:HI 3 "memory_operand")) (clobber (match_operand:DI 4 "memory_operand")) (clobber (match_scratch 5))] "reload_completed" [(parallel [(set (match_dup 0) - (unspec:DI [(match_dup 1)] UNSPEC_FIST_CEIL)) + (unspec:DI [(match_dup 1)] FIST_ROUNDING)) (use (match_dup 2)) (use (match_dup 3)) (clobber (match_dup 5))])]) -(define_insn "fist2_ceil" +(define_insn "fist2_" [(set (match_operand:SWI24 0 "memory_operand" "=m") (unspec:SWI24 [(match_operand:XF 1 "register_operand" "f")] - UNSPEC_FIST_CEIL)) + FIST_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" "* return output_fix_trunc (insn, operands, false);" [(set_attr "type" "fistp") - (set_attr "i387_cw" "ceil") + (set_attr "i387_cw" "") (set_attr "mode" "")]) -(define_insn "fist2_ceil_with_temp" +(define_insn "fist2__with_temp" [(set (match_operand:SWI24 0 "nonimmediate_operand" "=m,?r") (unspec:SWI24 [(match_operand:XF 1 "register_operand" "f,f")] - UNSPEC_FIST_CEIL)) + FIST_ROUNDING)) (use (match_operand:HI 2 "memory_operand" "m,m")) (use (match_operand:HI 3 "memory_operand" "m,m")) (clobber (match_operand:SWI24 4 "memory_operand" "=X,m"))] @@ -15540,19 +15501,19 @@ && flag_unsafe_math_optimizations" "#" [(set_attr "type" "fistp") - (set_attr "i387_cw" "ceil") + (set_attr "i387_cw" "") (set_attr "mode" "")]) (define_split [(set (match_operand:SWI24 0 "register_operand") (unspec:SWI24 [(match_operand:XF 1 "register_operand")] - UNSPEC_FIST_CEIL)) + FIST_ROUNDING)) (use (match_operand:HI 2 "memory_operand")) (use (match_operand:HI 3 "memory_operand")) (clobber (match_operand:SWI24 4 "memory_operand"))] "reload_completed" [(parallel [(set (match_dup 4) - (unspec:SWI24 [(match_dup 1)] UNSPEC_FIST_CEIL)) + (unspec:SWI24 [(match_dup 1)] FIST_ROUNDING)) (use (match_dup 2)) (use (match_dup 3))]) (set (match_dup 0) (match_dup 4))]) @@ -15560,154 +15521,47 @@ (define_split [(set (match_operand:SWI24 0 "memory_operand") (unspec:SWI24 [(match_operand:XF 1 "register_operand")] - UNSPEC_FIST_CEIL)) + FIST_ROUNDING)) (use (match_operand:HI 2 "memory_operand")) (use (match_operand:HI 3 "memory_operand")) (clobber (match_operand:SWI24 4 "memory_operand"))] "reload_completed" [(parallel [(set (match_dup 0) - (unspec:SWI24 [(match_dup 1)] UNSPEC_FIST_CEIL)) + (unspec:SWI24 [(match_dup 1)] FIST_ROUNDING)) (use (match_dup 2)) (use (match_dup 3))])]) -(define_expand "lceilxf2" +(define_expand "lxf2" [(parallel [(set (match_operand:SWI248x 0 "nonimmediate_operand") (unspec:SWI248x [(match_operand:XF 1 "register_operand")] - UNSPEC_FIST_CEIL)) + FIST_ROUNDING)) (clobber (reg:CC FLAGS_REG))])] "TARGET_USE_FANCY_MATH_387 && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387) && flag_unsafe_math_optimizations") -(define_expand "lceil2" +(define_expand "lfloor2" [(match_operand:SWI48 0 "nonimmediate_operand") (match_operand:MODEF 1 "register_operand")] "SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH && !flag_trapping_math" { - ix86_expand_lfloorceil (operands[0], operands[1], false); - DONE; -}) - -(define_expand "btruncxf2" - [(use (match_operand:XF 0 "register_operand")) - (use (match_operand:XF 1 "register_operand"))] - "TARGET_USE_FANCY_MATH_387 - && flag_unsafe_math_optimizations" -{ - if (optimize_insn_for_size_p ()) + if (TARGET_64BIT && optimize_insn_for_size_p ()) FAIL; - emit_insn (gen_frndintxf2_trunc (operands[0], operands[1])); + ix86_expand_lfloorceil (operands[0], operands[1], true); DONE; }) -(define_expand "btrunc2" - [(use (match_operand:MODEF 0 "register_operand")) - (use (match_operand:MODEF 1 "register_operand"))] - "(TARGET_USE_FANCY_MATH_387 - && (!(SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH) - || TARGET_MIX_SSE_I387) - && flag_unsafe_math_optimizations) - || (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH - && !flag_trapping_math)" +(define_expand "lceil2" + [(match_operand:SWI48 0 "nonimmediate_operand") + (match_operand:MODEF 1 "register_operand")] + "SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH + && !flag_trapping_math" { - if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH - && !flag_trapping_math) - { - if (TARGET_ROUND) - emit_insn (gen_sse4_1_round2 - (operands[0], operands[1], GEN_INT (ROUND_TRUNC))); - else if (optimize_insn_for_size_p ()) - FAIL; - else if (TARGET_64BIT || (mode != DFmode)) - ix86_expand_trunc (operands[0], operands[1]); - else - ix86_expand_truncdf_32 (operands[0], operands[1]); - } - else - { - rtx op0, op1; - - if (optimize_insn_for_size_p ()) - FAIL; - - op0 = gen_reg_rtx (XFmode); - op1 = gen_reg_rtx (XFmode); - emit_insn (gen_extendxf2 (op1, operands[1])); - emit_insn (gen_frndintxf2_trunc (op0, op1)); - - emit_insn (gen_truncxf2_i387_noop (operands[0], op0)); - } + ix86_expand_lfloorceil (operands[0], operands[1], false); DONE; }) -;; Rounding mode control word calculation could clobber FLAGS_REG. -(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)) - (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_MASK_PM] = 1; - - operands[2] = assign_386_stack_local (HImode, SLOT_CW_STORED); - operands[3] = assign_386_stack_local (HImode, SLOT_CW_MASK_PM); - - emit_insn (gen_frndintxf2_mask_pm_i387 (operands[0], operands[1], - operands[2], operands[3])); - DONE; -} - [(set_attr "type" "frndint") - (set_attr "i387_cw" "mask_pm") - (set_attr "mode" "XF")]) - -(define_insn "frndintxf2_mask_pm_i387" - [(set (match_operand:XF 0 "register_operand" "=f") - (unspec:XF [(match_operand:XF 1 "register_operand" "0")] - UNSPEC_FRNDINT_MASK_PM)) - (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\tfclex\n\tfldcw\t%2" - [(set_attr "type" "frndint") - (set_attr "i387_cw" "mask_pm") - (set_attr "mode" "XF")]) - -(define_expand "nearbyintxf2" - [(use (match_operand:XF 0 "register_operand")) - (use (match_operand:XF 1 "register_operand"))] - "TARGET_USE_FANCY_MATH_387 - && flag_unsafe_math_optimizations" -{ - emit_insn (gen_frndintxf2_mask_pm (operands[0], operands[1])); - DONE; -}) - -(define_expand "nearbyint2" - [(use (match_operand:MODEF 0 "register_operand")) - (use (match_operand:MODEF 1 "register_operand"))] - "TARGET_USE_FANCY_MATH_387 - && (!(SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH) - || TARGET_MIX_SSE_I387) - && flag_unsafe_math_optimizations" -{ - rtx op0 = gen_reg_rtx (XFmode); - rtx op1 = gen_reg_rtx (XFmode); - - emit_insn (gen_extendxf2 (op1, operands[1])); - emit_insn (gen_frndintxf2_mask_pm (op0, op1)); - - emit_insn (gen_truncxf2_i387_noop (operands[0], op0)); - DONE; -}) - (define_insn "fxam2_i387" [(set (match_operand:HI 0 "register_operand" "=a") (unspec:HI