🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #100

Re: Performance of xchg reg,reg

#100
From: Anton Ertl
Date: Wed, 14 Oct 2026 07:00
33 lines
2792 bytes
Lawrence =?iso-8859-13?q?D=FFOliveiro?= <ldo@nz.invalid> writes:
>On Tue, 13 Oct 2026 08:43:47 GMT, Anton Ertl wrote:
>
>> On Zen5, even a 5-register cycle can be profitably implemented with
>> xchg when you have no spare register, a 4-register cycle even when
>> you have a spare register. For Zen4 and Zen3 cyc4 (for mem) and cyc3
>> (for reg) are borderline cases, and for shorter cycles xchg is
>> better.
>>
>> On Intel processors, xchg is so slow that it never is profitable to
>> use it. The slowness takes on extreme values in the E-cores, with
>> slowdowns by a factor >10 for cyc4 and cyc5.
>
>You’d think both companies would be running similar kinds of
>instruction workloads to find the things worth optimizing in their CPU
>architectures. But perhaps not ...

Or maybe, given the structure of the renamer, an AMD engineer saw a
relatively easy way to implement xchg efficiently, and did it, without
first looking at how often xchg occurs in benchmark programs.  And at
Intel, either no engineer thought about this, or the structure of the
renamer makes an efficient implementation much harder.

It makes me wonder, however, why cyc2xchg is more expensive than
cyc2reg, though.  An easy implementation should be to decode xchg reg,
reg into three mov reg, reg (i.e., what cyc2reg implements), where the
spare register is a non-architectural register.  But on every measured
Intel microarchitecture cyc2xchg is substantially slower than cyc2reg.

- anton
-- 
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
  Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
Technical Details
Message-ID: <2026Oct14.090023@mips.complang.tuwien.ac.at>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <2026Oct13.104347@mips.complang.tuwien.ac.at> <11ami2v$11dqu$3@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!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.arch
Subject: Re: Performance of xchg reg,reg
Date: Wed, 14 Oct 2026 07:00:23 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 33
Message-ID: <2026Oct14.090023@mips.complang.tuwien.ac.at>
References: <2026Oct13.104347@mips.complang.tuwien.ac.at> <11ami2v$11dqu$3@dont-email.me>
Injection-Date: Wed, 14 Oct 2026 07:11:46 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="1317364"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19qvGQ7jdw4Zgj+y99ZPmcw"; posting-host="4798f8a33d7cba4f1cfb66046bec21f9"
Cancel-Lock: sha1:uyYalhta1lcEZOGpijfdtmamu+Q= sha256:nVMgPlQ/yaiuVrKt5DkOwDFd+RbcKGvqlxdYII618MY=
	sha1:3OXqDWC1c8qIhZvy744PLqugIEE= sha256:3gkONmTMc7bmtuxIce64swFiU8k0/iMy7Zvs9pZG0yU=
X-newsreader: xrn 10.11