{"id":811262,"url":"http://patchwork.ozlabs.org/api/1.2/patches/811262/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170907224051.21518-23-richard.henderson@linaro.org/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.2/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170907224051.21518-23-richard.henderson@linaro.org>","list_archive_url":null,"date":"2017-09-07T22:40:50","name":"[PULL,22/23] tcg/ppc: Look for shifted constants","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"825c138154249f599aeb84281636ad3c8924bcfc","submitter":{"id":72104,"url":"http://patchwork.ozlabs.org/api/1.2/people/72104/?format=json","name":"Richard Henderson","email":"richard.henderson@linaro.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170907224051.21518-23-richard.henderson@linaro.org/mbox/","series":[{"id":2073,"url":"http://patchwork.ozlabs.org/api/1.2/series/2073/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=2073","date":"2017-09-07T22:40:28","name":"[PULL,01/23] tcg: Move USE_DIRECT_JUMP discriminator to tcg/cpu/tcg-target.h","version":1,"mbox":"http://patchwork.ozlabs.org/series/2073/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/811262/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/811262/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"R2HaYZob\"; dkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xpG7C2wZVz9s81\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  8 Sep 2017 08:57:27 +1000 (AEST)","from localhost ([::1]:42581 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dq5jh-0007z1-HU\n\tfor incoming@patchwork.ozlabs.org; Thu, 07 Sep 2017 18:57:25 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:52400)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <richard.henderson@linaro.org>) id 1dq5UJ-0003IV-N4\n\tfor qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:36 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <richard.henderson@linaro.org>) id 1dq5UE-0008Qr-Rp\n\tfor qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:31 -0400","from mail-pf0-x22b.google.com ([2607:f8b0:400e:c00::22b]:35371)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <richard.henderson@linaro.org>)\n\tid 1dq5UE-0008Q0-LJ\n\tfor qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:26 -0400","by mail-pf0-x22b.google.com with SMTP id g13so1630258pfm.2\n\tfor <qemu-devel@nongnu.org>; Thu, 07 Sep 2017 15:41:26 -0700 (PDT)","from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net.\n\t[97.126.108.236]) by smtp.gmail.com with ESMTPSA id\n\th19sm770678pfh.142.2017.09.07.15.41.24\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tThu, 07 Sep 2017 15:41:24 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=aB8kwe4MCaWs6fQf1wJvIS4sD6K4qPPRJRJMHMGczQ0=;\n\tb=R2HaYZob2j7TcxBAlIpSlXx8Kgtdoy98AIB5khS83uFP8X3JE3mtZvYmxSIQGZEPxi\n\tm/QRbnjfjc7z1SQlJM1wRBu6xXdw3fgQc235D2yLxDmk+59EAcAxnyGevEaR+q1i17l+\n\tL+SxVtFDQcdFrzMiZKqNjkslnvRHD9nYE8JJ8=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=aB8kwe4MCaWs6fQf1wJvIS4sD6K4qPPRJRJMHMGczQ0=;\n\tb=Q13jB7SANqVdtOlfQV+XJhe0eFBjoZKIASVBCSsPUZXI8wbBP5XlYVYEidxzyLRNOR\n\tMRpUzrjBD+GGwyNytrOJWunYKyzhcaqj4FhJCiPX20f+4awJ7rtyVu3tVjp/r5t6dKtn\n\t4n+ilPBZafTNEEdBPX+AYy0Qm2HX0TjcFMznRQ0hx1XxPJozpdCSTNB8DqgQEEVmR85A\n\thB11bQrPb2pmRlkKgMUs/3DMIxtlsu3xtVogk6WzST87Z7gKAyIoFFjRjZ9ZF7E7/Wyl\n\tlivLZsLe0qwbeo6QKypnOUDffdHDrW/SuBZjII8NZtplY1tFJrTwCS7v6qFPg86XE8cd\n\tyx3w==","X-Gm-Message-State":"AHPjjUheC1gi6pB6xCmhPvtCpn/Vvqy7mar8to8Xf1WbfKsH8CXrD5Hk\n\tI4GDBgWqCel0xig84aQILg==","X-Google-Smtp-Source":"ADKCNb4IjyZ6qzEkrv5Am0lcbFsUmMPfmCXgYDRbVNINnjJwuCwsSdkU4t1R1o3a65FOkQh9E2QVsA==","X-Received":"by 10.84.217.14 with SMTP id o14mr1080148pli.20.1504824085356;\n\tThu, 07 Sep 2017 15:41:25 -0700 (PDT)","From":"Richard Henderson <richard.henderson@linaro.org>","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\n\trecognized.","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":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"peter.maydell@linaro.org, Richard Henderson <rth@twiddle.net>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"From: Richard Henderson <rth@twiddle.net>\n\nSigned-off-by: Richard Henderson <rth@twiddle.net>\n---\n tcg/ppc/tcg-target.inc.c | 58 +++++++++++++++++++++++++++++++++++++++---------\n 1 file changed, 48 insertions(+), 10 deletions(-)","diff":"diff --git a/tcg/ppc/tcg-target.inc.c b/tcg/ppc/tcg-target.inc.c\nindex bc14d2c9c6..df709c4a96 100644\n--- a/tcg/ppc/tcg-target.inc.c\n+++ b/tcg/ppc/tcg-target.inc.c\n@@ -593,11 +593,26 @@ static inline void tcg_out_shri64(TCGContext *s, TCGReg dst, TCGReg src, int c)\n     tcg_out_rld(s, RLDICL, dst, src, 64 - c, c);\n }\n \n+/* Emit a move into ret of arg, if it can be done in one insn.  */\n+static bool tcg_out_movi_one(TCGContext *s, TCGReg ret, tcg_target_long arg)\n+{\n+    if (arg == (int16_t)arg) {\n+        tcg_out32(s, ADDI | TAI(ret, 0, arg));\n+        return true;\n+    }\n+    if (arg == (int32_t)arg && (arg & 0xffff) == 0) {\n+        tcg_out32(s, ADDIS | TAI(ret, 0, arg >> 16));\n+        return true;\n+    }\n+    return false;\n+}\n+\n static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,\n                              tcg_target_long arg, bool in_prologue)\n {\n     intptr_t tb_diff;\n-    int32_t high;\n+    tcg_target_long tmp;\n+    int shift;\n \n     tcg_debug_assert(TCG_TARGET_REG_BITS == 64 || type == TCG_TYPE_I32);\n \n@@ -606,8 +621,7 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,\n     }\n \n     /* Load 16-bit immediates with one insn.  */\n-    if (arg == (int16_t)arg) {\n-        tcg_out32(s, ADDI | TAI(ret, 0, arg));\n+    if (tcg_out_movi_one(s, ret, arg)) {\n         return;\n     }\n \n@@ -618,12 +632,11 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,\n         return;\n     }\n \n-    /* Load 32-bit immediates with two insns.  */\n+    /* Load 32-bit immediates with two insns.  Note that we've already\n+       eliminated bare ADDIS, so we know both insns are required.  */\n     if (TCG_TARGET_REG_BITS == 32 || arg == (int32_t)arg) {\n         tcg_out32(s, ADDIS | TAI(ret, 0, arg >> 16));\n-        if (arg & 0xffff) {\n-            tcg_out32(s, ORI | SAI(ret, ret, arg));\n-        }\n+        tcg_out32(s, ORI | SAI(ret, ret, arg));\n         return;\n     }\n     if (arg == (uint32_t)arg && !(arg & 0x8000)) {\n@@ -632,15 +645,40 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,\n         return;\n     }\n \n+    /* Load masked 16-bit value.  */\n+    if (arg > 0 && (arg & 0x8000)) {\n+        tmp = arg | 0x7fff;\n+        if ((tmp & (tmp + 1)) == 0) {\n+            int mb = clz64(tmp + 1) + 1;\n+            tcg_out32(s, ADDI | TAI(ret, 0, arg));\n+            tcg_out_rld(s, RLDICL, ret, ret, 0, mb);\n+            return;\n+        }\n+    }\n+\n+    /* Load common masks with 2 insns.  */\n+    shift = ctz64(arg);\n+    tmp = arg >> shift;\n+    if (tmp == (int16_t)tmp) {\n+        tcg_out32(s, ADDI | TAI(ret, 0, tmp));\n+        tcg_out_shli64(s, ret, ret, shift);\n+        return;\n+    }\n+    shift = clz64(arg);\n+    if (tcg_out_movi_one(s, ret, arg << shift)) {\n+        tcg_out_shri64(s, ret, ret, shift);\n+        return;\n+    }\n+\n     /* Load addresses within 2GB of TB with 2 (or rarely 3) insns.  */\n     if (!in_prologue && USE_REG_TB && tb_diff == (int32_t)tb_diff) {\n         tcg_out_mem_long(s, ADDI, ADD, ret, TCG_REG_TB, tb_diff);\n         return;\n     }\n \n-    high = arg >> 31 >> 1;\n-    tcg_out_movi(s, TCG_TYPE_I32, ret, high);\n-    if (high) {\n+    tmp = arg >> 31 >> 1;\n+    tcg_out_movi(s, TCG_TYPE_I32, ret, tmp);\n+    if (tmp) {\n         tcg_out_shli64(s, ret, ret, 32);\n     }\n     if (arg & 0xffff0000) {\n","prefixes":["PULL","22/23"]}