Article View: comp.arch
Article #148Re: Performance of xchg reg,reg
From: EricP
Date: Fri, 16 Oct 2026 13:47
Date: Fri, 16 Oct 2026 13:47
38 lines
2100 bytes
2100 bytes
On 2026-Oct-15 03:06, Anton Ertl wrote:
> anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
>> MitchAlsup <user5857@newsgrouper.org.invalid> writes:
>>> Unlike Mainframes where sort is bread-and-butter operation, on PCs
>>> (and similar) it is not.
>>
>> And the relevance of that for "Performance of xchg reg,reg" is?
>
> To give you an idea what xchg reg,reg is good for:
>
> long foo(long a, long b);
>
> long bar(long a, long b)
> {
> return foo(b,a);
> }
>
> Both gcc-16 and clang-19 (even with -mtune=znver5) compile this to:
>
> 0000000000000000 <bar>:
> 0: 48 89 f8 mov %rdi,%rax
> 3: 48 89 f7 mov %rsi,%rdi
> 6: 48 89 c6 mov %rax,%rsi
> 9: e9 00 00 00 00 jmp e <bar+0xe> #actually jmp foo
>
> This could be replaced with
>
> xchg %rdi,%rsi
> jmp foo
There is also the xor swap which doesn't need an extra register
xor rax,rbx
xor rbx,rax
xor rax,rbx
Technical Details
Message-ID:
<2WpAS.163763$Zbg.15006@fx35.iad>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx35.iad.POSTED!not-for-mailReferences:
<2026Oct13.104347@mips.complang.tuwien.ac.at> <11ami2v$11dqu$3@dont-email.me> <2026Oct14.090023@mips.complang.tuwien.ac.at> <1792017353-5857@newsgrouper.org> <2026Oct15.080534@mips.complang.tuwien.ac.at> <2026Oct15.090653@mips.complang.tuwien.ac.at>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx35.iad.POSTED!not-for-mail MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Performance of xchg reg,reg Newsgroups: comp.arch References: <2026Oct13.104347@mips.complang.tuwien.ac.at> <11ami2v$11dqu$3@dont-email.me> <2026Oct14.090023@mips.complang.tuwien.ac.at> <1792017353-5857@newsgrouper.org> <2026Oct15.080534@mips.complang.tuwien.ac.at> <2026Oct15.090653@mips.complang.tuwien.ac.at> Content-Language: en-CA From: EricP <ThatWouldBeTelling@thevillage.com> In-Reply-To: <2026Oct15.090653@mips.complang.tuwien.ac.at> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Lines: 38 Message-ID: <2WpAS.163763$Zbg.15006@fx35.iad> X-Complaints-To: abuse@UsenetServer.com NNTP-Posting-Date: Fri, 16 Oct 2026 13:47:42 UTC Date: Fri, 16 Oct 2026 09:47:39 -0400 X-Received-Bytes: 1868