Skip to content

Commit

Permalink
[NativeAOT] fix debug assert on large number of virtual methods (#77106)
Browse files Browse the repository at this point in the history
According to the ARM docs for this op code:

https://developer.arm.com/documentation/ddi0596/2020-12/Base-Instructions/LDR--immediate---Load-Register--immediate--?lang=en

> For the 64-bit variant: is the optional positive immediate byte offset, a multiple of 8 in the range 0 to 32760, defaulting to 0 and encoded in the "imm12" field as <pimm>/8.

You can see that once the offset has been devided by 8, it will be in the range [0, 4095], which will fit in the 12 bits allocated for the offset.
  • Loading branch information
AustinWise committed Oct 18, 2022
1 parent 3ba1dd2 commit 8393c4e
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,24 @@ public void EmitLDR(Register regDst, Register regAddr)

public void EmitLDR(Register regDst, Register regSrc, int offset)
{
Debug.Assert(offset >= -255 && offset <= 4095);
if (offset >= 0)
if (offset >= 0 && offset <= 32760)
{
Debug.Assert(offset % 8 == 0);

offset /= 8;

Builder.EmitUInt((uint)(0b11_1110_0_1_0_1_000000000000_00000_00000u | ((uint)offset << 10) | ((uint)regSrc << 5) | (uint)regDst));
}
else
else if (offset >= -255 && offset < 0)
{
uint o = (uint)offset & 0x1FF;

Builder.EmitUInt((uint)(0b11_1110_0_0_010_000000000_1_1_00000_00000u | (o << 12) | ((uint)regSrc << 5) | (uint)regDst));
}
else
{
throw new NotImplementedException();
}
}

public void EmitCMP(Register reg, sbyte immediate)
Expand Down

0 comments on commit 8393c4e

Please sign in to comment.