更新时间:2023-02-20 22:40:57
确定经过大量的研究(伤心!我知道),我认为已经回答了我的问题:
OK after much research (sad I know!), I think have answered my own question:
答案是也许。
显然,JIT编译做寻找模式(见的 http://blogs.msdn.com/b/clrcodegeneration/archive/2009/08/13/array-bounds-check-elimination-in-the-clr.aspx )以决定何时以及如何阵列边界检查可以被优化,但无论是我被猜测在与否不知相同的模式。
The answer is Maybe. Apparently the JIT compilers do look for patterns (see http://blogs.msdn.com/b/clrcodegeneration/archive/2009/08/13/array-bounds-check-elimination-in-the-clr.aspx) to decide when and how array bounds checking can be optimized but whether it is the same pattern I was guessing at or not I don't know.
在这种情况下,它是一个有争议的问题,因为相对速度增加(2)是由于东西比这更多。原来,64 JIT编译器足够聪明摸出一个数组长度是否是恒定的(而且似乎也解开的循环次数多):因此,代码只是界限在每个迭代结束和检查每个解开成为刚: -
In this case, it is a moot point because the relative speed increase of (2) was due to something more than that. Turns out that the x64 JIT compiler is clever enough to work out whether an array length is constant (and seemingly also a multiple of the number of unrolls in a loop): So the code was only bounds checking at the end of each iteration and the each unroll became just:-
total += intArray[j]; j++;
00000081 8B 44 0B 10 mov eax,dword ptr [rbx+rcx+10h]
00000085 03 F0 add esi,eax
我通过改变应用,让数组的大小在命令行上指定的,看到不同的汇编输出证明了这一点。
I proved this by changing the app to let the array size be specified on the command line and seeing the different assembler output.
本练习中发现其他的事情: -
Other things discovered during this excercise:-