From 2c0126e3ef23ed7962d8fe36b0249fb4256e8d0b Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Mon, 22 Apr 2024 13:24:17 +0200 Subject: [PATCH] aarch64: Fix swap_atomic retry * lightening/aarch64-cpu.c (swap_atomic): If the swap fails, and the dst register was the same as the val, we would stomple val during the retry. Fixes https://github.com/wingo/fibers/issues/83#issuecomment-2068847127. --- lightening/aarch64-cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lightening/aarch64-cpu.c b/lightening/aarch64-cpu.c index 13aa351e9..2eaf74406 100644 --- a/lightening/aarch64-cpu.c +++ b/lightening/aarch64-cpu.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2017, 2019 Free Software Foundation, Inc. + * Copyright (C) 2013-2017, 2019, 2024 Free Software Foundation, Inc. * * This file is part of GNU lightning. * @@ -2532,10 +2532,10 @@ str_atomic(jit_state_t *_jit, int32_t loc, int32_t val) static void swap_atomic(jit_state_t *_jit, int32_t dst, int32_t loc, int32_t val) { - void *retry = jit_address(_jit); int32_t result = jit_gpr_regno(get_temp_gpr(_jit)); int32_t val_or_tmp = dst == val ? jit_gpr_regno(get_temp_gpr(_jit)) : val; movr(_jit, val_or_tmp, val); + void *retry = jit_address(_jit); LDAXR(_jit, dst, loc); STLXR(_jit, val_or_tmp, loc, result); jit_patch_there(_jit, bnei(_jit, result, 0), retry);