🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #157

Re: Performance of xchg reg,reg

#157
From: Scott Lurndal
Date: Fri, 16 Oct 2026 20:48
43 lines
2913 bytes
Thomas Koenig <tkoenig@netcologne.de> writes:
>Dan Cross <cross@spitfire.i.gajendra.net> schrieb:
>> In article <20261016113441.00002a5f@yahoo.com>,
>> Michael S  <already5chosen@yahoo.com> wrote:
>>>On Fri, 16 Oct 2026 05:50:55 GMT
>>>anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:
>>>
>>>> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>>>> >Well, for some reason the LOCK prefix is implied for XCHG.  
>>>> 
>>>> According to <https://www.felixcloutier.com/x86/xchg> (which is based
>>>> on (I think) Intel's documentation):
>>>> 
>>>> |If a memory operand is referenced, the processor’s locking protocol is
>>>> |automatically implemented for the duration of the exchange operation,
>>>> |regardless of the presence or absence of the LOCK prefix or of the
>>>> |value of the IOPL.
>>>> 
>>>> This does not cover the "xchg reg, reg" case.
>>>> 
>>>> <https://www.felixcloutier.com/x86/lock> says:
>>>> |The XCHG instruction always asserts the LOCK# signal regardless of the
>>>> |presence or absence of the LOCK prefix.
>>>> 
>>>> This seems to include the "xchg reg, reg" case, 
>>>
>>>No, it does not.
>>
>> Unfortunately, the information is spread across two sections,
>> and they contradict.  The description in the `LOCK` prefix
>> section in the latest version of the Intel SDM includes the text
>> Anton quoted, while the description of `XCHG` itself makes clear
>> that the destination operand must be a memory operand for the
>> locking protocol to automatically apply.  Which is correct?
>
>What would be the meaning of LOCK with memory operands?  I can't
>think of any.

Did you mean 'without memory operands'?   It's clear that there
is no need to acquire the cache and/or system lock if there
are no memory operands, and a substantial performance penalty;
besides, which cache line would it use for the case where both
operands are registers?
Technical Details
Message-ID: <g4wAS.119956$2%g.24960@fx41.iad>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer05.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx41.iad.POSTED!not-for-mail
References: <2026Oct13.104347@mips.complang.tuwien.ac.at> <11arg45$2p70p$1@dont-email.me> <2026Oct16.075055@mips.complang.tuwien.ac.at> <20261016113441.00002a5f@yahoo.com> <11atq3a$nqi$1@reader2.panix.com> <11au1vu$3ks5m$2@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer05.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx41.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: scott@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Performance of xchg reg,reg
Newsgroups: comp.arch
References: <2026Oct13.104347@mips.complang.tuwien.ac.at> <11arg45$2p70p$1@dont-email.me> <2026Oct16.075055@mips.complang.tuwien.ac.at> <20261016113441.00002a5f@yahoo.com> <11atq3a$nqi$1@reader2.panix.com> <11au1vu$3ks5m$2@dont-email.me>
Lines: 43
Message-ID: <g4wAS.119956$2%g.24960@fx41.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 16 Oct 2026 20:48:12 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 16 Oct 2026 20:48:12 GMT
X-Received-Bytes: 2681