public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/49244] New: no intrinsics to emit 'lock bts' and 'lock btc'
@ 2011-05-31 19:38 desrt at desrt dot ca
  2011-06-01  6:55 ` [Bug other/49244] " jakub at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: desrt at desrt dot ca @ 2011-05-31 19:38 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-11-10  9:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-31 19:38 [Bug other/49244] New: no intrinsics to emit 'lock bts' and 'lock btc' desrt at desrt dot ca
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

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).