为什么不JIT内联这个? [英] why won't JIT inline this?
问题描述
我已经为库函数编写了一个自定义的替代品
Math.Pow(double x,double y)表示y的特定条件
整数和> = 0。它的速度是Math.Pow()的两倍,但我无法获得编译内联编译它的
。我尝试了很多不同的方法,但似乎没什么用。我正在使用本机
模式进行调试,我确实看到属性得到内联,如我所料。
有什么想法吗?
C#代码,IL代码和优化的反汇编如下:
C#代码:
public static double IntPower(double x, int y)
{
double r = 1;
while(y> 0)
{
r * = x;
y--;
}
返回r;
}
ILDASM:
..method public hidebysig static float64 IntPower(float64 x,
int32 y)cil managed
{
//代码大小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_00 13:starg.sy
IL_0015:ldarg.1
IL_0016:ldc.i4.0
IL_0017:bgt.s IL_000c
IL_0019:ldloc.0
IL_001a:ret
} //方法结束EMath :: IntPower
反汇编:
设置并调用IntPower()函数:
02FD04E5推40080000h
02FD04EA推0
02FD04EC mov ecx,2
02FD04F1来电dword ptr ds:[3E6854h] ...
IntPower功能:
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
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
推荐答案
模糊< tr ****** @ earthlink.net>写道:
Fuzzy <tr******@earthlink.net> wrote:
我已经为库函数编写了一个自定义替换函数
Math.Pow(double x,double y),因为y的特定条件是整数和> = 0 。它的速度是Math.Pow()的两倍,但我不能让编译器内联编译它。我尝试过很多不同的方法,但似乎没什么用。我正在以原生
模式进行调试,我确实看到属性得到内联,如我所料。
任何想法?
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?
我相信JIT编译器没有内联任何涉及循环的东西。
-
Jon Skeet - < sk *** @ pobox .com>
http://www.pobox.com/~skeet
如果回复该组,请不要给我发邮件
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
模糊 < TR ****** @ earthlink.net>在消息中写道
news:95 ************************** @ posting.google.c om ...
"Fuzzy" <tr******@earthlink.net> wrote in message
news:95**************************@posting.google.c om...
我已经为库函数编写了一个自定义替换函数
Math.Pow(double x,double y),因为y的特定条件是整数和> = 0。它的速度是Math.Pow()的两倍,但我不能让编译器内联编译它。我尝试过很多不同的方法,但似乎没什么用。我正在以原生
模式进行调试,我确实看到属性得到内联,如我所料。
任何想法?
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?
JITter不会内联复杂的流量控制,复杂的这里意味着
其他任何东西然后if / then / else(在你的情况下)。
Willy。
The JITter will not inline complex flow controls, complex here means
anything else then if/then/else (in your case while).
Willy.
Jon Skeet [C#MVP]< sk *** @ pobox.com>在消息新闻中写道:< MP ************************ @ msnews.microsoft。 com> ...
< clipped>
Jon Skeet [C# MVP] <sk***@pobox.com> wrote in message news:<MP************************@msnews.microsoft. com>...
<clipped>
我认为JIT编译器没有内联任何涉及循环的内容。
I believe the JIT compiler doesn''t inline anything involving loops.
这真的令人失望。这个循环非常小,可以轻松地内联
。我会手动内联它,看看性能如何改变b $ b;并且还看看计算时间是什么指数值
压倒函数调用开销。
感谢您的回复。
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.
这篇关于为什么不JIT内联这个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!