From: Uros Bizjak Date: Wed, 10 Mar 2004 22:36:22 +0000 (+0100) Subject: optabs.h (enum optab_index): Add new OTI_exp10 and OTI_exp2. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a251102ea16801ffecedfd591603dbaf90a42337;p=gcc.git optabs.h (enum optab_index): Add new OTI_exp10 and OTI_exp2. 2004-03-10 Uros Bizjak * optabs.h (enum optab_index): Add new OTI_exp10 and OTI_exp2. (exp10_optab, exp2_optab): Define corresponding macros. * optabs.c (init_optabs): Initialize exp10_optab and exp2_optab. * genopinit.c (optabs): Implement exp10_optab and exp2_optab using exp10?f2 and exp2?f2 patterns. * builtins.c (expand_builtin_mathfn): Handle BUILT_IN_EXP10{,F,L} using exp10_optab, and BUILT_IN_EXP2{,F,L} using exp2_optab. (expand_builtin): Expand BUILT_IN_EXP10{,F,L} and BUILT_IN_EXP2{,F,L} using expand_builtin_mathfn if flag_unsafe_math_optimizations is set. * config/i386/i386.md (exp10sf2, exp10df2, exp10xf2, exp2sf2, exp2df2, exp2xf2): New patterns to implement exp10, exp10f, exp10l, exp2, exp2f and exp2l built-ins as inline x87 intrinsics. * gcc.dg/builtins-34.c: New test. From-SVN: r79279 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a64ba71aa21..0f3c63e46e5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,19 @@ +2004-03-10 Uros Bizjak + + * optabs.h (enum optab_index): Add new OTI_exp10 and OTI_exp2. + (exp10_optab, exp2_optab): Define corresponding macros. + * optabs.c (init_optabs): Initialize exp10_optab and exp2_optab. + * genopinit.c (optabs): Implement exp10_optab and exp2_optab + using exp10?f2 and exp2?f2 patterns. + * builtins.c (expand_builtin_mathfn): Handle BUILT_IN_EXP10{,F,L} + using exp10_optab, and BUILT_IN_EXP2{,F,L} using exp2_optab. + (expand_builtin): Expand BUILT_IN_EXP10{,F,L} and BUILT_IN_EXP2{,F,L} + using expand_builtin_mathfn if flag_unsafe_math_optimizations is set. + + * config/i386/i386.md (exp10sf2, exp10df2, exp10xf2, exp2sf2, + exp2df2, exp2xf2): New patterns to implement exp10, exp10f, exp10l, + exp2, exp2f and exp2l built-ins as inline x87 intrinsics. + 2004-03-10 Anthony Green * doc/invoke.texi (ARM Options): Fix -mpfu typo. diff --git a/gcc/builtins.c b/gcc/builtins.c index 1eeedd254bc..daf06e8fc3e 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -1629,6 +1629,14 @@ expand_builtin_mathfn (tree exp, rtx target, rtx subtarget) case BUILT_IN_EXPF: case BUILT_IN_EXPL: errno_set = true; builtin_optab = exp_optab; break; + case BUILT_IN_EXP10: + case BUILT_IN_EXP10F: + case BUILT_IN_EXP10L: + errno_set = true; builtin_optab = exp10_optab; break; + case BUILT_IN_EXP2: + case BUILT_IN_EXP2F: + case BUILT_IN_EXP2L: + errno_set = true; builtin_optab = exp2_optab; break; case BUILT_IN_LOG: case BUILT_IN_LOGF: case BUILT_IN_LOGL: @@ -5107,6 +5115,12 @@ expand_builtin (tree exp, rtx target, rtx subtarget, enum machine_mode mode, case BUILT_IN_EXP: case BUILT_IN_EXPF: case BUILT_IN_EXPL: + case BUILT_IN_EXP10: + case BUILT_IN_EXP10F: + case BUILT_IN_EXP10L: + case BUILT_IN_EXP2: + case BUILT_IN_EXP2F: + case BUILT_IN_EXP2L: case BUILT_IN_LOG: case BUILT_IN_LOGF: case BUILT_IN_LOGL: diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 2bee3576f3f..c9e7c8caa52 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -15268,6 +15268,7 @@ (set (match_dup 4) (mult:XF (match_dup 2) (match_dup 3))) (set (match_dup 5) (unspec:XF [(match_dup 4)] UNSPEC_FRNDINT)) (set (match_dup 6) (minus:XF (match_dup 4) (match_dup 5))) + (set (match_dup 7) (unspec:XF [(match_dup 6)] UNSPEC_F2XM1)) (set (match_dup 9) (plus:XF (match_dup 7) (match_dup 8))) (parallel [(set (match_operand:DF 0 "register_operand" "") @@ -15309,6 +15310,136 @@ emit_move_insn (operands[7], CONST1_RTX (XFmode)); /* fld1 */ }) +(define_expand "exp10sf2" + [(set (match_dup 2) + (float_extend:XF (match_operand:SF 1 "register_operand" ""))) + (set (match_dup 4) (mult:XF (match_dup 2) (match_dup 3))) + (set (match_dup 5) (unspec:XF [(match_dup 4)] UNSPEC_FRNDINT)) + (set (match_dup 6) (minus:XF (match_dup 4) (match_dup 5))) + (set (match_dup 7) (unspec:XF [(match_dup 6)] UNSPEC_F2XM1)) + (set (match_dup 9) (plus:XF (match_dup 7) (match_dup 8))) + (parallel [(set (match_operand:SF 0 "register_operand" "") + (unspec:SF [(match_dup 9) (match_dup 5)] UNSPEC_FSCALE)) + (clobber (match_scratch:SF 5 ""))])] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && flag_unsafe_math_optimizations" +{ + rtx temp; + int i; + + for (i=2; i<10; i++) + operands[i] = gen_reg_rtx (XFmode); + temp = standard_80387_constant_rtx (6); /* fldl2t */ + emit_move_insn (operands[3], temp); + emit_move_insn (operands[8], CONST1_RTX (XFmode)); /* fld1 */ +}) + +(define_expand "exp10df2" + [(set (match_dup 2) + (float_extend:XF (match_operand:DF 1 "register_operand" ""))) + (set (match_dup 4) (mult:XF (match_dup 2) (match_dup 3))) + (set (match_dup 5) (unspec:XF [(match_dup 4)] UNSPEC_FRNDINT)) + (set (match_dup 6) (minus:XF (match_dup 4) (match_dup 5))) + (set (match_dup 7) (unspec:XF [(match_dup 6)] UNSPEC_F2XM1)) + (set (match_dup 9) (plus:XF (match_dup 7) (match_dup 8))) + (parallel [(set (match_operand:DF 0 "register_operand" "") + (unspec:DF [(match_dup 9) (match_dup 5)] UNSPEC_FSCALE)) + (clobber (match_scratch:DF 5 ""))])] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && flag_unsafe_math_optimizations" +{ + rtx temp; + int i; + + for (i=2; i<10; i++) + operands[i] = gen_reg_rtx (XFmode); + temp = standard_80387_constant_rtx (6); /* fldl2t */ + emit_move_insn (operands[3], temp); + emit_move_insn (operands[8], CONST1_RTX (XFmode)); /* fld1 */ +}) + +(define_expand "exp10xf2" + [(set (match_dup 3) (mult:XF (match_operand:XF 1 "register_operand" "") + (match_dup 2))) + (set (match_dup 4) (unspec:XF [(match_dup 3)] UNSPEC_FRNDINT)) + (set (match_dup 5) (minus:XF (match_dup 3) (match_dup 4))) + (set (match_dup 6) (unspec:XF [(match_dup 5)] UNSPEC_F2XM1)) + (set (match_dup 8) (plus:XF (match_dup 6) (match_dup 7))) + (parallel [(set (match_operand:XF 0 "register_operand" "") + (unspec:XF [(match_dup 8) (match_dup 4)] UNSPEC_FSCALE)) + (clobber (match_scratch:XF 5 ""))])] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && flag_unsafe_math_optimizations" +{ + rtx temp; + int i; + + for (i=2; i<9; i++) + operands[i] = gen_reg_rtx (XFmode); + temp = standard_80387_constant_rtx (6); /* fldl2t */ + emit_move_insn (operands[2], temp); + emit_move_insn (operands[7], CONST1_RTX (XFmode)); /* fld1 */ +}) + +(define_expand "exp2sf2" + [(set (match_dup 2) + (float_extend:XF (match_operand:SF 1 "register_operand" ""))) + (set (match_dup 3) (unspec:XF [(match_dup 2)] UNSPEC_FRNDINT)) + (set (match_dup 4) (minus:XF (match_dup 2) (match_dup 3))) + (set (match_dup 5) (unspec:XF [(match_dup 4)] UNSPEC_F2XM1)) + (set (match_dup 7) (plus:XF (match_dup 5) (match_dup 6))) + (parallel [(set (match_operand:SF 0 "register_operand" "") + (unspec:SF [(match_dup 7) (match_dup 3)] UNSPEC_FSCALE)) + (clobber (match_scratch:SF 3 ""))])] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && flag_unsafe_math_optimizations" +{ + int i; + + for (i=2; i<8; i++) + operands[i] = gen_reg_rtx (XFmode); + emit_move_insn (operands[6], CONST1_RTX (XFmode)); /* fld1 */ +}) + +(define_expand "exp2df2" + [(set (match_dup 2) + (float_extend:XF (match_operand:DF 1 "register_operand" ""))) + (set (match_dup 3) (unspec:XF [(match_dup 2)] UNSPEC_FRNDINT)) + (set (match_dup 4) (minus:XF (match_dup 2) (match_dup 3))) + (set (match_dup 5) (unspec:XF [(match_dup 4)] UNSPEC_F2XM1)) + (set (match_dup 7) (plus:XF (match_dup 5) (match_dup 6))) + (parallel [(set (match_operand:DF 0 "register_operand" "") + (unspec:DF [(match_dup 7) (match_dup 3)] UNSPEC_FSCALE)) + (clobber (match_scratch:DF 3 ""))])] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && flag_unsafe_math_optimizations" +{ + int i; + + for (i=2; i<8; i++) + operands[i] = gen_reg_rtx (XFmode); + emit_move_insn (operands[6], CONST1_RTX (XFmode)); /* fld1 */ +}) + +(define_expand "exp2xf2" + [(set (match_dup 2) (match_operand:XF 1 "register_operand" "")) + (set (match_dup 3) (unspec:XF [(match_dup 2)] UNSPEC_FRNDINT)) + (set (match_dup 4) (minus:XF (match_dup 2) (match_dup 3))) + (set (match_dup 5) (unspec:XF [(match_dup 4)] UNSPEC_F2XM1)) + (set (match_dup 7) (plus:XF (match_dup 5) (match_dup 6))) + (parallel [(set (match_operand:XF 0 "register_operand" "") + (unspec:XF [(match_dup 7) (match_dup 3)] UNSPEC_FSCALE)) + (clobber (match_scratch:XF 3 ""))])] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && flag_unsafe_math_optimizations" +{ + int i; + + for (i=2; i<8; i++) + operands[i] = gen_reg_rtx (XFmode); + emit_move_insn (operands[6], CONST1_RTX (XFmode)); /* fld1 */ +}) + (define_expand "atansf2" [(parallel [(set (match_operand:SF 0 "register_operand" "") (unspec:SF [(match_dup 2) diff --git a/gcc/genopinit.c b/gcc/genopinit.c index 52a224e6d53..b3b651821c0 100644 --- a/gcc/genopinit.c +++ b/gcc/genopinit.c @@ -125,6 +125,8 @@ static const char * const optabs[] = "sin_optab->handlers[$A].insn_code = CODE_FOR_$(sin$a2$)", "cos_optab->handlers[$A].insn_code = CODE_FOR_$(cos$a2$)", "exp_optab->handlers[$A].insn_code = CODE_FOR_$(exp$a2$)", + "exp10_optab->handlers[$A].insn_code = CODE_FOR_$(exp10$a2$)", + "exp2_optab->handlers[$A].insn_code = CODE_FOR_$(exp2$a2$)", "log_optab->handlers[$A].insn_code = CODE_FOR_$(log$a2$)", "log10_optab->handlers[$A].insn_code = CODE_FOR_$(log10$a2$)", "log2_optab->handlers[$A].insn_code = CODE_FOR_$(log2$a2$)", diff --git a/gcc/optabs.c b/gcc/optabs.c index 4fd6ae6aa1e..b9439a7dcd6 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -5274,6 +5274,8 @@ init_optabs (void) sin_optab = init_optab (UNKNOWN); cos_optab = init_optab (UNKNOWN); exp_optab = init_optab (UNKNOWN); + exp10_optab = init_optab (UNKNOWN); + exp2_optab = init_optab (UNKNOWN); log_optab = init_optab (UNKNOWN); log10_optab = init_optab (UNKNOWN); log2_optab = init_optab (UNKNOWN); diff --git a/gcc/optabs.h b/gcc/optabs.h index 496ba1a6fc8..765e169cb46 100644 --- a/gcc/optabs.h +++ b/gcc/optabs.h @@ -154,6 +154,10 @@ enum optab_index OTI_cos, /* Exponential */ OTI_exp, + /* Base-10 Exponential */ + OTI_exp10, + /* Base-2 Exponential */ + OTI_exp2, /* Natural Logarithm */ OTI_log, /* Base-10 Logarithm */ @@ -263,6 +267,8 @@ extern GTY(()) optab optab_table[OTI_MAX]; #define sin_optab (optab_table[OTI_sin]) #define cos_optab (optab_table[OTI_cos]) #define exp_optab (optab_table[OTI_exp]) +#define exp10_optab (optab_table[OTI_exp10]) +#define exp2_optab (optab_table[OTI_exp2]) #define log_optab (optab_table[OTI_log]) #define log10_optab (optab_table[OTI_log10]) #define log2_optab (optab_table[OTI_log2]) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b2aef9c75e2..21b2f0583dd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2004-03-10 Uros Bizjak + + * gcc.dg/builtins-34.c: New test. + 2004-03-10 Kaveh R. Ghazi * gcc.dg/torture/builtin-nonneg-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/builtins-34.c b/gcc/testsuite/gcc.dg/builtins-34.c new file mode 100644 index 00000000000..fb6062be14c --- /dev/null +++ b/gcc/testsuite/gcc.dg/builtins-34.c @@ -0,0 +1,48 @@ +/* Copyright (C) 2004 Free Software Foundation. + + Check that exp10, exp10f, exp10l, exp2, exp2f and exp2l + built-in functions compile. + + Written by Uros Bizjak, 13th February 2004. */ + +/* { dg-do compile } */ +/* { dg-options "-O2 -ffast-math" } */ + +extern double exp10(double); +extern double exp2(double); +extern float exp10f(float); +extern float exp2f(float); +extern long double exp10l(long double); +extern long double exp2l(long double); + + +double test1(double x) +{ + return exp10(x); +} + +double test2(double x) +{ + return exp2(x); +} + +float test1f(float x) +{ + return exp10f(x); +} + +float test2f(float x) +{ + return exp2f(x); +} + +long double test1l(long double x) +{ + return exp10l(x); +} + +long double test2l(long double x) +{ + return exp2l(x); +} +