public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Ulrich Drepper <drepper@cygnus.com>
To: Mark Kettenis <kettenis@wins.uva.nl>
Cc: libc-hacker@sourceware.cygnus.com
Subject: Re: Atomic operations
Date: Sat, 01 Jan 2000 21:36:00 -0000	[thread overview]
Message-ID: <m3zoup6nsb.fsf@localhost.localnet> (raw)
In-Reply-To: <200001020416.FAA03369@delius.kettenis.local>

Mark Kettenis <kettenis@wins.uva.nl> writes:

> At the end of this message you'll find how these operations can be
> implemented for the i386.  The idea is that the `if'-statements will
> all be optimized away.  The only `problem' is the fact that the lock
> will always be present, even if it is not used.  I would be interested
> in a way to eleminate the lock when possible.  However, I don't think
> wasting a few bytes is going tobe a big problem.

It's an interesting concept.  But I don't think we have to be that
general.  Why should be allow atomic objects of other than the natual
sizes?  The only possible motivation is size but then, with the
spinlock, this is more than nullified (on platforms which don't need
them).

I think defining types atomic_t and uatomic_t (latter is unsigned)
which are guaranteed to have at least 32 bits should be enough.  Do
you know about situations where this is not the case?

The only problem I could see is that you want to have longer types
also on 32bit platforms.  Then I'd suggest

	atomic_least32_t
	uatomic_least32_t
	atomic_least64_t
	uatomic_least64_t

Of course we need then something like your macros since modifying the
64 bit object does not work without it on a 32 bit platform.  Maybe we
can even define atomic_least8_t etc and on platforms like x86 we can
define these with the minimal amount of bits.  So maybe:


#define atomic_object(class, name, size, oper) \
  atomic_object_##oper (class, name, size)

#define atomic_object_INC(class, name, size) \
  class int##size##_t name

#define atomic_object_DEC(class, name, size) \
  class int##size##_t name

#define atomic_object_INC_DEC(class, name, size) \
  class int##size##_t name

#define atomic_object_XADD(class, name, size) \
  class int##size##_t name; \
  __libc_lock_define_initialized (class, __atomic_lock_##name)

#define atomic_object_INC_XADD(class, name, size) \
  class int##size##_t name; \
  __libc_lock_define_initialized (class, __atomic_lock_##name)


The `oper' parameter to atomic_object would then have to be one of

			XADD		CMPX		XADD_CMPX
	INC		INC_XADD	INC_CMPX	INC_XADD_CMPX
	DEC		DEC_XADD	DEC_CMPX	DEC_XADD_CMPX
	INC_DEC		INC_DEC_XADD	INC_DEC_CMPX	INC_DEC_XADD_CMPX


Which shouldn't be too bad.


>     __asm__ __volatile__ ("lock; incl %0" : : "m" (NAME) : "memory")

This does not work.  `lock' only works on

	bt, bts, btr, btc, xchg, add, adc, and


-- 
---------------.      drepper at gnu.org  ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Cygnus Solutions `--' drepper at cygnus.com   `------------------------

      reply	other threads:[~2000-01-01 21:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-01 20:16 Mark Kettenis
2000-01-01 21:36 ` Ulrich Drepper [this message]

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=m3zoup6nsb.fsf@localhost.localnet \
    --to=drepper@cygnus.com \
    --cc=kettenis@wins.uva.nl \
    --cc=libc-hacker@sourceware.cygnus.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).