From patchwork Tue Nov 21 21:25:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 119409 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5816274qgn; Tue, 21 Nov 2017 13:33:33 -0800 (PST) X-Google-Smtp-Source: AGs4zMZc80Bil+U3kLOWnIE/oI7XelHLu2FhmY9uET+v3uUIg2Q0AIZXxpUjKUDBBgoQ3idT/7OA X-Received: by 10.13.234.195 with SMTP id t186mr11834124ywe.326.1511300013374; Tue, 21 Nov 2017 13:33:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511300013; cv=none; d=google.com; s=arc-20160816; b=TtVwkstcxigmuee08B8i6rHxCqPCLNSxhmzbWygUU2RyBK+bt+Kv5/z4Z4k5jj1y0Q 8xbsZI4CYCTimHzoh8pG3K9mgdIzhrRv0l+y+9f7e2/9DvsQVQkxnixspbc9WNLJFZ/w zqHRk34lz8uyrmtmB3sVGEBAkQQ3tcKEThEyeB6kyAUwM6SC1F21yFexzQqwBvF34J99 4C1c2J/dbSI/4DYohLGd8cgZMDVHM3OR2DrrrdCeYfO9DdipFYWycZE3hQH/LEwe06Wb fQ3W3sIYAxW62IJiBEyh3Cr7GGL2JzAoWTKSkmEdbZRz3rX/EZXVNi3KVS8xPEN0EYcS I1fA== 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:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=btHN6BlYfEMHw/3KsRDCBldcyv8BDSFRKPzXoGS7RHA=; b=W4eduaG8WKan9ddzhNoaQ2I45oaShFjGm16c5v/0LAFmAxqdxvpdILFjXj66LywmOE SIkJylJwS94KFb5dJE5xohm8gAVmM8VYLNkNqzBXWExngN4T6vU5iN84h0uCnMgJ+xIG VXWHrdYIboFptFdmS88DlEDDpA3JqTrRVbNt/Ap+aVYXu8Fprhwd7AIXtgiI+eYhPjT7 vHnHmP1o1sOSMSd8sIdJITZFZFXrlQt1VY0wCvlU/j30bVywbVmxrpYGURN5GvJ2RPyK txxo0HQlOi1g9VjdHhffDge4bTzXTu4TGWNnE07NWzj4dTR6QN5Nt12UzOpZf0AJzdsW rzOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Vah0ub7s; 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 n66si3151748ybn.48.2017.11.21.13.33.33 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 21 Nov 2017 13:33:33 -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=Vah0ub7s; 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]:36602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHGAe-0000Ou-QQ for patch@linaro.org; Tue, 21 Nov 2017 16:33:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHG54-0004J8-QM for qemu-devel@nongnu.org; Tue, 21 Nov 2017 16:27:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eHG53-0007fT-GX for qemu-devel@nongnu.org; Tue, 21 Nov 2017 16:27:46 -0500 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:42741) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eHG53-0007ez-7y for qemu-devel@nongnu.org; Tue, 21 Nov 2017 16:27:45 -0500 Received: by mail-wm0-x243.google.com with SMTP id l188so4522980wma.1 for ; Tue, 21 Nov 2017 13:27:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=btHN6BlYfEMHw/3KsRDCBldcyv8BDSFRKPzXoGS7RHA=; b=Vah0ub7sAwA2RojUccd7K0ErmiRDPoTVusby4r/gZyciin0QG94bQIfZEtHOrgy2M8 K6xfN12559Kch+ca6HjfMUTf3vB835FAeo09cm0T+8UTUP7XNvZyT6EmDXRkTc4g6OWc qEK85+WDm0CLon6lynOyVMBpsKMD8gj+9NyAw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=btHN6BlYfEMHw/3KsRDCBldcyv8BDSFRKPzXoGS7RHA=; b=MBO7IVK0lCWkIyAS6GZxlU4ltr4+OUAmLFBSGrO+uoXLO4JLolZFr8dJXxAg9KEwv6 PqaFgOmEHd06E5cAj0SpPjeAHBxAitDzgsKE/eAcRhzshBKOzTO0r9FtPbcm4Vtsffgq PM4Vfqdb3WynlN86wJGExhWB9zG7kOd9uxOc+QL39USeIqW9ixZBzUdOCnX/4L0K9VUr 8NJ+jVIjSBWQG5UzFhFb9fIVC4VUJdwAQARt6d1xqspcQlF90Mr08O3uNI33L2/bCzdN x1J20i2VGNrvv2GPD1v497Okebj5KTMzGFA1f+H3zpzSv/A9V5u3lBdIqEzH5PqM1c5z 6zLQ== X-Gm-Message-State: AJaThX5ZVt8bmvLdLV4kySWznkwknZuWuYACVLEq3/MKWmEQHzYt0eLy OsNI28aXJQxUWpAbMVxlP23BHS5Nxkc= X-Received: by 10.28.73.193 with SMTP id w184mr2397763wma.3.1511299664002; Tue, 21 Nov 2017 13:27:44 -0800 (PST) Received: from cloudburst.twiddle.net (70.red-37-158-60.dynamicip.rima-tde.net. [37.158.60.70]) by smtp.gmail.com with ESMTPSA id e124sm706517wmg.34.2017.11.21.13.27.43 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Nov 2017 13:27:43 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 21 Nov 2017 22:25:14 +0100 Message-Id: <20171121212534.5177-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171121212534.5177-1-richard.henderson@linaro.org> References: <20171121212534.5177-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PATCH v6 06/26] 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This will be required for storing vector constants. Signed-off-by: Richard Henderson --- tcg/tcg-pool.inc.c | 115 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 93 insertions(+), 22 deletions(-) -- 2.13.6 diff --git a/tcg/tcg-pool.inc.c b/tcg/tcg-pool.inc.c index 8a85131405..0f76e7bee3 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; + int addend : 32; + int rtype : 16; + int nlong : 16; + 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; }