Commit b3810360 by Kaveh R. Ghazi Committed by Kaveh Ghazi

* convert.c (convert_to_real): Reformat using switch stmt.

From-SVN: r79667
parent 9d363a56
2004-03-18 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* convert.c (convert_to_real): Reformat using switch stmt.
2004-03-18 Mark Mitchell <mark@codesourcery.com> 2004-03-18 Mark Mitchell <mark@codesourcery.com>
* c-common.c (pointer_int_sum): Do not complain about using * c-common.c (pointer_int_sum): Do not complain about using
......
...@@ -131,44 +131,48 @@ convert_to_real (tree type, tree expr) ...@@ -131,44 +131,48 @@ convert_to_real (tree type, tree expr)
present in runtime. */ present in runtime. */
/* Convert (float)sqrt((double)x) where x is float into sqrtf(x) */ /* Convert (float)sqrt((double)x) where x is float into sqrtf(x) */
if (optimize if (optimize
&& (fcode == BUILT_IN_SQRT
|| fcode == BUILT_IN_SQRTL
|| fcode == BUILT_IN_SIN
|| fcode == BUILT_IN_SINL
|| fcode == BUILT_IN_COS
|| fcode == BUILT_IN_COSL
|| fcode == BUILT_IN_EXP
|| fcode == BUILT_IN_EXPL
|| fcode == BUILT_IN_LOG
|| fcode == BUILT_IN_LOGL)
&& (TYPE_MODE (type) == TYPE_MODE (double_type_node) && (TYPE_MODE (type) == TYPE_MODE (double_type_node)
|| TYPE_MODE (type) == TYPE_MODE (float_type_node))) || TYPE_MODE (type) == TYPE_MODE (float_type_node)))
{ {
tree arg0 = strip_float_extensions (TREE_VALUE (TREE_OPERAND (expr, 1))); switch (fcode)
tree newtype = type; {
#define CASE_MATHFN(FN) case BUILT_IN_##FN: case BUILT_IN_##FN##L:
/* We have (outertype)sqrt((innertype)x). Choose the wider mode from CASE_MATHFN (SQRT)
the both as the safe type for operation. */ CASE_MATHFN (SIN)
if (TYPE_PRECISION (TREE_TYPE (arg0)) > TYPE_PRECISION (type)) CASE_MATHFN (COS)
newtype = TREE_TYPE (arg0); CASE_MATHFN (EXP)
CASE_MATHFN (LOG)
/* Be careful about integer to fp conversions. #undef CASE_MATHFN
These may overflow still. */
if (FLOAT_TYPE_P (TREE_TYPE (arg0))
&& TYPE_PRECISION (newtype) < TYPE_PRECISION (itype)
&& (TYPE_MODE (newtype) == TYPE_MODE (double_type_node)
|| TYPE_MODE (newtype) == TYPE_MODE (float_type_node)))
{
tree arglist;
tree fn = mathfn_built_in (newtype, fcode);
if (fn)
{ {
arglist = build_tree_list (NULL_TREE, fold (convert_to_real (newtype, arg0))); tree arg0 = strip_float_extensions (TREE_VALUE (TREE_OPERAND (expr, 1)));
expr = build_function_call_expr (fn, arglist); tree newtype = type;
if (newtype == type)
return expr; /* We have (outertype)sqrt((innertype)x). Choose the wider mode from
the both as the safe type for operation. */
if (TYPE_PRECISION (TREE_TYPE (arg0)) > TYPE_PRECISION (type))
newtype = TREE_TYPE (arg0);
/* Be careful about integer to fp conversions.
These may overflow still. */
if (FLOAT_TYPE_P (TREE_TYPE (arg0))
&& TYPE_PRECISION (newtype) < TYPE_PRECISION (itype)
&& (TYPE_MODE (newtype) == TYPE_MODE (double_type_node)
|| TYPE_MODE (newtype) == TYPE_MODE (float_type_node)))
{
tree arglist;
tree fn = mathfn_built_in (newtype, fcode);
if (fn)
{
arglist = build_tree_list (NULL_TREE, fold (convert_to_real (newtype, arg0)));
expr = build_function_call_expr (fn, arglist);
if (newtype == type)
return expr;
}
}
} }
default:
break;
} }
} }
if (optimize if (optimize
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment