arm: add half-word __xchg
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 arm: add half-word __xchg
* Alexander Shishkin (virtuoso at slind.org) wrote:
[...]
Quoted 7 lines
(quoted diff) +7
-0+/* + * emulate __xchg() using 32-bit __cmpxchg() + * + * This is done by taking the word-aligned word that contains *ptr, + * calculating a mask which will cover the ptr part of said word and + * using it to replace *ptr with x in the word. + */
Review
Quoted 10 lines
(quoted diff) +10
-0+static inline unsigned long __xchg_generic(unsigned long x, + volatile void *ptr, int size) +{ + unsigned long *ptrbase, mask, new, ret; + int shift; + + ptrbase = object_align_floor((unsigned long *)ptr); + +#ifdef BIG_ENDIAN + shift = (~(unsigned long)ptr & (4 - size)) * 8;
Sorry if I am slow on the uptake, but I still don't figure out exactly how the line above works. Some more detailed explanation would be welcome.
Thanks,
Mathieu
Quoted 20 lines
(quoted diff) +20
-0+#else + shift = ((unsigned long)ptr - (unsigned long)ptrbase) * 8; +#endif + + mask = ~(((1 << (size * 8)) - 1) << shift); + new = x << shift; + + ret = *ptrbase; + while (1) { + unsigned long tmp = __cmpxchg(ptrbase, ret, (ret & mask) | new, + 4); + if (tmp == ret) + break; + ret = tmp; + } + + return ret; +} +#endif +
Signature · 4 lines
Mathieu Desnoyers Operating System Efficiency R&D Consultant EfficiOS Inc. http://www.efficios.com