From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 25307386EC47; Sat, 23 Jan 2021 19:37:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 25307386EC47 From: "jeffhurchalla at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/98801] Request for a conditional move built-in function Date: Sat, 23 Jan 2021 19:37:11 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jeffhurchalla at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 23 Jan 2021 19:37:11 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98801 --- Comment #2 from Jeff Hurchalla --- Relying on improved codegen, I believe we have the current problem that the= re are times that a programmer knows a conditional is unpredictable, yet it wo= uld be impossible for a compiler to know. There's no documented way for a programmer to inform the compiler. There might also be cases (beyond my re= alm) for security where execution time can't be allowed to vary due to a mispredicted branch - again with no way to tell the compiler to use a conditional move, or branchless code. Barring a built-in function for conditional move, I'd alternatively request a documented canonical form to = use in C that provides conditional moves when the ISA supports it (hypothetical= ly, the earlier ugly bit-hack example could work for this due to its clear inte= nt, whereas the ternary operator example could not due to unclear intent). Wit= hout a canonical form, could a compiler anticipate the near infinite number of w= ays a programmer might express it in C, even when the intent is clear? I'd certainly prefer a conditional move built-in function, if it's a possibility. It's clear and simple from a user's point of view. The translation to a machine instruction also seems pretty direct and limited in scope. Most ISAs support the instruction - ARM aarch64/A64/A32, x86_64, PP= C.=20 The one I know of that doesn't automatically is RISC-V, which needs the bit manipulation extension.=