mailing list of musl libc
 help / color / mirror / code / Atom feed
* 64-bit atomic ops on 32-bit ARM
@ 2014-02-05 22:56 Matthew Fernandez
  2014-02-05 23:06 ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Fernandez @ 2014-02-05 22:56 UTC (permalink / raw)
  To: musl

Hi all,

The header atomic.h contains a couple of functions for operations on 64-bit types. Despite their
name, these do not appear to be atomic to me. For example:

  static inline void a_and_64(volatile uint64_t *p, uint64_t v)
  {
    union { uint64_t v; uint32_t r[2]; } u = { v };
    a_and((int *)p, u.r[0]);
    a_and((int *)p+1, u.r[1]);
  }

Have I misunderstood something or is there some other reason behind their implementation? AIUI on
certain ARM platforms there is actually no way to implement atomic 64-bit ops without kernel support.

If replying, please CC me directly as I'm not on the list.

Thanks,
Matt

________________________________

The information in this e-mail may be confidential and subject to legal professional privilege and/or copyright. National ICT Australia Limited accepts no liability for any damage caused by this email or its attachments.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: 64-bit atomic ops on 32-bit ARM
  2014-02-05 22:56 64-bit atomic ops on 32-bit ARM Matthew Fernandez
@ 2014-02-05 23:06 ` Rich Felker
  2014-02-05 23:08   ` Matthew Fernandez
  0 siblings, 1 reply; 3+ messages in thread
From: Rich Felker @ 2014-02-05 23:06 UTC (permalink / raw)
  To: musl; +Cc: Matthew Fernandez

On Thu, Feb 06, 2014 at 09:56:47AM +1100, Matthew Fernandez wrote:
> Hi all,
> 
> The header atomic.h contains a couple of functions for operations on 64-bit types. Despite their
> name, these do not appear to be atomic to me. For example:
> 
>  static inline void a_and_64(volatile uint64_t *p, uint64_t v)

The function name is simply a misnomer. It should be called "atomic
bitclear" (and, for "or", "atomic bitset). That's the only way it's
actually used. In other words we don't care that the and/or operation
on both words happen atomically with respect to one another, only that
each bit individually behaves atomically with respect to being set and
cleared.

BTW, changing the name and semantics would also allow us to drop from
performing two atomic operations to just performing on atomic
operation (on the word that actually needs to change). This would be a
fairly significant optimization, I think. But for now it's not a bug,
just a missed optimization.

Rich


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: 64-bit atomic ops on 32-bit ARM
  2014-02-05 23:06 ` Rich Felker
@ 2014-02-05 23:08   ` Matthew Fernandez
  0 siblings, 0 replies; 3+ messages in thread
From: Matthew Fernandez @ 2014-02-05 23:08 UTC (permalink / raw)
  To: Rich Felker, musl

Ah, so it's used for operating on 64-bit bitfields. Presumably the meaning of each bit is orthogonal
to the others so the atomicity of the write as a whole is irrelevant. Thanks for the clarification,
Rich.

On 06/02/14 10:06, Rich Felker wrote:
> On Thu, Feb 06, 2014 at 09:56:47AM +1100, Matthew Fernandez wrote:
>> Hi all,
>>
>> The header atomic.h contains a couple of functions for operations on 64-bit types. Despite their
>> name, these do not appear to be atomic to me. For example:
>>
>>   static inline void a_and_64(volatile uint64_t *p, uint64_t v)
>
> The function name is simply a misnomer. It should be called "atomic
> bitclear" (and, for "or", "atomic bitset). That's the only way it's
> actually used. In other words we don't care that the and/or operation
> on both words happen atomically with respect to one another, only that
> each bit individually behaves atomically with respect to being set and
> cleared.
>
> BTW, changing the name and semantics would also allow us to drop from
> performing two atomic operations to just performing on atomic
> operation (on the word that actually needs to change). This would be a
> fairly significant optimization, I think. But for now it's not a bug,
> just a missed optimization.
>
> Rich
>

________________________________

The information in this e-mail may be confidential and subject to legal professional privilege and/or copyright. National ICT Australia Limited accepts no liability for any damage caused by this email or its attachments.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-02-05 23:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-05 22:56 64-bit atomic ops on 32-bit ARM Matthew Fernandez
2014-02-05 23:06 ` Rich Felker
2014-02-05 23:08   ` Matthew Fernandez

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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).