Article View: comp.arch
Article #161Re: Performance of xchg reg,reg
From: Dan Cross
Date: Sat, 17 Oct 2026 02:50
Date: Sat, 17 Oct 2026 02:50
43 lines
2884 bytes
2884 bytes
In article <11au1vu$3ks5m$2@dont-email.me>, Thomas Koenig <tkoenig@netcologne.de> wrote: >Dan Cross <cross@spitfire.i.gajendra.net> schrieb: >> 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. Using the `LOCK` prefix without a destination operand that is a memory operand is an error, and the SDM is quite explicit about that. In fact, it says that an explicit `LOCK` prefix on an `XCHG` a register destination operand is _not_ permitted and "may" generate an `#UD` exception. But sadly, when talking about an `XCHG` _without_ an explicit operand, it is left ambiguous; all it says is that, "The `XCHG` instruction always asserts the `LOCK#` signal regardless of the presence or absence of the `LOCK` prefix." Devoid of the rest of the surrounding context, one could interpret that to mean that an `XCHG` _always_ forces a bus lock, irrespective of the type of its desintation operand. Why? I have no idea; as I said, I'm in the camp of going with what the description of `XCHG` itself says, and not the what the description of the `LOCK` prefix says: that sentence is _not_ devoid of context, and besides, there has not been a physical `LOCK#` signal coming out of an Intel Xeon package since Nehalem. I suppose one could imagine it forcing a poor-man's barrier to prevent later loads from being reorderd before it (loads can't migrate before locked instructions). But we've got explicit fence instructions for that, so I don't buy it. I suspect that sentence is just poorly phrased. - Dan C.
Technical Details
Message-ID:
<11aunpn$8c6$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> <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!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: Sat, 17 Oct 2026 02:50:31 -0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Message-ID: <11aunpn$8c6$1@reader2.panix.com> References: <2026Oct13.104347@mips.complang.tuwien.ac.at> <11atq3a$nqi$1@reader2.panix.com> <11au1vu$3ks5m$2@dont-email.me> Injection-Date: Sat, 17 Oct 2026 02:50:31 -0000 (UTC) Injection-Info: reader2.panix.com; posting-host="spitfire.i.gajendra.net:166.84.136.80"; logging-data="8582"; mail-complaints-to="abuse@panix.com" X-Newsreader: trn 4.0-test77 (Sep 1, 2010) Originator: cross@spitfire.i.gajendra.net (Dan Cross)