Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Mar 1997 17:54:32 +0100
From:      Eivind Eklund <eivind@dimaga.com>
To:        brian@utell.co.uk
Cc:        Bruce Evans <bde@zeta.org.au>, ache@nagual.ru, brian@awfulhak.demon.co.uk, brian@utell.co.uk, current@FreeBSD.ORG
Subject:   Re: ppp 
Message-ID:  <3.0.32.19970311175431.00bf5900@dimaga.com>

next in thread | raw e-mail | index | archive | help
At 03:44 PM 3/11/97 +0000, Brian Somers wrote:
>&= ~ isn't guaranteed atomic ?  Yeuch.  I'd tend to go with Andrey's
>suggestion that I use an int array rather than a bit array.  I assume
>that ++ and -- are guaranteed to be atomic (if they're not, I'm in *lots*
>of trouble).

You're in lots of trouble.

The only operation even _likely_ to be atomic is storing a word.  Remember,
most RISC processors can't operate on values not in registrers - thus, they
need a load, an operation and a store.  To give examples close to what you
were asking about:

/* Pseudo-C syntax.  Used on some DSPs.  NOTE: All = operations must have a
non-dereferenced register on at least one side of the operator; all
operations more complex than = must have registers on both sides (&=, +=,
etc). Only the x= and = operators are allowed; certain if-goto's can also
be used. */

/* var &= 0x800; */
	r0 = &var;	/* Variable to operate on. */
	r1 = 0x800;	/* Immediate value */
	r2 = *r0;	/* Fetch contents of variable */
	r2 &= r1;	/* Do operation */
	*r0 = r2;	/* Store result */

/* var++ */
	r0 = &var;
	r1 = 1;
	r2 = *r0;
	r2 += r1;
	*r0 = r2;


Of course, this is close to as nasty as they come.  Most processors will
let you add/and immediate values directly to registers.  But they are not
all, and  they still don't become any more atomic than the above.

Besides, even a store is not guaranteed to be atomic - a friend of mine
told of a guy he studied with who had made a computer with a single
instruction (add and skip if zero), clocked it at a couple of gigaherz, and
proved it to be Turing complete.  This could be your next port ;-)



Eivind Eklund perhaps@yes.no http://maybe.yes.no/perhaps/ eivind@freebsd.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3.0.32.19970311175431.00bf5900>