public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "desrt at desrt dot ca" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug other/49244] New: no intrinsics to emit 'lock bts' and 'lock btc' Date: Tue, 31 May 2011 19:38:00 -0000 [thread overview] Message-ID: <bug-49244-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49244 Summary: no intrinsics to emit 'lock bts' and 'lock btc' Product: gcc Version: unknown Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: other AssignedTo: unassigned@gcc.gnu.org ReportedBy: desrt@desrt.ca I want to be able to code this function: bool set_and_test (int *a, int bit) { uint mask = (1u << bit); return (__sync_fetch_and_or (a, mask) & mask) != 0; } and have GCC not emit a loop on amd64 and x86. GCC presently emits a loop for __sync_fetch_and_or() in this case. That's because asm "lock or" discards the previous value, so it can only be used in cases that the result is ignored. Since we do a comparison with the value, GCC has to do the loop. This special case (set and test a single bit) corresponds quite directly to the 'lock bts' assembly instruction, though. GCC could emit that instead. It would be nice if GCC could detect (by magic?) that I am only interested in this single bit or (probably much easier) expose an intrinsic that lets me access this functionality on platforms that it exists and falls back to using __sync_fetch_and_or() otherwise.
next reply other threads:[~2011-05-31 19:25 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-05-31 19:38 desrt at desrt dot ca [this message] 2011-06-01 6:55 ` [Bug other/49244] " jakub at gcc dot gnu.org 2011-06-02 23:07 ` desrt at desrt dot ca 2012-08-23 9:47 ` [Bug target/49244] " mgorny at gentoo dot org 2021-10-04 14:52 ` [Bug target/49244] __sync or __atomic builtins will not emit 'lock bts/btr/btc' jakub at gcc dot gnu.org 2021-10-06 2:16 ` hjl.tools at gmail dot com 2021-10-06 8:00 ` jakub at gcc dot gnu.org 2021-11-10 9:17 ` cvs-commit at gcc dot gnu.org
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-49244-4@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: linkBe 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).