gfoidl / Stochastics

Stochastic tools, distrubution, analysis
MIT License
3 stars 0 forks source link

Stack spill in Unsafe.As<Vector256<double>, Vector128<double>> #76

Closed gfoidl closed 6 years ago

gfoidl commented 6 years ago

In https://github.com/gfoidl/Stochastics/blob/17a5633aade6a13f261844f2f4717b72a0f6029e/source/gfoidl.Stochastics/VectorHelper.cs#L67 current JIT do a stack spill (issue is tracked in coreclr).

00007FF880D343A7  lea         rax,[rcx+8]
00007FF880D343AB  vmovupd     ymm0,ymmword ptr [rax]
00007FF880D343B0  vhaddpd     ymm0,ymm0,ymm0
00007FF880D343B5  vmovupd     ymmword ptr [rsp],ymm0        ; stack spill
00007FF880D343BB  vmovupd     ymm0,ymmword ptr [rsp]        ; stack spill
00007FF880D343C1  vextractf128 xmm0,ymm0,1
00007FF880D343C7  vmovupd     xmm1,xmmword ptr [rsp]        ; stack spill
00007FF880D343CD  vaddpd      xmm0,xmm1,xmm0

Ideally it just should be

00007FF880D24553  lea         rax,[rcx+8]
00007FF880D24557  vmovupd     ymm0,ymmword ptr [rax]
00007FF880D2455C  vhaddpd     ymm0,ymm0,ymm0
00007FF880D24561  vextractf128 xmm1,ymm0,1
00007FF880D24567  vaddpd      xmm0,xmm0,xmm1