🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c++
Article #952

Re: What does this code

#952
From: Michael S
Date: Fri, 20 Nov 2026 09:44
36 lines
2085 bytes
On Fri, 20 Nov 2026 08:48:56 +0100
Bonita Montero <Bonita.Montero@gmail.com> wrote:

> Cool code without any branches and conditional
> moves if the compiler does it as I intended.
> 
> inline xsm_lock::operator int() const noexcept
> {
> 	return (int)m_shared | -(int)!m_pMtx;
> }
> 
> m_pMtx is a pointer.
> Chris, I'm sure *you* would use relacy with that.
> 

The code that people could read and understand is compiled to exactly
the same asm on RISC-V:
https://godbolt.org/z/vbvxTGMv5
And on ARM64:
https://godbolt.org/z/rv9GT7fxM
And on x86-64:
https://godbolt.org/z/fsGb4Keq3

That's clang.

With gcc readable code is compiled to better x86-64 asm than the tricky
one:
https://godbolt.org/z/7zhMdrEzo

The same number of instructions in bot cases, but in readable vesrsion
dependency chain is shorter (2 vs 3).

ARM64 is the same again:
https://godbolt.org/z/641WfW9ds

Technical Details
Message-ID: <20261120114427.00002e24@yahoo.com>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11dou16$2vlr8$1@raubtier-asyl.eternal-september.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Michael S <already5chosen@yahoo.com>
Newsgroups: comp.lang.c++
Subject: Re: What does this code
Date: Fri, 20 Nov 2026 11:44:27 +0200
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <20261120114427.00002e24@yahoo.com>
References: <11dou16$2vlr8$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 20 Nov 2026 09:44:25 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2785104"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+8kjsJU46YLa2GNwQ+FyCMynX5JEAfElU="; posting-host="c9277e243488dd36750115eaaca8b400"
Cancel-Lock: sha1:qTEVD5Q19t2gi42DpFrhXT8sw3Y= sha256:hKg0uDlmH1hAy78qyH02jnE6XAUVclYoHO4JDVgdxJ0=
	sha1:RmGD3rHJ+dE2Vtix2pC3Y5vk9wQ= sha256:4gmCdHJTSn2aBuYIDk8dnBS6ThnVNAcFsKIqpITuEyg=
X-Newsreader: Claws Mail 4.1.1 (GTK 3.24.34; x86_64-w64-mingw32)