From mboxrd@z Thu Jan 1 00:00:00 1970 From: Graeme Russ Date: Thu, 16 Jun 2011 21:07:53 +1000 Subject: [U-Boot] [PATCH v3 02/10] armv7: add miscellaneous utility macros In-Reply-To: <20110615125150.C7F7E138EF1F@gemini.denx.de> References: <1299589658-30896-1-git-send-email-aneesh@ti.com> <1305202276-27784-3-git-send-email-aneesh@ti.com> <20110515184421.D7AB91491B06@gemini.denx.de> <4DD13DA3.3030505@ti.com> <4DECF8DA.9030806@ti.com> <20110606185046.BB8991736815@gemini.denx.de> <4DEDE8D9.7030306@ti.com> <20110607103923.7E1CC1B993A8@gemini.denx.de> <4DEE161B.2050402@ti.com> <20110607154028.D6540195494F@gemini.denx.de> <4DEF62A6.7060706@ti.com> <20110608214124.849821B993A8@gemini.denx.de> <4DF71FBF.6030408@ti.com> <20110614105115.01D6611EEDAF@gemini.denx.de> <4DF7488A.6000909@ti.com> <20110614135335.A750811EEDAF@gemini.denx.de> <4DF871E3.8080307@ti.com> <20110615092014.F080219E5AC1@gemini.denx.de> <4DF89102.9040508@ti.com> <20110615120447.9EEC4655C6@gemini.denx.de> <4DF8A8CF.5000308@gmail.com> <20110615125150.C7F7E138EF1F@gemini.denx.de> Message-ID: <4DF9E409.1060600@gmail.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 15/06/11 22:51, Wolfgang Denk wrote: > Dear Graeme Russ, > > In message <4DF8A8CF.5000308@gmail.com> you wrote: >> >> And to set the value then you have: >> >> reg &= ~a_mask; /* Clear a_val */ >> reg |= (a_val << a_shift) & a_mask; /* Set new a_val */ > > This could be done using > > clrsetbits_le32(®, a_mask, a_val << a_shift); Not quite: clrsetbits_le32(®, a_mask, (a_val << a_shift) & a_mask); is equivalent except that, as already pointed out, clrsetbits and friends: a) Are not portable because only ARM and PPC define them which makes them, by definition, non-standard b) Each invocation results in a read barrier plus a write barrier c) If the hardware register is sensitive to partial updates (i.e. requires all bit-fields to be updated in on operation) this requires a read into a local variable, calls to clrsetbits against that variable and finally a write-back - Lots of memory barriers I know I'm going over old ground, and it's not that I am against clrsetbits, it's just good to know the limitations up-front. So remember, clrsetbits is not platform independent, prevents the compiler from optimising and will most likely impose a performance hit Regards, Graeme