<br><br><div class="gmail_quote">On Thu, Jan 22, 2009 at 12:53 PM, David Farber <span dir="ltr">&lt;<a href="mailto:dfarber@numenor.com">dfarber@numenor.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div style="word-wrap:break-word">
<div>Eliot - I know you&#39;ve already moved past this problem, but in the future, gcc -S foo.c will create foo.s with the assembly generated by gcc.</div></div></blockquote><div><br></div><div>Um, I know :) &nbsp;Trouble is gcc also optimizes so it may not always generate the code you expect. &nbsp;For example,</div>
<div><br></div><div>issignedshift(v) { return (v &gt;&gt; 1) &lt; 0 ? 1 : 0; }</div><div><br></div><div>will, with -O4, generate</div><div><br></div><div>&nbsp;&nbsp; &nbsp; &nbsp; movl 4(%esp), %eax</div><div>&nbsp;&nbsp; &nbsp; &nbsp; sarl $31,%eax</div><div>
&nbsp;&nbsp; &nbsp; &nbsp; ret</div><div><br></div><div>because it works out this is the quickest way to generate a 1 if v is negative and doesn&#39;t generate a compare at all.</div><div><br></div><div>BTW, I&#39;ve been abusing gcc&#39;s -S output for a long time. &nbsp;Back in the 80&#39;s I used to generate direct-threaded-code VMs using gcc where I would edit the -S output with sed to produce the opcodes for the threaded code machine stripped of the prolog and epilog gcc would produce. &nbsp;I&#39;ve also produced JIT-compiled BitBlt by similar means with a number of different compilers. &nbsp;-S has been my friend for many years.</div>
<div><br></div><div>Cheers!</div><div>Eliot</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 style="word-wrap:break-word"><div>
</div><div><br></div><font color="#888888"><div>David</div></font><div><div></div><div class="Wj3C7c"><br><div><div>On Jan 21, 2009, at 2:08 PM, Eliot Miranda wrote:</div><br><blockquote type="cite">Hi Martin, &nbsp;can you send me the assembly? &nbsp;Or show me the opcodes? When I try this it doesn&#39;t work. &nbsp;So I must be doing something differently.<div>
<br>and Hi! &nbsp;Robert Hirschfeld mentioned you when he and I met last week.</div> <div><br><div class="gmail_quote">On Wed, Jan 21, 2009 at 11:06 AM, Martin Beck <span dir="ltr">&lt;<a href="mailto:martin.beck@hpi.uni-potsdam.de" target="_blank">martin.beck@hpi.uni-potsdam.de</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Hi Eliot,<br> <div><br> Eliot Miranda wrote:<br> &gt; Hi All,<br> &gt; &nbsp; &nbsp; anyone know the x86/IA32 really well? &nbsp;If so, read on. &nbsp;Otherwise save<br>
 &gt; yourself the yawn.<br> &gt;<br> </div>[...]<br> <div>&gt; (my emphasis added). &nbsp;But neither the Bochs simulator nor my Intel Core Duo<br> &gt; set the flags when doing sarl $1, %eax when %eax contains -1. &nbsp;Have I<br>
 &gt; misread, or is the manual wrong?<br> &gt;<br> </div>I cannot confirm this. Using this simple C-Program:<br> <br> int calc(int i) {<br> &nbsp;return i &gt;&gt; 1;<br> }<br> <br> int main() {<br> &nbsp;printf(&quot;%i\n&quot;, calc(-1));<br>
 }<br> <br> my GCC 4.3.2 generates a sarl %eax instruction as the assembler output<br> shows. Debugging it with Kdbg shows a change of the flags after the<br> instruction. In fact, CF and SF are set as (more or less) expected. I<br>
 also have a Intel Core 2 Duo.<br> <br> Regards,<br> <font color="#888888">Martin<br> <br> </font></blockquote></div><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:14px">
<br></div> </blockquote></div><br></div></div></div><br><br>
<br></blockquote></div><br>