You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here we have a TYP_MASK local that is live across a suspension point. Runtime async thus saves it to memory across the suspension, and the backend asserts when it sees the mask-typed STOREIND:
I will move this to .NET 11. Runtime async is experimental and I think it is ok if there are rough edges in the intersection between runtime async and mask based hardware intrinsics.
The way the instructions work for SIMD is a bit interesting where the lookup tables have them "unprefixed" and so we'd have 0x0F91 or 0x0F6691 as the code. We then call emitGetAdjustedSize which is supposed to "fix" this based on the encoding we'll actually end up using (such as VEX or EVEX).
It looks like we'd hit this path for KMOVB or KMOVQ, which likely has been untested due to there not being TYP_MASK fields since its a synthetic JIT only type and so we'd only ever spill to the stack before. Most other paths (like emitInsSizeSV and emitInsSizeCV) just reuse emitInsSize where-as emitInsSizeAM has its own logic (which looks largely unnecessary since it's really just emitInsSize + addressing mode sizing).
The short term fix would be to just include the kmov instructions here as well in the assert. The long term "better" fix would be to update emitInsSizeAM to just reuse emitInsSize like everything else does and then simply compute the addressing mode requirements as additional on that (modR/M byte, if any displacement exists, etc). -- The special handling for cmpxchg "should" be generally handled elsewhere since that'd be required for 16-bit stack accesses and otherwise can remain special cased as an addition on top of emitInsSize just for the emitInsSizeAM path, so we have less duplicated logic.
Thanks @tannergooding. Does it mean you think this is only an assertion problem?
To be clear, we don't see these asserts on x64, and it appears things are working correctly there. So only x86 is affected, and it sounds like it might even be working fine in release builds there.
Does it mean you think this is only an assertion problem?
At least at a glance it looks like an assert problem. I'm a bit surprised that its only occurring for x86, but that might be due to kmovq being a special instruction that supports a 64-bit memory read/write even in 32-bit mode (much like movq does).
Activity
[-]JIT: (attrSize == EA_4BYTE) || (attrSize == EA_PTRSIZE) || (attrSize == EA_16BYTE) || (attrSize == EA_32BYTE) || (attrSize == EA_64BYTE) || (ins == INS_movzx) || (ins == INS_movsx) || (ins == INS_cmpxchg) || isPrefetch(ins)[/-][+]JIT: Assertion failed '(attrSize == EA_4BYTE) || (attrSize == EA_PTRSIZE) || (attrSize == EA_16BYTE) || (attrSize == EA_32BYTE) || (attrSize == EA_64BYTE) || (ins == INS_movzx) || (ins == INS_movsx) || (ins == INS_cmpxchg) || isPrefetch(ins)' in 'C0:M1():ushort:this' during 'Generate code'[/+]dotnet-policy-service commentedon Aug 20, 2025
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
[-]JIT: Assertion failed '(attrSize == EA_4BYTE) || (attrSize == EA_PTRSIZE) || (attrSize == EA_16BYTE) || (attrSize == EA_32BYTE) || (attrSize == EA_64BYTE) || (ins == INS_movzx) || (ins == INS_movsx) || (ins == INS_cmpxchg) || isPrefetch(ins)' in 'C0:M1():ushort:this' during 'Generate code'[/-][+]JIT: [runtime async] Assertion failed '(attrSize == EA_4BYTE) || (attrSize == EA_PTRSIZE) || (attrSize == EA_16BYTE) || (attrSize == EA_32BYTE) || (attrSize == EA_64BYTE) || (ins == INS_movzx) || (ins == INS_movsx) || (ins == INS_cmpxchg) || isPrefetch(ins)' in 'C0:M1():ushort:this' during 'Generate code'[/+]jakobbotsch commentedon Aug 21, 2025
Attached SPMI collection on fad7576
col.zip
jakobbotsch commentedon Aug 21, 2025
Here we have a
TYP_MASKlocal that is live across a suspension point. Runtime async thus saves it to memory across the suspension, and the backend asserts when it sees the mask-typedSTOREIND:Seems to work fine on x64. @tannergooding there is nothing fundamentally preventing storing a mask variable like this to memory, right?
JulieLeeMSFT commentedon Sep 2, 2025
@jakobbotsch, PTAL.
jakobbotsch commentedon Sep 10, 2025
I will move this to .NET 11. Runtime async is experimental and I think it is ok if there are rough edges in the intersection between runtime async and mask based hardware intrinsics.
tannergooding commentedon Sep 10, 2025
Sorry, missed the tag.
Correct, nothing prevents it and its required for things like calls since all mask registers are volatile.
This should simply be a
kmovq [mem], k1and when the suspend is done akmovq k1, [mem](using appropriate register, of course).tannergooding commentedon Sep 10, 2025
We should have one of:
The way the instructions work for SIMD is a bit interesting where the lookup tables have them "unprefixed" and so we'd have
0x0F91or0x0F6691as thecode. We then callemitGetAdjustedSizewhich is supposed to "fix" this based on the encoding we'll actually end up using (such as VEX or EVEX).It looks like we'd hit this path for
KMOVBorKMOVQ, which likely has been untested due to there not beingTYP_MASKfields since its a synthetic JIT only type and so we'd only ever spill to the stack before. Most other paths (likeemitInsSizeSVandemitInsSizeCV) just reuseemitInsSizewhere-asemitInsSizeAMhas its own logic (which looks largely unnecessary since it's really justemitInsSize+ addressing mode sizing).The short term fix would be to just include the
kmovinstructions here as well in the assert. The long term "better" fix would be to updateemitInsSizeAMto just reuseemitInsSizelike everything else does and then simply compute the addressing mode requirements as additional on that (modR/M byte, if any displacement exists, etc). -- The special handling forcmpxchg"should" be generally handled elsewhere since that'd be required for 16-bit stack accesses and otherwise can remain special cased as an addition on top ofemitInsSizejust for theemitInsSizeAMpath, so we have less duplicated logic.jakobbotsch commentedon Sep 10, 2025
Thanks @tannergooding. Does it mean you think this is only an assertion problem?
To be clear, we don't see these asserts on x64, and it appears things are working correctly there. So only x86 is affected, and it sounds like it might even be working fine in release builds there.
tannergooding commentedon Sep 10, 2025
At least at a glance it looks like an assert problem. I'm a bit surprised that its only occurring for x86, but that might be due to
kmovqbeing a special instruction that supports a 64-bit memory read/write even in 32-bit mode (much likemovqdoes).jakobbotsch commentedon Sep 11, 2025
Maybe the assert just passes on x64 since it includes a check against
EA_PTRSIZE? I think the mask size was 8 bytes when I looked.tannergooding commentedon Sep 11, 2025
That looks to be the case. The assert is:
So this is basically boiling down to "only fail for EA_1/2BYTE if the instruction isn't movzx/movsx/cmpxchg/prefetch"
While for x86 it also extends to EA_8BYTE since we don't normally support that on 32-bit.