From nobody Sun May 19 03:12:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1674004330; cv=none; d=zohomail.com; s=zohoarc; b=CcbtNpcQ+OwqzLusuA8VCFk57PkrEXdaYonvDOgzqEcMjeJ94eV4kxZufd10PqA7rQJa0ya/baMLGfyTHoZEtCYl1MdHrgiV4UA3QcMODGB6Fy++wOjqvb9Esj+BZrDcHp40qIsAffQu51Lx8SbgaGTH/QIo4I2XPt78DLgSGYk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674004330; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qJICZPpEEH1YcFNc4HKSAZHC1I0j/ycDAOKP1+ciRvM=; b=T2m2wpVs5dKj1cGMuZEJowFniRShAAKUrCr3ZYINU/YT698ZG+aGFOjOlvymgm3r5sCi5jLE5Dgb3wWrk3c3kl98/sE+Q68tltK50kRhivxL1SCDl/us+fZnwJX6sznOSiMwLjNLIPwOvIlX4lETdboZXhG8u9Ylt2HpaBCJmxA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674004330246511.4578699257959; Tue, 17 Jan 2023 17:12:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzF-0001zp-Qm; Tue, 17 Jan 2023 20:11:33 -0500 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 1pHwzD-0001yM-KL for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:31 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzC-0002E7-1J for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:31 -0500 Received: by mail-pl1-x629.google.com with SMTP id b17so27832080pld.7 for ; Tue, 17 Jan 2023 17:11:29 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qJICZPpEEH1YcFNc4HKSAZHC1I0j/ycDAOKP1+ciRvM=; b=ZDdSPp1lvFUT3nkatBK0VpJ036GL0DmupgGx9xVzbbAe4BFuCTfJr1iCQFUztPIzD8 Ez7HPemwTiwpX/3CE1+EAhzHsz5vovEXGDUu1ohEHGLBoI/8+EU8TIDwbNY84owiOm7v AHDNihsIBx3muvavpx6eUTpN1ptf9oA3uzgKVJ2QvWXr28f4r98dVzCHRWhkpqafXNP6 IZ209/ysTYTeELxYS1EEsUHLUaHtJNktTaJ4rcxeiHgwLrjaEyy4iPRgEl+qm+CyHC4S ncn5LXloorspmhmLbiZ9QiwpmIsGcJWErNozo/pRpiCIUOMwoVpQaReFGa3z7gvdRufh eWUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qJICZPpEEH1YcFNc4HKSAZHC1I0j/ycDAOKP1+ciRvM=; b=pH0gu7NCZ9yW0yokrwfWbXVq5jR7/TAycbiA4fBj8UNgRWaji7zNxeGZ++FLW3rk+i mqnWe3AO85fF3IULTjmnawPCGVFGOLqJ3Oibi5Y7OVnFjG2Vf319Gv3OtHEAO3+JnjnP Pvf2Ac0HqQ78Y5euSWS21i64j9a02RiOgu0WiEgfBBMugzpmCe0vezdEzq9Sv56JFtSy ktjTk5oYusgd+pebSyEmtdLtR1iw5Cj5ulsSAXUeyz9D3hQ9lRPrQJJ0dek67eeVSSmm 5gqFvItX50ac5ZgrwjAslI96ZHKqOn2bJK1jmQqhDTFMxXgSjqKRKO807c1sFXDcNULA 8HVw== X-Gm-Message-State: AFqh2kq5v50n5pPxgVsDu+ewdkXlvo1kOOAYRa0OT0KZSTMC3M0wr6bi wHWMNV69s1YNEZUoTeTZJ97e+VpQfZZ1XASI X-Google-Smtp-Source: AMrXdXsOhulXIq2XQNm+EprtsAv7h+PkbFgDqz8kiTMgfAE2pH2p0Ci7Oy3kEtouF2sbRkgTjTEJsQ== X-Received: by 2002:a17:902:ce08:b0:193:3594:82e4 with SMTP id k8-20020a170902ce0800b00193359482e4mr6337015plg.18.1674004288619; Tue, 17 Jan 2023 17:11:28 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name Subject: [PATCH v2 01/10] target/loongarch: Enable the disassembler for host tcg Date: Tue, 17 Jan 2023 15:11:14 -1000 Message-Id: <20230118011123.392823-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1674004331744100007 Content-Type: text/plain; charset="utf-8" Reuse the decodetree based disassembler from target/loongarch/ for tcg/loongarch64/. The generation of decode-insns.c.inc into ./libcommon.fa.p/ could eventually result in conflict, if any other host requires the same trick, but this is good enough for now. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: WANG Xuerui --- disas.c | 2 ++ target/loongarch/meson.build | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/disas.c b/disas.c index 3b31315f40..c9fa38e6d7 100644 --- a/disas.c +++ b/disas.c @@ -198,6 +198,8 @@ static void initialize_debug_host(CPUDebug *s) s->info.cap_insn_split =3D 6; #elif defined(__hppa__) s->info.print_insn =3D print_insn_hppa; +#elif defined(__loongarch64) + s->info.print_insn =3D print_insn_loongarch; #endif } =20 diff --git a/target/loongarch/meson.build b/target/loongarch/meson.build index 6376f9e84b..690633969f 100644 --- a/target/loongarch/meson.build +++ b/target/loongarch/meson.build @@ -3,7 +3,6 @@ gen =3D decodetree.process('insns.decode') loongarch_ss =3D ss.source_set() loongarch_ss.add(files( 'cpu.c', - 'disas.c', )) loongarch_tcg_ss =3D ss.source_set() loongarch_tcg_ss.add(gen) @@ -24,6 +23,8 @@ loongarch_softmmu_ss.add(files( 'iocsr_helper.c', )) =20 +common_ss.add(when: 'CONFIG_LOONGARCH_DIS', if_true: [files('disas.c'), ge= n]) + loongarch_ss.add_all(when: 'CONFIG_TCG', if_true: [loongarch_tcg_ss]) =20 target_arch +=3D {'loongarch': loongarch_ss} --=20 2.34.1 From nobody Sun May 19 03:12:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1674004365; cv=none; d=zohomail.com; s=zohoarc; b=N+HCjEFvJFla1kkH+KLvK6MnXrJky4G/zz0vvWz704g6rV74jMAjlOZvWeGK/udgLLuMPaxXEgP1inqz1GXHqb4SmQLgfFXGiKkyUvy/qPoEQyBOkdO4RIBEMIxStfABN0RBiUyv/hL6sId7Tgtb1vF4/msu9+xfFCC7Mldyh7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674004365; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vX/i9PddUxPpu4wKsNIpRjvexpTXXwf910s7846V1ss=; b=dAzmFYkwZg6Ekv03dPwsyNK0agLGVQAHTSqlaFgO/bVkpmRsoR0HrTH5x0RKRgc7RTNmsHpzEuahs4gwuA3VIItw3zFjaUGKjPd8D0R9HbTwXdhk6IqTFXA5DdY0MUwT0CH8gyDDdXejYYOIA0Po5djEcttqFZVntgYxV4PeA7Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674004365601944.8404390288633; Tue, 17 Jan 2023 17:12:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzG-00020W-TU; Tue, 17 Jan 2023 20:11:34 -0500 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 1pHwzF-0001zS-Dw for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:33 -0500 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzD-0002EI-Pm for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:33 -0500 Received: by mail-pj1-x102c.google.com with SMTP id a14-20020a17090a70ce00b00229a2f73c56so708566pjm.3 for ; Tue, 17 Jan 2023 17:11:31 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vX/i9PddUxPpu4wKsNIpRjvexpTXXwf910s7846V1ss=; b=s3UPhLDxxfSmawKS23EyN6J7QF1stx430KGbnjPhvJn8vqi0SkDH3UPJfsQ1dTuei/ ssP5O34Kl8C+2ReW7a+DEai5ra5MFlOadnfm1edNwvRb0p6TEDblc9b9YhlFa+DgI6lH uEenrbqAsowGcXJhaMgprMdCEUssJ3lUJWMdCoU2BayBa7nh1QTAsgUxznpjGJtzZcUG 50ssdK0xiOyDwzPU74XlSRMSC2bFPFS7R+fWbgm2ZUz/416ozrH2+5MMIC/DZiCOnsdT nQdkc+HVg/gzp9Dk07Tge9/BtLI+AZdTZE40KlpuFN8F7ECeswSVoPwEOGu/RiwHB/NY M6lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vX/i9PddUxPpu4wKsNIpRjvexpTXXwf910s7846V1ss=; b=LCs8on5aEIy6vxu9dNanojTyB3qXfbBhJGU6Bk8hysczVuClLdX4p+4xz/NtDsX5v2 NmR5KT0oNFppkPS33FUuAF43fWRLfOWKlcqHsz4jYVsb1jkhE4XbGdwTH12/0lyT+D3B YLPBZUK/4qaSGOS9zkF0YhNIKK8m/Cs0IrPJCKgUFVr64iExlt/rz3E4nErhpkZ6sK4q ZTMcss75rji3Yq2S0p9jjS+DS9oM6bquKLT2oAOEDb0OCxl39xHPdlY8Jc4q1J1w9Wyb B34LEVBW7CvhNZC8gHCAPXfk3CfciZtoa5sstc8097KKulbRZIN1IIbZGtWECSx+pvP3 BbjQ== X-Gm-Message-State: AFqh2kpx5csVDt/j3WOiPgY0Ij+RZjJJgkniKRcVMDTBbHM5DqOjOMKp 3O1GolvCvZrAQVsuVZ2pHN+dBYp8eHD2XOTj X-Google-Smtp-Source: AMrXdXvJtMUAMKk/0sjdPoJ9yhhVGanWQeyasG3h4pc3b/y/H4PBTPJp/fL7y5X0eBSJkvJqO9Sr5g== X-Received: by 2002:a17:902:bf03:b0:194:9847:9cd4 with SMTP id bi3-20020a170902bf0300b0019498479cd4mr5092959plb.60.1674004290009; Tue, 17 Jan 2023 17:11:30 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name Subject: [PATCH v2 02/10] target/loongarch: Disassemble jirl properly Date: Tue, 17 Jan 2023 15:11:15 -1000 Message-Id: <20230118011123.392823-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1674004365863100001 Content-Type: text/plain; charset="utf-8" While jirl shares the same instruction format as bne etc, it is not assembled the same. In particular, rd is printed first not second and the immediate is not pc-relative. Decode into the arg_rr_i structure, which prints correctly. This changes the "offs" member to "imm", to update translate. Signed-off-by: Richard Henderson Reviewed-by: WANG Xuerui --- target/loongarch/disas.c | 2 +- target/loongarch/insn_trans/trans_branch.c.inc | 2 +- target/loongarch/insns.decode | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/target/loongarch/disas.c b/target/loongarch/disas.c index 858dfcc53a..7cffd853ec 100644 --- a/target/loongarch/disas.c +++ b/target/loongarch/disas.c @@ -628,7 +628,7 @@ INSN(beqz, r_offs) INSN(bnez, r_offs) INSN(bceqz, c_offs) INSN(bcnez, c_offs) -INSN(jirl, rr_offs) +INSN(jirl, rr_i) INSN(b, offs) INSN(bl, offs) INSN(beq, rr_offs) diff --git a/target/loongarch/insn_trans/trans_branch.c.inc b/target/loonga= rch/insn_trans/trans_branch.c.inc index 65dbdff41e..a860f7e733 100644 --- a/target/loongarch/insn_trans/trans_branch.c.inc +++ b/target/loongarch/insn_trans/trans_branch.c.inc @@ -23,7 +23,7 @@ static bool trans_jirl(DisasContext *ctx, arg_jirl *a) TCGv dest =3D gpr_dst(ctx, a->rd, EXT_NONE); TCGv src1 =3D gpr_src(ctx, a->rj, EXT_NONE); =20 - tcg_gen_addi_tl(cpu_pc, src1, a->offs); + tcg_gen_addi_tl(cpu_pc, src1, a->imm); tcg_gen_movi_tl(dest, ctx->base.pc_next + 4); gen_set_gpr(a->rd, dest, EXT_NONE); tcg_gen_lookup_and_goto_ptr(); diff --git a/target/loongarch/insns.decode b/target/loongarch/insns.decode index 3fdc6e148c..de7b8f0f3c 100644 --- a/target/loongarch/insns.decode +++ b/target/loongarch/insns.decode @@ -67,6 +67,7 @@ @rr_ui12 .... ...... imm:12 rj:5 rd:5 &rr_i @rr_i14s2 .... .... .............. rj:5 rd:5 &rr_i imm=3D%i14s2 @rr_i16 .... .. imm:s16 rj:5 rd:5 &rr_i +@rr_i16s2 .... .. ................ rj:5 rd:5 &rr_i imm=3D%offs= 16 @hint_r_i12 .... ...... imm:s12 rj:5 hint:5 &hint_r_i @rrr_sa2p1 .... ........ ... .. rk:5 rj:5 rd:5 &rrr_sa sa=3D%sa= 2p1 @rrr_sa2 .... ........ ... sa:2 rk:5 rj:5 rd:5 &rrr_sa @@ -444,7 +445,7 @@ beqz 0100 00 ................ ..... ..... = @r_offs21 bnez 0100 01 ................ ..... ..... @r_offs21 bceqz 0100 10 ................ 00 ... ..... @c_offs21 bcnez 0100 10 ................ 01 ... ..... @c_offs21 -jirl 0100 11 ................ ..... ..... @rr_offs16 +jirl 0100 11 ................ ..... ..... @rr_i16s2 b 0101 00 .......................... @offs26 bl 0101 01 .......................... @offs26 beq 0101 10 ................ ..... ..... @rr_offs16 --=20 2.34.1 From nobody Sun May 19 03:12:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1674004397; cv=none; d=zohomail.com; s=zohoarc; b=mZd1ThgzCTek/O+DbnEHMi8VcFE1YrBe7bjQNGaedrLjRoueX1RGithgewJufaPXJsIuYB/Oh5pjoGF4qckgVRp4pKvFbw6MlWc92Co5tEykufxgBX3FVebKEmQdy8pxRSyeupEHzvTQ5jkcdpuhI8JgY0Z3x+5kfBh4uqFPSCk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674004397; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Q2Z9v9cYvm0JH0FW34M0lXW5HnvaE2SPN1rqJqhu+FM=; b=daSuYO4AdCTH5xTj67yiVoI4Z3q2194PtvbD8ngpwb6QSOhg0fHDL6efNbWUT7uLK1CeN8ibmoRwoNwBWSeHH7w1MdNxOPl2V5+H627xQasyL6HiDZLjxN61cMEd7Xf2Wk5ibmGneMM06P4S4S2t1ASeQCfREeXWjg9awUarEvc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674004397480815.7697659182132; Tue, 17 Jan 2023 17:13:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzI-000215-E3; Tue, 17 Jan 2023 20:11:36 -0500 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 1pHwzG-00020C-BN for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:34 -0500 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzE-0002EU-R6 for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:34 -0500 Received: by mail-pj1-x102a.google.com with SMTP id bj3so31015314pjb.0 for ; Tue, 17 Jan 2023 17:11:32 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q2Z9v9cYvm0JH0FW34M0lXW5HnvaE2SPN1rqJqhu+FM=; b=sSp3k1kOwCGQm9fVKfiK9B7k75+stPVLywi6h5odTQpQ8aNTD7up3DUf5sF91rwo73 ZIeD5SF4GsZc2fFZqPx0aeQRP0fa/M2fEcmxic/hDdR4j1hCc+7eE6KRwGU7Pn2mD+Mw z9IQTpqJfSFtD9c9rywZy9jNjboU01KdX8DdBEZmyZFJTChRMSGOdv1XotzIZDvgAIpT SNmf2tka27bhGjolzUpsVwZTk6vY24HAP6FQK62cDsjzr72AIgq3uzCrZuMBYLn5hdfc EZV0vvWqUsROnbgXU710ashIW0mduAy2CuoDGlBfvwaQa/leKXScsv3ahzS0KWUDcoTx KyWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q2Z9v9cYvm0JH0FW34M0lXW5HnvaE2SPN1rqJqhu+FM=; b=EBlFCxTrJzDLgJX+dyM9apjty3+LlxXXZqijhL7pzWKfhjavlMY83GPHAzPxk4+to0 vbIzhSpxcRKYl/yVLQRlj49qQLtjGEC2jIoei+MfLtrl6bmP1aycjlJP7hR8koXOvIf2 iPXZWTd1gQAt1/KhxgHfUnXEHvrWg+BoUIrHeFnO0/EfOrSLcghqlaw6lw27dHxeE1mq lZmU2SNo7cApdHERJDkGBptai2VaZhxoM+VQRGN+kKQooDihu1d4aiZvV8Vw08NzdM3G UbthiEqgtc3cQuzVT30HlLyWNEdbzZEYLF4fiOfDzBa/Myu8BTuAOgqB83mPBZ+u3LMY I3ZQ== X-Gm-Message-State: AFqh2kpa++X6idvhpP3z/eQnALFzO/hjV3ZOXOA9f3VkrrKz+It7kLxL KXIq6d91ypiV55UxtqB6SiXAtfcnn5pEeD6h X-Google-Smtp-Source: AMrXdXv1QnG5qYi0HAGteD5iK7o34pJy2skC7EGXJ+TfDPOKlPA267rmiTQU0KvYCnKXEAicnZeOgw== X-Received: by 2002:a17:902:8c94:b0:18f:a27c:fe with SMTP id t20-20020a1709028c9400b0018fa27c00femr5919952plo.55.1674004291390; Tue, 17 Jan 2023 17:11:31 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name Subject: [PATCH v2 03/10] target/loongarch: Disassemble pcadd* addresses Date: Tue, 17 Jan 2023 15:11:16 -1000 Message-Id: <20230118011123.392823-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1674004398007100002 Content-Type: text/plain; charset="utf-8" Print both the raw field and the resolved pc-relative address, as we do for branches. Signed-off-by: Richard Henderson Reviewed-by: WANG Xuerui --- target/loongarch/disas.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/target/loongarch/disas.c b/target/loongarch/disas.c index 7cffd853ec..2e93e77e0d 100644 --- a/target/loongarch/disas.c +++ b/target/loongarch/disas.c @@ -519,10 +519,6 @@ INSN(fsel, fffc) INSN(addu16i_d, rr_i) INSN(lu12i_w, r_i) INSN(lu32i_d, r_i) -INSN(pcaddi, r_i) -INSN(pcalau12i, r_i) -INSN(pcaddu12i, r_i) -INSN(pcaddu18i, r_i) INSN(ll_w, rr_i) INSN(sc_w, rr_i) INSN(ll_d, rr_i) @@ -755,3 +751,36 @@ static bool trans_fcmp_cond_##suffix(DisasContext *ctx= , \ =20 FCMP_INSN(s) FCMP_INSN(d) + +#define PCADD_INSN(name) \ +static bool trans_##name(DisasContext *ctx, arg_##name *a) \ +{ \ + output(ctx, #name, "r%d, %d # 0x%" PRIx64, \ + a->rd, a->imm, gen_##name(ctx->pc, a->imm)); \ + return true; \ +} + +static uint64_t gen_pcaddi(uint64_t pc, int imm) +{ + return pc + (imm << 2); +} + +static uint64_t gen_pcalau12i(uint64_t pc, int imm) +{ + return (pc + (imm << 12)) & ~0xfff; +} + +static uint64_t gen_pcaddu12i(uint64_t pc, int imm) +{ + return pc + (imm << 12); +} + +static uint64_t gen_pcaddu18i(uint64_t pc, int imm) +{ + return pc + ((uint64_t)(imm) << 18); +} + +PCADD_INSN(pcaddi) +PCADD_INSN(pcalau12i) +PCADD_INSN(pcaddu12i) +PCADD_INSN(pcaddu18i) --=20 2.34.1 From nobody Sun May 19 03:12:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1674004327; cv=none; d=zohomail.com; s=zohoarc; b=Mp3WY5+IHn15sHDAhqMuaMp4V5DwA5UGnu8i+F5nq+Mu8ZF8irHlTAkBh6pPvBhpdTQF7cVaW3yYbCG1DZ3mePuqaC9PAbX6o9b7Uv3uYK2X2DnXMemnmd7178RWhxj/6t8wyDxQZFvR9vS5mExzHBwM4FXuB+7pFFOy51YKfRs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674004327; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=us8czsx2kIC6irS16c66/8rQTL9kieqCt5u2bB0B4KM=; b=VaFHQyFk4Lxhe1NbZXZbe7v9Yw1a2+9tQYCvcUnDFJy0GVB4loEByaZTYvNqbHR/O3wrvP7m5E2D8WCFrhFOSRPHU4Rb1ejf1R4geQdCYi9tiRUdkJvOxeFyMICkBoKMQ869pfTKf/QmbF12kCmPGQhInTWbTd5On5G4JfbqRtA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674004327607910.7296879062545; Tue, 17 Jan 2023 17:12:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzJ-00021R-Ca; Tue, 17 Jan 2023 20:11:37 -0500 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 1pHwzH-00020w-S9 for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:36 -0500 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzG-0002Ec-4p for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:35 -0500 Received: by mail-pl1-x62b.google.com with SMTP id d3so35321538plr.10 for ; Tue, 17 Jan 2023 17:11:33 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=us8czsx2kIC6irS16c66/8rQTL9kieqCt5u2bB0B4KM=; b=iPotovUuOdodeMf1wHccQkEnUoBN0C15nINJ1kUkRt+EKZORPTnTaGCCHbPzmbV9TO YvnAioBzdJp4t+Rni9Lrp6a6P/M3PPtyhLa2tvn3phUj46Sn+ObToG8svdIYj4g/R/rf zvrF4kQHRfgHXzoXDzFbaf3dtOOdTjBzSXvPuklXVaKKidhjWCTFg906X4vkxBGdD6hd 0w/YmeHOmTXe/AHfcrWqIWAbBWNAp62YIsx3wVGtAa6IcccqkYdnuPBokkYZ46OTRm9e 3NOPbdmlap5vJUxqk5qF/oPXDB+F2CWMhKydKkCXuI/acFNFl0VHb2xS2f+w88duoTaF kqHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=us8czsx2kIC6irS16c66/8rQTL9kieqCt5u2bB0B4KM=; b=ZAGlSKi9PAyCsAqVGKrvN/4ZNz9B5dkpPNE3QSNxlnvVtGsN+eaCwGlYecpjf5kCfe KpvW9b8wbPT3KDARB2nuwmGsBdOv00OJMlL4/rslwH9Fjzmdt4Q2Y2xB4PP+Yb2lbwQl knWIwEqZ/R9/dNLnDJHTpxgU05RXsCbO5/B6e3fen65FOlhCv4EqNifgYlAPukt3CHNy W1DrrL+Q1J+fntTFtAkN2AZyjQTpWpuZjACkrV11TZs6++7vGLtRnvfN+77+SE670pIT H1WR/ck5IARHvYp9tBCU52lhtADz1LHNtFvJqFwnvDdfxehqFimZZphWT8QeTIp9ZowP 84wg== X-Gm-Message-State: AFqh2kr3zuxLd68d17plGhqPCyzSt23yp3TPoNyGgLlnfW6QLAyYmeS1 4NwWwwcktMXt2jOPrnrXlb+P22A8WnTG9xpS X-Google-Smtp-Source: AMrXdXsD94IvolSRq5W8S7oeo9/NECGR7tJGTAJ6nwVGDlrXZXzJchwJ07kgNW69nka3ouQF7C9vRQ== X-Received: by 2002:a17:902:6904:b0:193:3354:1c22 with SMTP id j4-20020a170902690400b0019333541c22mr4212123plk.39.1674004292840; Tue, 17 Jan 2023 17:11:32 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name, Rui Wang Subject: [PATCH v2 04/10] tcg/loongarch64: Optimize immediate loading Date: Tue, 17 Jan 2023 15:11:17 -1000 Message-Id: <20230118011123.392823-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1674004330053100003 Content-Type: text/plain; charset="utf-8" From: Rui Wang diff: Imm Before After 0000000000000000 addi.w rd, zero, 0 addi.w rd, zero, 0 lu52i.d rd, zero, 0 00000000fffff800 lu12i.w rd, -1 addi.w rd, zero, -2048 ori rd, rd, 2048 lu32i.d rd, 0 lu32i.d rd, 0 ... Signed-off-by: Rui Wang Message-Id: <20221107144713.845550-1-wangrui@loongson.cn> Signed-off-by: Richard Henderson Reviewed-by: WANG Xuerui --- tcg/loongarch64/tcg-target.c.inc | 35 +++++++++++--------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.= c.inc index 3174557ce3..428f3abd71 100644 --- a/tcg/loongarch64/tcg-target.c.inc +++ b/tcg/loongarch64/tcg-target.c.inc @@ -274,16 +274,6 @@ static bool tcg_out_mov(TCGContext *s, TCGType type, T= CGReg ret, TCGReg arg) return true; } =20 -static bool imm_part_needs_loading(bool high_bits_are_ones, - tcg_target_long part) -{ - if (high_bits_are_ones) { - return part !=3D -1; - } else { - return part !=3D 0; - } -} - /* Loads a 32-bit immediate into rd, sign-extended. */ static void tcg_out_movi_i32(TCGContext *s, TCGReg rd, int32_t val) { @@ -291,16 +281,16 @@ static void tcg_out_movi_i32(TCGContext *s, TCGReg rd= , int32_t val) tcg_target_long hi12 =3D sextreg(val, 12, 20); =20 /* Single-instruction cases. */ - if (lo =3D=3D val) { - /* val fits in simm12: addi.w rd, zero, val */ - tcg_out_opc_addi_w(s, rd, TCG_REG_ZERO, val); - return; - } - if (0x800 <=3D val && val <=3D 0xfff) { + if (hi12 =3D=3D 0) { /* val fits in uimm12: ori rd, zero, val */ tcg_out_opc_ori(s, rd, TCG_REG_ZERO, val); return; } + if (hi12 =3D=3D sextreg(lo, 12, 20)) { + /* val fits in simm12: addi.w rd, zero, val */ + tcg_out_opc_addi_w(s, rd, TCG_REG_ZERO, val); + return; + } =20 /* High bits must be set; load with lu12i.w + optional ori. */ tcg_out_opc_lu12i_w(s, rd, hi12); @@ -334,8 +324,7 @@ static void tcg_out_movi(TCGContext *s, TCGType type, T= CGReg rd, =20 intptr_t pc_offset; tcg_target_long val_lo, val_hi, pc_hi, offset_hi; - tcg_target_long hi32, hi52; - bool rd_high_bits_are_ones; + tcg_target_long hi12, hi32, hi52; =20 /* Value fits in signed i32. */ if (type =3D=3D TCG_TYPE_I32 || val =3D=3D (int32_t)val) { @@ -366,25 +355,25 @@ static void tcg_out_movi(TCGContext *s, TCGType type,= TCGReg rd, return; } =20 + hi12 =3D sextreg(val, 12, 20); hi32 =3D sextreg(val, 32, 20); hi52 =3D sextreg(val, 52, 12); =20 /* Single cu52i.d case. */ - if (ctz64(val) >=3D 52) { + if ((hi52 !=3D 0) && (ctz64(val) >=3D 52)) { tcg_out_opc_cu52i_d(s, rd, TCG_REG_ZERO, hi52); return; } =20 /* Slow path. Initialize the low 32 bits, then concat high bits. */ tcg_out_movi_i32(s, rd, val); - rd_high_bits_are_ones =3D (int32_t)val < 0; =20 - if (imm_part_needs_loading(rd_high_bits_are_ones, hi32)) { + /* Load hi32 and hi52 explicitly when they are unexpected values. */ + if (hi32 !=3D sextreg(hi12, 20, 20)) { tcg_out_opc_cu32i_d(s, rd, hi32); - rd_high_bits_are_ones =3D hi32 < 0; } =20 - if (imm_part_needs_loading(rd_high_bits_are_ones, hi52)) { + if (hi52 !=3D sextreg(hi32, 20, 12)) { tcg_out_opc_cu52i_d(s, rd, rd, hi52); } } --=20 2.34.1 From nobody Sun May 19 03:12:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1674004341; cv=none; d=zohomail.com; s=zohoarc; b=WMweQHvbOBG15E7lu6BtcyVg1il1uCekk8MedCd5C8Pw/APRHY4Z8WJQZFXmS1h1xj2V9VE3E3hyaWazc5/auLR4Lz2EDh+Cw1CuO9Rr+1TmAS0IbCH9goCUi4bBE2mx+omVEExdkKXt+EKHWzFzj4UDf24Qlvqguh1YQk0AgWw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674004341; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eXmkIhIsuv2GneKn/fEVnv+GUooitbhPBGl3nWaEWcQ=; b=haGHUUq0SFJNVq4i4Nkw9Y7kk7M3WxdF+veCYM9kPwg8SfAT58/yh5QC61JNKRuzW8BiOpMpw5ok8NyOamSGoNASYGFWUV5M2Iumg/MhmJDQJJGJCwqenwvX2mm+iwbJ0DvbP3kBPlkFPsOMYjbGFN/bXewJpE4o3maWNc2C0PQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674004341031718.9553776627332; Tue, 17 Jan 2023 17:12:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzK-000228-Qs; Tue, 17 Jan 2023 20:11:38 -0500 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 1pHwzJ-00021S-Fj for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:37 -0500 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzH-0002Ep-NT for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:37 -0500 Received: by mail-pl1-x634.google.com with SMTP id k18so11306936pll.5 for ; Tue, 17 Jan 2023 17:11:35 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eXmkIhIsuv2GneKn/fEVnv+GUooitbhPBGl3nWaEWcQ=; b=j7bLVCaQ+kGVkaNNYh7B0+LHYsh49B2n8JQTgiMj7zN0zoob2FEwNH42wFf3Iwv4tW /1E48c6kmtnQi6y9NPxAvQyfsr32sLpwjoJS4HLHhjFfx/aYdRU4aubNzl26s+4gFEDs FqbGUmJKORiLwN+TNDIff3PWdSHNPd6Uh7rrhrToX+GccOzzVA9vHwJ0pO3bcsytROnt FDRYEhG5CrGUDoui6Qznh1W3tmn8Qp8K2DgLXc3LxZSrOO5RvwSnpXlIfGhMZFFVEaJe je4GF+7lwlBDiofYPTKeBuXVw/B1O6U7A3NsSHcJv22cSk0HJS3Zej95rPR22VqUb4kP nIeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eXmkIhIsuv2GneKn/fEVnv+GUooitbhPBGl3nWaEWcQ=; b=2Fyp0MItIXeXDg330FpXKN4aduHZ2incMjvkwY7VXJkQVcMsRcQdjdWPiM44fON2Vb IKaKq+epATUYpaZWbdmPp0WJNUehxEvPKTFEn8GyW91sptKlTyF+UFRcT+ahIzkV8199 kTKaxva7NrRVtZXV84vaVUfPN2fA9xMT87ekxgb//+IlLEByYQaXd34nDjsKdcmADIX+ Kxy/XHeSRITY1sIR9Enypy41z/NdWwlA5cEN1toZPlq8AkJ1SboM1xw5hf8p9/L9GGts XHDf9avso/02UZKO25QSltUSWfYBJQfYDJy0kJSQDs4s+UF9EK+THQOanXTr8kthGnsz yRWw== X-Gm-Message-State: AFqh2kr883na593Uhgbq/v+l99pNC5jdJaXHrzHxepsy+zcX10xEoxDe UL37+tjSgAeSWSQgbpEtGX45fFBvx0Ym1htb X-Google-Smtp-Source: AMrXdXvnOmWsHuD4RxosoqtwO9ajQ1W9FwEfKbnnn/2YvtAZlUZAJRYSKExFUZX58QiIjNWo6crPSw== X-Received: by 2002:a17:903:182:b0:194:7532:fb10 with SMTP id z2-20020a170903018200b001947532fb10mr7403618plg.40.1674004294218; Tue, 17 Jan 2023 17:11:34 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name Subject: [PATCH v2 05/10] tcg/loongarch64: Update tcg-insn-defs.c.inc Date: Tue, 17 Jan 2023 15:11:18 -1000 Message-Id: <20230118011123.392823-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1674004341828100001 Content-Type: text/plain; charset="utf-8" Regenerate with ADDU16I included: $ cd loongarch-opcodes/scripts/go $ go run ./genqemutcgdefs > $QEMU/tcg/loongarch64/tcg-insn-defs.c.inc Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: WANG Xuerui --- tcg/loongarch64/tcg-insn-defs.c.inc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) mode change 100644 =3D> 100755 tcg/loongarch64/tcg-insn-defs.c.inc diff --git a/tcg/loongarch64/tcg-insn-defs.c.inc b/tcg/loongarch64/tcg-insn= -defs.c.inc old mode 100644 new mode 100755 index d162571856..b5bb0c5e73 --- a/tcg/loongarch64/tcg-insn-defs.c.inc +++ b/tcg/loongarch64/tcg-insn-defs.c.inc @@ -4,7 +4,7 @@ * * This file is auto-generated by genqemutcgdefs from * https://github.com/loongson-community/loongarch-opcodes, - * from commit 961f0c60f5b63e574d785995600c71ad5413fdc4. + * from commit 25ca7effe9d88101c1cf96c4005423643386d81f. * DO NOT EDIT. */ =20 @@ -74,6 +74,7 @@ typedef enum { OPC_ANDI =3D 0x03400000, OPC_ORI =3D 0x03800000, OPC_XORI =3D 0x03c00000, + OPC_ADDU16I_D =3D 0x10000000, OPC_LU12I_W =3D 0x14000000, OPC_CU32I_D =3D 0x16000000, OPC_PCADDU2I =3D 0x18000000, @@ -710,6 +711,13 @@ tcg_out_opc_xori(TCGContext *s, TCGReg d, TCGReg j, ui= nt32_t uk12) tcg_out32(s, encode_djuk12_insn(OPC_XORI, d, j, uk12)); } =20 +/* Emits the `addu16i.d d, j, sk16` instruction. */ +static void __attribute__((unused)) +tcg_out_opc_addu16i_d(TCGContext *s, TCGReg d, TCGReg j, int32_t sk16) +{ + tcg_out32(s, encode_djsk16_insn(OPC_ADDU16I_D, d, j, sk16)); +} + /* Emits the `lu12i.w d, sj20` instruction. */ static void __attribute__((unused)) tcg_out_opc_lu12i_w(TCGContext *s, TCGReg d, int32_t sj20) --=20 2.34.1 From nobody Sun May 19 03:12:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1674004396; cv=none; d=zohomail.com; s=zohoarc; b=hGBkmlFC9WzlLserMAfRYAWGSg+sX8onso/1eDOKjXcBghEPYZmARxILoj2SOCT+Nl8EEYyjiIx0hjppJB3N5WFzJD+WSqSR6AfJg+GxVFZHxzyvodR+x8AxcEbnsLFlYfTuEiOfFLMlWgaRVZqhn1JaeY2PFnpGNnVRod/A8Wo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674004396; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BFlw89atOzM4lr6R+FnGh+9BiIOC0mo/qQqa+yTQyuU=; b=cILlKP+oYW93PJ3PHTN7DLlw82td/LnNIJ916T0DiN5UuLBrAyM7T3F/SM6MM4hDLuULSP0MLnKMNJox7ZVJElPuYRML1U5rUMy3k2HleuAAMLIAB4i4fYIi/kDCfN6n2uH4aF5b9/QWqWdKAppdFZA2AgKdLKk9tR23HHooAAs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674004396001829.5167290779024; Tue, 17 Jan 2023 17:13:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzN-00024F-1y; Tue, 17 Jan 2023 20:11:41 -0500 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 1pHwzL-00022K-1u for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:39 -0500 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzJ-0002F1-98 for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:38 -0500 Received: by mail-pj1-x102e.google.com with SMTP id z1-20020a17090a66c100b00226f05b9595so693722pjl.0 for ; Tue, 17 Jan 2023 17:11:36 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BFlw89atOzM4lr6R+FnGh+9BiIOC0mo/qQqa+yTQyuU=; b=JOC5E+1R0IlDT3m9m4VboAUnM07Jx0rcVvzv9g68MOMqjmJHoxWh5v3gRmBVanWx9R Bs2EiWaZ+iMETFMaZCjZ5Z+9PRTh/0mDEaS390c9UoZmEiTLR011BCWSeHbdmeXI05VJ edajM5ujkIvlYugxfcpsiCy8xsJU8PX4fHcU/tMPxgxu+yeLMKrOHsje+kk9ib94oSkS uVIjkFYTJuuGR/ppY8LW6GeRdao2sKBlZqynfKIGNhypk+uNo8hernz7Zrrr8djB/GWJ KjHfZyyekMBfB8cYX3Th8w5yrTB4FqUnrZq5h/DGYCNziO5KhnDLQBKkD2T1O8LFbVya VIBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BFlw89atOzM4lr6R+FnGh+9BiIOC0mo/qQqa+yTQyuU=; b=6D2UACFztmEPDKWIBQm4pmAAiPCRRZ42BG1yNU6zrfM61b1alKXn4y4MVIBpsUtESZ vl/70RzaaoRIB/zNKPGPWIi9Rq/zFAdkuF3XYJKToTxAY1dNUTp1R02gwkHxudngDzWC vxc2gDOI6kRK+ppwdqcMsiZCfRX/+9fRWbOaYpwjvV8oEoC3TfAGe+Vo2qyg/iJaHOA8 zRi55CFec2p0xEqUvYwUH4mO3kqVqpd23vdFzvGB0gTud5T+tY5TGs4JbK73Lxs8PRuO Jtrou338eLwMLiRT+WntVWGMPBvtzWKakxPT9LaNynxJNIpahoUOAtLBKjCh43CsVIZg 1PyA== X-Gm-Message-State: AFqh2kqUv83GequBB3Zk+9qeMDBVaR3I4oB92tHf4du9aCd2TugHBpdw 0VHGb1nsnE1+ED8t8kBhkrGdhhwLLHvkoDgO X-Google-Smtp-Source: AMrXdXt6veXsRfpzsYQdR00Wz78e28x2dVqfG+oCQ+yVHKsDjOcCN0UpfZoZO+VC9iHaaj1kmgM4Lg== X-Received: by 2002:a17:903:32c1:b0:194:7c95:dc3c with SMTP id i1-20020a17090332c100b001947c95dc3cmr7607094plr.12.1674004295626; Tue, 17 Jan 2023 17:11:35 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name Subject: [PATCH v2 06/10] tcg/loongarch64: Introduce tcg_out_addi Date: Tue, 17 Jan 2023 15:11:19 -1000 Message-Id: <20230118011123.392823-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1674004398013100003 Content-Type: text/plain; charset="utf-8" Adjust the constraints to allow any int32_t for immediate addition. Split immediate adds into addu16i + addi, which covers quite a lot of the immediate space. For the hole in the middle, load the constant into TMP0 instead. Signed-off-by: Richard Henderson Reviewed-by: WANG Xuerui --- tcg/loongarch64/tcg-target-con-set.h | 4 +- tcg/loongarch64/tcg-target-con-str.h | 2 +- tcg/loongarch64/tcg-target.c.inc | 57 ++++++++++++++++++++++++---- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/tcg/loongarch64/tcg-target-con-set.h b/tcg/loongarch64/tcg-tar= get-con-set.h index 349c672687..7b5a7a3f5d 100644 --- a/tcg/loongarch64/tcg-target-con-set.h +++ b/tcg/loongarch64/tcg-target-con-set.h @@ -23,9 +23,11 @@ C_O1_I1(r, L) C_O1_I2(r, r, rC) C_O1_I2(r, r, ri) C_O1_I2(r, r, rI) +C_O1_I2(r, r, rJ) C_O1_I2(r, r, rU) C_O1_I2(r, r, rW) C_O1_I2(r, r, rZ) C_O1_I2(r, 0, rZ) -C_O1_I2(r, rZ, rN) +C_O1_I2(r, rZ, ri) +C_O1_I2(r, rZ, rJ) C_O1_I2(r, rZ, rZ) diff --git a/tcg/loongarch64/tcg-target-con-str.h b/tcg/loongarch64/tcg-tar= get-con-str.h index c3986a4fd4..541ff47fa9 100644 --- a/tcg/loongarch64/tcg-target-con-str.h +++ b/tcg/loongarch64/tcg-target-con-str.h @@ -21,7 +21,7 @@ REGS('L', ALL_GENERAL_REGS & ~SOFTMMU_RESERVE_REGS) * CONST(letter, TCG_CT_CONST_* bit set) */ CONST('I', TCG_CT_CONST_S12) -CONST('N', TCG_CT_CONST_N12) +CONST('J', TCG_CT_CONST_S32) CONST('U', TCG_CT_CONST_U12) CONST('Z', TCG_CT_CONST_ZERO) CONST('C', TCG_CT_CONST_C12) diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.= c.inc index 428f3abd71..8cc6c5eec2 100644 --- a/tcg/loongarch64/tcg-target.c.inc +++ b/tcg/loongarch64/tcg-target.c.inc @@ -126,7 +126,7 @@ static const int tcg_target_call_oarg_regs[] =3D { =20 #define TCG_CT_CONST_ZERO 0x100 #define TCG_CT_CONST_S12 0x200 -#define TCG_CT_CONST_N12 0x400 +#define TCG_CT_CONST_S32 0x400 #define TCG_CT_CONST_U12 0x800 #define TCG_CT_CONST_C12 0x1000 #define TCG_CT_CONST_WSZ 0x2000 @@ -161,7 +161,7 @@ static bool tcg_target_const_match(int64_t val, TCGType= type, int ct) if ((ct & TCG_CT_CONST_S12) && val =3D=3D sextreg(val, 0, 12)) { return true; } - if ((ct & TCG_CT_CONST_N12) && -val =3D=3D sextreg(-val, 0, 12)) { + if ((ct & TCG_CT_CONST_S32) && val =3D=3D (int32_t)val) { return true; } if ((ct & TCG_CT_CONST_U12) && val >=3D 0 && val <=3D 0xfff) { @@ -378,6 +378,45 @@ static void tcg_out_movi(TCGContext *s, TCGType type, = TCGReg rd, } } =20 +static void tcg_out_addi(TCGContext *s, TCGType type, TCGReg rd, + TCGReg rs, tcg_target_long imm) +{ + tcg_target_long lo12 =3D sextreg(imm, 0, 12); + tcg_target_long hi16 =3D sextreg(imm - lo12, 16, 16); + + /* + * Note that there's a hole in between hi16 and lo12: + * + * 3 2 1 0 + * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + * ...+-------------------------------+-------+-----------------------+ + * | hi16 | | lo12 | + * ...+-------------------------------+-------+-----------------------+ + * + * For bits within that hole, it's more efficient to use LU12I and ADD. + */ + if (imm =3D=3D (hi16 << 16) + lo12) { + if (hi16) { + tcg_out_opc_addu16i_d(s, rd, rs, hi16); + rs =3D rd; + } + if (type =3D=3D TCG_TYPE_I32) { + tcg_out_opc_addi_w(s, rd, rs, lo12); + } else if (lo12) { + tcg_out_opc_addi_d(s, rd, rs, lo12); + } else { + tcg_out_mov(s, type, rd, rs); + } + } else { + tcg_out_movi(s, type, TCG_REG_TMP0, imm); + if (type =3D=3D TCG_TYPE_I32) { + tcg_out_opc_add_w(s, rd, rs, TCG_REG_TMP0); + } else { + tcg_out_opc_add_d(s, rd, rs, TCG_REG_TMP0); + } + } +} + static void tcg_out_ext8u(TCGContext *s, TCGReg ret, TCGReg arg) { tcg_out_opc_andi(s, ret, arg, 0xff); @@ -1350,14 +1389,14 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, =20 case INDEX_op_add_i32: if (c2) { - tcg_out_opc_addi_w(s, a0, a1, a2); + tcg_out_addi(s, TCG_TYPE_I32, a0, a1, a2); } else { tcg_out_opc_add_w(s, a0, a1, a2); } break; case INDEX_op_add_i64: if (c2) { - tcg_out_opc_addi_d(s, a0, a1, a2); + tcg_out_addi(s, TCG_TYPE_I64, a0, a1, a2); } else { tcg_out_opc_add_d(s, a0, a1, a2); } @@ -1365,14 +1404,14 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, =20 case INDEX_op_sub_i32: if (c2) { - tcg_out_opc_addi_w(s, a0, a1, -a2); + tcg_out_addi(s, TCG_TYPE_I32, a0, a1, -a2); } else { tcg_out_opc_sub_w(s, a0, a1, a2); } break; case INDEX_op_sub_i64: if (c2) { - tcg_out_opc_addi_d(s, a0, a1, -a2); + tcg_out_addi(s, TCG_TYPE_I64, a0, a1, -a2); } else { tcg_out_opc_sub_d(s, a0, a1, a2); } @@ -1586,8 +1625,9 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpc= ode op) return C_O1_I2(r, r, ri); =20 case INDEX_op_add_i32: + return C_O1_I2(r, r, ri); case INDEX_op_add_i64: - return C_O1_I2(r, r, rI); + return C_O1_I2(r, r, rJ); =20 case INDEX_op_and_i32: case INDEX_op_and_i64: @@ -1616,8 +1656,9 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpc= ode op) return C_O1_I2(r, 0, rZ); =20 case INDEX_op_sub_i32: + return C_O1_I2(r, rZ, ri); case INDEX_op_sub_i64: - return C_O1_I2(r, rZ, rN); + return C_O1_I2(r, rZ, rJ); =20 case INDEX_op_mul_i32: case INDEX_op_mul_i64: --=20 2.34.1 From nobody Sun May 19 03:12:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1674004335; cv=none; d=zohomail.com; s=zohoarc; b=W4IDlircQeF/ga+cIe09y0DI7zAlb9ZBEaV27dFpvMaVApuXVqf9bKY+krkNacPlMB449+4uhU9ehwm7/khAWtepdItkeoDGNZjPYeCy0rE7fWCaXWIMnk1RcGZNIfU0QUvf4a5sBcasgC3xgDFbjXqI9vW51L3MrviDN3Mcuu4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674004335; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gExyabd9pGuUtJyQvwd0z6FyfSDRDLkdZQb2qbC5yco=; b=kdG8lH5Eg9FiZ+G84wmKoKUq1iIsMdjkchFqUJvBiLdJbaRRlnbeycBbSBGLH07GS+zvg6r97InFpm9hVfQCGkKkdZW99fD9FEXI7x4HCA7rimkqORY6qRWeHPtrU3RRiu4BsVLy347YYdZP7/RJ6wCCOf4uyMJmlJNaS7dx4xA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167400433598893.31347585130322; Tue, 17 Jan 2023 17:12:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzN-00024Z-OQ; Tue, 17 Jan 2023 20:11:41 -0500 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 1pHwzM-00023p-5s for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:40 -0500 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzK-0002FC-BA for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:39 -0500 Received: by mail-pj1-x1029.google.com with SMTP id y3-20020a17090a390300b00229add7bb36so653027pjb.4 for ; Tue, 17 Jan 2023 17:11:37 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gExyabd9pGuUtJyQvwd0z6FyfSDRDLkdZQb2qbC5yco=; b=xOeBK20givcp1kwuiZRvPzEWTDCETB5hhwsJntKrSPV+NF3LEHNArMoAzgj6UzWmVu 9hskHrQ7iTKnqw1Zu5Mswj1U4AkQBkKJxQobD0yFizVCF6n3Vy1rOHDscGhGd0ad2M0P R0kktujnZ6GCB5qxKU7poWcPKyiRYIpVCPmYEmYZzixpnjAFGTorD5Hzq9DZWpi/Onud nIi0ElXTpkFSuxbEfn8oO/Vr70ZcHAgXXF8GvC9pqJKjChx5FUfnhmEtKNunaiQNmt+L UmaVazj8OVxb5nIhbKa+YEgOi4HW1mBuUxKLUfIKMnm3ti1PH0Haz9L7c1nTov7ImtGv Ub9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gExyabd9pGuUtJyQvwd0z6FyfSDRDLkdZQb2qbC5yco=; b=3oFCGfeXONO1qxPp2xKVqjVlxNPMzdhrQH8hjYKfpF1QRI/8luhZowqH0j/tWaO5CE CGMtatsYzd+VYMlTedGBMCpGsWlddDdleLuIv+hyR5ro+kQpdfGx2MhldUf2OBU/heQN bp0jYp+Jcu7Gm4xsmF1qrcxVxSxH3jL2vpTjKgYchvEKJSyRJHXkVtLiQk+9Hj9yCcWj NbeLx9ZqF+sXH3tHNIbUJIYJuNVj1RtQR+kVYmHmygIqXSb83uOlIK5hEQ1zpd+/dC9k EmCBgC5jrd/fxV9USqwBEIrNE7nppNKPlj1IPlrWuhM6EFtfqn94YDHx8En46liwa4uQ l6HQ== X-Gm-Message-State: AFqh2kp8twRsuOA1cTkX6kdkV6ohDseKo5MLm4h3NHfE7E8F5tdur9jN toFmCk8l4igCXj9sueRqJK00aHA8e6EtRzGS X-Google-Smtp-Source: AMrXdXsSBbHOcXuR/1l3LMauAuRMjZ/1ZbtNWxq5uQNxnj+9q7bdrJrP5JQsBgyAhpjbgELfctErPA== X-Received: by 2002:a17:903:2289:b0:194:9290:fa6f with SMTP id b9-20020a170903228900b001949290fa6fmr7831031plh.25.1674004296913; Tue, 17 Jan 2023 17:11:36 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name Subject: [PATCH v2 07/10] tcg/loongarch64: Improve setcond expansion Date: Tue, 17 Jan 2023 15:11:20 -1000 Message-Id: <20230118011123.392823-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1674004337736100003 Content-Type: text/plain; charset="utf-8" Split out a helper function, tcg_out_setcond_int, which does not always produce the complete boolean result, but returns a set of flags to do so. Accept all int32_t as constant input, so that LE/GT can adjust the constant to LT. Signed-off-by: Richard Henderson Reviewed-by: WANG Xuerui --- tcg/loongarch64/tcg-target.c.inc | 165 +++++++++++++++++++++---------- 1 file changed, 115 insertions(+), 50 deletions(-) diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.= c.inc index 8cc6c5eec2..ccc1c0f392 100644 --- a/tcg/loongarch64/tcg-target.c.inc +++ b/tcg/loongarch64/tcg-target.c.inc @@ -469,64 +469,131 @@ static void tcg_out_clzctz(TCGContext *s, LoongArchI= nsn opc, tcg_out_opc_or(s, a0, TCG_REG_TMP0, a0); } =20 -static void tcg_out_setcond(TCGContext *s, TCGCond cond, TCGReg ret, - TCGReg arg1, TCGReg arg2, bool c2) -{ - TCGReg tmp; +#define SETCOND_INV TCG_TARGET_NB_REGS +#define SETCOND_NEZ (SETCOND_INV << 1) +#define SETCOND_FLAGS (SETCOND_INV | SETCOND_NEZ) =20 - if (c2) { - tcg_debug_assert(arg2 =3D=3D 0); +static int tcg_out_setcond_int(TCGContext *s, TCGCond cond, TCGReg ret, + TCGReg arg1, tcg_target_long arg2, bool c2) +{ + int flags =3D 0; + + switch (cond) { + case TCG_COND_EQ: /* -> NE */ + case TCG_COND_GE: /* -> LT */ + case TCG_COND_GEU: /* -> LTU */ + case TCG_COND_GT: /* -> LE */ + case TCG_COND_GTU: /* -> LEU */ + cond =3D tcg_invert_cond(cond); + flags ^=3D SETCOND_INV; + break; + default: + break; } =20 switch (cond) { - case TCG_COND_EQ: - if (c2) { - tmp =3D arg1; - } else { - tcg_out_opc_sub_d(s, ret, arg1, arg2); - tmp =3D ret; - } - tcg_out_opc_sltui(s, ret, tmp, 1); - break; - case TCG_COND_NE: - if (c2) { - tmp =3D arg1; - } else { - tcg_out_opc_sub_d(s, ret, arg1, arg2); - tmp =3D ret; - } - tcg_out_opc_sltu(s, ret, TCG_REG_ZERO, tmp); - break; - case TCG_COND_LT: - tcg_out_opc_slt(s, ret, arg1, arg2); - break; - case TCG_COND_GE: - tcg_out_opc_slt(s, ret, arg1, arg2); - tcg_out_opc_xori(s, ret, ret, 1); - break; case TCG_COND_LE: - tcg_out_setcond(s, TCG_COND_GE, ret, arg2, arg1, false); - break; - case TCG_COND_GT: - tcg_out_setcond(s, TCG_COND_LT, ret, arg2, arg1, false); - break; - case TCG_COND_LTU: - tcg_out_opc_sltu(s, ret, arg1, arg2); - break; - case TCG_COND_GEU: - tcg_out_opc_sltu(s, ret, arg1, arg2); - tcg_out_opc_xori(s, ret, ret, 1); - break; case TCG_COND_LEU: - tcg_out_setcond(s, TCG_COND_GEU, ret, arg2, arg1, false); + /* + * If we have a constant input, the most efficient way to implement + * LE is by adding 1 and using LT. Watch out for wrap around for = LEU. + * We don't need to care for this for LE because the constant input + * is still constrained to int32_t, and INT32_MAX+1 is representab= le + * in the 64-bit temporary register. + */ + if (c2) { + if (cond =3D=3D TCG_COND_LEU) { + /* unsigned <=3D -1 is true */ + if (arg2 =3D=3D -1) { + tcg_out_movi(s, TCG_TYPE_REG, ret, !(flags & SETCOND_I= NV)); + return ret; + } + cond =3D TCG_COND_LTU; + } else { + cond =3D TCG_COND_LT; + } + arg2 +=3D 1; + } else { + TCGReg tmp =3D arg2; + arg2 =3D arg1; + arg1 =3D tmp; + cond =3D tcg_swap_cond(cond); /* LE -> GE */ + cond =3D tcg_invert_cond(cond); /* GE -> LT */ + flags ^=3D SETCOND_INV; + } break; - case TCG_COND_GTU: - tcg_out_setcond(s, TCG_COND_LTU, ret, arg2, arg1, false); + default: break; + } + + switch (cond) { + case TCG_COND_NE: + flags |=3D SETCOND_NEZ; + if (!c2) { + tcg_out_opc_xor(s, ret, arg1, arg2); + } else if (arg2 =3D=3D 0) { + ret =3D arg1; + } else if (arg2 >=3D 0 && arg2 <=3D 0xfff) { + tcg_out_opc_xori(s, ret, arg1, arg2); + } else { + tcg_out_addi(s, TCG_TYPE_REG, ret, arg1, -arg2); + } + break; + + case TCG_COND_LT: + case TCG_COND_LTU: + if (c2) { + if (arg2 >=3D -0x800 && arg2 <=3D 0x7ff) { + if (cond =3D=3D TCG_COND_LT) { + tcg_out_opc_slti(s, ret, arg1, arg2); + } else { + tcg_out_opc_sltui(s, ret, arg1, arg2); + } + break; + } + tcg_out_movi(s, TCG_TYPE_REG, TCG_REG_TMP0, arg2); + arg2 =3D TCG_REG_TMP0; + } + if (cond =3D=3D TCG_COND_LT) { + tcg_out_opc_slt(s, ret, arg1, arg2); + } else { + tcg_out_opc_sltu(s, ret, arg1, arg2); + } + break; + default: g_assert_not_reached(); break; } + + return ret | flags; +} + +static void tcg_out_setcond(TCGContext *s, TCGCond cond, TCGReg ret, + TCGReg arg1, tcg_target_long arg2, bool c2) +{ + int tmpflags =3D tcg_out_setcond_int(s, cond, ret, arg1, arg2, c2); + + if (tmpflags !=3D ret) { + TCGReg tmp =3D tmpflags & ~SETCOND_FLAGS; + + switch (tmpflags & SETCOND_FLAGS) { + case SETCOND_INV: + /* Intermediate result is boolean: simply invert. */ + tcg_out_opc_xori(s, ret, tmp, 1); + break; + case SETCOND_NEZ: + /* Intermediate result is zero/non-zero: test !=3D 0. */ + tcg_out_opc_sltu(s, ret, TCG_REG_ZERO, tmp); + break; + case SETCOND_NEZ | SETCOND_INV: + /* Intermediate result is zero/non-zero: test =3D=3D 0. */ + tcg_out_opc_sltui(s, ret, tmp, 1); + break; + default: + g_assert_not_reached(); + } + } } =20 /* @@ -1646,18 +1713,16 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGO= pcode op) case INDEX_op_ctz_i64: return C_O1_I2(r, r, rW); =20 - case INDEX_op_setcond_i32: - case INDEX_op_setcond_i64: - return C_O1_I2(r, r, rZ); - case INDEX_op_deposit_i32: case INDEX_op_deposit_i64: /* Must deposit into the same register as input */ return C_O1_I2(r, 0, rZ); =20 case INDEX_op_sub_i32: + case INDEX_op_setcond_i32: return C_O1_I2(r, rZ, ri); case INDEX_op_sub_i64: + case INDEX_op_setcond_i64: return C_O1_I2(r, rZ, rJ); =20 case INDEX_op_mul_i32: --=20 2.34.1 From nobody Sun May 19 03:12:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1674004357; cv=none; d=zohomail.com; s=zohoarc; b=TJrI35AWO5ziJvi7gPu5HFpLvgi7Ey+CREASQKn9E6UM/RgVbfy3kWpqGbc6RzFOU/Aa8EpC3nbwQccYim+yEx9GrqloF5CbvKDbVaXNLbGAEWQqwhYCn5I+FTgBpIos2QFCaDhvJAxa/Cg7Fjxmj8S8992Z2o7W8psdA5Wx5WQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674004357; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=di6N0vCGrpxWgO4hD16WY7qQUgaqSSofB9q2lj/lJG4=; b=W3R9vzz5ZFf0vJvcuX3fU/UFyvTbZgNrVANCbbsGq0gUD0bzG8WD9R9mP7vRMi/6/sjhBZTOydLjWJMmKubONiCg2/4VqjjQHCTZ7R8fupc/gaAyNC6Bo/XGcby0CM6fPltMgoaXAY2V9qyLCOlOe9ffGX7MFTVJT443IgOf9Dg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674004357020906.7588106393698; Tue, 17 Jan 2023 17:12:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzO-00027F-Ga; Tue, 17 Jan 2023 20:11:42 -0500 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 1pHwzN-00024S-DH for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:41 -0500 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzL-0002FV-Nk for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:41 -0500 Received: by mail-pj1-x102e.google.com with SMTP id gz9-20020a17090b0ec900b002290bda1b07so635809pjb.1 for ; Tue, 17 Jan 2023 17:11:39 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=di6N0vCGrpxWgO4hD16WY7qQUgaqSSofB9q2lj/lJG4=; b=tmIYp5OIpIWHVYofD6pgKSZYCAKeY0nUi6RiH0NXATZfGILkug6rO0X2feiuT4386p ZYA7Sevznhv2b4ie8X2Y0VJXHO3R8VR1TfL0hyYK9k82XsEX1Ttn5JDk/483sdDx9Lx+ 3cNHH7ko7eODorOl1Lx2onFdBUyRHi0SP+xqKVl/oZIhZH7nUhOM2vOcAZZrdZijBfPe 9SIW3wiyPQFypdU9/CmxMT7p/fB8aMYauqAGZCzW62+0hxJyOCZEfQayl9MQxOvtpObs cNn9My7H1INYU2yoPWObXchjO1yUzelQ+xSoogqxuQzs+k95ZeTwpa1uNiguqamq3sv3 w7UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=di6N0vCGrpxWgO4hD16WY7qQUgaqSSofB9q2lj/lJG4=; b=MUF9l4nX9E6Q8hYAXGci4p0Nkd8LF9c88TePJGrsw1z5MReqHInkSPCTQPVywAEig5 CitNRcFF1LziHizhjY9IonE6FsMO98tx7bIGyB9VhgT0QQDaWSVTT31z3wK75boOX+eb p1ywCsippGk5zw40AI+Xkc4tpow3ezxs+lXQn6I2qS6ysjkV9m0zJnviKZ6pJWg/w+FV 2rbjiuPoH/CFX+paVfRUvw1XoilRXG8dO8rY5Ulty18zRSLKqHtapNaA4gkpQujl30Gb +rvloz3Ffof2Aft+VnU8Hmvdn2X3hcD9DNKo7+oiKoGjZGyAb9hryD+pslsTcFaSFb2N 8u7g== X-Gm-Message-State: AFqh2kpmghJNopKW66i/PDEOIY2LZ9mrB4LVpX3zThVF0aR3ERktxg/5 JR+d4N/dBsVBkILhhv89zW3GGZprC4GXPGdu X-Google-Smtp-Source: AMrXdXvLR2r3HUgS/86yMnv9PO9+XmOSL6BywJB7rMXlL8acZMCM6iQqn0F6Vqeusag5yG3jwq3ouQ== X-Received: by 2002:a17:902:c1d2:b0:194:7400:7c14 with SMTP id c18-20020a170902c1d200b0019474007c14mr5792877plc.34.1674004298492; Tue, 17 Jan 2023 17:11:38 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name Subject: [PATCH v2 08/10] tcg/loongarch64: Implement movcond Date: Tue, 17 Jan 2023 15:11:21 -1000 Message-Id: <20230118011123.392823-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1674004357856100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson Reviewed-by: WANG Xuerui --- tcg/loongarch64/tcg-target-con-set.h | 1 + tcg/loongarch64/tcg-target.h | 4 ++-- tcg/loongarch64/tcg-target.c.inc | 33 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/tcg/loongarch64/tcg-target-con-set.h b/tcg/loongarch64/tcg-tar= get-con-set.h index 7b5a7a3f5d..172c107289 100644 --- a/tcg/loongarch64/tcg-target-con-set.h +++ b/tcg/loongarch64/tcg-target-con-set.h @@ -31,3 +31,4 @@ C_O1_I2(r, 0, rZ) C_O1_I2(r, rZ, ri) C_O1_I2(r, rZ, rJ) C_O1_I2(r, rZ, rZ) +C_O1_I4(r, rZ, rJ, rZ, rZ) diff --git a/tcg/loongarch64/tcg-target.h b/tcg/loongarch64/tcg-target.h index 1c3e48d662..533a539ce9 100644 --- a/tcg/loongarch64/tcg-target.h +++ b/tcg/loongarch64/tcg-target.h @@ -97,7 +97,7 @@ typedef enum { #define TCG_TARGET_CALL_ARG_I64 TCG_CALL_ARG_NORMAL =20 /* optional instructions */ -#define TCG_TARGET_HAS_movcond_i32 0 +#define TCG_TARGET_HAS_movcond_i32 1 #define TCG_TARGET_HAS_div_i32 1 #define TCG_TARGET_HAS_rem_i32 1 #define TCG_TARGET_HAS_div2_i32 0 @@ -133,7 +133,7 @@ typedef enum { #define TCG_TARGET_HAS_qemu_st8_i32 0 =20 /* 64-bit operations */ -#define TCG_TARGET_HAS_movcond_i64 0 +#define TCG_TARGET_HAS_movcond_i64 1 #define TCG_TARGET_HAS_div_i64 1 #define TCG_TARGET_HAS_rem_i64 1 #define TCG_TARGET_HAS_div2_i64 0 diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.= c.inc index ccc1c0f392..29d75c80eb 100644 --- a/tcg/loongarch64/tcg-target.c.inc +++ b/tcg/loongarch64/tcg-target.c.inc @@ -596,6 +596,30 @@ static void tcg_out_setcond(TCGContext *s, TCGCond con= d, TCGReg ret, } } =20 +static void tcg_out_movcond(TCGContext *s, TCGCond cond, TCGReg ret, + TCGReg c1, tcg_target_long c2, bool const2, + TCGReg v1, TCGReg v2) +{ + int tmpflags =3D tcg_out_setcond_int(s, cond, TCG_REG_TMP0, c1, c2, co= nst2); + TCGReg t; + + /* Standardize the test below to t !=3D 0. */ + if (tmpflags & SETCOND_INV) { + t =3D v1, v1 =3D v2, v2 =3D t; + } + + t =3D tmpflags & ~SETCOND_FLAGS; + if (v1 =3D=3D TCG_REG_ZERO) { + tcg_out_opc_masknez(s, ret, v2, t); + } else if (v2 =3D=3D TCG_REG_ZERO) { + tcg_out_opc_maskeqz(s, ret, v1, t); + } else { + tcg_out_opc_masknez(s, TCG_REG_TMP2, v2, t); /* t ? 0 : v2 */ + tcg_out_opc_maskeqz(s, TCG_REG_TMP1, v1, t); /* t ? v1 : 0 */ + tcg_out_opc_or(s, ret, TCG_REG_TMP1, TCG_REG_TMP2); + } +} + /* * Branch helpers */ @@ -1538,6 +1562,11 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, tcg_out_setcond(s, args[3], a0, a1, a2, c2); break; =20 + case INDEX_op_movcond_i32: + case INDEX_op_movcond_i64: + tcg_out_movcond(s, args[5], a0, a1, a2, c2, args[3], args[4]); + break; + case INDEX_op_ld8s_i32: case INDEX_op_ld8s_i64: tcg_out_ldst(s, OPC_LD_B, a0, a1, a2); @@ -1741,6 +1770,10 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOp= code op) case INDEX_op_remu_i64: return C_O1_I2(r, rZ, rZ); =20 + case INDEX_op_movcond_i32: + case INDEX_op_movcond_i64: + return C_O1_I4(r, rZ, rJ, rZ, rZ); + default: g_assert_not_reached(); } --=20 2.34.1 From nobody Sun May 19 03:12:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1674004395; cv=none; d=zohomail.com; s=zohoarc; b=Bv9Jd1Aqjz+hFpNcCrTSyUsRVADl8/0E7kW1IJckncPZeVQItUZiApnQ1l6yNUw/7VZaAhmbt+szOMN8625DO1kPcY7lYHR4ki43oNUiNRmLOexI/Y4YO3OHOGncXgt0bKd5a4WEvBcAJQys9LB+6gPN5vBtIsHwKWf0mAZRMu0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674004395; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oe653jAwb+trclLqO5xizolsekcbMLByW/eiNLY2YMk=; b=IoS8hSP+koJ4RdTjY0G8tIp79lu1OiW9LHcXUJGqg3HgPqOVvyvXRF38Xl9edJsXIjRZVAXuSi8nWe1ui26/cbcFmiDm20sdoXG5qepF5see+Xjv1lM2d19tM3DbonFKW/Ttwu8EGtIM+ZSW8w5OAtXCoAvbkzwJL3kLzomd7z0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167400439596544.208565005609216; Tue, 17 Jan 2023 17:13:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzR-0002BN-Fn; Tue, 17 Jan 2023 20:11:45 -0500 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 1pHwzP-00028I-14 for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:43 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzN-0002Fl-B4 for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:42 -0500 Received: by mail-pl1-x630.google.com with SMTP id r21so3249119plg.13 for ; Tue, 17 Jan 2023 17:11:40 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oe653jAwb+trclLqO5xizolsekcbMLByW/eiNLY2YMk=; b=T8Ni+FSxd8awv/RgOySrM1axkRtVYW3VxzPhJ6km9unzqRLP1T/q8JqS7I19wG+r0Q zZe92g1lSnpPjTREUrx5g+azQXSZVBHVXgoMMlCAmtn2P5I1HycPvTBEXASuIQFBWou8 BTSRaFENSLVADRfZleKt1kNsKkRXzKrki+ZIuq9yv88OvEvGBx0brYPEy8ctHKJvC9Vh d8vz9sSS1NEWw40xk5ofZN1Q8jrdbc5JWL2AL52I2ai6fBnkAs6l1dpC3dIcQdR/JfT+ /lxiB1bVwH9e00DLDYXyHuZ0QUYwWdQZZP/ynRRC9bXAV7+dn0MwqDYVwbb7sh4UVAmQ iKAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oe653jAwb+trclLqO5xizolsekcbMLByW/eiNLY2YMk=; b=dfOcnMRGq5ilMBk2pgDzFD824riwxizanvNiszXd2IXasyl2IsWOoXbhdQbSDbpJ1j MJ73pdG+VobxDaL6btGJlKVn3bLZ2biXxIXNdxtqqUsYoRnf0eKyYzG5peqoCb0q7Oyh QF4CV12nlbEQhHMYZKki17g7J49az/hoyuEsfCbo5LuQt3UpjZzOb0axBfZw57QRvg87 9A0N9VBcEQKutVpdhMQTximCyC2236jxjwA5X798P5m5o09v72iL4OdS2Lfhn//C75M6 VSooa+YlHO/rj82eIEtXcz2sHIH/jKH7XGAeAQz2y+ae9z3h1/NdhPmzCh1NSUOrTlwp 4xxA== X-Gm-Message-State: AFqh2kpZB2zNHDpS2cvx/9rMiEasRLT0O5jk3UlOQjeZ1cl3csUBF30P Xxe/Eo20bD06iIzASfGpdFLKwLQqG8DOcxq3 X-Google-Smtp-Source: AMrXdXu8NplU1Zwdp7oWRetMHiJDzISRFw36JSJChB7CYfqRB7yAZx93Yxw5OpiCFv86X1ouL78y2w== X-Received: by 2002:a17:902:ab94:b0:194:62d9:9a86 with SMTP id f20-20020a170902ab9400b0019462d99a86mr5490670plr.59.1674004299900; Tue, 17 Jan 2023 17:11:39 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name Subject: [PATCH v2 09/10] tcg/loongarch64: Use tcg_pcrel_diff in tcg_out_ldst Date: Tue, 17 Jan 2023 15:11:22 -1000 Message-Id: <20230118011123.392823-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1674004397996100001 Content-Type: text/plain; charset="utf-8" Take the w^x split into account when computing the pc-relative distance to an absolute pointer. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: WANG Xuerui --- tcg/loongarch64/tcg-target.c.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.= c.inc index 29d75c80eb..d6926bdb83 100644 --- a/tcg/loongarch64/tcg-target.c.inc +++ b/tcg/loongarch64/tcg-target.c.inc @@ -702,7 +702,7 @@ static void tcg_out_ldst(TCGContext *s, LoongArchInsn o= pc, TCGReg data, intptr_t imm12 =3D sextreg(offset, 0, 12); =20 if (offset !=3D imm12) { - intptr_t diff =3D offset - (uintptr_t)s->code_ptr; + intptr_t diff =3D tcg_pcrel_diff(s, (void *)offset); =20 if (addr =3D=3D TCG_REG_ZERO && diff =3D=3D (int32_t)diff) { imm12 =3D sextreg(diff, 0, 12); --=20 2.34.1 From nobody Sun May 19 03:12:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1674004350; cv=none; d=zohomail.com; s=zohoarc; b=YOt+IdEVqh3jwUBQW/AcKQTC9HeM/2sUqsaI8G+MJ90BuLltJM56wmF4qQGEug0Qv7HTB75JT7BDlEN7JOvRoEu1O7sX8d/BrXu5wV7RT3RJt+lSoiy0gE9KPsMkJQhSN3JuMqCFnNPwdYpXiMnC6e8Ex82o2vXUqUWolJbqNz0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674004350; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ytAJL1IPjLRLHB3vJNA4P2zaPkmMQ8wgfVfWBQ9Mma4=; b=CXSDUlv0K/n5ZaE1IYyc6UAo3p1wy4EgxRZYfV6vlyOpB3pQHCN2MBBBnIY13bi/S/yMBP+FC48QHttPRQQ+4aoF+LlWPtpv9Mos9w/lGD0LVUeczLhTWCSHif7SPXdQ3e4BxYijXL2y0+HRudhGp536P0r+V0RgoZej3DA2qCI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16740043509521008.7900847597614; Tue, 17 Jan 2023 17:12:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHwzS-0002BP-17; Tue, 17 Jan 2023 20:11:46 -0500 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 1pHwzQ-0002Au-H2 for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:44 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHwzO-0002Fv-OK for qemu-devel@nongnu.org; Tue, 17 Jan 2023 20:11:44 -0500 Received: by mail-pl1-x631.google.com with SMTP id d9so35315880pll.9 for ; Tue, 17 Jan 2023 17:11:42 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id s7-20020a170902988700b0017ec1b1bf9fsm21660259plp.217.2023.01.17.17.11.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 17:11:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ytAJL1IPjLRLHB3vJNA4P2zaPkmMQ8wgfVfWBQ9Mma4=; b=KOb1kpEm2GplxDBXYq6B8uP0gY1w0nXw/C6X3A9FUahCjK0YPyRuq7C997NyJJGOxi xMKOmWfsOCdSWAW8uxCD16zHsCG1AlGEPHW1nV3H5EBAE8f0ZQlGLfEiVcBJTvknPzPp wT4oOXlHY+H8JiJtGbio9nAZA45/IGJizrSCQz5cSHMmy+os+WYptacIii7IdQ2PEbpR VkaitHwz6pJhj1IahiHjyKBQAL45ZPCpKk0/xAcD3TbZU1smDFBbXsNxQaIAtTp7sIm1 JivnqvvkN9+dU7/tpygJIIowZUXiy7dWX7N/87k/w+D/n9BrBMk8kpt4BYE1B0MKS90O A34w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ytAJL1IPjLRLHB3vJNA4P2zaPkmMQ8wgfVfWBQ9Mma4=; b=WKErP0sH/p7pZzWtzlx1I98XUny0rbKbFwtqowWpGbqQ90dXySBEgBLqAzrw01ichb PlyKcmo/a6vaAij7tgjomBXhg63n6GFtIwEJC1rUSxBYaIkP57T/zVy8jQZcmC+StZlz UWCUeQJ8TZmUPaQ5HNvXFtOM3kd56eK0WzaTn6/Y/bMgZ25TpaQ3/gRRbUty3VLXkL/N Zk4fRH+w3Ran+cgqSq/z/xLA4OWZ33FIO13eCdqnWmj05qmfMYu15891pde5itPSFnTl Fbl36og+wree40Yio2Gwd1BxsSamCs4/5Gx4PxnxgQdB49NL6whbxAYPcxozpQzEAb92 CDXQ== X-Gm-Message-State: AFqh2krCO+vZ+lrWFvfLbhHflhJ9+fKjN+7wTcJpud7aPpFjd37syAax fUCIAhhdi3AXox1s+lhNmNbvvAkWHW39aVhq X-Google-Smtp-Source: AMrXdXvTrxyU+8UT+7Pl2km3nD4CKRW1BXXrAXDSYjhiZMtRqkrg+toYqYWlP6yfJGPi4fz3sdYsHw== X-Received: by 2002:a17:902:c409:b0:194:a854:6274 with SMTP id k9-20020a170902c40900b00194a8546274mr5761898plk.60.1674004301194; Tue, 17 Jan 2023 17:11:41 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name Subject: [PATCH v2 10/10] tcg/loongarch64: Reorg goto_tb implementation Date: Tue, 17 Jan 2023 15:11:23 -1000 Message-Id: <20230118011123.392823-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230118011123.392823-1-richard.henderson@linaro.org> References: <20230118011123.392823-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1674004351806100003 Content-Type: text/plain; charset="utf-8" The old implementation replaces two insns, swapping between b nop and pcaddu18i tmp, jirl zero, tmp, & 0xffff There is a race condition in which a thread could be stopped at the jirl, i.e. with the top of the address loaded, and when restarted we have re-linked to a different TB, so that the top half no longer matches the bottom half. Note that while we never directly re-link to a different TB, we can link, unlink, and link again all while the stopped thread remains stopped. The new implementation replaces only one insn, swapping between b and pcadd tmp, falling through to load the address from tmp, and branch. Signed-off-by: Richard Henderson Reviewed-by: WANG Xuerui --- tcg/loongarch64/tcg-target.h | 7 +--- tcg/loongarch64/tcg-target.c.inc | 72 ++++++++++++++------------------ 2 files changed, 33 insertions(+), 46 deletions(-) diff --git a/tcg/loongarch64/tcg-target.h b/tcg/loongarch64/tcg-target.h index 533a539ce9..8b151e7f6f 100644 --- a/tcg/loongarch64/tcg-target.h +++ b/tcg/loongarch64/tcg-target.h @@ -42,11 +42,8 @@ =20 #define TCG_TARGET_INSN_UNIT_SIZE 4 #define TCG_TARGET_NB_REGS 32 -/* - * PCADDU18I + JIRL sequence can give 20 + 16 + 2 =3D 38 bits - * signed offset, which is +/- 128 GiB. - */ -#define MAX_CODE_GEN_BUFFER_SIZE (128 * GiB) + +#define MAX_CODE_GEN_BUFFER_SIZE ((size_t)-1) =20 typedef enum { TCG_REG_ZERO, diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.= c.inc index d6926bdb83..ce4a153887 100644 --- a/tcg/loongarch64/tcg-target.c.inc +++ b/tcg/loongarch64/tcg-target.c.inc @@ -1151,37 +1151,6 @@ static void tcg_out_qemu_st(TCGContext *s, const TCG= Arg *args) #endif } =20 -/* LoongArch uses `andi zero, zero, 0` as NOP. */ -#define NOP OPC_ANDI -static void tcg_out_nop(TCGContext *s) -{ - tcg_out32(s, NOP); -} - -void tb_target_set_jmp_target(const TranslationBlock *tb, int n, - uintptr_t jmp_rx, uintptr_t jmp_rw) -{ - tcg_insn_unit i1, i2; - ptrdiff_t upper, lower; - uintptr_t addr =3D tb->jmp_target_addr[n]; - ptrdiff_t offset =3D (ptrdiff_t)(addr - jmp_rx) >> 2; - - if (offset =3D=3D sextreg(offset, 0, 26)) { - i1 =3D encode_sd10k16_insn(OPC_B, offset); - i2 =3D NOP; - } else { - tcg_debug_assert(offset =3D=3D sextreg(offset, 0, 36)); - lower =3D (int16_t)offset; - upper =3D (offset - lower) >> 16; - - i1 =3D encode_dsj20_insn(OPC_PCADDU18I, TCG_REG_TMP0, upper); - i2 =3D encode_djsk16_insn(OPC_JIRL, TCG_REG_ZERO, TCG_REG_TMP0, lo= wer); - } - uint64_t pair =3D ((uint64_t)i2 << 32) | i1; - qatomic_set((uint64_t *)jmp_rw, pair); - flush_idcache_range(jmp_rx, jmp_rw, 8); -} - /* * Entry-points */ @@ -1202,22 +1171,43 @@ static void tcg_out_exit_tb(TCGContext *s, uintptr_= t a0) static void tcg_out_goto_tb(TCGContext *s, int which) { /* - * Ensure that patch area is 8-byte aligned so that an - * atomic write can be used to patch the target address. + * Direct branch, or load indirect address, to be patched + * by tb_target_set_jmp_target. Check indirect load offset + * in range early, regardless of direct branch distance, + * via assert within tcg_out_opc_pcaddu2i. */ - if ((uintptr_t)s->code_ptr & 7) { - tcg_out_nop(s); - } + uintptr_t i_addr =3D get_jmp_target_addr(s, which); + intptr_t i_disp =3D tcg_pcrel_diff(s, (void *)i_addr); + set_jmp_insn_offset(s, which); - /* - * actual branch destination will be patched by - * tb_target_set_jmp_target later - */ - tcg_out_opc_pcaddu18i(s, TCG_REG_TMP0, 0); + tcg_out_opc_pcaddu2i(s, TCG_REG_TMP0, i_disp >> 2); + + /* Finish the load and indirect branch. */ + tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_TMP0, TCG_REG_TMP0, 0); tcg_out_opc_jirl(s, TCG_REG_ZERO, TCG_REG_TMP0, 0); set_jmp_reset_offset(s, which); } =20 +void tb_target_set_jmp_target(const TranslationBlock *tb, int n, + uintptr_t jmp_rx, uintptr_t jmp_rw) +{ + uintptr_t d_addr =3D tb->jmp_target_addr[n]; + ptrdiff_t d_disp =3D (ptrdiff_t)(d_addr - jmp_rx) >> 2; + tcg_insn_unit insn; + + /* Either directly branch, or load slot address for indirect branch. */ + if (d_disp =3D=3D sextreg(d_disp, 0, 26)) { + insn =3D encode_sd10k16_insn(OPC_B, d_disp); + } else { + uintptr_t i_addr =3D (uintptr_t)&tb->jmp_target_addr[n]; + intptr_t i_disp =3D i_addr - jmp_rx; + insn =3D encode_dsj20_insn(OPC_PCADDU2I, TCG_REG_TMP0, i_disp >> 2= ); + } + + qatomic_set((tcg_insn_unit *)jmp_rw, insn); + flush_idcache_range(jmp_rx, jmp_rw, 4); +} + static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg args[TCG_MAX_OP_ARGS], const int const_args[TCG_MAX_OP_ARGS]) --=20 2.34.1