@@ -5158,7 +5158,7 @@ inline UNATIVE_OFFSET emitter::emitInsSizeSVCalcDisp(instrDesc* id, code_t code,
51585158 ssize_t compressedDsp;
51595159 bool fitsInByte;
51605160
5161- if (TryEvexCompressDisp8Byte(id, offs, &compressedDsp, &fitsInByte))
5161+ if (TryEvexCompressDisp8Byte(id, int( offs) , &compressedDsp, &fitsInByte))
51625162 {
51635163 if (!TakesEvexPrefix(id))
51645164 {
@@ -5213,7 +5213,7 @@ inline UNATIVE_OFFSET emitter::emitInsSizeSVCalcDisp(instrDesc* id, code_t code,
52135213 {
52145214 ssize_t compressedDsp;
52155215
5216- if (TryEvexCompressDisp8Byte(id, offs, &compressedDsp, &useSmallEncoding))
5216+ if (TryEvexCompressDisp8Byte(id, int( offs) , &compressedDsp, &useSmallEncoding))
52175217 {
52185218 if (!TakesEvexPrefix(id))
52195219 {
@@ -14694,6 +14694,8 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc)
1469414694 }
1469514695 else if (TakesEvexPrefix(id) || TakesApxExtendedEvexPrefix(id))
1469614696 {
14697+ ssize_t compressedDsp;
14698+ assert(!TryEvexCompressDisp8Byte(id, dsp, &compressedDsp, &dspInByte));
1469714699 dspInByte = false;
1469814700 }
1469914701 else
@@ -15577,6 +15579,8 @@ BYTE* emitter::emitOutputSV(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc)
1557715579 }
1557815580 else if (TakesEvexPrefix(id) || TakesApxExtendedEvexPrefix(id))
1557915581 {
15582+ ssize_t compressedDsp;
15583+ assert(!TryEvexCompressDisp8Byte(id, dsp, &compressedDsp, &dspInByte));
1558015584 dspInByte = false;
1558115585 }
1558215586 else
@@ -15626,10 +15630,26 @@ BYTE* emitter::emitOutputSV(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc)
1562615630 // Adjust the offset by the amount currently pushed on the CPU stack
1562715631 dsp += emitCurStackLvl;
1562815632
15629- if (TakesEvexPrefix(id ) || TakesApxExtendedEvexPrefix(id ))
15633+ if (IsEvexEncodableInstruction(ins ) || IsApxExtendedEvexInstruction(ins ))
1563015634 {
15631- assert(!HasCompressedDisplacement(id));
15632- dspInByte = false;
15635+ if (HasCompressedDisplacement(id))
15636+ {
15637+ ssize_t compressedDsp;
15638+ bool isCompressed = TryEvexCompressDisp8Byte(id, dsp, &compressedDsp, &dspInByte);
15639+
15640+ assert(isCompressed && dspInByte);
15641+ dsp = (int)compressedDsp;
15642+ }
15643+ else if (TakesEvexPrefix(id) || TakesApxExtendedEvexPrefix(id))
15644+ {
15645+ ssize_t compressedDsp;
15646+ assert(!TryEvexCompressDisp8Byte(id, dsp, &compressedDsp, &dspInByte));
15647+ dspInByte = false;
15648+ }
15649+ else
15650+ {
15651+ dspInByte = ((signed char)dsp == (ssize_t)dsp);
15652+ }
1563315653 }
1563415654 else
1563515655 {
@@ -18020,13 +18040,27 @@ bool emitter::TryEvexCompressDisp8Byte(instrDesc* id, ssize_t dsp, ssize_t* comp
1802018040 return *fitsInByte;
1802118041 }
1802218042
18023- if (*fitsInByte && !TakesEvexPrefix(id) )
18043+ if (*fitsInByte)
1802418044 {
18025- // We already fit into a byte and do not otherwise require the EVEX prefix
18026- // which means we can use the VEX encoding instead and be even smaller.
18045+ if (!TakesEvexPrefix(id))
18046+ {
18047+ // We already fit into a byte and do not otherwise require the EVEX prefix
18048+ // which means we can use the VEX encoding instead and be even smaller.
1802718049
18028- assert(*compressedDsp == dsp);
18029- return false;
18050+ assert(*compressedDsp == dsp);
18051+ return false;
18052+ }
18053+ }
18054+ else
18055+ {
18056+ ssize_t compressedTest = dsp / 64;
18057+
18058+ if (static_cast<signed char>(compressedTest) != compressedTest)
18059+ {
18060+ // We are larger than the maximum possible compressed displacement
18061+ assert(*compressedDsp == dsp);
18062+ return false;
18063+ }
1803018064 }
1803118065
1803218066 insTupleType tt = insTupleTypeInfo(ins);
0 commit comments