Article View: comp.arch
Article #234Re: Performance of xchg reg,reg
From: Dan Cross
Date: Tue, 20 Oct 2026 02:00
Date: Tue, 20 Oct 2026 02:00
34 lines
2554 bytes
2554 bytes
In article <jwv8q3uqrxf.fsf-monnier+comp.arch@gnu.org>, Stefan Monnier <monnier@iro.umontreal.ca> wrote: >Anton Ertl [2026-10-18 16:57:26] wrote: >> And actually all the stuff about XCHG with memory operands does not >> contradict this sentence. It could be understood as meaning that >> while all the other aspects of locking don't apply to "XCHG reg, reg", >> the assertion of the LOCK# signal still has to occur, and that's why >> Intel processors implement a slow XCHG reg, reg. > >How could code witness the difference? > >I believe AMD can claim that its behavior is consistent with the >behavior you'd get when asserting the LOCK# signal. The effects of a bus lock include disallowing memory operations (except for instruction fetches or page table accesses) passing a locked operation. If `XCHG reg,reg` where indeed treated as though it asserted `LOCK#` for the duration of its execution, it could be (ab)used to force that behavior: From sec 11.1.2.2 of SDM Volume 3a (Sept 2026 version): |Locked operations are atomic with respect to all other memory |operations and all externally visible events. Only instruction |fetch and page table accesses can pass locked instructions. |Locked instructions can be used to synchronize data written by |one processor and read by another processor. For example, this could be used before releasing a lock to prevent a load from migrating into the critical section (though on a TSO machine this should be ok, since a load can't be reordered before a store to the same location). - Dan C.
Technical Details
Message-ID:
<11b6i0g$f44$1@reader2.panix.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!panix!.POSTED.spitfire.i.gajendra.net!not-for-mailReferences:
<2026Oct13.104347@mips.complang.tuwien.ac.at> <20261018184318.00000bee@yahoo.com> <2026Oct18.185726@mips.complang.tuwien.ac.at> <jwv8q3uqrxf.fsf-monnier+comp.arch@gnu.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!panix!.POSTED.spitfire.i.gajendra.net!not-for-mail From: cross@spitfire.i.gajendra.net (Dan Cross) Newsgroups: comp.arch Subject: Re: Performance of xchg reg,reg Date: Tue, 20 Oct 2026 02:00:48 -0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Message-ID: <11b6i0g$f44$1@reader2.panix.com> References: <2026Oct13.104347@mips.complang.tuwien.ac.at> <20261018184318.00000bee@yahoo.com> <2026Oct18.185726@mips.complang.tuwien.ac.at> <jwv8q3uqrxf.fsf-monnier+comp.arch@gnu.org> Injection-Date: Tue, 20 Oct 2026 02:00:48 -0000 (UTC) Injection-Info: reader2.panix.com; posting-host="spitfire.i.gajendra.net:166.84.136.80"; logging-data="15492"; mail-complaints-to="abuse@panix.com" X-Newsreader: trn 4.0-test77 (Sep 1, 2010) Originator: cross@spitfire.i.gajendra.net (Dan Cross)