Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Message-ID | <4DD136D5.10705@SPAM.comp-arch.net> (permalink) |
|---|---|
| Date | 2011-05-16 07:38 -0700 |
| From | "Andy \"Krazy\" Glew" <andy@SPAM.comp-arch.net> |
| Organization | comp-arch.net |
| Newsgroups | comp.arch |
| Subject | Re: What are the various alternate uses for the PC's LSB ? |
| References | (3 earlier) <nqev98-qvt2.ln1@ntp6.tmsw.no> <iqjjk2$ldo$1@dont-email.me> <op70a8-sru2.ln1@ntp6.tmsw.no> <4DCF1B96.6090106@SPAM.comp-arch.net> <9hh7a8-5ha.ln1@ntp6.tmsw.no> |
On 5/16/2011 5:22 AM, Terje Mathisen wrote:
> Andy "Krazy" Glew wrote:
>> On 5/13/2011 10:53 AM, Terje Mathisen wrote:
>>> Test&Set, in the form XCHG reg,[mem] is the original x86 sync primitive,
>>> the main problem is that it only provides a boolean gate, not something
>>> which can be used as-is.
>>
>> Nit-pocking:
>>
>> XCHG is atomic exchange, not test-and-set.
>>
>> test-and-set is something more primitive.
>
> Nit-picking indeed:
>
> IMHO xchg is the more primitive, since you need to wrap it in a loop to
> aquire an access token or similar:
>
> mov ax,1
> ;; lea bx,[flag_variable]
> spinloop:
> xchg ax,[bx]
> test ax,ax
> jnz spinloop
>
> Terje
Terminology check:
dst_or_flag := bit-oriented-test-and-set(location,bitnum) ::
<atomic>
tmp := load( location ) ; old value
dest_or_flag := (tmp >> bitnum) & 1; old value of bit
tmp |= 1<<bitnum;
store( location, tmp )
</atomic>
dst_or_flag := int-oriented-test-and-set(location) ::
<atomic>
tmp := load( location ) ; old value
dest_or_flag := tmp; old value of int, or maybe compare to zero
tmp = 1;
store( location, tmp )
</atomic>
dst := xchg(regnew,location)
<atomic>
dest := load( location ) ; old value
store( location, regnew )
</atomic>
dst := cmpxchg(cmpval,regnew,location)
<atomic>
tmp := load( location ) ; old value
dest := temp
if( dest == cmpval )
tmp = regnew
else
tmp = tmp
store( location, tmp )
</atomic>
The test-and-sets always need to be wrapped in a spinloop to acquire an
access token or similar. Called a test-and-set spinloop.
XCHG can be treated as a test-and-set, and wrapped in a spinloop.
Or you can use a Graunke Thakkar lock, and insert onto a queue, no spinloop.
Ditto CMPXCHG, except the non-spinloop queue insert for CMPXCHG is
better known.
This is why I call test-and-set more primitive: because it typically
only sets a single bit, or sets an integer to a fixed value, it cannot
be used for queue insertion. But is easier to implement externally.
Back to comp.arch | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: What are the various alternate uses for the PC's LSB ? "Paul A. Clayton" <paaronclayton@gmail.com> - 2011-05-12 08:49 -0700
Re: What are the various alternate uses for the PC's LSB ? whygee <yg@yg.yg> - 2011-05-13 02:01 +0200
Re: What are the various alternate uses for the PC's LSB ? "Andy \"Krazy\" Glew" <andy@SPAM.comp-arch.net> - 2011-05-12 20:32 -0700
Re: What are the various alternate uses for the PC's LSB ? Terje Mathisen <"terje.mathisen at tmsw.no"> - 2011-05-13 12:47 +0200
Re: What are the various alternate uses for the PC's LSB ? Stephen Fuld <SFuld@alumni.cmu.edu.invalid> - 2011-05-13 08:44 -0700
Re: What are the various alternate uses for the PC's LSB ? Terje Mathisen <"terje.mathisen at tmsw.no"> - 2011-05-13 19:53 +0200
Re: What are the various alternate uses for the PC's LSB ? Stephen Fuld <SFuld@alumni.cmu.edu.invalid> - 2011-05-13 11:36 -0700
Re: What are the various alternate uses for the PC's LSB ? Terje Mathisen <"terje.mathisen at tmsw.no"> - 2011-05-13 22:26 +0200
Re: What are the various alternate uses for the PC's LSB ? "Andy \"Krazy\" Glew" <andy@SPAM.comp-arch.net> - 2011-05-14 17:17 -0700
Re: What are the various alternate uses for the PC's LSB ? Terje Mathisen <"terje.mathisen at tmsw.no"> - 2011-05-16 14:22 +0200
Re: What are the various alternate uses for the PC's LSB ? "Andy \"Krazy\" Glew" <andy@SPAM.comp-arch.net> - 2011-05-16 07:38 -0700
Re: What are the various alternate uses for the PC's LSB ? "Andy \"Krazy\" Glew" <andy@SPAM.comp-arch.net> - 2011-05-14 17:14 -0700
Re: What are the various alternate uses for the PC's LSB ? rpw3@rpw3.org (Rob Warnock) - 2011-05-13 07:45 -0500
csiph-web