From patchwork Fri Jun 24 03:48:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 9196509 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D655E60871 for ; Fri, 24 Jun 2016 04:03:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C81A928476 for ; Fri, 24 Jun 2016 04:03:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BACD528488; Fri, 24 Jun 2016 04:03:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9BC1028476 for ; Fri, 24 Jun 2016 04:03:53 +0000 (UTC) Received: from localhost ([::1]:40624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGILQ-00066f-RC for patchwork-qemu-devel@patchwork.kernel.org; Fri, 24 Jun 2016 00:03:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGI6j-0007a9-L7 for qemu-devel@nongnu.org; Thu, 23 Jun 2016 23:48:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bGI6c-0001oK-DK for qemu-devel@nongnu.org; Thu, 23 Jun 2016 23:48:40 -0400 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:35220) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGI6c-0001o8-2H for qemu-devel@nongnu.org; Thu, 23 Jun 2016 23:48:34 -0400 Received: by mail-pf0-x243.google.com with SMTP id t190so8139115pfb.2 for ; Thu, 23 Jun 2016 20:48:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=OvjML/h1qH658m5TtssPxrTqxctxJX4FD1+d/oHNjtw=; b=gSGhqn+Xc/KMKcRNBhKCsDBGfhbuhz3dLDhx5cFCC94agw7ME00KqwDYISGX/g7MIX wE6Oh5Rn+Gy+o8D/Nfm9w6z25hUO1xR//jZrlpzn8liT8roA2AzEHl8iHVaAntwmbpco iP61Fs+YzA75g6le2XUlYvTUVFxFLIDAZYuS5+3sc6cMcPxxEv/ZuP2GLM+jQ2X20Y2J ck2DByhgnTQDxw5GnCt5dhrTZjknjTI00lkWqTdqlKB9nl5gOaoF5m0jq5RcKNq+ze5+ hTdAHX5NvtigUWsRRwq84CTFsCifg2plEhBhZrDgaYCFq8DL9/Vi33Pt6TvzqMhPwFxB adGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=OvjML/h1qH658m5TtssPxrTqxctxJX4FD1+d/oHNjtw=; b=hy/Zq+lSab2uDHPJ5bWeehkt5TzHxf8NWl13EpGWxyMn8HLHYGEaR5DGSj6uwXQwfT V89l0AKNjW1yBoOVBuQNgtDmK21ThgBPQ2sjPPVFLD+UJ8VOw9UnFCQcdT+zWo04v5rc IfUIlG0A8/iw/rAcyb4mDMCxs0y2E5m7jQMmaEOg9cHhf2ui0HL/aTyGPVkBkKxG/UyQ cHKMEXDqvPOdZNCq5TZNT8f4+hyCVZ8izQ3e+YqNyD5kU5bbVFZpywyMXSlX/Bf32mlo 9+qAT4L/rIK3OzrxRP5oVYaCF0ONOwZmdI3jCPLYHeB3Zxwt4UXLRrItSA0siaNB82qG KYUQ== X-Gm-Message-State: ALyK8tItKnNkV9oEqUXKlM9XiFO6HCaaoseFKrSPdLaLgFwy23HsUb6UeDDI9OCeAAm6vg== X-Received: by 10.98.68.152 with SMTP id m24mr3345275pfi.35.1466740113236; Thu, 23 Jun 2016 20:48:33 -0700 (PDT) Received: from pike.twiddle.net (71-37-54-227.tukw.qwest.net. [71.37.54.227]) by smtp.gmail.com with ESMTPSA id p129sm3309134pfb.73.2016.06.23.20.48.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Jun 2016 20:48:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 23 Jun 2016 20:48:23 -0700 Message-Id: <1466740107-15042-6-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1466740107-15042-1-git-send-email-rth@twiddle.net> References: <1466740107-15042-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::243 Subject: [Qemu-devel] [PATCH v3 5/9] tcg: Reorg TCGOp chaining 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: mark.cave-ayland@ilande.co.uk, atar4qemu@gmail.com, aurelien@aurel32.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Instead of using -1 as end of chain, use 0, and link through the 0 entry as a fully circular double-linked list. Signed-off-by: Richard Henderson --- include/exec/gen-icount.h | 2 +- tcg/optimize.c | 8 ++------ tcg/tcg-op.c | 2 +- tcg/tcg.c | 32 ++++++++++++-------------------- tcg/tcg.h | 20 ++++++++++++-------- 5 files changed, 28 insertions(+), 36 deletions(-) diff --git a/include/exec/gen-icount.h b/include/exec/gen-icount.h index a011324..5f16077 100644 --- a/include/exec/gen-icount.h +++ b/include/exec/gen-icount.h @@ -59,7 +59,7 @@ static void gen_tb_end(TranslationBlock *tb, int num_insns) } /* Terminate the linked list. */ - tcg_ctx.gen_op_buf[tcg_ctx.gen_last_op_idx].next = -1; + tcg_ctx.gen_op_buf[tcg_ctx.gen_op_buf[0].prev].next = 0; } static inline void gen_io_start(void) diff --git a/tcg/optimize.c b/tcg/optimize.c index c0d975b..8df7fc7 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -103,11 +103,7 @@ static TCGOp *insert_op_before(TCGContext *s, TCGOp *old_op, .prev = prev, .next = next }; - if (prev >= 0) { - s->gen_op_buf[prev].next = oi; - } else { - s->gen_first_op_idx = oi; - } + s->gen_op_buf[prev].next = oi; old_op->prev = oi; return new_op; @@ -583,7 +579,7 @@ void tcg_optimize(TCGContext *s) nb_globals = s->nb_globals; reset_all_temps(nb_temps); - for (oi = s->gen_first_op_idx; oi >= 0; oi = oi_next) { + for (oi = s->gen_op_buf[0].next; oi != 0; oi = oi_next) { tcg_target_ulong mask, partmask, affected; int nb_oargs, nb_iargs, i; TCGArg tmp; diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c index 569cdc6..62d91b4 100644 --- a/tcg/tcg-op.c +++ b/tcg/tcg-op.c @@ -52,7 +52,7 @@ static void tcg_emit_op(TCGContext *ctx, TCGOpcode opc, int args) int pi = oi - 1; tcg_debug_assert(oi < OPC_BUF_SIZE); - ctx->gen_last_op_idx = oi; + ctx->gen_op_buf[0].prev = oi; ctx->gen_next_op_idx = ni; ctx->gen_op_buf[oi] = (TCGOp){ diff --git a/tcg/tcg.c b/tcg/tcg.c index 400e69c..bb1efe2 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -437,9 +437,9 @@ void tcg_func_start(TCGContext *s) s->goto_tb_issue_mask = 0; #endif - s->gen_first_op_idx = 0; - s->gen_last_op_idx = -1; - s->gen_next_op_idx = 0; + s->gen_op_buf[0].next = 1; + s->gen_op_buf[0].prev = 0; + s->gen_next_op_idx = 1; s->gen_next_parm_idx = 0; s->be = tcg_malloc(sizeof(TCGBackendData)); @@ -868,7 +868,7 @@ void tcg_gen_callN(TCGContext *s, void *func, TCGArg ret, /* Make sure the calli field didn't overflow. */ tcg_debug_assert(s->gen_op_buf[i].calli == real_args); - s->gen_last_op_idx = i; + s->gen_op_buf[0].prev = i; s->gen_next_op_idx = i + 1; s->gen_next_parm_idx = pi; @@ -1004,7 +1004,7 @@ void tcg_dump_ops(TCGContext *s) TCGOp *op; int oi; - for (oi = s->gen_first_op_idx; oi >= 0; oi = op->next) { + for (oi = s->gen_op_buf[0].next; oi != 0; oi = op->next) { int i, k, nb_oargs, nb_iargs, nb_cargs; const TCGOpDef *def; const TCGArg *args; @@ -1016,7 +1016,7 @@ void tcg_dump_ops(TCGContext *s) args = &s->gen_opparam_buf[op->args]; if (c == INDEX_op_insn_start) { - qemu_log("%s ----", oi != s->gen_first_op_idx ? "\n" : ""); + qemu_log("%s ----", oi != s->gen_op_buf[0].next ? "\n" : ""); for (i = 0; i < TARGET_INSN_START_WORDS; ++i) { target_ulong a; @@ -1287,18 +1287,10 @@ void tcg_op_remove(TCGContext *s, TCGOp *op) int next = op->next; int prev = op->prev; - if (next >= 0) { - s->gen_op_buf[next].prev = prev; - } else { - s->gen_last_op_idx = prev; - } - if (prev >= 0) { - s->gen_op_buf[prev].next = next; - } else { - s->gen_first_op_idx = next; - } + s->gen_op_buf[next].prev = prev; + s->gen_op_buf[prev].next = next; - memset(op, -1, sizeof(*op)); + memset(op, 0, sizeof(*op)); #ifdef CONFIG_PROFILER s->del_op_count++; @@ -1344,7 +1336,7 @@ static void tcg_liveness_analysis(TCGContext *s) mem_temps = tcg_malloc(s->nb_temps); tcg_la_func_end(s, dead_temps, mem_temps); - for (oi = s->gen_last_op_idx; oi >= 0; oi = oi_prev) { + for (oi = s->gen_op_buf[0].prev; oi != 0; oi = oi_prev) { int i, nb_iargs, nb_oargs; TCGOpcode opc_new, opc_new2; bool have_opc_new2; @@ -2321,7 +2313,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) { int n; - n = s->gen_last_op_idx + 1; + n = s->gen_op_buf[0].prev + 1; s->op_count += n; if (n > s->op_count_max) { s->op_count_max = n; @@ -2380,7 +2372,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) tcg_out_tb_init(s); num_insns = -1; - for (oi = s->gen_first_op_idx; oi >= 0; oi = oi_next) { + for (oi = s->gen_op_buf[0].next; oi != 0; oi = oi_next) { TCGOp * const op = &s->gen_op_buf[oi]; TCGArg * const args = &s->gen_opparam_buf[op->args]; TCGOpcode opc = op->opc; diff --git a/tcg/tcg.h b/tcg/tcg.h index cc14560..49b396d 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -520,17 +520,21 @@ typedef struct TCGOp { unsigned callo : 2; unsigned calli : 6; - /* Index of the arguments for this op, or -1 for zero-operand ops. */ - signed args : 16; + /* Index of the arguments for this op, or 0 for zero-operand ops. */ + unsigned args : 16; - /* Index of the prex/next op, or -1 for the end of the list. */ - signed prev : 16; - signed next : 16; + /* Index of the prex/next op, or 0 for the end of the list. */ + unsigned prev : 16; + unsigned next : 16; } TCGOp; -QEMU_BUILD_BUG_ON(NB_OPS > 0xff); -QEMU_BUILD_BUG_ON(OPC_BUF_SIZE >= 0x7fff); -QEMU_BUILD_BUG_ON(OPPARAM_BUF_SIZE >= 0x7fff); +/* Make sure operands fit in the bitfields above. */ +QEMU_BUILD_BUG_ON(NB_OPS > (1 << 8)); +QEMU_BUILD_BUG_ON(OPC_BUF_SIZE > (1 << 16)); +QEMU_BUILD_BUG_ON(OPPARAM_BUF_SIZE > (1 << 16)); + +/* Make sure that we don't overflow 64 bits without noticing. */ +QEMU_BUILD_BUG_ON(sizeof(TCGOp) > 8); struct TCGContext { uint8_t *pool_cur, *pool_end;