<div dir="ltr">I agree these lines need the MRMSrcReg argument removed.<div><br></div><div><div>      def TEST8rr  : BinOpRR_F<0x84, "test", Xi8 , X86testpat, MRMSrcReg>;</div><div>      def TEST16rr : BinOpRR_F<0x84, "test", Xi16, X86testpat, MRMSrcReg>;</div><div>      def TEST32rr : BinOpRR_F<0x84, "test", Xi32, X86testpat, MRMSrcReg>;</div><div>      def TEST64rr : BinOpRR_F<0x84, "test", Xi64, X86testpat, MRMSrcReg>;</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 30, 2015 at 3:31 PM, Ahmed Bougacha <span dir="ltr"><<a href="mailto:ahmed.bougacha@gmail.com" target="_blank">ahmed.bougacha@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I was talking about CMP, but the PR is about TEST only, right?<br>
<br>
If so, I think the right fix is to use the default MRMDestReg Format<br>
for TEST*rr, like we do for the other MR-encoded instructions.  Craig,<br>
does that sound right to you?<br>
<br>
On Mon, Mar 30, 2015 at 1:32 PM, Rafael Espíndola<br>
<<a href="mailto:rafael.espindola@gmail.com">rafael.espindola@gmail.com</a>> wrote:<br>
>> I can't say anything about reasons, but this doesn't seem like a<br>
>> printing issue, rather one of default encoding?  There's 38/39 for "r/m,<br>
>> r", and 3A/3B for "r, r/m":  I guess MC and GAS don't agree on that.<br>
><br>
> The encoding is different, but the instructions are symmetrical.<br>
<br>
Disregard, that doesn't apply to TEST, which only has one opcode.<br>
Sorry about the noise!<br>
<br>
Back to the actual issue:  I think MC is wrong. In the SDM, looking at<br>
the RM encoding of TEST:  it takes op1 = ModRM:r/m, and op2 =<br>
ModRM:reg.<br>
<br>
In AT&T syntax, for:<br>
<br>
  test %ebx, %eax<br>
<br>
The ModRM byte should be 0xd8 (2.1.5, table 2-2).   Feeding that to MC<br>
gives us 0xc3 instead:<br>
<br>
  testl %ebx, %eax              ## encoding: [0x85,0xc3]<br>
                                          ## <MCInst #2894 TEST32rr<br>
                                          ##  <MCOperand Reg:19><br>
                                          ##  <MCOperand Reg:21>><br>
<br>
However, disassembling via MC the MR encoding for CMP, which is 0x39<br>
0xd8, we get:<br>
<br>
  cmpl %ebx, %eax              ## encoding: [0x39,0xd8]<br>
                                          ## <MCInst #540 CMP32rr<br>
                                          ##  <MCOperand Reg:19><br>
                                          ##  <MCOperand Reg:21>><br>
<br>
Tying it back to the .td, we defined TEST*rr with the MRMSrcReg<br>
format, and CMP with MRMDestReg, and this is the root problem.<br>
Grepping around for MRMSrcReg, we use it for the RM encoding: IMUL,<br>
ADCX, and the various "r, r/m" _REV instructions.  The MRMDestReg<br>
format is for the MR encoding, and should be used for TEST.<br>
<span class="HOEnZb"><font color="#888888"><br>
-Ahmed<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">~Craig</div>
</div>