public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jeffhurchalla at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-98801-4-ur5Mj9x5tM@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-98801-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98801

--- Comment #2 from Jeff Hurchalla <jeffhurchalla at gmail dot com> ---
Relying on improved codegen, I believe we have the current problem that there
are times that a programmer knows a conditional is unpredictable, yet it would
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 realm)
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 (hypothetically,
the earlier ugly bit-hack example could work for this due to its clear intent,
whereas the ternary operator example could not due to unclear intent).  Without
a canonical form, could a compiler anticipate the near infinite number of ways
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, PPC. 
The one I know of that doesn't automatically is RISC-V, which needs the bit
manipulation extension.

  parent reply	other threads:[~2021-01-23 19:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-23  4:47 [Bug c++/98801] New: " jeffhurchalla at gmail dot com
2021-01-23  6:53 ` [Bug c++/98801] " pinskia at gcc dot gnu.org
2021-01-23 19:37 ` jeffhurchalla at gmail dot com [this message]
2021-01-23 20:28 ` jeffhurchalla at gmail dot com
2021-01-25  9:36 ` [Bug middle-end/98801] " rguenth at gcc dot gnu.org
2021-01-25 19:19 ` peter at cordes dot ca
2021-01-26  0:17 ` jeffhurchalla at gmail dot com
2021-01-27  5:18 ` jeffhurchalla at gmail dot com
2023-05-27 17:56 ` richard.yao at alumni dot stonybrook.edu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-98801-4-ur5Mj9x5tM@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).