From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754947AbZEYXEG (ORCPT ); Mon, 25 May 2009 19:04:06 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755047AbZEYXDx (ORCPT ); Mon, 25 May 2009 19:03:53 -0400 Received: from mx-out.daemonmail.net ([216.104.160.38]:33281 "EHLO mx-out.daemonmail.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755150AbZEYXDw (ORCPT ); Mon, 25 May 2009 19:03:52 -0400 From: "Michael S. Zick" Reply-To: lkml@morethan.org To: "H. Peter Anvin" Subject: Re: [BUG FIX] Make x86_32 uni-processor Atomic ops, Atomic Date: Mon, 25 May 2009 18:03:48 -0500 User-Agent: KMail/1.9.9 Cc: Harald Welte , Ingo Molnar , Thomas Gleixner , linux-kernel@vger.kernel.org, Alan Cox References: <200905221139.26941.lkml@morethan.org> <200905251610.43071.lkml@morethan.org> <4A1B0ACD.8020502@zytor.com> In-Reply-To: <4A1B0ACD.8020502@zytor.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200905251803.51478.lkml@morethan.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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 : 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 >