<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Jan 22, 2009, at 1:59 PM, Eliot Miranda wrote:</div><div><br></div><blockquote type="cite"><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>></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'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 :)  Trouble is gcc also optimizes so it may not always generate the code you expect.  For example,</div> <div><br></div><div>issignedshift(v) { return (v >> 1) &lt; 0 ? 1 : 0; }</div><div><br></div><div>will, with -O4, generate</div><div><br></div><div>       movl 4(%esp), %eax</div><div>       sarl $31,%eax</div><div>        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't generate a compare at all.</div><div><br></div><div>BTW, I've been abusing gcc's -S output for a long time.  Back in the 80'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.  I've also produced JIT-compiled BitBlt by similar means with a number of different compilers.  -S has been my friend for many years.</div> <div><br></div><div>Cheers!</div><div>Eliot</div></div></blockquote><div><br></div><div>Ok, ok.  It's just that when I looked at the assembler output for Martin's example, it looked like it covered the case you were fighting.  (I didn't step through it with a debugger.)</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">        .text</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">.globl _calc</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_calc:</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">        pushl   %ebp</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">        movl    %esp, %ebp</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">        subl    $8, %esp</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">        movl    8(%ebp), %eax</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">        sarl    %eax</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">        leave</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">        ret</div><div><br></div></div><div>Then you said "can you send me the assembly?  Or show me the opcodes?" instead of something like "What gcc version/flags are you using."</div><div><br></div><div>A thousand apologies for having impugned your knowledge of gcc.</div><div><br></div><div>I will now go away before you taunt me a second time.</div><div><br></div><div>:)</div><div><br></div><div>David</div><div><br></div></div></body></html>