<div dir="ltr">This cast:<div><div>-  int32_t offset = MO.getImm();</div><div>+  int64_t offset = MO.getImm();</div></div><div><br></div><div>The value is encoded in 12 bits. 8 are the core value, 4 dictacte rotation.</div>
<div>It is possible to encode numbers larger that  2^31.</div><div>the MO contains the actual  number, not the one to be encoded.</div><div>as such casting from int64 to int32 produces signed overflow - undefined behavior.</div>
<div><br></div><div>on x86 this flips the sign bit cause the instruction to be encoded as a subtract instead of an add.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Aug 13, 2013 at 2:37 PM, Mihail Popa <span dir="ltr"><<a href="mailto:mihail.popa@gmail.com" target="_blank">mihail.popa@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">This cast:<div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">
On Tue, Aug 13, 2013 at 2:14 PM, Renato Golin <span dir="ltr"><<a href="mailto:renato.golin@linaro.org" target="_blank">renato.golin@linaro.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>On 13 August 2013 10:05, Mihail Popa <span dir="ltr"><<a href="mailto:mihail.popa@gmail.com" target="_blank">mihail.popa@gmail.com</a>></span> wrote:<br>

</div><div class="gmail_extra"><div class="gmail_quote"><div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>As such it is possible to add or subtract a 32-bit unsigned number.</div></div></div></blockquote>


<div><br></div></div><div>But, immediate values are up to 12-bits long, why is 32-bit not enough?</div><div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div dir="ltr"><div><div>The cast to int32_t is undefined and triggers incorrect encoding. Keeping the original</div><div>int64_t type is safe, as all subsequent casts are to uint32_t.</div></div></div></blockquote><div>

</div>
</div></div><br></div><div class="gmail_extra">Which cast?</div><div class="gmail_extra"><br></div><div class="gmail_extra">I could be wrong, but this sounds like you're fixing a problem in the wrong place...</div><div class="gmail_extra">


<br></div><div class="gmail_extra">cheers,</div><div class="gmail_extra">--renato</div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>