From patchwork Tue Dec 6 04:40:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 631324 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2940388pvb; Mon, 5 Dec 2022 20:42:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf5zdSKVJUm5xpTLnk0DnsUAflEqhq3flilgruYzUCwQHvnFg5bPOaedcntGp0N6wTiM8eOK X-Received: by 2002:a37:bf83:0:b0:6fa:588b:add0 with SMTP id p125-20020a37bf83000000b006fa588badd0mr77403479qkf.758.1670301721999; Mon, 05 Dec 2022 20:42:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670301721; cv=none; d=google.com; s=arc-20160816; b=c/mhNk7H/rSbOeHhd2pbpCFJ/k4JaWxIgM6AarDClchOlCReVW4Zmi/hNKQA+OGweQ 4np7aWHYkOsIOnOqtjFHTdPtppZhl2bmc1OuJ9w5ZP+Eqe21tRmrF6B8WKH2QpuF91Di Zc7gkDB9GK00EhmDExRfkYeWdjn98ITujPsY/Ky87H/BoksT3oPwSNBO7T6Ms+yk5JLW z7WHwJcwkjrywLJ6UxnxY5Nz3BME4IBaXW8WpAYQWiyjnU6hRhSedF9JXct+3MBmoc8M mjhYdV96qX5/VqXWFjvHu2+NBS44mo+JRXGYNwXhgkv+wQNpyq4JGb7oiA7Wj6BtSj7Z aTtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5F058NLeHjKlkmfIxljmYxzTUffR2aWn7r+JcDjVNcg=; b=u1vsuUCE6Yzc9/A5ZHx/xJBJzK5McdUPTwzzSDzyqaDUBYEJQqMRFfjmMbKzQMof/9 Qbx05tuxaOoRtvf4hm/pDOpiPtsB5EuJ1Y2YH6VNUiltE9AzM0wFAmdwHw5JV/WK3oWG b/nLCQgiE9hZdor/06HtYDLisl1O4I8/sjz8U1daXXD94VGlIOC/iwsVhdfbRvTY0Ggx MK15RW0ToD+PYZFw2/dXY2jGJDOv7wf3TkA3m9d0X7KPgmbFzF52NvncMdnQ0LvHRZP3 Q6/spXPKrXhTFu34wfA7vbtEtyLTE/V6np6J2SN4QBnC6eV09Uisw9jgYGWH9gGEmtiU 0/6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pNBvk6Ec; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id cf27-20020a05622a401b00b003a594d0c93dsi9225293qtb.496.2022.12.05.20.42.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Dec 2022 20:42:01 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pNBvk6Ec; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p2PlO-0003BM-Ci; Mon, 05 Dec 2022 23:41:02 -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 1p2PlL-0003AY-U5 for qemu-devel@nongnu.org; Mon, 05 Dec 2022 23:41:00 -0500 Received: from mail-oi1-x232.google.com ([2607:f8b0:4864:20::232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p2PlK-00030Z-2L for qemu-devel@nongnu.org; Mon, 05 Dec 2022 23:40:59 -0500 Received: by mail-oi1-x232.google.com with SMTP id r11so9924571oie.13 for ; Mon, 05 Dec 2022 20:40:57 -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=5F058NLeHjKlkmfIxljmYxzTUffR2aWn7r+JcDjVNcg=; b=pNBvk6Ecp+5+H2AFfx325Tv8v1+qJ1xtZRCkTHdkdvuRTwJctt+79mtved0xB2dRFc /gQ+X/1OwgsiRxeKx8Zy/vOv3ESDotXGazTqxKhMfDkEeEbDbKuCfNP5MD7ukaAN+mQ7 QKEIe/MZrA797wPTGjAcUPXWQxjqKER071i8j5OZ78Q/nVN6oEosJoUlqz8ou2w9VAnZ AjYxQ8BhPzCV8TWpaGYYzTmMSSU8s1OEusx9mLvvgmMvw+AHE6+/LJjKHVs/MaqmdH+i VeOrEeu5xJlsiGNzoM2o60LWMwgzSIWGJdy2IaLWd7tV/dOCaUeWtriX/q08DXqbubA/ 5Aug== 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=5F058NLeHjKlkmfIxljmYxzTUffR2aWn7r+JcDjVNcg=; b=KyKbC1IebrTtC5wht0SnD9F4N//gRAN75jxXQPWpdpN0fHMjmQsn2VppWjuzpTXPpQ g/IpkhIIv4enkyW4ohiaxdrYDjyEO/qjtT53OOIFTwb0lzIc3jJW46K1gvTqlTOL6TiQ Q2QYWgYaUQfvoOIpq+kCBcQsSZ4bN0PWZP/9k6XW4j3ZK676gK18r8jklLeZJkB7d3Ni Tzvz2GVJr9b9VA30BicxlNGI2i1TXjozI2dk/yWU0jdeGiJaqnHOiAvzjr6soY0f6byz fTiRXyQqQwXer2Aj6OWTPkr1TiTYmcrU6/zkCIY6ddnIFO67UXcK1pYfLcLIAVX08XJy DTng== X-Gm-Message-State: ANoB5pnukdOr+yxvuG/gKYT2KyS1CFv9KlDnt8/93gZhx2AGlwS00PO2 HZ+hoOhMelevpjoY2YuKgk/MJi7Soj98DNDGwLA= X-Received: by 2002:aca:1218:0:b0:35c:abd7:80cb with SMTP id 24-20020aca1218000000b0035cabd780cbmr2155355ois.243.1670301656671; Mon, 05 Dec 2022 20:40:56 -0800 (PST) Received: from stoup.. ([2806:102e:18:70b5:d104:21c2:8c7e:77e6]) by smtp.gmail.com with ESMTPSA id z6-20020a05687041c600b001442fada152sm7561864oac.46.2022.12.05.20.40.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 20:40:56 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Rui Wang Subject: [PATCH 2/8] tcg/loongarch64: Optimize immediate loading Date: Mon, 5 Dec 2022 22:40:45 -0600 Message-Id: <20221206044051.322543-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221206044051.322543-1-richard.henderson@linaro.org> References: <20221206044051.322543-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::232; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x232.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 --- 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 c05b19a084..b2350f2cc7 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, TCGReg ret, TCGReg arg) return true; } -static bool imm_part_needs_loading(bool high_bits_are_ones, - tcg_target_long part) -{ - if (high_bits_are_ones) { - return part != -1; - } else { - return part != 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 = sextreg(val, 12, 20); /* Single-instruction cases. */ - if (lo == val) { - /* val fits in simm12: addi.w rd, zero, val */ - tcg_out_opc_addi_w(s, rd, TCG_REG_ZERO, val); - return; - } - if (0x800 <= val && val <= 0xfff) { + if (hi12 == 0) { /* val fits in uimm12: ori rd, zero, val */ tcg_out_opc_ori(s, rd, TCG_REG_ZERO, val); return; } + if (hi12 == 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; + } /* 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, TCGReg rd, 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; /* Value fits in signed i32. */ if (type == TCG_TYPE_I32 || val == (int32_t)val) { @@ -366,25 +355,25 @@ static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd, return; } + hi12 = sextreg(val, 12, 20); hi32 = sextreg(val, 32, 20); hi52 = sextreg(val, 52, 12); /* Single cu52i.d case. */ - if (ctz64(val) >= 52) { + if ((hi52 != 0) && (ctz64(val) >= 52)) { tcg_out_opc_cu52i_d(s, rd, TCG_REG_ZERO, hi52); return; } /* Slow path. Initialize the low 32 bits, then concat high bits. */ tcg_out_movi_i32(s, rd, val); - rd_high_bits_are_ones = (int32_t)val < 0; - if (imm_part_needs_loading(rd_high_bits_are_ones, hi32)) { + /* Load hi32 and hi52 explicitly when they are unexpected values. */ + if (hi32 != sextreg(hi12, 20, 20)) { tcg_out_opc_cu32i_d(s, rd, hi32); - rd_high_bits_are_ones = hi32 < 0; } - if (imm_part_needs_loading(rd_high_bits_are_ones, hi52)) { + if (hi52 != sextreg(hi32, 20, 12)) { tcg_out_opc_cu52i_d(s, rd, rd, hi52); } }