optabs.h (enum optab_index): Add new OTI_asin and OTI_acos.

2004-04-20  Uros Bizjak  <uros@kss-loka.si>

	* optabs.h (enum optab_index): Add new OTI_asin and OTI_acos.
	(asin_optab, acos_optab): Define corresponding macros.
	* optabs.c (init_optabs): Initialize asin_optab and acos_optab.
	* genopinit.c (optabs): Implement asin_optab and acos_optab
	using asin?f2 and acos?f2 patterns.
	* builtins.c (expand_builtin_mathfn): Handle BUILT_IN_ASIN{,F,L}
	using asin_optab, and BUILT_IN_ACOS{,F,L} using acos_optab.
	(expand_builtin): Expand BUILT_IN_ASIN{,F,L} and BUILT_IN_ACOS{,F,L}
	using expand_builtin_mathfn if flag_unsafe_math_optimizations is set.

	* config/i386/i386.md (asindf2, asinsf2, asinxf2, acosdf2,
	acossf2, acosxf2): New expanders to implement asin, asinf, asinl,
	acos, acosf and acosl built-ins as inline x87 intrinsics.

	* gcc.dg/builtins-39.c: New test.

From-SVN: r80921
This commit is contained in:
Uros Bizjak 2004-04-20 21:40:31 +02:00 committed by Roger Sayle
parent 7b1521e0f4
commit c56122d841
8 changed files with 226 additions and 0 deletions

View file

@ -1,3 +1,19 @@
2004-04-20 Uros Bizjak <uros@kss-loka.si>
* optabs.h (enum optab_index): Add new OTI_asin and OTI_acos.
(asin_optab, acos_optab): Define corresponding macros.
* optabs.c (init_optabs): Initialize asin_optab and acos_optab.
* genopinit.c (optabs): Implement asin_optab and acos_optab
using asin?f2 and acos?f2 patterns.
* builtins.c (expand_builtin_mathfn): Handle BUILT_IN_ASIN{,F,L}
using asin_optab, and BUILT_IN_ACOS{,F,L} using acos_optab.
(expand_builtin): Expand BUILT_IN_ASIN{,F,L} and BUILT_IN_ACOS{,F,L}
using expand_builtin_mathfn if flag_unsafe_math_optimizations is set.
* config/i386/i386.md (asindf2, asinsf2, asinxf2, acosdf2,
acossf2, acosxf2): New expanders to implement asin, asinf, asinl,
acos, acosf and acosl built-ins as inline x87 intrinsics.
2004-04-20 Paul Brook <paul@codesourcery.com>
* config/arm/arm.c (arm_legitimate_address_p): Use rtx_equal_p.

View file

@ -1585,6 +1585,14 @@ expand_builtin_mathfn (tree exp, rtx target, rtx subtarget)
case BUILT_IN_LOG2F:
case BUILT_IN_LOG2L:
errno_set = true; builtin_optab = log2_optab; break;
case BUILT_IN_ASIN:
case BUILT_IN_ASINF:
case BUILT_IN_ASINL:
builtin_optab = asin_optab; break;
case BUILT_IN_ACOS:
case BUILT_IN_ACOSF:
case BUILT_IN_ACOSL:
builtin_optab = acos_optab; break;
case BUILT_IN_TAN:
case BUILT_IN_TANF:
case BUILT_IN_TANL:
@ -5204,6 +5212,12 @@ expand_builtin (tree exp, rtx target, rtx subtarget, enum machine_mode mode,
case BUILT_IN_TAN:
case BUILT_IN_TANF:
case BUILT_IN_TANL:
case BUILT_IN_ASIN:
case BUILT_IN_ASINF:
case BUILT_IN_ASINL:
case BUILT_IN_ACOS:
case BUILT_IN_ACOSF:
case BUILT_IN_ACOSL:
case BUILT_IN_ATAN:
case BUILT_IN_ATANF:
case BUILT_IN_ATANL:

View file

@ -15284,6 +15284,140 @@
DONE;
})
(define_expand "asindf2"
[(set (match_dup 2)
(float_extend:XF (match_operand:DF 1 "register_operand" "")))
(set (match_dup 3) (mult:XF (match_dup 2) (match_dup 2)))
(set (match_dup 5) (minus:XF (match_dup 4) (match_dup 3)))
(set (match_dup 6) (sqrt:XF (match_dup 5)))
(parallel [(set (match_dup 7)
(unspec:XF [(match_dup 6) (match_dup 2)]
UNSPEC_FPATAN))
(clobber (match_scratch:XF 8 ""))])
(set (match_operand:DF 0 "register_operand" "")
(float_truncate:DF (match_dup 7)))]
"! 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[4], CONST1_RTX (XFmode)); /* fld1 */
})
(define_expand "asinsf2"
[(set (match_dup 2)
(float_extend:XF (match_operand:SF 1 "register_operand" "")))
(set (match_dup 3) (mult:XF (match_dup 2) (match_dup 2)))
(set (match_dup 5) (minus:XF (match_dup 4) (match_dup 3)))
(set (match_dup 6) (sqrt:XF (match_dup 5)))
(parallel [(set (match_dup 7)
(unspec:XF [(match_dup 6) (match_dup 2)]
UNSPEC_FPATAN))
(clobber (match_scratch:XF 8 ""))])
(set (match_operand:SF 0 "register_operand" "")
(float_truncate:SF (match_dup 7)))]
"! 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[4], CONST1_RTX (XFmode)); /* fld1 */
})
(define_expand "asinxf2"
[(set (match_dup 2)
(mult:XF (match_operand:XF 1 "register_operand" "")
(match_dup 1)))
(set (match_dup 4) (minus:XF (match_dup 3) (match_dup 2)))
(set (match_dup 5) (sqrt:XF (match_dup 4)))
(parallel [(set (match_operand:XF 0 "register_operand" "")
(unspec:XF [(match_dup 5) (match_dup 1)]
UNSPEC_FPATAN))
(clobber (match_scratch:XF 6 ""))])]
"! TARGET_NO_FANCY_MATH_387 && TARGET_80387
&& flag_unsafe_math_optimizations"
{
int i;
for (i=2; i<6; i++)
operands[i] = gen_reg_rtx (XFmode);
emit_move_insn (operands[3], CONST1_RTX (XFmode)); /* fld1 */
})
(define_expand "acosdf2"
[(set (match_dup 2)
(float_extend:XF (match_operand:DF 1 "register_operand" "")))
(set (match_dup 3) (mult:XF (match_dup 2) (match_dup 2)))
(set (match_dup 5) (minus:XF (match_dup 4) (match_dup 3)))
(set (match_dup 6) (sqrt:XF (match_dup 5)))
(parallel [(set (match_dup 7)
(unspec:XF [(match_dup 2) (match_dup 6)]
UNSPEC_FPATAN))
(clobber (match_scratch:XF 8 ""))])
(set (match_operand:DF 0 "register_operand" "")
(float_truncate:DF (match_dup 7)))]
"! 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[4], CONST1_RTX (XFmode)); /* fld1 */
})
(define_expand "acossf2"
[(set (match_dup 2)
(float_extend:XF (match_operand:SF 1 "register_operand" "")))
(set (match_dup 3) (mult:XF (match_dup 2) (match_dup 2)))
(set (match_dup 5) (minus:XF (match_dup 4) (match_dup 3)))
(set (match_dup 6) (sqrt:XF (match_dup 5)))
(parallel [(set (match_dup 7)
(unspec:XF [(match_dup 2) (match_dup 6)]
UNSPEC_FPATAN))
(clobber (match_scratch:XF 8 ""))])
(set (match_operand:SF 0 "register_operand" "")
(float_truncate:SF (match_dup 7)))]
"! 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[4], CONST1_RTX (XFmode)); /* fld1 */
})
(define_expand "acosxf2"
[(set (match_dup 2)
(mult:XF (match_operand:XF 1 "register_operand" "")
(match_dup 1)))
(set (match_dup 4) (minus:XF (match_dup 3) (match_dup 2)))
(set (match_dup 5) (sqrt:XF (match_dup 4)))
(parallel [(set (match_operand:XF 0 "register_operand" "")
(unspec:XF [(match_dup 1) (match_dup 5)]
UNSPEC_FPATAN))
(clobber (match_scratch:XF 6 ""))])]
"! TARGET_NO_FANCY_MATH_387 && TARGET_80387
&& flag_unsafe_math_optimizations"
{
int i;
for (i=2; i<6; i++)
operands[i] = gen_reg_rtx (XFmode);
emit_move_insn (operands[3], CONST1_RTX (XFmode)); /* fld1 */
})
(define_insn "*fyl2x_sfxf3"
[(set (match_operand:SF 0 "register_operand" "=f")
(unspec:SF [(match_operand:SF 2 "register_operand" "0")

View file

@ -124,7 +124,9 @@ static const char * const optabs[] =
"nearbyint_optab->handlers[$A].insn_code = CODE_FOR_$(nearbyint$a2$)",
"sincos_optab->handlers[$A].insn_code = CODE_FOR_$(sincos$a3$)",
"sin_optab->handlers[$A].insn_code = CODE_FOR_$(sin$a2$)",
"asin_optab->handlers[$A].insn_code = CODE_FOR_$(asin$a2$)",
"cos_optab->handlers[$A].insn_code = CODE_FOR_$(cos$a2$)",
"acos_optab->handlers[$A].insn_code = CODE_FOR_$(acos$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$)",

View file

@ -5380,7 +5380,9 @@ init_optabs (void)
nearbyint_optab = init_optab (UNKNOWN);
sincos_optab = init_optab (UNKNOWN);
sin_optab = init_optab (UNKNOWN);
asin_optab = init_optab (UNKNOWN);
cos_optab = init_optab (UNKNOWN);
acos_optab = init_optab (UNKNOWN);
exp_optab = init_optab (UNKNOWN);
exp10_optab = init_optab (UNKNOWN);
exp2_optab = init_optab (UNKNOWN);

View file

@ -152,8 +152,12 @@ enum optab_index
OTI_sincos,
/* Sine */
OTI_sin,
/* Inverse sine */
OTI_asin,
/* Cosine */
OTI_cos,
/* Inverse cosine */
OTI_acos,
/* Exponential */
OTI_exp,
/* Base-10 Exponential */
@ -271,7 +275,9 @@ extern GTY(()) optab optab_table[OTI_MAX];
#define sqrt_optab (optab_table[OTI_sqrt])
#define sincos_optab (optab_table[OTI_sincos])
#define sin_optab (optab_table[OTI_sin])
#define asin_optab (optab_table[OTI_asin])
#define cos_optab (optab_table[OTI_cos])
#define acos_optab (optab_table[OTI_acos])
#define exp_optab (optab_table[OTI_exp])
#define exp10_optab (optab_table[OTI_exp10])
#define exp2_optab (optab_table[OTI_exp2])

View file

@ -1,3 +1,7 @@
2004-04-20 Uros Bizjak <uros@kss-loka.si>
* gcc.dg/builtins-39.c: New test.
2004-04-20 Aldy Hernandez <aldyh@redhat.com>
* gcc.dg/vmx/vmx.exp: Change DEFAULT_CFLAGS to DEFAULT_VMXCFLAGS.

View file

@ -0,0 +1,48 @@
/* Copyright (C) 2004 Free Software Foundation.
Check that asin, asinf, asinl, acos, acosf
and acosl built-in functions compile.
Written by Uros Bizjak, 20th April 2004. */
/* { dg-do compile } */
/* { dg-options "-O2 -ffast-math" } */
extern double asin(double);
extern double acos(double);
extern float asinf(float);
extern float acosf(float);
extern long double asinl(long double);
extern long double acosl(long double);
double test1(double x)
{
return asin(x);
}
double test2(double x)
{
return acos(x);
}
float test1f(float x)
{
return asinf(x);
}
float test2f(float x)
{
return acosf(x);
}
long double test1l(long double x)
{
return asinl(x);
}
long double test2l(long double x)
{
return acosl(x);
}