From nobody Tue Dec 16 03:25:46 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632416940498224.66563690227144; Thu, 23 Sep 2021 10:09:00 -0700 (PDT) Received: from localhost ([::1]:36204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mTSDT-0002uk-Fn for importer@patchew.org; Thu, 23 Sep 2021 13:08:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTS59-0005nF-39 for qemu-devel@nongnu.org; Thu, 23 Sep 2021 13:00:23 -0400 Received: from [115.28.160.31] (port=54372 helo=mailbox.box.xen0n.name) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTS57-0005Tu-1H for qemu-devel@nongnu.org; Thu, 23 Sep 2021 13:00:22 -0400 Received: from ld50.lan (unknown [101.88.29.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by mailbox.box.xen0n.name (Postfix) with ESMTPSA id AD1FB60AF5; Fri, 24 Sep 2021 01:00:17 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=xen0n.name; s=mail; t=1632416417; bh=WeVd1O7SqVii76mgKhgAHLKjKU0Q9HApYewH7kIhhjg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TPB0GqYXYnYNMb9N92KrBwVlEs9rm1Vr4Z+512mXCJ8XBvky7b+pEhBK1+AAIIPgX t4ohgZpfoeu47X2dJd9wt3nUjDOUJKBJ5pd1C9Fedb/1uH+5q5Stkh6wl1ukPR8IOw mak1onP/daoo1cq+fp5BDplOkIOKgGcA41Gnmpx0= From: WANG Xuerui To: qemu-devel@nongnu.org Subject: [PATCH v4 09/30] tcg/loongarch64: Implement tcg_out_mov and tcg_out_movi Date: Fri, 24 Sep 2021 00:59:18 +0800 Message-Id: <20210923165939.729081-10-git@xen0n.name> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210923165939.729081-1-git@xen0n.name> References: <20210923165939.729081-1-git@xen0n.name> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 115.28.160.31 (failed) 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=115.28.160.31; envelope-from=git@xen0n.name; helo=mailbox.box.xen0n.name X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: WANG Xuerui , Peter Maydell , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632416941579100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: WANG Xuerui Reviewed-by: Richard Henderson --- tcg/loongarch64/tcg-target.c.inc | 111 +++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.= c.inc index 8f7c556c37..afaed5017a 100644 --- a/tcg/loongarch64/tcg-target.c.inc +++ b/tcg/loongarch64/tcg-target.c.inc @@ -247,6 +247,115 @@ static void tcg_out_mb(TCGContext *s, TCGArg a0) tcg_out_opc_dbar(s, 0); } =20 +static bool tcg_out_mov(TCGContext *s, TCGType type, TCGReg ret, TCGReg ar= g) +{ + if (ret =3D=3D arg) { + return true; + } + switch (type) { + case TCG_TYPE_I32: + case TCG_TYPE_I64: + /* + * Conventional register-register move used in LoongArch is + * `or dst, src, zero`. + */ + tcg_out_opc_or(s, ret, arg, TCG_REG_ZERO); + break; + default: + g_assert_not_reached(); + } + return true; +} + +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; + } +} + +static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd, + tcg_target_long val) +{ + if (type =3D=3D TCG_TYPE_I32) { + val =3D (int32_t)val; + } + + /* Single-instruction cases. */ + tcg_target_long low =3D sextreg(val, 0, 12); + if (low =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) { + /* val fits in uimm12: ori rd, zero, val */ + tcg_out_opc_ori(s, rd, TCG_REG_ZERO, val); + return; + } + + /* Test for PC-relative values that can be loaded faster. */ + intptr_t pc_offset =3D tcg_pcrel_diff(s, (void *)val); + if (pc_offset =3D=3D sextreg(pc_offset, 0, 22) && (pc_offset & 3) =3D= =3D 0) { + tcg_out_opc_pcaddu2i(s, rd, pc_offset >> 2); + return; + } + + if (pc_offset =3D=3D (int32_t)pc_offset) { + /* Load using pcalau12i + ori. */ + tcg_target_long pc_hi =3D (val - pc_offset) >> 12; + tcg_target_long val_hi =3D val >> 12; + tcg_target_long offset_hi =3D val_hi - pc_hi; + tcg_debug_assert(offset_hi =3D=3D sextreg(offset_hi, 0, 20)); + tcg_out_opc_pcalau12i(s, rd, offset_hi); + if (low !=3D 0) { + tcg_out_opc_ori(s, rd, rd, low & 0xfff); + } + return; + } + + /* + * Slow path: at most lu12i.w + ori + cu32i.d + cu52i.d. + * + * Chop upper bits into 3 immediate-field-sized segments respectively. + */ + tcg_target_long upper =3D sextreg(val, 12, 20); + tcg_target_long higher =3D sextreg(val, 32, 20); + tcg_target_long top =3D sextreg(val, 52, 12); + bool rd_written =3D false; + bool rd_high_bits_are_ones =3D false; + + if (upper !=3D 0) { + tcg_out_opc_lu12i_w(s, rd, upper); + rd_written =3D true; + rd_high_bits_are_ones =3D upper < 0; + } + if (low !=3D 0) { + tcg_out_opc_ori(s, rd, rd_written ? rd : TCG_REG_ZERO, low & 0xfff= ); + rd_written =3D true; + } + + if (imm_part_needs_loading(rd_high_bits_are_ones, higher)) { + if (!rd_written) { + /* + * cu32i.d only has 1 input register, yet rd is still untouched + * by now. We must zero it here. + */ + tcg_out_opc_or(s, rd, TCG_REG_ZERO, TCG_REG_ZERO); + } + tcg_out_opc_cu32i_d(s, rd, higher); + rd_written =3D true; + rd_high_bits_are_ones =3D higher < 0; + } + + if (imm_part_needs_loading(rd_high_bits_are_ones, top)) { + tcg_out_opc_cu52i_d(s, rd, rd_written ? rd : TCG_REG_ZERO, top); + } +} + /* * Entry-points */ @@ -262,6 +371,8 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, tcg_out_mb(s, a0); break; =20 + case INDEX_op_mov_i32: /* Always emitted via tcg_out_mov. */ + case INDEX_op_mov_i64: default: g_assert_not_reached(); } --=20 2.33.0