Sujet : Re: ({
De : Bonita.Montero (at) *nospam* gmail.com (Bonita Montero)
Groupes : comp.lang.c++Date : 22. Mar 2025, 16:14:42
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vrmk4n$7524$1@raubtier-asyl.eternal-september.org>
References : 1 2
User-Agent : Mozilla Thunderbird
Am 21.03.2025 um 09:58 schrieb Bonita Montero:
({ int y = foo (); int z;
if (y > 0) z = y;
else z = - y;
z; })
If the sign of y is badly predictible you may chose:
z = (y >> sizeof(y) * CHAR_BIT - 1) * y;
Sorry, your code is more efficient since it can be substituted by
a negate i a second register and a conditional move. But some archi-
tectures like RISC-V don't have conditional moves and my code would
be the most efficient way to handle this.