https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121148
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> --- We also have handwritten assembly versions which need to be checked by target maintainers: libstdc++-v3/config/cpu/cris/atomicity.h has three different assembly implementations of __exchange_and add I think the ADD.D instruction will wrap, so this has the desired behaviour.