From: mathieu.desnoyers@polymtl.ca (Mathieu Desnoyers)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] arm: add half-word __xchg
Date: Fri, 6 Aug 2010 13:00:21 -0400 [thread overview]
Message-ID: <20100806170021.GA31135@Krystal> (raw)
In-Reply-To: <1281034718-14499-1-git-send-email-virtuoso@slind.org>
* 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
parent reply other threads:[~2010-08-06 17:00 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <1281034718-14499-1-git-send-email-virtuoso@slind.org>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100806170021.GA31135@Krystal \
--to=mathieu.desnoyers@polymtl.ca \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).