Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1764328AbXHWTay (ORCPT ); Thu, 23 Aug 2007 15:30:54 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1757665AbXHWTaS (ORCPT ); Thu, 23 Aug 2007 15:30:18 -0400 Received: from gate.crashing.org ([63.228.1.57]:54517 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756302AbXHWTaP (ORCPT ); Thu, 23 Aug 2007 15:30:15 -0400 In-Reply-To: References: <46C03885.7000109@redhat.com> <20070813112452.GK24018@shell.boston.redhat.com> <46CC42EF.3030602@redhat.com> <8fc86c23579e12b012891d6e69b1b107@kernel.crashing.org> Mime-Version: 1.0 (Apple Message framework v623) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: Content-Transfer-Encoding: 7bit Cc: Hirokazu Takata , "Robert P. J. Day" , paulmck@linux.vnet.ibm.com, linux-kernel@vger.kernel.org, "Luck, Tony" , akpm@linux-foundation.org, linux-arch@vger.kernel.org, Chris Snook , Chris Friesen From: Segher Boessenkool Subject: Re: [PATCH 11/23] make atomic_read() and atomic_set() behavior consistent on m32r Date: Thu, 23 Aug 2007 21:29:41 +0200 To: Linus Torvalds X-Mailer: Apple Mail (2.623) Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1599 Lines: 65 > The inline asm version has the EXACT SAME PROBLEM as the "volatile" > version has: it means that the compiler is unable to combine trivial > instructions. This simply isn't true. The compiler *can* combine asm stuff: typedef struct { int counter; } atomic_t; static inline __attribute__((pure)) int atomic_read(const atomic_t *v) { int x; asm("ld %0,@%1" : "=r"(x) : "r"(&v->counter), "m"(v->counter)); return x; } int f(atomic_t *x) { return atomic_read(x) + atomic_read(x); } int g(atomic_t *x) { return 0 * atomic_read(x); } generates f: ld r0,@r0 slli r0,#1 jmp lr g: ldi r0,#0 jmp lr > So why the *hell* you'd expect the asm version to be smaller, I can't > imagine. I expect it to be smaller than the current code, which uses the "big hammer" volatile version. We're talking about m32r here, not x86. Even when using "volatile asm" it shouldn't generate much bigger code. Anyhow, I answered my own question: on m32r, you cannot use "m" with ld/st insns, since autoincrement modes don't work there (the assembler complains, at least). So you have to force the address into a reg instead, and _that_ causes the size increase. > If the code needs barriers, the code should damn well add them. Sure. I'm not suggesting otherwise. Segher - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/