lkml.org 
[lkml]   [2009]   [May]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [BUG FIX] Make x86_32 uni-processor Atomic ops, Atomic
Date
On Mon May 25 2009, H. Peter Anvin wrote:
> Michael S. Zick wrote:
> > On Mon May 25 2009, Michael S. Zick wrote:
> >
> > In actual application, this *should not* make a difference.
> >
>
> No kidding. This is a valid transformation for integers, since it is
> all done with 2's-complement arithmetic.
>

Load Effective Address does two's complement arithmetic?
I'll take your word for it.

For example:

#include <stdio.h>

extern int diff_umask(int mask, int *cnt1, int *cnt2)
{ return (((mask - *cnt1) + *cnt2) & mask); }

int main() {
int msk = 0x7fffffff; /* max positive */
int idx1 = 0x7ffffffd; /* max positive - 2 */
int idx2 = 0x7fffffff; /* max positive */

int rst;

rst = diff_umask(msk, &idx1, &idx2);
printf("\n\t%d\n", rst); /* " 1 " - correct */
}

But that is because when it is compiled as a
single source file, gcc is hardcoding the lea
adjustment when it is not an external file:
(compare to the above listings)
Like I wrote - I don't use 31-bit ring buffers, so I don't care.

objdump -d testdiff:
- - - snip - - -
080483b0 <diff_umask>:
80483b0: 8b 44 24 0c mov 0xc(%esp),%eax
80483b4: 8b 4c 24 04 mov 0x4(%esp),%ecx
80483b8: 8b 10 mov (%eax),%edx
80483ba: 8d 04 11 lea (%ecx,%edx,1),%eax
80483bd: 8b 54 24 08 mov 0x8(%esp),%edx
80483c1: 2b 02 sub (%edx),%eax
80483c3: 21 c8 and %ecx,%eax
80483c5: c3 ret
- - - snip - - -

Mike

> Floating-point numbers is a whole other game.
>
> -hpa
>




\
 
 \ /
  Last update: 2009-05-26 01:07    [W:0.108 / U:0.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site