<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,0)">tl;dr, I'd like to add my own instruction, but I'm running into problems due to my lack of x86 encoding/decoding understanding.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,0)">Hello all. Currently, I'm working on adding my own x86 instruction. I have done this once before; the basic process I used was:</div><div class="gmail_default"><ol><li><font color="#000000" face="arial, helvetica, sans-serif">Find an unused opcode, e.g. 0xF1 in this table: <a href="http://ref.x86asm.net/coder32.html">http://ref.x86asm.net/coder32.html</a></font></li><li>Insert an instruction into lib/Target/X86/X86InstrInfo.td using this opcode.</li></ol><div>In this case, I used 0xF1, and created the following instruction:</div><div><div><br></div><div><font face="monospace, monospace">def CACHE_OPERAND_B64i : RIi64<0xF1, AddRegFrm, (outs GR64:$unused),</font></div><div><font face="monospace, monospace">                (ins i64imm:$b), "cache_operand_b_i64\t$b",</font></div><div><font face="monospace, monospace">                [(int_cache_operand_b_i64 i64imm:$b)]>,</font></div><div><font face="monospace, monospace">                Requires<[In64BitMode]>;</font></div></div><div><br></div><div>However, when I compile, I'm getting errors of the form:</div><div><br></div><div><div><font face="monospace, monospace">Error: Primary decode conflict: TEST64ri32 would overwrite CACHE_OPERAND_B64i</font></div><div><font face="monospace, monospace">ModRM   199</font></div><div><font face="monospace, monospace">Opcode  247</font></div><div><font face="monospace, monospace">Context IC_64BIT_REXW</font></div></div><div><br></div><div>When I look at the definition of TEST64ri32, I see:</div><div><br></div><div><font face="monospace, monospace">let Predicates = [In64BitMode] in</font></div><div><font face="monospace, monospace">def TEST64ri32 : BinOpRI_F<0xF6, "test", Xi64, X86testpat, MRM0r>;</font></div><div><div><br></div><div>It looks like TEST64ri32 is using opcode 0xF6 -- why is there a conflict with 0xF1?</div><div><br></div><div>Even if I comment out TEST64ri32 (which I recognize is not a good idea), I still get a similar error:</div><div><br></div><div><font face="monospace, monospace">Error: Primary decode conflict: NOT64r would overwrite CACHE_OPERAND_B64i</font></div><div><font face="monospace, monospace">ModRM   215</font></div><div><font face="monospace, monospace">Opcode  247

<br class="gmail-Apple-interchange-newline"><span style="color:rgb(34,34,34);font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Context IC_64BIT_REXW</span></font>

</div></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Which corresponds to the definition:<br></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="text-align:start;text-indent:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><font face="monospace, monospace"><div>def NOT64r : RI<0xF7, MRM2r, (outs GR64:$dst), (ins GR64:$src1), </div><div>                "not{q}\t$dst",</div><div>                [(set GR64:$dst, (not GR64:$src1))], IIC_UNARY_REG>;</div></font></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Again, why does 0xF7 conflict with 0xF1?</span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Thanks,</span></div><div>Gus Smith</div><div><br></div><div>P.S. If this looks hacky, that's because it is; I'm not sure what the correct way to add an instruction into x86 is, if there even is one. Pointers along that line are appreciated.</div></div></div>