From: Uros Bizjak Date: Tue, 20 Apr 2004 19:40:31 +0000 (+0200) Subject: optabs.h (enum optab_index): Add new OTI_asin and OTI_acos. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c56122d841f0a8f8941f435e9e0e98d3b04f937b;p=gcc.git optabs.h (enum optab_index): Add new OTI_asin and OTI_acos. 2004-04-20 Uros Bizjak * 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9c58eedd324..fb0b0929be7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,19 @@ +2004-04-20 Uros Bizjak + + * 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 * config/arm/arm.c (arm_legitimate_address_p): Use rtx_equal_p. diff --git a/gcc/builtins.c b/gcc/builtins.c index 66b4a638db4..c7627c053da 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -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: diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 2c498e0bf9f..c0a3ff4cfe5 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -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") diff --git a/gcc/genopinit.c b/gcc/genopinit.c index f817969cf99..95d53107ae2 100644 --- a/gcc/genopinit.c +++ b/gcc/genopinit.c @@ -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$)", diff --git a/gcc/optabs.c b/gcc/optabs.c index e8f4dc055da..b32315ba463 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -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); diff --git a/gcc/optabs.h b/gcc/optabs.h index 16caa1855d6..2e0a47ab9e9 100644 --- a/gcc/optabs.h +++ b/gcc/optabs.h @@ -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]) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index af0cb755604..c88423e1cbb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2004-04-20 Uros Bizjak + + * gcc.dg/builtins-39.c: New test. + 2004-04-20 Aldy Hernandez * gcc.dg/vmx/vmx.exp: Change DEFAULT_CFLAGS to DEFAULT_VMXCFLAGS. diff --git a/gcc/testsuite/gcc.dg/builtins-39.c b/gcc/testsuite/gcc.dg/builtins-39.c new file mode 100644 index 00000000000..6359be2b30e --- /dev/null +++ b/gcc/testsuite/gcc.dg/builtins-39.c @@ -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); +} +