<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi Ryan,</div><div class=""><br class=""></div><div class="">simm16 and uimm16 from the Mips target are primarily about assembly matching and printing rather than instruction selection. They're the same thing to the instruction selector. They're both an 'imm' with the result type limited to i32. For instruction selection, the thing to focus on is immSExt16 and immZExt16 since these determine whether the match is successful or not.</div><div class=""><br class=""></div><div class="">The reason both immSExt16 and immZExt16 exist is that the 32-bit arithmetic operations can only take a sign-extended 16-bit immediate (so -0x8000 is acceptable, but 0x8000 is not). Meanwhile, the 32-bit bitwise operations* can only take a zero-extended 16-bits (0x8000 is acceptable but -0x8000 is not).</div><div class=""><br class=""></div><div class="">*They're actually register-width but that doesn't matter for this topic.</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 15 Feb 2017, at 20:29, Ryan Taylor via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">I believe that the idea of simm16 and uimm16 was taken over from MipsInstrInfo.td. It's entirely possible that the concepts were misunderstood then.</div><div class=""> </div><div class="">So, a broader question, what is the best way to map down to an unsigned/signed sub/add (is this even possible)? How to add signed/unsigned immediates?</div><div class=""><br class=""></div><div class="">Thanks.</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Feb 15, 2017 at 3:14 PM, Friedman, Eli <span dir="ltr" class=""><<a href="mailto:efriedma@codeaurora.org" target="_blank" class="">efriedma@codeaurora.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 2/15/2017 11:37 AM, Ryan Taylor via llvm-dev wrote:<br class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I see. If I put simm16 and immSExt16x in place of uimm16 and immZExt16x respectively, the imm matches but it prints out -32768 (which is invalid for sub16u). We are using uimm16 not match unsigned but for PrintMethod, effectively uimm16 and simm16 are both Operand<i16>. I'm still unclear why simm16 matches and uimm16 does not. Here is the pattern if that helps at all.<br class="">
<br class="">
So just as a reference:<br class="">
<br class="">
def simm16      : Operand<i16> {<br class="">
  let DecoderMethod= "DecodeSimm16";<br class="">
  let OperandType = "OPERAND_IMMEDIATE";<br class="">
}<br class="">
<br class="">
def uimm16      : Operand<i16> {<br class="">
  let PrintMethod = "printUnsignedImm";<br class="">
  let OperandType = "OPERAND_IMMEDIATE";<br class="">
}<br class="">
<br class="">
def immSExt16x : ImmLeaf<i16, [{ return isInt<16>(Imm); }]>;<br class="">
def immZExt16x : ImmLeaf<i16, [{ return isUInt<16>(Imm); }]>;<br class="">
</blockquote>
<br class=""></span>
"Imm" in ImmLeaf is an int64_t, sign-extended from your immediate type (in this case, int16_t).  You'd need to insert an explicit cast to uint16_t to get the behavior you want.<br class="">
<br class="">
I'm not sure why you're doing this, though; every 16-bit integer immediate fits into a 16-bit integer, so a correctly implemented "immZExt16x" is just equivalent to "imm".<div class="HOEnZb"><div class="h5"><br class="">
<br class="">
-Eli<br class="">
<br class="">
-- <br class="">
Employee of Qualcomm Innovation Center, Inc.<br class="">
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project<br class="">
<br class="">
</div></div></blockquote></div><br class=""></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></div></body></html>