All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arm: add half-word __xchg
       [not found] <1281034718-14499-1-git-send-email-virtuoso@slind.org>
@ 2010-08-06 17:00 ` Mathieu Desnoyers
  0 siblings, 0 replies; only message in thread
From: Mathieu Desnoyers @ 2010-08-06 17:00 UTC (permalink / raw)
  To: linux-arm-kernel

* Alexander Shishkin (virtuoso at slind.org) wrote:
[...]
> +/*
> + * 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.
> + */
> +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

> +#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
> +
-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-08-06 17:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1281034718-14499-1-git-send-email-virtuoso@slind.org>
2010-08-06 17:00 ` [PATCH] arm: add half-word __xchg Mathieu Desnoyers

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.