[squeak-dev] x86 sarl curiosity...

David Farber dfarber at numenor.com
Fri Jan 23 00:19:14 UTC 2009

On Jan 22, 2009, at 1:59 PM, Eliot Miranda wrote:

> On Thu, Jan 22, 2009 at 12:53 PM, David Farber  
> <dfarber at numenor.com> wrote:
> 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.
> Um, I know :)  Trouble is gcc also optimizes so it may not always  
> generate the code you expect.  For example,
> issignedshift(v) { return (v >> 1) < 0 ? 1 : 0; }
> will, with -O4, generate
>        movl 4(%esp), %eax
>        sarl $31,%eax
>        ret
> 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.
> 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.
> Cheers!
> Eliot

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.)

.globl _calc
         pushl   %ebp
         movl    %esp, %ebp
         subl    $8, %esp
         movl    8(%ebp), %eax
         sarl    %eax

Then you said "can you send me the assembly?  Or show me the  
opcodes?" instead of something like "What gcc version/flags are you  

A thousand apologies for having impugned your knowledge of gcc.

I will now go away before you taunt me a second time.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20090122/a5c00f6d/attachment.htm

More information about the Squeak-dev mailing list