optabs.h (enum optab_index): Add new OTI_exp10 and OTI_exp2.

2004-03-10  Uros Bizjak  <uros@kss-loka.si>

	* 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
This commit is contained in:
Uros Bizjak 2004-03-10 23:36:22 +01:00 committed by Roger Sayle
parent 5199e2c6f1
commit a251102ea1
8 changed files with 223 additions and 0 deletions

View File

@ -1,3 +1,19 @@
2004-03-10 Uros Bizjak <uros@kss-loka.si>
* 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 <green@redhat.com>
* doc/invoke.texi (ARM Options): Fix -mpfu typo.

View File

@ -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:

View File

@ -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)

View File

@ -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$)",

View File

@ -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);

View File

@ -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])

View File

@ -1,3 +1,7 @@
2004-03-10 Uros Bizjak <uros@kss-loka.si>
* gcc.dg/builtins-34.c: New test.
2004-03-10 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* gcc.dg/torture/builtin-nonneg-1.c: New test.

View File

@ -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);
}