473,386 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

why won't JIT inline this?

I have written a custom replacement for library function
Math.Pow(double x, double y) for the specific condition of y being
integer and >=0. It is twice as fast as Math.Pow(), but I cannot get
the compiler to inline compile it. I've tried many different
approaches, but nothing seems to work. I am debugging in native
mode, and I do see property get's inlined as I would expect.

Any ideas?

C# code, IL code, and the optimized disassembly follow:

C# code:
public static double IntPower(double x, int y)
{
double r=1;
while (y>0)
{
r*=x;
y--;
}
return r;
}
ILDASM:
..method public hidebysig static float64 IntPower(float64 x,
int32 y) cil managed
{
// Code size 27 (0x1b)
.maxstack 2
.locals init (float64 V_0)
IL_0000: ldc.r8 1.
IL_0009: stloc.0
IL_000a: br.s IL_0015
IL_000c: ldloc.0
IL_000d: ldarg.0
IL_000e: mul
IL_000f: stloc.0
IL_0010: ldarg.1
IL_0011: ldc.i4.1
IL_0012: sub
IL_0013: starg.s y
IL_0015: ldarg.1
IL_0016: ldc.i4.0
IL_0017: bgt.s IL_000c
IL_0019: ldloc.0
IL_001a: ret
} // end of method EMath::IntPower

disassembly:
set and call IntPower() function:
02FD04E5 push 40080000h
02FD04EA push 0
02FD04EC mov ecx,2
02FD04F1 call dword ptr ds:[3E6854h] ...
IntPower function:
02FD07B0 fld1
02FD07B2 cmp ecx,0
02FD07B5 jle 02FD07C3
02FD07B7 fld qword ptr [esp+4]
02FD07BB fmulp st(1),st
02FD07BD dec ecx
02FD07BE cmp ecx,0
02FD07C1 jg 02FD07B7
02FD07C3 ret 8
Nov 15 '05 #1
10 1481
Fuzzy <tr******@earthlink.net> wrote:
I have written a custom replacement for library function
Math.Pow(double x, double y) for the specific condition of y being
integer and >=0. It is twice as fast as Math.Pow(), but I cannot get
the compiler to inline compile it. I've tried many different
approaches, but nothing seems to work. I am debugging in native
mode, and I do see property get's inlined as I would expect.

Any ideas?


I believe the JIT compiler doesn't inline anything involving loops.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2

"Fuzzy" <tr******@earthlink.net> wrote in message
news:95**************************@posting.google.c om...
I have written a custom replacement for library function
Math.Pow(double x, double y) for the specific condition of y being
integer and >=0. It is twice as fast as Math.Pow(), but I cannot get
the compiler to inline compile it. I've tried many different
approaches, but nothing seems to work. I am debugging in native
mode, and I do see property get's inlined as I would expect.

Any ideas?


The JITter will not inline complex flow controls, complex here means
anything else then if/then/else (in your case while).

Willy.
Nov 15 '05 #3
Jon Skeet [C# MVP] <sk***@pobox.com> wrote in message news:<MP************************@msnews.microsoft. com>...
<clipped>

I believe the JIT compiler doesn't inline anything involving loops.


That's really disappointing. This loop is so small that it could
easily be inlined. I'll manually inline it to see how the performance
changes; and also see at what exponent value the calculation time
overwhelms the function call overhead.

Thanks for the response.
Nov 15 '05 #4
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message news:<O#**************@TK2MSFTNGP11.phx.gbl>...
"Fuzzy" <tr******@earthlink.net> wrote in message
news:95**************************@posting.google.c om...
I have written a custom replacement for library function
Math.Pow(double x, double y) for the specific condition of y being
integer and >=0. It is twice as fast as Math.Pow(), but I cannot get
the compiler to inline compile it. I've tried many different
approaches, but nothing seems to work. I am debugging in native
mode, and I do see property get's inlined as I would expect.

Any ideas?


The JITter will not inline complex flow controls, complex here means
anything else then if/then/else (in your case while).

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;
Nov 15 '05 #5
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

"Fuzzy" <tr******@earthlink.net> wrote in message
news:95**************************@posting.google.c om...
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message

news:<O#**************@TK2MSFTNGP11.phx.gbl>...
"Fuzzy" <tr******@earthlink.net> wrote in message
news:95**************************@posting.google.c om...
I have written a custom replacement for library function
Math.Pow(double x, double y) for the specific condition of y being
integer and >=0. It is twice as fast as Math.Pow(), but I cannot get
the compiler to inline compile it. I've tried many different
approaches, but nothing seems to work. I am debugging in native
mode, and I do see property get's inlined as I would expect.

Any ideas?


The JITter will not inline complex flow controls, complex here means
anything else then if/then/else (in your case while).

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;

Nov 15 '05 #6
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.

"Fuzzy" <tr******@earthlink.net> wrote in message
news:95**************************@posting.google.c om...
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:<O#**************@TK2MSFTNGP11.phx.gbl>...
"Fuzzy" <tr******@earthlink.net> wrote in message
news:95**************************@posting.google.c om...
>I have written a custom replacement for library function
> Math.Pow(double x, double y) for the specific condition of y being
> integer and >=0. It is twice as fast as Math.Pow(), but I cannot get
> the compiler to inline compile it. I've tried many different
> approaches, but nothing seems to work. I am debugging in native
> mode, and I do see property get's inlined as I would expect.
>
> Any ideas?
>


The JITter will not inline complex flow controls, complex here means
anything else then if/then/else (in your case while).

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;

Nov 15 '05 #7
> No, as I said only If/then/else control constructs, nothing that would
involve conditional looping.


And what about switch-statements?

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #8
Nope.

Willy.

"cody" <do*********************@gmx.de> wrote in message
news:eB**************@TK2MSFTNGP12.phx.gbl...
No, as I said only If/then/else control constructs, nothing that would
involve conditional looping.


And what about switch-statements?

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk

Nov 15 '05 #9
> >> 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..

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 15 '05 #10
But in most cases generates lot more code. JIT won't inline anything over 20
instructions.

Jerry

"cody" <do*********************@gmx.de> wrote in message
news:#d**************@TK2MSFTNGP10.phx.gbl...
> 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..

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk

Nov 15 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Heath | last post by:
What might cause a div to refuse to go to the width that I have tried to set for it? See #mainBody and .box Here are the styles and the html below: body, #container { padding: 10px 10px...
1
by: Patrick | last post by:
I am trying to get "first-letter" to work inline withing an anchor. Actually I have not been able to get it to work within an <a> tag whether inline, linked, or embedded. Using IE6 service pack 1....
20
by: Grumble | last post by:
Hello everyone, As far as I understand, the 'inline' keyword is a hint for the compiler to consider the function in question as a candidate for inlining, yes? What happens when a function with...
27
by: Nicholas Couch | last post by:
I have a little form with a couple of dynamically generated list boxes. When the user makes a selection from the first box, the second box is refreshed. When they make a selection from the second...
5
by: dje | last post by:
In the OnClick event on a radioButtonList, I run a javascript to show/hide the appropriate div along with a submit button, which displays as expected. The problem is the submit no longer works on...
5
by: Barry | last post by:
Hi, group First, I write same cases I've already known, I don't concern that specific compiler really do inline or not. Please check them if they are right, and add the cases I miss 1. //...
2
by: Barry | last post by:
Hi, group First, I write same cases I've already known, I don't concern that specific compiler really do inline or not. Please check them if they are right, and add the cases I miss 1. //...
5
by: Summercool | last post by:
wow... i didn't know that, for <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http:// www.w3.org/TR/html4/loose.dtd"> <span style="width: 100px; background:...
4
by: z55177 | last post by:
My domain: http://www.esthevision.cz/ This is the cause of my problem. The template is supposed to look somewhat like this: PINK STRIPE http://themebot.com/website-templates/ht... I created an...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.