From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dirk Behme Date: Thu, 30 Dec 2010 11:39:13 +0100 Subject: [U-Boot] [RFC PATCH v2] ARM: Avoid compiler optimization for usages of readb, writeb and friends. In-Reply-To: <20101229231004.GA17999@mail.gnudd.com> References: <4D1B0228.7000608@googlemail.com> <1292711230-3234-1-git-send-email-holler@ahsoftware.de> <20101222080206.A0CA3EA652A@gemini.denx.de> <20101229231004.GA17999@mail.gnudd.com> Message-ID: <4D1C6151.1050704@googlemail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 30.12.2010 00:10, Alessandro Rubini wrote: > Dirk Behme: >> Just for the record: >> >> The trick is to ensure that the __arch_putx() containing the volatile >> is not the last statement in the GCC statement-expression. So, using >> something like >> >> #define writeb(v,c) ({ __iowmb(); __arch_putb(v,c); v;}) >> >> (note the additional 'v;') should result in correct code, too. > > Yes, that's good. Also "0" may work, and may be more readable, (or not, > according to who reads it). Yes, indeed, #define writeb(v,c) ({ __iowmb(); __arch_putb(v,c); 0;}) seems to work, too :) Thanks Dirk >> The patches sent by Wolfgang and Alexander using >> >> #define writeb(v,c) do { __iowmb(); __arch_putb(v,c); } while (0) >> >> do the same with a slightly different syntax, so these patches are >> fine, too. > > It's not just different syntax, it's different semantics. > > The ({...}) trick turns statements into expressions, while the "do > {...} while(0)" does not. I'd better not forbid statements like > > while (reg = readb(addr), reg != VALUE) { .... } > > or > > if (readb(addr) == VALUE) { ... } > > or > swtich (readb(addr)) { ... } > > While I agree they may in general not be clean, I can forsee > meaningful uses. Moreover, I'd better allow expression-looking macros > to really behave like expressions -- otherwise error messages are quite > hard to understand for the unaquainted. > > IMHO, the only reason to use "do {} while(0)" over statemente > expressions is being portable but in u-boot we are gcc-specific > anyways. > > /alessandro >