From patchwork Thu Sep 7 22:40:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111985 Delivered-To: patch@linaro.org Received: by 10.37.128.210 with SMTP id c18csp763413ybm; Thu, 7 Sep 2017 15:51:05 -0700 (PDT) X-Received: by 10.200.5.132 with SMTP id a4mr1444622qth.316.1504824665488; Thu, 07 Sep 2017 15:51:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824665; cv=none; d=google.com; s=arc-20160816; b=HdLldwpP6obR73DoJ/1aiHOz1kJsX4fWS4R50tK9QG7uFgGwWpgtJkuG8o8M5olZx7 bMEa59Ij2zev4InQkzRI06zz7at1NW5Wq8WCpy4BcHD5AIDSmrIUHpDsFqBByNCy0HAP +PlFXSWKWB78kisingptSKt5MoXPvHOL4YTr6CdJQNsFq+Hy/3V0D6I6DYnErMVedpU+ LitnU3c2FEtVLm0Fn6F7rfoQ2qiebFLEVOcIDirrBFq2udB94b87YiOme0ROQ7mHfMKf DTG3b3lVk/P64mUNKN4LkquNPb2tkKqAMNKDTKfTpTlZkvOXiBvGaz/e5/cTPDRZNpIw 9NnQ== 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=VckR6G8VPrq0GOmaJPbnP93dBEfN3HLPmvmvcRM4IWU=; b=Jx/Gcoriclhrmx6BwLfYdoJhPgARLjiCwSnNiK0oD3eLjHWOqfYimKxkaUagZap+EG 9xSeIoR9CzrtAKJmCalB4EDppddy+vUnb8syabFfJq5UnZV7+cPTJcjstSe7VLj4cDsm IWeB7hLZrL6ujkGxms/BCaVIYDh+CtXr25JlSnY3eu7hqONp5zlCjjtKX0Ethlf8i5OR tIYvcLhiNUQYHhaP/qRH6RQ/D8/hGKjeqKys4K9GwZAIho/vB6ejpQMe6m4OrU7DIco/ 4A/1F4RR3YswmnF2kXei+9Tje4gdOGD169MvNh/W0Iuyk9i3bB5BiNwR5w4JL2RwEE6Z HM5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=DTF7DrSt; 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 g4si472299qti.519.2017.09.07.15.51.05 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:51:05 -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=DTF7DrSt; 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]:42554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5dX-0002fz-98 for patch@linaro.org; Thu, 07 Sep 2017 18:51:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5U8-00039U-Vy for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5U4-0008IK-9a for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:21 -0400 Received: from mail-pf0-x229.google.com ([2607:f8b0:400e:c00::229]:32923) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5U4-0008I1-2e for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:16 -0400 Received: by mail-pf0-x229.google.com with SMTP id y29so860349pff.0 for ; Thu, 07 Sep 2017 15:41:15 -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=VckR6G8VPrq0GOmaJPbnP93dBEfN3HLPmvmvcRM4IWU=; b=DTF7DrSt7mPWu+RNcM6sal5Fb9PxWETIPQMOFIcy1OymCD0oKre594uonn8/s2gXKi EGI0e6PmeE7lCKRUQUuxUjkCVMskd/5DzHaMaf3WrJzIeATZLNTu3k6JbHJbXm7Dbvb2 GzGEPYwfrHo3pKnHYGi0vdwyS4twaUY2cxEQk= 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=VckR6G8VPrq0GOmaJPbnP93dBEfN3HLPmvmvcRM4IWU=; b=sOFvlqoSPpLyEX9r2Ruu2oU51YWmvSCYRJux5PGfNSzKEuedoFafcMy8zgPsydihSs knQ3/djlihrppuJH7X+mugZqdnHbb9U43sPXxvNkfrcRuCpQy+PBofAZMLLvH0o4QBB1 VTTzjJgizHTiyUHJd2I2gW4e/jFZx0K8Y5LlV/CZbrzsZyJ/x3bS+hgpMUyFEREAqIAu GdlMGclYvH2aGn6+2FCQFH3db5YNnxLBI5gnJSkglt6JgmGfSjeB8RZx+fPkWylppnf9 S4CE+CdZp2bSMSgPFv8Afs8WrfsT3qPwp8TFV400hGCCrCqxt/zWIbaXfCh3xydZwIps hekQ== X-Gm-Message-State: AHPjjUgKZuNydvEAzsGxPXwqGh0Dy7/GaJ/pP6MTdWrU31+X5erPy6nf bKI2czu1yJ7n/kSSWuB6rg== X-Google-Smtp-Source: ADKCNb68/T24mW6po1TsPmkHb2+PD3ICI0o8ur0X4HVER5ZMEj/X4F+qVersYGwAQNYFHSastY/4HA== X-Received: by 10.101.67.2 with SMTP id j2mr949323pgq.182.1504824074754; Thu, 07 Sep 2017 15:41:14 -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.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:42 -0700 Message-Id: <20170907224051.21518-15-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::229 Subject: [Qemu-devel] [PULL 14/23] tcg/sparc: Use constant pool for movi 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/sparc/tcg-target.h | 2 ++ tcg/sparc/tcg-target.inc.c | 77 +++++++++++++++++++++++++++++++++------------- 2 files changed, 58 insertions(+), 21 deletions(-) -- 2.13.5 diff --git a/tcg/sparc/tcg-target.h b/tcg/sparc/tcg-target.h index da98743817..d8339bf010 100644 --- a/tcg/sparc/tcg-target.h +++ b/tcg/sparc/tcg-target.h @@ -175,4 +175,6 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop) void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); +#define TCG_TARGET_NEED_POOL_LABELS + #endif diff --git a/tcg/sparc/tcg-target.inc.c b/tcg/sparc/tcg-target.inc.c index 7d73c25347..bd7c1461c6 100644 --- a/tcg/sparc/tcg-target.inc.c +++ b/tcg/sparc/tcg-target.inc.c @@ -22,6 +22,8 @@ * THE SOFTWARE. */ +#include "tcg-pool.inc.c" + #ifdef CONFIG_DEBUG_TCG static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = { "%g0", @@ -292,33 +294,46 @@ static inline int check_fit_i32(int32_t val, unsigned int bits) static void patch_reloc(tcg_insn_unit *code_ptr, int type, intptr_t value, intptr_t addend) { - uint32_t insn; + uint32_t insn = *code_ptr; + intptr_t pcrel; - tcg_debug_assert(addend == 0); - value = tcg_ptr_byte_diff((tcg_insn_unit *)value, code_ptr); + value += addend; + pcrel = tcg_ptr_byte_diff((tcg_insn_unit *)value, code_ptr); switch (type) { case R_SPARC_WDISP16: - if (!check_fit_ptr(value >> 2, 16)) { - tcg_abort(); - } - insn = *code_ptr; + assert(check_fit_ptr(pcrel >> 2, 16)); insn &= ~INSN_OFF16(-1); - insn |= INSN_OFF16(value); - *code_ptr = insn; + insn |= INSN_OFF16(pcrel); break; case R_SPARC_WDISP19: - if (!check_fit_ptr(value >> 2, 19)) { - tcg_abort(); - } - insn = *code_ptr; + assert(check_fit_ptr(pcrel >> 2, 19)); insn &= ~INSN_OFF19(-1); - insn |= INSN_OFF19(value); - *code_ptr = insn; + insn |= INSN_OFF19(pcrel); + break; + case R_SPARC_13: + /* Note that we're abusing this reloc type for our own needs. */ + if (!check_fit_ptr(value, 13)) { + int adj = (value > 0 ? 0xff8 : -0x1000); + value -= adj; + assert(check_fit_ptr(value, 13)); + *code_ptr++ = (ARITH_ADD | INSN_RD(TCG_REG_T2) + | INSN_RS1(TCG_REG_TB) | INSN_IMM13(adj)); + insn ^= INSN_RS1(TCG_REG_TB) ^ INSN_RS1(TCG_REG_T2); + } + insn &= ~INSN_IMM13(-1); + insn |= INSN_IMM13(value); break; + case R_SPARC_32: + /* Note that we're abusing this reloc type for our own needs. */ + code_ptr[0] = deposit32(code_ptr[0], 0, 22, value >> 10); + code_ptr[1] = deposit32(code_ptr[1], 0, 10, value); + return; default: - tcg_abort(); + g_assert_not_reached(); } + + *code_ptr = insn; } /* parse target specific constraints */ @@ -474,12 +489,24 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, return; } - if (USE_REG_TB && !in_prologue) { - intptr_t diff = arg - (uintptr_t)s->code_gen_ptr; - if (check_fit_ptr(diff, 13)) { - tcg_out_arithi(s, ret, TCG_REG_TB, diff, ARITH_ADD); - return; + if (!in_prologue) { + if (USE_REG_TB) { + intptr_t diff = arg - (uintptr_t)s->code_gen_ptr; + if (check_fit_ptr(diff, 13)) { + tcg_out_arithi(s, ret, TCG_REG_TB, diff, ARITH_ADD); + } else { + new_pool_label(s, arg, R_SPARC_13, s->code_ptr, + -(intptr_t)s->code_gen_ptr); + tcg_out32(s, LDX | INSN_RD(ret) | INSN_RS1(TCG_REG_TB)); + /* May be used to extend the 13-bit range in patch_reloc. */ + tcg_out32(s, NOP); + } + } else { + new_pool_label(s, arg, R_SPARC_32, s->code_ptr, 0); + tcg_out_sethi(s, ret, 0); + tcg_out32(s, LDX | INSN_RD(ret) | INSN_RS1(ret) | INSN_IMM13(0)); } + return; } /* A 64-bit constant decomposed into 2 32-bit pieces. */ @@ -1058,6 +1085,14 @@ static void tcg_target_qemu_prologue(TCGContext *s) #endif } +static void tcg_out_nop_fill(tcg_insn_unit *p, int count) +{ + int i; + for (i = 0; i < count; ++i) { + p[i] = NOP; + } +} + #if defined(CONFIG_SOFTMMU) /* Perform the TLB load and compare.