From patchwork Fri Jan 26 04:57:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 126005 Delivered-To: patch@linaro.org Received: by 10.46.84.92 with SMTP id y28csp482572ljd; Fri, 26 Jan 2018 09:14:56 -0800 (PST) X-Google-Smtp-Source: AH8x226foqnWiNuiJ7g24jd4vHxhBKIEpQlF6Uq7kNAMT+t1uoP3njFdWHrPRo+J4DjlOsZgetIi X-Received: by 10.37.15.68 with SMTP id 65mr11574333ybp.524.1516986896776; Fri, 26 Jan 2018 09:14:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516986896; cv=none; d=google.com; s=arc-20160816; b=yzu6UZkt8UVbs3OvcaTurt3akT0KEdFYTb8ulMmXy/fn89ubCyGOHjFA04TG32G0Iu ID6od8HK4hWE9n06hBRmUbo9sUGvrVEi/fh2ODGPVdDMQGkFUWafj+reZKT9znmcUNRq QAsYjb6OkaNUGHe23Srincjr49KN6mA8duf5mrTxi3/+KTP3AsMJAYufWe7DmIk7D6Yk Hky6lenLxeDPwkx9xQ9Hs1xljnUuN/svKlVvBZJziLJ8uhIEZAufu1U4yBRgULVQED0S 4lZQi2w5QrivcwBu1lH13YYZZQldJ89GthSYfCO+xxbT7JQb1RSmflF7bbhgatXH71Qw QDpg== 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=I0QCG+SxLQ1x3O6au141T3GoSWwxzGWMKMPYOBNSkd4=; b=xUK7Sb8Yd1PZtGrnhbiH3qfkgWI9NJgeLCTCP8URA/yAkl+EMG7tPeJGillDtMTvxY edQQMSgUfZbJttj4R/1GvBONjunWKlT1yBcAftm6o096ILzvxkldU5Lr2NdlhBnRt976 wYyhyB/N+oWv2FbKHtG5BVOqkrqCXOOIO0u5W3Z+3LCD5EDKqY0IgK+FoxEo7HzzlUUw dky2uyFoxKU5CGaceFWtirF9lH/pN8WdXOLb2O1U2LyLbrI/yHFmgj85ak9x8Mm7pA2w 0yTxctasd4YfdbGCDngEY4IK/PqjSaA3bmXzdxA83UeYvskY4tYq+xcPoTcPZBLvp0jY 0Yjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Pe6XwXel; 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 d21si395575ybe.287.2018.01.26.09.14.56 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 26 Jan 2018 09:14:56 -0800 (PST) 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=Pe6XwXel; 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]:39943 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef7aa-0004FO-3q for patch@linaro.org; Fri, 26 Jan 2018 12:14:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49272) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef7aC-0004DG-Uy for qemu-devel@nongnu.org; Fri, 26 Jan 2018 12:14:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ef7a7-00023A-TF for qemu-devel@nongnu.org; Fri, 26 Jan 2018 12:14:32 -0500 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:36650) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ef7a4-00020D-Tv for qemu-devel@nongnu.org; Fri, 26 Jan 2018 12:14:27 -0500 Received: by mail-pf0-x243.google.com with SMTP id 23so664704pfp.3 for ; Fri, 26 Jan 2018 09:14:24 -0800 (PST) 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=I0QCG+SxLQ1x3O6au141T3GoSWwxzGWMKMPYOBNSkd4=; b=Pe6XwXeluyM/HdgKeepvKsCTpSFpqW9stciYThdAOA48H1Oy/wlMF9O2pl5xdwpIOs 8Gd/fuAGg3GaHBokjreXWTWnkK7kYSlzEfAozcLl6qJgMPbNFUo0AE7YDsZl3lEM870w hHkyqh1eXBR2ftuMfSRR6GTeIlsl9Q9BmlyaY= 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=I0QCG+SxLQ1x3O6au141T3GoSWwxzGWMKMPYOBNSkd4=; b=TUu+/nzCiks37aNpTtvJZbgdLPFv+BLQsrZTGAmorCyEgc84unYvlmIn35vdk7rDut bxupXQVt5+/lMBj37olqD9vEg8s0LiB6+uaL9aBj8HAqGSXDej2f8VaZn9traFv8EP4J WKio16mL/piay3zZqIGiKFx574rPiuGMhVARlDTF+BiRvFb1jmGGjzIziCQLklayHJkB pRjaFE2hIOJBFXE5K5kDV8eUyXgxz3KoZOVk9AkuHVO6OUpfITxxchODNTA4MoL+Zr5b bQfci8EMLGUkJrOerbNDf+t+3520+FARfBQYlat24IaKIl5zY2pRPxBYCFyGv/ZYaQkD x37A== X-Gm-Message-State: AKwxytfDARytyFCrEO9iUEOscSQEToM4j0zfEd974oCVELJVaz66/vsk Hjz9QddA172fG7S07ArgbRLIzw+Fkbk= X-Received: by 2002:a17:902:bf05:: with SMTP id bi5-v6mr13738790plb.32.1516942678182; Thu, 25 Jan 2018 20:57:58 -0800 (PST) Received: from cloudburst.twiddle.net (174-21-6-47.tukw.qwest.net. [174.21.6.47]) by smtp.gmail.com with ESMTPSA id q67sm20460313pfi.164.2018.01.25.20.57.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Jan 2018 20:57:56 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 25 Jan 2018 20:57:23 -0800 Message-Id: <20180126045742.5487-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180126045742.5487-1-richard.henderson@linaro.org> References: <20180126045742.5487-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::243 Subject: [Qemu-devel] [PATCH v11 01/20] tcg: Allow multiple word entries into the constant pool 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 Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This will be required for storing vector constants. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- tcg/tcg-pool.inc.c | 115 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 93 insertions(+), 22 deletions(-) -- 2.14.3 Reviewed-by: Alex Bennée diff --git a/tcg/tcg-pool.inc.c b/tcg/tcg-pool.inc.c index 8a85131405..ecf7c9282b 100644 --- a/tcg/tcg-pool.inc.c +++ b/tcg/tcg-pool.inc.c @@ -22,39 +22,110 @@ typedef struct TCGLabelPoolData { struct TCGLabelPoolData *next; - tcg_target_ulong data; tcg_insn_unit *label; - intptr_t addend; - int type; + int32_t addend; + uint16_t rtype; + uint16_t nlong; + tcg_target_ulong data[]; } TCGLabelPoolData; -static void new_pool_label(TCGContext *s, tcg_target_ulong data, int type, - tcg_insn_unit *label, intptr_t addend) +static TCGLabelPoolData *new_pool_alloc(TCGContext *s, int nlong, int rtype, + tcg_insn_unit *label, int addend) { - TCGLabelPoolData *n = tcg_malloc(sizeof(*n)); - TCGLabelPoolData *i, **pp; + TCGLabelPoolData *n = tcg_malloc(sizeof(TCGLabelPoolData) + + sizeof(tcg_target_ulong) * nlong); - n->data = data; n->label = label; - n->type = type; n->addend = addend; + n->rtype = rtype; + n->nlong = nlong; + return n; +} + +static void new_pool_insert(TCGContext *s, TCGLabelPoolData *n) +{ + TCGLabelPoolData *i, **pp; + int nlong = n->nlong; /* Insertion sort on the pool. */ - for (pp = &s->pool_labels; (i = *pp) && i->data < data; pp = &i->next) { - continue; + for (pp = &s->pool_labels; (i = *pp) != NULL; pp = &i->next) { + if (nlong > i->nlong) { + break; + } + if (nlong < i->nlong) { + continue; + } + if (memcmp(n->data, i->data, sizeof(tcg_target_ulong) * nlong) >= 0) { + break; + } } n->next = *pp; *pp = n; } +/* The "usual" for generic integer code. */ +static inline void new_pool_label(TCGContext *s, tcg_target_ulong d, int rtype, + tcg_insn_unit *label, int addend) +{ + TCGLabelPoolData *n = new_pool_alloc(s, 1, rtype, label, addend); + n->data[0] = d; + new_pool_insert(s, n); +} + +/* For v64 or v128, depending on the host. */ +static inline void new_pool_l2(TCGContext *s, int rtype, tcg_insn_unit *label, + int addend, tcg_target_ulong d0, + tcg_target_ulong d1) +{ + TCGLabelPoolData *n = new_pool_alloc(s, 2, rtype, label, addend); + n->data[0] = d0; + n->data[1] = d1; + new_pool_insert(s, n); +} + +/* For v128 or v256, depending on the host. */ +static inline void new_pool_l4(TCGContext *s, int rtype, tcg_insn_unit *label, + int addend, tcg_target_ulong d0, + tcg_target_ulong d1, tcg_target_ulong d2, + tcg_target_ulong d3) +{ + TCGLabelPoolData *n = new_pool_alloc(s, 4, rtype, label, addend); + n->data[0] = d0; + n->data[1] = d1; + n->data[2] = d2; + n->data[3] = d3; + new_pool_insert(s, n); +} + +/* For v256, for 32-bit host. */ +static inline void new_pool_l8(TCGContext *s, int rtype, tcg_insn_unit *label, + int addend, tcg_target_ulong d0, + tcg_target_ulong d1, tcg_target_ulong d2, + tcg_target_ulong d3, tcg_target_ulong d4, + tcg_target_ulong d5, tcg_target_ulong d6, + tcg_target_ulong d7) +{ + TCGLabelPoolData *n = new_pool_alloc(s, 8, rtype, label, addend); + n->data[0] = d0; + n->data[1] = d1; + n->data[2] = d2; + n->data[3] = d3; + n->data[4] = d4; + n->data[5] = d5; + n->data[6] = d6; + n->data[7] = d7; + new_pool_insert(s, n); +} + /* To be provided by cpu/tcg-target.inc.c. */ static void tcg_out_nop_fill(tcg_insn_unit *p, int count); static bool tcg_out_pool_finalize(TCGContext *s) { TCGLabelPoolData *p = s->pool_labels; - tcg_target_ulong d, *a; + TCGLabelPoolData *l = NULL; + void *a; if (p == NULL) { return true; @@ -62,24 +133,24 @@ static bool tcg_out_pool_finalize(TCGContext *s) /* ??? Round up to qemu_icache_linesize, but then do not round again when allocating the next TranslationBlock structure. */ - a = (void *)ROUND_UP((uintptr_t)s->code_ptr, sizeof(tcg_target_ulong)); + a = (void *)ROUND_UP((uintptr_t)s->code_ptr, + sizeof(tcg_target_ulong) * p->nlong); tcg_out_nop_fill(s->code_ptr, (tcg_insn_unit *)a - s->code_ptr); s->data_gen_ptr = a; - /* Ensure the first comparison fails. */ - d = p->data + 1; - for (; p != NULL; p = p->next) { - if (p->data != d) { - d = p->data; - if (unlikely((void *)a > s->code_gen_highwater)) { + size_t size = sizeof(tcg_target_ulong) * p->nlong; + if (!l || l->nlong != p->nlong || memcmp(l->data, p->data, size)) { + if (unlikely(a > s->code_gen_highwater)) { return false; } - *a++ = d; + memcpy(a, p->data, size); + a += size; + l = p; } - patch_reloc(p->label, p->type, (intptr_t)(a - 1), p->addend); + patch_reloc(p->label, p->rtype, (intptr_t)a - size, p->addend); } - s->code_ptr = (void *)a; + s->code_ptr = a; return true; }