From nobody Sun Apr 13 19:14:31 2025 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=1685038315; cv=none; d=zohomail.com; s=zohoarc; b=n0OiSIUbq/yMDp4sB+P6NNitFRLDWe60SewJPa0G8CtdDHz+IurGt+xup78Ekn4VlNSNX0k0ITzxYit6dvmsu83/m4UCaQSzdmOVvra1bZO5xnXBMa/XUFidVlTRdN25+RyKdgj3YsVxg0rrBjMEHp+ChVTnbgiQ717/DIhXyeI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685038315; h=Content-Transfer-Encoding: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=mZHgKT7Em8u8wS7a0495i+fKR6g+xWDjFn9ZPfkhSxA=; b=DHxVY70NY3Ya3smk7NEd1m9BC967EHKQ5hhxNS6ri88QzhdqI8N76XAYdY51oxPu2bX7KmDtBYpSVd+rWDqFevstV23cacQuRSz4RXhy7+Yu63objuI+VO9ghzMbsKLl3bYRYSrmg58HlkYbT6ErOgFOeDsDQt4Jzk9eqfusmm8= 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 1685038315482350.9252059767797; Thu, 25 May 2023 11:11:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q2FQJ-0008Pk-Ak; Thu, 25 May 2023 14:10:51 -0400 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 1q2FQH-0008OF-5s for qemu-devel@nongnu.org; Thu, 25 May 2023 14:10:49 -0400 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 1q2FQF-0005tc-FD for qemu-devel@nongnu.org; Thu, 25 May 2023 14:10:48 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1ae50da739dso12485065ad.1 for ; Thu, 25 May 2023 11:10:47 -0700 (PDT) Received: from stoup.. ([2602:ae:1598:4c01:7ac5:31cc:3997:3a16]) by smtp.gmail.com with ESMTPSA id m18-20020a170902db1200b001aae64e9b36sm1710243plx.114.2023.05.25.11.10.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 11:10:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1685038246; x=1687630246; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=mZHgKT7Em8u8wS7a0495i+fKR6g+xWDjFn9ZPfkhSxA=; b=s4XaNTJwR0n5IbxiEU2xtRRiRkxnVsEhcAjYn8e1ErdXp1uz+5W/+Zct37NM8sfyid BKaQDPsJ83PB6wds6lup0ufYwSwgaUHzCq9GVKGEEjTLzk+bXHeHaEB6kYzoqwPdqN5s QpMQR9jzrX0arnPv4ozqCfMSO9ac/1ehevCdsP2D6LaDGNyc3mugG3BZKtgZzTCXcSFI fYEP2IPofdqDjYzDFYtGTZfqk+xiKZp+WDADu7VyfVprwRijzQMvru80NMQq5qsv9AuB 7nJkItV9Bw8vQ2DIDecc94jYVIQLpl62Ik3jeHJOR1+8ilM5KhM4SM8qW5bwzkrw4S7M LF3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685038246; x=1687630246; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mZHgKT7Em8u8wS7a0495i+fKR6g+xWDjFn9ZPfkhSxA=; b=Ulhxk9Yfx4CO/SiwZoIsJzKtIxxIa1D/5EjXfYrSSaDhMFlv3jJAFKfJlctpE2fdlM 0I50fqTYkuz9iZQChQUYro0ksZIRTuzrQbXtEK49UMvP0hBf9P4sm3lGQpBMYS/7ePre +g12XZAvGKDmSm0PtvkYSTHpbCGJWijiudLBa0uAvm+TfdusrM0tIrq3qWBhkHAymop2 jp5wQ6Tzt1Z8zOa4xRMOzWGZ8VE6qHG9SX7t0BGhtuvp9DjAu2XjzrPieCAE1eqf084r tkAEQuYRUWbwQuFua8mDzLdLWb483YqNDYA0jtWJlm86anDgGnN+lVeMl4+oVmV3tp4W HfPw== X-Gm-Message-State: AC+VfDzoRHKlP8F0ESKGBQIsjA7MZDYHpSkzD39GvSr35Cj1W0fySxje S54Xef5SuRTqSKLc9STIfNRhr3XHuRB2iq0+1PA= X-Google-Smtp-Source: ACHHUZ6426yrE36gFbgY4mDTXcAMug5pmPd6raEWTztKEcOUXEKSdQ4OT+zFhbXnLk3EdNeeHoiHkg== X-Received: by 2002:a17:902:d4ca:b0:1b0:440:7f5f with SMTP id o10-20020a170902d4ca00b001b004407f5fmr1305295plg.49.1685038246220; Thu, 25 May 2023 11:10:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 10/23] tcg/mips: Try three insns with shift and add in tcg_out_movi Date: Thu, 25 May 2023 11:10:23 -0700 Message-Id: <20230525181036.1559435-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230525181036.1559435-1-richard.henderson@linaro.org> References: <20230525181036.1559435-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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1685038316379100009 Content-Type: text/plain; charset="utf-8" These sequences are inexpensive to test. Maxing out at three insns results in the same space as a load plus the constant pool entry. Signed-off-by: Richard Henderson --- tcg/mips/tcg-target.c.inc | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tcg/mips/tcg-target.c.inc b/tcg/mips/tcg-target.c.inc index 9fab424ecc..b86a0679af 100644 --- a/tcg/mips/tcg-target.c.inc +++ b/tcg/mips/tcg-target.c.inc @@ -569,6 +569,7 @@ static void tcg_out_movi_int(TCGContext *s, TCGType typ= e, TCGReg ret, tcg_target_long arg, TCGReg tbreg) { tcg_target_long tmp; + int sh, lo; =20 if (TCG_TARGET_REG_BITS =3D=3D 64 && type =3D=3D TCG_TYPE_I32) { arg =3D (int32_t)arg; @@ -591,6 +592,49 @@ static void tcg_out_movi_int(TCGContext *s, TCGType ty= pe, TCGReg ret, return; } =20 + /* + * Load bitmasks with a right-shift. This is good for things + * like 0x0fff_ffff_ffff_fff0: ADDUI r,0,0xff00 + DSRL r,r,4. + * or similarly using LUI. For this to work, bit 31 must be set. + */ + if (arg > 0 && (int32_t)arg < 0) { + sh =3D clz64(arg); + if (tcg_out_movi_one(s, ret, arg << sh)) { + tcg_out_dsrl(s, ret, ret, sh); + return; + } + } + + /* + * Load slightly larger constants using left-shift. + * Limit this sequence to 3 insns to avoid too much expansion. + */ + sh =3D ctz64(arg); + if (sh && tcg_out_movi_two(s, ret, arg >> sh)) { + tcg_out_dsll(s, ret, ret, sh); + return; + } + + /* + * Load slightly larger constants using left-shift and add/or. + * Prefer addi with a negative immediate when that would produce + * a larger shift. For this to work, bits 15 and 16 must be set. + */ + lo =3D arg & 0xffff; + if (lo) { + if ((arg & 0x18000) =3D=3D 0x18000) { + lo =3D (int16_t)arg; + } + tmp =3D arg - lo; + sh =3D ctz64(tmp); + tmp >>=3D sh; + if (tcg_out_movi_one(s, ret, tmp)) { + tcg_out_dsll(s, ret, ret, sh); + tcg_out_opc_imm(s, lo < 0 ? OPC_DADDIU : OPC_ORI, ret, ret, lo= ); + return; + } + } + /* Otherwise, put 64-bit constants into the constant pool. */ tcg_out_movi_pool(s, ret, arg, tbreg); } --=20 2.34.1