From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tony Garnock-Jones Newsgroups: gmane.lisp.guile.bugs Subject: bug#70474: [PATCH 2/2] Replace aarch64 CAS and atomic-swap generated JIT code with CASAL and SWPAL instructions Date: Fri, 19 Apr 2024 22:48:53 +0200 Message-ID: <6cacb4fa-4547-469b-b28c-c621e664e8be@leastfixedpoint.com> References: <825897f1-19fa-4f6a-b459-8db93791d1c3@leastfixedpoint.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28644"; mail-complaints-to="usenet@ciao.gmane.io" To: 70474@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Fri Apr 19 22:50:03 2024 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rxvBJ-0007CX-VE for guile-bugs@m.gmane-mx.org; Fri, 19 Apr 2024 22:50:02 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rxvBB-0007GA-PY; Fri, 19 Apr 2024 16:49:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rxvB9-0007FY-7f for bug-guile@gnu.org; Fri, 19 Apr 2024 16:49:51 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rxvB8-00059C-Ty for bug-guile@gnu.org; Fri, 19 Apr 2024 16:49:50 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rxvBN-0002jh-1m for bug-guile@gnu.org; Fri, 19 Apr 2024 16:50:05 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <825897f1-19fa-4f6a-b459-8db93791d1c3@leastfixedpoint.com> Resent-From: Tony Garnock-Jones Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Fri, 19 Apr 2024 20:50:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70474 X-GNU-PR-Package: guile Original-Received: via spool by 70474-submit@debbugs.gnu.org id=B70474.171355975910044 (code B ref 70474); Fri, 19 Apr 2024 20:50:04 +0000 Original-Received: (at 70474) by debbugs.gnu.org; 19 Apr 2024 20:49:19 +0000 Original-Received: from localhost ([127.0.0.1]:60306 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rxvAb-0002bi-11 for submit@debbugs.gnu.org; Fri, 19 Apr 2024 16:49:19 -0400 Original-Received: from smoke.leastfixedpoint.com ([81.4.107.66]:46806 helo=mail.leastfixedpoint.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rxvAY-0002aB-2s for 70474@debbugs.gnu.org; Fri, 19 Apr 2024 16:49:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leastfixedpoint.com; s=default; t=1713559734; bh=5GvdGAiEy6L8uduTPQHO6lj7mWJFAtq4mOkXDAynviM=; h=Date:From:Subject:To; b=AvUrIBeXA5R/WstxMZ8Tb99EqaRDEv7uVau7xCET6u7Sn3jvnh7khJh10HJ7QuVKv /4SgBMANkkOzKwlh+9UsNXE3V3ErIezSNmJhuKEadxzsM3I9vHlqNndbBS8t5mrbKy W+e+4TiIZHaGR+raVszcQ+cFNBo3f1o2Q7r+56aI= Original-Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.leastfixedpoint.com (Postfix) with ESMTPSA id 2F2743F69F for <70474@debbugs.gnu.org>; Fri, 19 Apr 2024 22:48:54 +0200 (CEST) Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.bugs:10809 Archived-At: This appears to make the problem go away. I'm new at working with `lightening` so I'm not confident I've covered everything that needs covering, particularly wrt the implementation of cas_atomic. But perhaps this can be a foundation for someone who knows more than I do to work from. --- libguile/lightening/lightening/aarch64-cpu.c | 41 ++++++-------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/libguile/lightening/lightening/aarch64-cpu.c b/libguile/lightening/lightening/aarch64-cpu.c index 13aa351e9..30766652f 100644 --- a/libguile/lightening/lightening/aarch64-cpu.c +++ b/libguile/lightening/lightening/aarch64-cpu.c @@ -223,8 +223,8 @@ oxxrs(jit_state_t *_jit, int32_t Op, #define A64_UMULH 0x9bc07c00 #define A64_LDAR 0xc8dffc00 #define A64_STLR 0xc89ffc00 -#define A64_LDAXR 0xc85ffc00 -#define A64_STLXR 0xc800fc00 +#define A64_SWPAL 0xf8e08000 +#define A64_CASAL 0xc8e0fc00 #define A64_STRBI 0x39000000 #define A64_LDRBI 0x39400000 #define A64_LDRSBI 0x39800000 @@ -664,15 +664,15 @@ STLR(jit_state_t *_jit, int32_t Rt, int32_t Rn) } static void -LDAXR(jit_state_t *_jit, int32_t Rt, int32_t Rn) +SWPAL(jit_state_t *_jit, int32_t Rt, int32_t Rn, int32_t Rs) { - return o_xx(_jit, A64_LDAXR, Rt, Rn); + return oxxx(_jit, A64_SWPAL, Rt, Rn, Rs); } static void -STLXR(jit_state_t *_jit, int32_t Rt, int32_t Rn, int32_t Rm) +CASAL(jit_state_t *_jit, int32_t Rt, int32_t Rn, int32_t Rs) { - return oxxx(_jit, A64_STLXR, Rt, Rn, Rm); + return oxxx(_jit, A64_CASAL, Rt, Rn, Rs); } static void @@ -2532,36 +2532,17 @@ 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); - LDAXR(_jit, dst, loc); - STLXR(_jit, val_or_tmp, loc, result); - jit_patch_there(_jit, bnei(_jit, result, 0), retry); - if (dst == val) unget_temp_gpr(_jit); - unget_temp_gpr(_jit); + SWPAL(_jit, dst, loc, val); } static void cas_atomic(jit_state_t *_jit, int32_t dst, int32_t loc, int32_t expected, int32_t desired) { - int32_t dst_or_tmp; - if (dst == loc || dst == expected || dst == expected) - dst_or_tmp = jit_gpr_regno(get_temp_gpr(_jit)); - else - dst_or_tmp = dst; - void *retry = jit_address(_jit); - LDAXR(_jit, dst_or_tmp, loc); - jit_reloc_t bad = bner(_jit, dst_or_tmp, expected); - int result = jit_gpr_regno(get_temp_gpr(_jit)); - STLXR(_jit, desired, loc, result); - jit_patch_there(_jit, bnei(_jit, result, 0), retry); - unget_temp_gpr(_jit); - jit_patch_here(_jit, bad); - movr(_jit, dst, dst_or_tmp); - unget_temp_gpr(_jit); + if (dst != expected) { + movr(_jit, dst, expected); + } + CASAL(_jit, desired, loc, dst); } static void -- 2.44.0