[Bug other/49244] New: no intrinsics to emit 'lock bts' and 'lock btc'

desrt at desrt dot ca gcc-bugzilla@gcc.gnu.org
Tue May 31 19:38:00 GMT 2011


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.



More information about the Gcc-bugs mailing list