https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102566
--- Comment #33 from Marko Mäkelä <marko.makela at mariadb dot com> --- When it comes to toggling the most significant bit, std::atomic::fetch_xor() could be translated to LOCK XADD which would be able to return all bits: #include <atomic> uint32_t toggle_by_add(std::atomic<uint32_t>& a) { return a.fetch_add(1U<<31); } uint32_t toggle_by_xor(std::atomic<uint32_t>& a) { return a.fetch_xor(1U<<31); }