https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102566
--- Comment #9 from Thiago Macieira <thiago at kde dot org> --- Looks like it doesn't work for the sign bit. $ cat /tmp/test.cpp #include <atomic> bool tbit(std::atomic<int> &i) { return i.fetch_or(CONSTANT, std::memory_order_relaxed) & CONSTANT; } $ ~/dev/gcc/bin/gcc -DCONSTANT='(1<<30)' -S -o - -O2 /tmp/test.cpp | sed -n '/startproc/,/endproc/p' .cfi_startproc lock btsl $30, (%rdi) setc %al ret .cfi_endproc $ ~/dev/gcc/bin/gcc -DCONSTANT='(1<<31)' -S -o - -O2 /tmp/test.cpp | sed -n '/startproc/,/endproc/p' .cfi_startproc movl (%rdi), %eax .L2: movl %eax, %ecx movl %eax, %edx orl $-2147483648, %ecx lock cmpxchgl %ecx, (%rdi) jne .L2 shrl $31, %edx movl %edx, %eax ret .cfi_endproc Changing to std::atomic<unsigned> makes no difference.