[gfortran] Exponentiation by integral exponents
Tobias Schlüter
tobias.schlueter@physik.uni-muenchen.de
Wed Apr 28 03:48:00 GMT 2004
Paul Brook wrote:
> On Tuesday 27 April 2004 23:07, Tobias Schlüter wrote:
>
>>Andrew Pinski wrote:
>>
>>>On Apr 27, 2004, at 17:14, Tobias Schlüter wrote:
>>>
>>>>FYI I have ported Andy's code for exponentiation by an integral
>>>>exponent to our tree. This is an implementation of Knuth's algorithm
>>
>>...
>>
>>
>>>You should not need it if you use __builtin_pow and you turn on
>>>flag_unsafe_math_optimizations on. Maybe the best way is to have
>>>another flag
>>>to say expand __builtin_pow always.
>>
>>Does the builtin recognize the case pow(x,(float)i), where i is an
>>integer? Then this sounds like a very good idea.
>
>
> Maybe the way to indicate we always want to expand __builtin_pow would be to
> pass the second parameter with an integer type. It may be easier to add
> __builtin_powi to avoid needing polymorphic builtins.
Definitely.
Anyway, I tried to implement Andrew's suggestion as a quick'n'dirty
hack. Right now I get an ICE. What is the correct way to generate the
equivalent of a typecast in C?
What I tried was this: gfc_conv_power_op has this code:
type = TREE_TYPE (lse.expr);
kind = expr->op1->ts.kind;
switch (expr->op2->ts.type)
{
case BT_INTEGER:
/* Integer powers are expanded inline as multiplications. */
gfc_conv_integer_power (se, lse.expr, rse.expr);
return;
Instead of calling gfc_integer_power and returning, I want to convert
rse.expr to the type of lse.expr. So I tried both of the following
(gfc_conv_expr_type has no explanatory comment, so I'm just guessing
that this might be the function I'm looking for):
gfc_conv_expr_type (&rse, expr->op2, type); // first try
rse.expr = convert (type, rse.expr); // second try
After that I select the function based on the type of lse.expr as in the
real case and continue as if rse.expr had not been int all the time.
What am I missing? I'm still within my first three hours of messing with
gcc trees, so I might well be missing the obvious.
- Tobi
More information about the Gcc
mailing list