Sharplab
https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBDAzgWwB8ABABgAJiBGAOgDkBXfGKASzFwG4BYAKD+IBmcgwB2ubADMYlAEzkAwnwDefcuvKRxGcq1E6AYtjAZo5ALzlZpFAA5O5APSOr5AHrkqVNRq24dejoAygAWrJI6ll48vBrksNgAJhCiADYAnuQAajAm0AA8gQB82bmmUEZ5UBbkojAA7qVVhfpFABSV5QCUMXE+6kJN5S0YJQAirABurIkwbTnNxeSTXRYlk05D0J3QvRp8AL5AA
Given
usingSystem.Numerics;publicunsafeclassC{constintFactor=2048;// 2 ^ 11constintShift=11;readonlyVector<int>VectorFactor=newVector<int>(Factor);publicVector<int>Divide(Vector<int>v)=>v/VectorFactor;}Output
The assembly output for x64 is:
; Core CLR v4.700.20.41105 on amd64C..ctor() L0000: vzeroupper L0003: moveax,0x800 L0008: vmovd xmm0,eax L000c: vpbroadcastdymm0,xmm0 L0011: vmovupd[rcx+8],ymm0 L0016: vzeroupper L0019: retC.Divide(System.Numerics.Vector`1<Int32>) L0000: pushrsi L0001: subrsp,0x50 L0005: vzeroupper L0008: movrsi,rdx L000b: movrdx,rsi L000e: vmovupdymm0,[rcx+8] L0013: vmovupd[rsp+0x20],ymm0 L0019: movrcx,rdx L001c: movrdx,r8 L001f: lear8,[rsp+0x20] L0024: call System.Numerics.Vector`1[[System.Int32, System.Private.CoreLib]].op_Division(System.Numerics.Vector`1<Int32>, System.Numerics.Vector`1<Int32>) L0029: movrax,rsi L002c: vzeroupper L002f: addrsp,0x50 L0033: poprsi L0034: ret
Expected
The division is inlined and division by constant is recognized and "optimal" SIMD is emitted e.g. with shifts or similar.
cc: @tannergooding
category:cq
theme:inlining
skill-level:intermediate
cost:medium
Sharplab
https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBDAzgWwB8ABABgAJiBGAOgDkBXfGKASzFwG4BYAKD+IBmcgwB2ubADMYlAEzkAwnwDefcuvKRxGcq1E6AYtjAZo5ALzlZpFAA5O5APSOr5AHrkqVNRq24dejoAygAWrJI6ll48vBrksNgAJhCiADYAnuQAajAm0AA8gQB82bmmUEZ5UBbkojAA7qVVhfpFABSV5QCUMXE+6kJN5S0YJQAirABurIkwbTnNxeSTXRYlk05D0J3QvRp8AL5AA
Given
Output
The assembly output for x64 is:
Expected
The division is inlined and division by constant is recognized and "optimal" SIMD is emitted e.g. with shifts or similar.
cc: @tannergooding
category:cq
theme:inlining
skill-level:intermediate
cost:medium