<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Olivier,<div><br></div><div>thanks for identifying that issue! Your fix corrects the specific testcase you provide, but it could produce incorrect results in other cases.</div><div><br></div><div>Here's a bit of background on necessary_prefix_location.</div><div><br></div><div>necessary_prefix_location is supposed to keep track of where prefixes like 66, f3, and f2 – which affect the class of instruction being decoded fundamentally – should be expected to be. If you look at the "Instruction Format" section of the Intel manuals (specifically, Volume 2A of the Intel 64 and IA-32 Architectures Software Developer's Manual), it specifies that</div><div><br></div><div>–</div><div>Some instructions may use F2H,F3H as a mandatory prefix to express distinct functionality. A mandatory prefix generally <b>should be placed after other optional prefixes</b> (exception to this is discussed in Section 2.2.1, “REX Prefixes”).</div><div>–</div><div><br></div><div>Also,</div><div><br></div><div>–</div><div>Some SSE2/SSE3/SSSE3/SSE4 instructions and instructions using a three-byte sequence of primary opcode bytes may use 66H as a mandatory prefix to express distinct functionality. A mandatory prefix generally <b>should be placed after other optional prefixes</b> (exception to this is discussed in Section 2.2.1, “REX Prefixes”).</div><div>–</div><div><br></div><div>This is why the decoder maintains a special location – necessary_prefix_location – at which f2, f3, or 66 must reside. Perhaps I ought to call it "mandatory_prefix_location"...</div><div><br></div><div>In the 64-bit case (under "REX Prefixes"), the manual states:</div><div><br></div><div>–</div><div>Only one REX prefix is allowed per instruction. If used, the REX prefix byte <b>must immediately precede the opcode byte or the escape opcode byte (0FH)</b>. When a REX prefix is used in conjunction with an instruction containing a mandatory prefix, <b>the mandatory prefix must come before the REX</b> so the REX prefix can be immediately preceding the opcode or the escape byte.</div><div>–</div><div><br></div><div>I took a quick look in the sources and saw that necessaryPrefixLocation was being set at two locations: line 382, and line 387. Those are both only enabled if insn->mode == MODE_64BIT, which in X86 (of course) it isn't. They are handling the specific 64-bit case; the 32-bit case is unhandled (as you spotted).</div><div><br></div><div>Your patch would set necessaryPrefixLocation to wherever the 66 prefix is found, which works most of the time but would break cases in which 66 is not used as a mandatory prefix, but merely as an optional prefix (the operand-size prefix). Although obscure, such a use is possible. I have attached a patch that solves the problem more generally.</div><div><br></div><div>Sean</div><div><br></div><div></div></body></html>