Article View: comp.lang.c++
Article #976Re: What does this code
From: Bonita Montero
Date: Sat, 21 Nov 2026 15:55
Date: Sat, 21 Nov 2026 15:55
42 lines
3210 bytes
3210 bytes
Am 21.11.2026 um 14:55 schrieb David Brown: > I think the branchless code will often be more efficient in practice > when the data is already in registers (but see Michael's comments about > the code - and he is quite experienced in that kind of thing). When the > data is in memory, not a register, I expect the branched code is better. The missprediction penalty is the same. > gcc generates the best object code - if my predictions are correct - > from the clearest source code, both in your struct method and for the > stand-alone function example. I istructed the compiler to do the right thing by placing an [[unlikely]] at the if; it didn't help. > In real usage, methods like this would be inlined, and the code > generated would depend on the surrounding source code. Yes, the surrounding code would be discarded or not depending on if the branch is predicted correctly or not; but the penalty itself is the same. > The code you wrote is not "cool" or "smart" - it is a smart-arse > hack that results in significantly poorer source code quality, ... The one using this code doesn't need to know that. For developers that come from C and have this lowlevel optimizations in mind it's easy to read. I wouldn't program like this all this time; but as this is a one liner it's easy to understand for the mentioned people. > and worse object code efficiency (though it probably makes no measurable > difference in real-world usage). It depends on the usage. > Before writing such ugly code, ... That's a matter of personal taste.
Technical Details
Message-ID:
<11dsetc$6ruh$1@raubtier-asyl.eternal-september.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mailReferences:
<11dou16$2vlr8$1@raubtier-asyl.eternal-september.org> <20261120114427.00002e24@yahoo.com> <11dp7lk$330qr$1@dont-email.me> <11dp9fv$33khk$1@raubtier-asyl.eternal-september.org> <11dpbgr$34a3s$1@dont-email.me> <11draqa$3qusi$1@raubtier-asyl.eternal-september.org> <11drvr5$12fg$2@dont-email.me> <11ds1o6$20l4$1@raubtier-asyl.eternal-september.org> <11ds7s0$3uj9$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail From: Bonita Montero <Bonita.Montero@gmail.com> Newsgroups: comp.lang.c++ Subject: Re: What does this code Date: Sat, 21 Nov 2026 16:55:24 +0100 Organization: A noiseless patient Spider Lines: 42 Message-ID: <11dsetc$6ruh$1@raubtier-asyl.eternal-september.org> References: <11dou16$2vlr8$1@raubtier-asyl.eternal-september.org> <20261120114427.00002e24@yahoo.com> <11dp7lk$330qr$1@dont-email.me> <11dp9fv$33khk$1@raubtier-asyl.eternal-september.org> <11dpbgr$34a3s$1@dont-email.me> <11draqa$3qusi$1@raubtier-asyl.eternal-september.org> <11drvr5$12fg$2@dont-email.me> <11ds1o6$20l4$1@raubtier-asyl.eternal-september.org> <11ds7s0$3uj9$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 21 Nov 2026 15:55:24 +0000 (UTC) Injection-Info: raubtier-asyl.eternal-september.org; logging-data="225233"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+4+zmEH+CR/qC8Iqu8JHFmmjhh6TMGfl8="; posting-host="518be46b840f2d139b0adffd4f215cdc" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1://g0VHeVHYPohmU2uyauUVJRURU= sha256:QhZ1lf3RjHvYXZuCkiOm6NZgNnPGBrtOiiEdOXvm9+A= sha1:y3gkZpI2V6GB9b4EoHzALgq1iis= sha256:wYACTHJbyCtDa0OrBdjhfNRg8iDhbBPN/KyQck2rlIY= In-Reply-To: <11ds7s0$3uj9$1@dont-email.me> Content-Language: de-DE