Hi All,<div><br></div><div>&nbsp;&nbsp; &nbsp;anyone know the x86/IA32 really well? &nbsp;If so, read on. &nbsp;Otherwise save yourself the yawn.</div><div><br></div><div>I just tried to save an instruction in Cog;s generated bitShift: primitive. &nbsp;It seems to me that SARL (shift arithmetic right long) should set the sign flag based on the result, in fact it says as much in the manual; I quote fro<span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;">m&nbsp;</span></span><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;">IA-32 Intel&reg; Architecture</span></span><span style="font: 12.0px Helvetica"><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;">&nbsp;</span></span><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;">Software Developer'</span></span><span style="font: 18.0px Times"><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;">s&nbsp;Manual Volume 2B: &nbsp;Instruction Set Reference, N-Z p 4-192</span></span></span></span></div>
<div><span class="Apple-style-span" style="font-size: small;"><br></span></div><div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica"><span class="Apple-style-span" style="font-size: small;">Flags Affected</span><span style="font: 12.0px Helvetica"><span class="Apple-style-span" style="font-size: small;">&nbsp;</span></span></p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Times"><span class="Apple-style-span" style="font-size: small;">The CF flag contains the value of the last bit shifted out of the destination operand; it is unde-&nbsp;</span></p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Times"><span class="Apple-style-span" style="font-size: small;">fined for SHL and SHR instructions where the count is greater than or equal to the size (in bits)&nbsp;</span></p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Times"><span class="Apple-style-span" style="font-size: small;">of the destination operand. The OF flag is affected only for 1-bit shifts (see "Description"</span><span style="font: 12.0px Helvetica"><span class="Apple-style-span" style="font-size: small;">&nbsp;</span></span></p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Times"><span class="Apple-style-span" style="font-size: small;">above); otherwise, it is undefined. <span class="Apple-style-span" style="font-weight: bold;">The SF, ZF, and PF flags are set according to the result.</span> If the&nbsp;</span></p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Times"><span class="Apple-style-span" style="font-size: small;">count is 0, the flags are not affected. For a non-zero count, the AF flag is undefined.</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Times">
<span class="Apple-style-span" style="font-size: 13px;"><span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;"><br></span></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Times">
<span class="Apple-style-span" style="font-size: 13px;"><span class="Apple-style-span" style="font-family: arial, helvetica, sans-serif;">(my emphasis added). &nbsp;But neither the Bochs simulator nor my Intel Core Duo set the flags when doing sarl $1, %eax when %eax contains -1. &nbsp;Have I misread, or is the manual wrong?</span></span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Times"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Times"><span class="Apple-style-span" style="font-family: arial; font-size: 13px;">TIA</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Times"><span class="Apple-style-span" style="font-family: arial; font-size: 13px;">Eliot</span></p></div>