From patchwork Thu Sep 7 22:40:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111994 Delivered-To: patch@linaro.org Received: by 10.37.128.210 with SMTP id c18csp769270ybm; Thu, 7 Sep 2017 15:58:29 -0700 (PDT) X-Received: by 10.200.50.93 with SMTP id y29mr1336700qta.301.1504825109058; Thu, 07 Sep 2017 15:58:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504825109; cv=none; d=google.com; s=arc-20160816; b=NMd+px5AAPLLDK1LDr/DNNAV2VsPGkTyJYHgr0xPKWh5VvVIXNqbH3tX+FYvUBLNv2 C1CFup37TWQgsUaXC01CPpk3ZXeAJLFAO0Tz7a6oQmvM0piUxDXu9cJU00y8Ah0FnDeP 83PzqVeOWJBdBXcMHIfI9YZzqTjpjXteLGQJW34HpiNAjodFcxSOqr3sRp6kAUWxWBgU E8v96lhsfo8uz3B9C1ywHC3Kgg2UnqxZFydVGgsT8t+CDFaF76aFA+G1XIyw4JrEgPqE Cp5AjV8ZeEgGc1bABRneNKM9Xy2UNCH7aq0J6V3LVIjxJSSSmulQNSRimoBsE3LDjZxg jRnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=aB8kwe4MCaWs6fQf1wJvIS4sD6K4qPPRJRJMHMGczQ0=; b=VBSTXNlk0kzTZe7Pp+TFmV6Wzvn9Fswme32WK+LTHSD8I7NhSgNnA+osNdSBXNMhro lYjUAV0l2EoFfK4rPKuw2VKE0MEvDtiKhxsAXnZPk2mJ79JmwHJ3cmTHm/fr6lNDtn9x GUYDSfSK4uLP041l9Xb2rPgApJ6dVHoGPgX7ac0MI4Ec5mcdCwuWebnyjILsJFbcJ8R7 lLwlIiwswNG2ZA8g06iSyjaczo7ATFGJzUdoA+2dQmgI9kuR+GMjYktNrOmtvjpdiDSk CvmzBiqO2m9E3CSs6s1PBQZwWnNcccLDlCxA5xoSi5II+D7KQo4WmwXaILBxFjdEI57q YZLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=R2HaYZob; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id z37si489855qtg.402.2017.09.07.15.58.28 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:58:29 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=R2HaYZob; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42584 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5kh-0000fL-16 for patch@linaro.org; Thu, 07 Sep 2017 18:58:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52400) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5UJ-0003IV-N4 for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5UE-0008Qr-Rp for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:31 -0400 Received: from mail-pf0-x22b.google.com ([2607:f8b0:400e:c00::22b]:35371) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5UE-0008Q0-LJ for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:26 -0400 Received: by mail-pf0-x22b.google.com with SMTP id g13so1630258pfm.2 for ; Thu, 07 Sep 2017 15:41:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aB8kwe4MCaWs6fQf1wJvIS4sD6K4qPPRJRJMHMGczQ0=; b=R2HaYZob2j7TcxBAlIpSlXx8Kgtdoy98AIB5khS83uFP8X3JE3mtZvYmxSIQGZEPxi m/QRbnjfjc7z1SQlJM1wRBu6xXdw3fgQc235D2yLxDmk+59EAcAxnyGevEaR+q1i17l+ L+SxVtFDQcdFrzMiZKqNjkslnvRHD9nYE8JJ8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aB8kwe4MCaWs6fQf1wJvIS4sD6K4qPPRJRJMHMGczQ0=; b=Q13jB7SANqVdtOlfQV+XJhe0eFBjoZKIASVBCSsPUZXI8wbBP5XlYVYEidxzyLRNOR MRpUzrjBD+GGwyNytrOJWunYKyzhcaqj4FhJCiPX20f+4awJ7rtyVu3tVjp/r5t6dKtn 4n+ilPBZafTNEEdBPX+AYy0Qm2HX0TjcFMznRQ0hx1XxPJozpdCSTNB8DqgQEEVmR85A hB11bQrPb2pmRlkKgMUs/3DMIxtlsu3xtVogk6WzST87Z7gKAyIoFFjRjZ9ZF7E7/Wyl livLZsLe0qwbeo6QKypnOUDffdHDrW/SuBZjII8NZtplY1tFJrTwCS7v6qFPg86XE8cd yx3w== X-Gm-Message-State: AHPjjUheC1gi6pB6xCmhPvtCpn/Vvqy7mar8to8Xf1WbfKsH8CXrD5Hk I4GDBgWqCel0xig84aQILg== X-Google-Smtp-Source: ADKCNb4IjyZ6qzEkrv5Am0lcbFsUmMPfmCXgYDRbVNINnjJwuCwsSdkU4t1R1o3a65FOkQh9E2QVsA== X-Received: by 10.84.217.14 with SMTP id o14mr1080148pli.20.1504824085356; Thu, 07 Sep 2017 15:41:25 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:50 -0700 Message-Id: <20170907224051.21518-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::22b Subject: [Qemu-devel] [PULL 22/23] tcg/ppc: Look for shifted constants X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Signed-off-by: Richard Henderson --- tcg/ppc/tcg-target.inc.c | 58 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 10 deletions(-) -- 2.13.5 diff --git a/tcg/ppc/tcg-target.inc.c b/tcg/ppc/tcg-target.inc.c index bc14d2c9c6..df709c4a96 100644 --- a/tcg/ppc/tcg-target.inc.c +++ b/tcg/ppc/tcg-target.inc.c @@ -593,11 +593,26 @@ static inline void tcg_out_shri64(TCGContext *s, TCGReg dst, TCGReg src, int c) tcg_out_rld(s, RLDICL, dst, src, 64 - c, c); } +/* Emit a move into ret of arg, if it can be done in one insn. */ +static bool tcg_out_movi_one(TCGContext *s, TCGReg ret, tcg_target_long arg) +{ + if (arg == (int16_t)arg) { + tcg_out32(s, ADDI | TAI(ret, 0, arg)); + return true; + } + if (arg == (int32_t)arg && (arg & 0xffff) == 0) { + tcg_out32(s, ADDIS | TAI(ret, 0, arg >> 16)); + return true; + } + return false; +} + static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, tcg_target_long arg, bool in_prologue) { intptr_t tb_diff; - int32_t high; + tcg_target_long tmp; + int shift; tcg_debug_assert(TCG_TARGET_REG_BITS == 64 || type == TCG_TYPE_I32); @@ -606,8 +621,7 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, } /* Load 16-bit immediates with one insn. */ - if (arg == (int16_t)arg) { - tcg_out32(s, ADDI | TAI(ret, 0, arg)); + if (tcg_out_movi_one(s, ret, arg)) { return; } @@ -618,12 +632,11 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, return; } - /* Load 32-bit immediates with two insns. */ + /* Load 32-bit immediates with two insns. Note that we've already + eliminated bare ADDIS, so we know both insns are required. */ if (TCG_TARGET_REG_BITS == 32 || arg == (int32_t)arg) { tcg_out32(s, ADDIS | TAI(ret, 0, arg >> 16)); - if (arg & 0xffff) { - tcg_out32(s, ORI | SAI(ret, ret, arg)); - } + tcg_out32(s, ORI | SAI(ret, ret, arg)); return; } if (arg == (uint32_t)arg && !(arg & 0x8000)) { @@ -632,15 +645,40 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, return; } + /* Load masked 16-bit value. */ + if (arg > 0 && (arg & 0x8000)) { + tmp = arg | 0x7fff; + if ((tmp & (tmp + 1)) == 0) { + int mb = clz64(tmp + 1) + 1; + tcg_out32(s, ADDI | TAI(ret, 0, arg)); + tcg_out_rld(s, RLDICL, ret, ret, 0, mb); + return; + } + } + + /* Load common masks with 2 insns. */ + shift = ctz64(arg); + tmp = arg >> shift; + if (tmp == (int16_t)tmp) { + tcg_out32(s, ADDI | TAI(ret, 0, tmp)); + tcg_out_shli64(s, ret, ret, shift); + return; + } + shift = clz64(arg); + if (tcg_out_movi_one(s, ret, arg << shift)) { + tcg_out_shri64(s, ret, ret, shift); + return; + } + /* Load addresses within 2GB of TB with 2 (or rarely 3) insns. */ if (!in_prologue && USE_REG_TB && tb_diff == (int32_t)tb_diff) { tcg_out_mem_long(s, ADDI, ADD, ret, TCG_REG_TB, tb_diff); return; } - high = arg >> 31 >> 1; - tcg_out_movi(s, TCG_TYPE_I32, ret, high); - if (high) { + tmp = arg >> 31 >> 1; + tcg_out_movi(s, TCG_TYPE_I32, ret, tmp); + if (tmp) { tcg_out_shli64(s, ret, ret, 32); } if (arg & 0xffff0000) {