diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 829306c861d..90586312033 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,33 @@ +2006-10-25 Uros Bizjak + + * optabs.h (enum optab_index): Rename OTI_drem to OTI_remainder. + (remainder_optab): Define corresponding macro. + (drem_optab): Remove. + * optabs.c (init_optabs): Initialize remainder_optab. Remove + drem_optab initialization. + * genopinit.c (optabs): Implement remainder_optab using + remainder?f3 patterns. Remove drem_optab. + * builtins.c (expand_builtin_mathfn_2): Handle + BUILT_IN_REMAINDER{,F,L} using remainder_optab. + (expand_builtin): Expand BUILT_IN_REMAINDER{,F,L} using + expand_builtin_mathfn_2. + + (expand_builtin) [BUILT_IN_FMOD, BUILT_IN_DREM]: Do not + depend on flag_unsafe_math_optimizations. + + * config/i386/i386.md ("remaindersf3", "remainderdf3") + ("remainderxf3"): Renamed from "drem{s,d,x}f3" expanders. + Do not depend on flag_unsafe_math_optimizations. Use + truncxf?f expander instead of truncxf?f_i387_noop. + + ("fpremxf4", "fprem1xf4"): Do not depend on + flag_unsafe_math_optimizations. + ("fmodsf3", "fmoddf3", "fmodxf3"): Do not depend on + flag_unsafe_math_optimizations. Use truncxf?f expander + instead of truncxf?f_i387_noop. + + * doc/md.texi (fmod, remainder): Document standard named pattern. + 2006-10-24 Richard Sandiford David Daney diff --git a/gcc/builtins.c b/gcc/builtins.c index ebb9a857629..6955cda2a83 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -1975,8 +1975,9 @@ expand_builtin_mathfn_2 (tree exp, rtx target, rtx subtarget) builtin_optab = ldexp_optab; break; CASE_FLT_FN (BUILT_IN_FMOD): builtin_optab = fmod_optab; break; + CASE_FLT_FN (BUILT_IN_REMAINDER): CASE_FLT_FN (BUILT_IN_DREM): - builtin_optab = drem_optab; break; + builtin_optab = remainder_optab; break; default: gcc_unreachable (); } @@ -5796,10 +5797,12 @@ expand_builtin (tree exp, rtx target, rtx subtarget, enum machine_mode mode, CASE_FLT_FN (BUILT_IN_ATAN2): CASE_FLT_FN (BUILT_IN_LDEXP): - CASE_FLT_FN (BUILT_IN_FMOD): - CASE_FLT_FN (BUILT_IN_DREM): if (! flag_unsafe_math_optimizations) break; + + CASE_FLT_FN (BUILT_IN_FMOD): + CASE_FLT_FN (BUILT_IN_REMAINDER): + CASE_FLT_FN (BUILT_IN_DREM): target = expand_builtin_mathfn_2 (exp, target, subtarget); if (target) return target; diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index ac26aabd0f9..aadf2ff8f85 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -15610,8 +15610,7 @@ UNSPEC_FPREM_U)) (set (reg:CCFP FPSR_REG) (unspec:CCFP [(const_int 0)] UNSPEC_NOP))] - "TARGET_USE_FANCY_MATH_387 - && flag_unsafe_math_optimizations" + "TARGET_USE_FANCY_MATH_387" "fprem" [(set_attr "type" "fpspc") (set_attr "mode" "XF")]) @@ -15621,8 +15620,7 @@ (use (match_operand:SF 1 "register_operand" "")) (use (match_operand:SF 2 "register_operand" ""))] "TARGET_USE_FANCY_MATH_387 - && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387) - && flag_unsafe_math_optimizations" + && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387)" { rtx label = gen_label_rtx (); @@ -15637,7 +15635,7 @@ emit_insn (gen_fpremxf4 (op1, op2, op1, op2)); ix86_emit_fp_unordered_jump (label); - emit_insn (gen_truncxfsf2_i387_noop (operands[0], op1)); + emit_insn (gen_truncxfsf2 (operands[0], op1)); DONE; }) @@ -15646,8 +15644,7 @@ (use (match_operand:DF 1 "register_operand" "")) (use (match_operand:DF 2 "register_operand" ""))] "TARGET_USE_FANCY_MATH_387 - && (!(TARGET_SSE2 && TARGET_SSE_MATH) || TARGET_MIX_SSE_I387) - && flag_unsafe_math_optimizations" + && (!(TARGET_SSE2 && TARGET_SSE_MATH) || TARGET_MIX_SSE_I387)" { rtx label = gen_label_rtx (); @@ -15662,7 +15659,7 @@ emit_insn (gen_fpremxf4 (op1, op2, op1, op2)); ix86_emit_fp_unordered_jump (label); - emit_insn (gen_truncxfdf2_i387_noop (operands[0], op1)); + emit_insn (gen_truncxfdf2 (operands[0], op1)); DONE; }) @@ -15670,8 +15667,7 @@ [(use (match_operand:XF 0 "register_operand" "")) (use (match_operand:XF 1 "register_operand" "")) (use (match_operand:XF 2 "register_operand" ""))] - "TARGET_USE_FANCY_MATH_387 - && flag_unsafe_math_optimizations" + "TARGET_USE_FANCY_MATH_387" { rtx label = gen_label_rtx (); @@ -15695,19 +15691,17 @@ UNSPEC_FPREM1_U)) (set (reg:CCFP FPSR_REG) (unspec:CCFP [(const_int 0)] UNSPEC_NOP))] - "TARGET_USE_FANCY_MATH_387 - && flag_unsafe_math_optimizations" + "TARGET_USE_FANCY_MATH_387" "fprem1" [(set_attr "type" "fpspc") (set_attr "mode" "XF")]) -(define_expand "dremsf3" +(define_expand "remaindersf3" [(use (match_operand:SF 0 "register_operand" "")) (use (match_operand:SF 1 "register_operand" "")) (use (match_operand:SF 2 "register_operand" ""))] "TARGET_USE_FANCY_MATH_387 - && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387) - && flag_unsafe_math_optimizations" + && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387)" { rtx label = gen_label_rtx (); @@ -15722,17 +15716,16 @@ emit_insn (gen_fprem1xf4 (op1, op2, op1, op2)); ix86_emit_fp_unordered_jump (label); - emit_insn (gen_truncxfsf2_i387_noop (operands[0], op1)); + emit_insn (gen_truncxfsf2 (operands[0], op1)); DONE; }) -(define_expand "dremdf3" +(define_expand "remainderdf3" [(use (match_operand:DF 0 "register_operand" "")) (use (match_operand:DF 1 "register_operand" "")) (use (match_operand:DF 2 "register_operand" ""))] "TARGET_USE_FANCY_MATH_387 - && (!(TARGET_SSE2 && TARGET_SSE_MATH) || TARGET_MIX_SSE_I387) - && flag_unsafe_math_optimizations" + && (!(TARGET_SSE2 && TARGET_SSE_MATH) || TARGET_MIX_SSE_I387)" { rtx label = gen_label_rtx (); @@ -15747,16 +15740,15 @@ emit_insn (gen_fprem1xf4 (op1, op2, op1, op2)); ix86_emit_fp_unordered_jump (label); - emit_insn (gen_truncxfdf2_i387_noop (operands[0], op1)); + emit_insn (gen_truncxfdf2 (operands[0], op1)); DONE; }) -(define_expand "dremxf3" +(define_expand "remainderxf3" [(use (match_operand:XF 0 "register_operand" "")) (use (match_operand:XF 1 "register_operand" "")) (use (match_operand:XF 2 "register_operand" ""))] - "TARGET_USE_FANCY_MATH_387 - && flag_unsafe_math_optimizations" + "TARGET_USE_FANCY_MATH_387" { rtx label = gen_label_rtx (); diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi index 3b30e361e30..a05f9d04a9e 100644 --- a/gcc/doc/md.texi +++ b/gcc/doc/md.texi @@ -3569,6 +3569,26 @@ corresponds to the C data type @code{double} and the @code{sqrtf} built-in function uses the mode which corresponds to the C data type @code{float}. +@cindex @code{fmod@var{m}3} instruction pattern +@item @samp{fmod@var{m}3} +Store the remainder of dividing operand 1 by operand 2 into +operand 0, rounded towards zero to an integer. + +The @code{fmod} built-in function of C always uses the mode which +corresponds to the C data type @code{double} and the @code{fmodf} +built-in function uses the mode which corresponds to the C data +type @code{float}. + +@cindex @code{remainder@var{m}3} instruction pattern +@item @samp{remainder@var{m}3} +Store the remainder of dividing operand 1 by operand 2 into +operand 0, rounded to the nearest integer. + +The @code{remainder} built-in function of C always uses the mode +which corresponds to the C data type @code{double} and the +@code{remainderf} built-in function uses the mode which corresponds +to the C data type @code{float}. + @cindex @code{cos@var{m}2} instruction pattern @item @samp{cos@var{m}2} Store the cosine of operand 1 into operand 0. diff --git a/gcc/genopinit.c b/gcc/genopinit.c index c9cea085852..4f7bd46595c 100644 --- a/gcc/genopinit.c +++ b/gcc/genopinit.c @@ -93,7 +93,7 @@ static const char * const optabs[] = "smod_optab->handlers[$A].insn_code = CODE_FOR_$(mod$a3$)", "umod_optab->handlers[$A].insn_code = CODE_FOR_$(umod$a3$)", "fmod_optab->handlers[$A].insn_code = CODE_FOR_$(fmod$a3$)", - "drem_optab->handlers[$A].insn_code = CODE_FOR_$(drem$a3$)", + "remainder_optab->handlers[$A].insn_code = CODE_FOR_$(remainder$a3$)", "ftrunc_optab->handlers[$A].insn_code = CODE_FOR_$(ftrunc$F$a2$)", "and_optab->handlers[$A].insn_code = CODE_FOR_$(and$a3$)", "ior_optab->handlers[$A].insn_code = CODE_FOR_$(ior$a3$)", diff --git a/gcc/optabs.c b/gcc/optabs.c index fe7ae065962..12fd34e5da2 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -5212,7 +5212,7 @@ init_optabs (void) smod_optab = init_optab (MOD); umod_optab = init_optab (UMOD); fmod_optab = init_optab (UNKNOWN); - drem_optab = init_optab (UNKNOWN); + remainder_optab = init_optab (UNKNOWN); ftrunc_optab = init_optab (UNKNOWN); and_optab = init_optab (AND); ior_optab = init_optab (IOR); diff --git a/gcc/optabs.h b/gcc/optabs.h index 58fb6905175..69dcbe11b91 100644 --- a/gcc/optabs.h +++ b/gcc/optabs.h @@ -98,7 +98,7 @@ enum optab_index OTI_umod, /* Floating point remainder functions */ OTI_fmod, - OTI_drem, + OTI_remainder, /* Convert float to integer in float fmt */ OTI_ftrunc, @@ -289,7 +289,7 @@ extern GTY(()) optab optab_table[OTI_MAX]; #define smod_optab (optab_table[OTI_smod]) #define umod_optab (optab_table[OTI_umod]) #define fmod_optab (optab_table[OTI_fmod]) -#define drem_optab (optab_table[OTI_drem]) +#define remainder_optab (optab_table[OTI_remainder]) #define ftrunc_optab (optab_table[OTI_ftrunc]) #define and_optab (optab_table[OTI_and]) #define ior_optab (optab_table[OTI_ior]) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b6903477832..264d5992d39 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2006-10-25 Uros Bizjak + + * gcc.dg/builtins-40.c: Also check remainder(), remainderf() + and remainderl() built-in functions. Remove -ffast-math from + dg-options. + 2006-10-24 Kaveh R. Ghazi * gcc.dg/torture/builtin-math-2.c: Add checks for asin, acos, diff --git a/gcc/testsuite/gcc.dg/builtins-40.c b/gcc/testsuite/gcc.dg/builtins-40.c index 405c8723309..982175a3a6b 100644 --- a/gcc/testsuite/gcc.dg/builtins-40.c +++ b/gcc/testsuite/gcc.dg/builtins-40.c @@ -1,18 +1,24 @@ /* Copyright (C) 2004 Free Software Foundation. - Check that fmod, fmodf, fmodl, drem, dremf and dreml + Check that fmod, fmodf, fmodl, drem, dremf, dreml, + remainder, remainderf and remainderl built-in functions compile. Written by Uros Bizjak, 5th May 2004. */ /* { dg-do compile } */ -/* { dg-options "-O2 -ffast-math" } */ +/* { dg-options "-O2" } */ extern double fmod(double, double); -extern double drem(double, double); extern float fmodf(float, float); -extern float dremf(float, float); extern long double fmodl(long double, long double); + +extern double remainder(double, double); +extern float remainderf(float, float); +extern long double remainderl(long double, long double); + +extern double drem(double, double); +extern float dremf(float, float); extern long double dreml(long double, long double); @@ -21,27 +27,42 @@ double test1(double x, double y) return fmod(x, y); } -double test2(double x, double y) -{ - return drem(x, y); -} - float test1f(float x, float y) { return fmodf(x, y); } -float test2f(float x, float y) -{ - return dremf(x, y); -} - long double test1l(long double x, long double y) { return fmodl(x, y); } +double test2(double x, double y) +{ + return remainder(x, y); +} + +float test2f(float x, float y) +{ + return remainderf(x, y); +} + long double test2l(long double x, long double y) +{ + return remainderl(x, y); +} + +double test3(double x, double y) +{ + return drem(x, y); +} + +float test3f(float x, float y) +{ + return dremf(x, y); +} + +long double test3l(long double x, long double y) { return dreml(x, y); }