> >I have written a custom replacement for library function
> > Math.Pow(double x, double y) for the specific condition of y being
[quoted text clipped - 9 lines]
>
> Willy.
SO, you think a 'goto' would be inlined? Something like:
IntPower(double x, int y)
{ r=1;
start:
if (y>1)
{ r*=x;
y--;
goto start;
}
return r;
Jerry III - 06 Feb 2004 05:13 GMT
I think it was said clearly, any flow control other than if/then/else won't
be inlined. Goto is not one of if/then/else.
Jerry
> > >I have written a custom replacement for library function
> > > Math.Pow(double x, double y) for the specific condition of y being
[quoted text clipped - 21 lines]
> }
> return r;
Willy Denoyette [MVP] - 06 Feb 2004 12:35 GMT
No, as I said only If/then/else control constructs, nothing that would
involve conditional looping.
Note that in your sample the call overhead is very small compared to the
execution time of the loop, especially when y is large.
Willy.
>> >I have written a custom replacement for library function
>> > Math.Pow(double x, double y) for the specific condition of y being
[quoted text clipped - 21 lines]
> }
> return r;
cody - 06 Feb 2004 18:16 GMT
> No, as I said only If/then/else control constructs, nothing that would
> involve conditional looping.
And what about switch-statements?

Signature
cody
[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Willy Denoyette [MVP] - 07 Feb 2004 18:48 GMT
Nope.
Willy.
>> No, as I said only If/then/else control constructs, nothing that would
>> involve conditional looping.
>
> And what about switch-statements?
cody - 07 Feb 2004 23:49 GMT
> >> No, as I said only If/then/else control constructs, nothing that would
> >> involve conditional looping.
> >
> > And what about switch-statements?
>
> Nope.
Why not? a switch is in most cases much faster than if..else if..

Signature
cody
[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Jerry III - 08 Feb 2004 04:23 GMT
But in most cases generates lot more code. JIT won't inline anything over 20
instructions.
Jerry
> > >> No, as I said only If/then/else control constructs, nothing that would
> > >> involve conditional looping.
[quoted text clipped - 10 lines]
> [Freeware, Games and Humor]
> www.deutronium.de.vu || www.deutronium.tk
> The JITter will not inline complex flow controls, complex here means
> anything else then if/then/else (in your case while).
>
> Willy.
Also avoid using and object or class variables in methods you want to
inline.
The following code, for instance, can't be inlined:
class Optimizer {
static int EnergyType = 1;
static double Energy(double dx, double dy, double dz, double rp) {
return (EnergyType == 1) ? rp*Math.Sqrt(1.0/(dx + dy + dz))
: 1.0;
}
}
CLR JIT can only inline very basic code. We generally inline all our
code by copy-and-paste, it is messy, but makes big difference in our case.
James
visumap.net
ThomasR - 08 Feb 2004 16:53 GMT
: Also avoid using and object or class variables in methods you want to
: inline.
[quoted text clipped - 10 lines]
: CLR JIT can only inline very basic code. We generally inline all our
: code by copy-and-paste, it is messy, but makes big difference in our case.
That's interesting that you can't get this code to inline. I have had
similar code inlined (though not with static variables).
For example, this type of code inlines in framework 1.0 fine in my app:
(note this is a struct, not a class, if that might make some difference?)
struct XYZ
{
private int mVal;
static int GetValue()
{
if mVal < 100
return mVal;
else
return SomeMoreComplicatedProcessingRequired();
}
}
tr - 08 Feb 2004 17:00 GMT
Code in previous post was incorrect. GetValue() IS NOT a static function.
struct XYZ
{
private int mVal;
public int GetValue()
{
if mVal < 100
return mVal;
else
return SomeMoreComplicatedProcessingRequired();
}
}