Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 16 May 2011 09:38:14 -0500 Message-ID: <4DD136D5.10705@SPAM.comp-arch.net> Date: Mon, 16 May 2011 07:38:13 -0700 From: "Andy \"Krazy\" Glew" Reply-To: andy@SPAM.comp-arch.net Organization: comp-arch.net User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.11) Gecko/20101013 Thunderbird/3.1.5 MIME-Version: 1.0 Newsgroups: comp.arch Subject: Re: What are the various alternate uses for the PC's LSB ? References: <9226d60e-0c97-4863-97ab-1fc568a7bb46@glegroupsg2000goo.googlegroups.com> <4DCCA664.9070207@SPAM.comp-arch.net> <4DCF1B96.6090106@SPAM.comp-arch.net> <9hh7a8-5ha.ln1@ntp6.tmsw.no> In-Reply-To: <9hh7a8-5ha.ln1@ntp6.tmsw.no> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Lines: 75 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-WSvNIoxhbQhAUAKabAOm/B/fczKvDDzrocBfr1l2Zeco2lIetxvlXiYEpCIxn9DKif2agxiv0uXIRQM!mgy6nGsOxYQH5qWIRL1ylme4u567KjY0IoO+vqP7jquOochiCgRH+EVPoA== X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3720 Xref: x330-a1.tempe.blueboxinc.net comp.arch:1617 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) :: tmp := load( location ) ; old value dest_or_flag := (tmp >> bitnum) & 1; old value of bit tmp |= 1< dst_or_flag := int-oriented-test-and-set(location) :: tmp := load( location ) ; old value dest_or_flag := tmp; old value of int, or maybe compare to zero tmp = 1; store( location, tmp ) dst := xchg(regnew,location) dest := load( location ) ; old value store( location, regnew ) dst := cmpxchg(cmpval,regnew,location) tmp := load( location ) ; old value dest := temp if( dest == cmpval ) tmp = regnew else tmp = tmp store( location, tmp ) 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.