<div dir="ltr">Hi Tim.<div><br></div><div>I think that my template method will actually work for all offsets. Let's take a case study: ldr<span style="white-space:pre-wrap">       </span>r0, [r1, #-4]</div><div>This is probably the most common offset-ed addressing mode. On ARM mode it maps to LDRi12.</div>

<div>LDRi12 has an operand of type "addrmode_imm12".</div><div><br></div><div>Lets look at two key methods for this operand type:</div><div>1. Creation: addMemImm12OffsetOperands (ARMAsmParser.cpp:1969)</div><div>
2. Decoding: DecodeAddrModeImm12Operand(ARMDisassembler:2059)</div><div><br></div><div>In the creation function, if you add a cout just before the first addOperand, you will see that the actual value held by MCOperand is "-4".</div>
<div>Also if you look at the decoder, you will see that it reads the magnitude, then adjusts the sign according to the U bit while treating INT32_MIN as negative zero.</div><div><br></div><div>This points to the reverse of the statements above: generally offsets are encoded in straight 2's complement arithmetic and converted to/from encoding format.</div>
<div>They are not held in MCOperands in encoding format! As such the template function should generally work.</div><div><br></div><div>Do you agree with this assessment?</div><div><br></div><div>Regarding the shifting of the immediate for ADR's PC-relative operand, I can of course have it shifted in the MCOperand if you insist. </div>
<div><br></div><div>Please let me know.</div><div><br></div><div>Regards,</div><div>Mihai</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jun 27, 2013 at 11:47 AM, Tim Northover <span dir="ltr"><<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Mihail,<br>
<br>
Good to see you posting again too.<br>
<div class="im"><br>
> Please correct me if I'm wrong, but ARM does indeed use 2's complement<br>
> arithmetic! There is indeed one slight deviation in that INT32_MIN is<br>
> sometimes regarded as negative zero (maybe that's a relic for a distant<br>
> dinosaur that used direct representation?) Either way, all ARM cores<br>
> that I can think of use 2's complement with this little occasional quirk.<br>
> Am I wrong here?<br>
<br>
</div>Ah, I see the branches do indeed use 2s complement. And the runtime<br>
arithmetic is too, of course. But the offset versions of load/store<br>
encode the immediate as a sign and distance.<br>
<br>
So after your explanation I think I'm happy to let the template go in<br>
at the start, with a name change to indicate what instructions it<br>
applies to better ("memory offset" is a valid concept for ldr/str<br>
too).<br>
<div class="im"><br>
>I believe that that answer is "straight, natural" representation,<br>
> but as I said, I'm not looking to fight a war<br>
> over this. Just adding my two pence to the discussion.<br>
<br>
</div>It's a discussion that's been had multiple times in the past. As you<br>
say, probably not worth pursuing again.<br>
<br>
Cheers.<br>
<span class="HOEnZb"><font color="#888888"><br>
Tim.<br>
</font></span></blockquote></div><br></div>