Refactor atomic compare_and_swap to make it fit for ARMv8-M Baseline