From patchwork Sat Feb 6 00:09: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: 8240641 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 461469F4DD for ; Sat, 6 Feb 2016 00:10:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9FE6F203B1 for ; Sat, 6 Feb 2016 00:10:49 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id BB289203C0 for ; Sat, 6 Feb 2016 00:10:48 +0000 (UTC) Received: from localhost ([::1]:50966 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRqSd-00086N-UY for patchwork-qemu-devel@patchwork.kernel.org; Fri, 05 Feb 2016 19:10:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56332) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRqSE-0007xU-RF for qemu-devel@nongnu.org; Fri, 05 Feb 2016 19:10:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aRqS9-0006sk-UD for qemu-devel@nongnu.org; Fri, 05 Feb 2016 19:10:22 -0500 Received: from mail-qk0-x22f.google.com ([2607:f8b0:400d:c09::22f]:35309) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRqS9-0006sf-Pp for qemu-devel@nongnu.org; Fri, 05 Feb 2016 19:10:17 -0500 Received: by mail-qk0-x22f.google.com with SMTP id o6so40839436qkc.2 for ; Fri, 05 Feb 2016 16:10:17 -0800 (PST) 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=uwgeLBFD3LYyojSjzJD139LuV591WrGJhBHnBl+YnCs=; b=kpAASwON9RY6rf98kCT1Oh5SctVXkHaHkn1ycR5wmTwalJxS+wFBHJwLIFwGW4mgMD xG76M0YxQFA75aZW9he+RnRpy7RJa5uTpe1XYEb4ii8QHfacFIvRLTIhwVAiBIk65Jxr PhzCzQCB3unuTH0W92aSG8lc3lFF0ePvzApmOLs+2dndwttCUkoafn06veGX1BbDMCdU BQPsfIT5Q/tMd9QGv9Aq3fN8vrOlRajPiquoK+h3LpOW1XZprOt//6qOF2RiPRyYe53p lFaM44QkryanEUKdnedwu7v3Jz0nsE4Y5YZflXqWhC/8GsoOLEozTo6fY86bTuSpNCL6 m7Xg== 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=uwgeLBFD3LYyojSjzJD139LuV591WrGJhBHnBl+YnCs=; b=iG+7DmcOomF4R6wjkWwf4Ts9HJA3RE+dtzlHJxjbBd256nvq5nKLmJNuL4xOg3Mc7G 1cdDO3Ll7xN+Q1zimEpJgWazn3wJvrrbZVRTxxzxZ9dyDAMZVHvDsnMzwwNvboUNpxmc GwvwBYGI9iv6XeE10RhW9nKZiQ52oxVg/xB3cF0zSBC5XlBGqnf2ZWuSjEF2NzYQgAKC GjktLdBOE7Kl933OC5hEAOnsCvI0Cc77AxU5i2AJM4599V4gUsvC6bGYOCvqXwYtmgTD IELilsyXPzHZow4kifUo5kZ7Xtnray+L66ergZZvduJ752ZQfYpoJG+4tGLpIcVcZqsj tz/Q== X-Gm-Message-State: AG10YOQRsNP8+HtZt/bCCZijT5A9Xz4Cbd/HCqmRHPNCMeHqwttuWQINrBhBBxvGnn2RQw== X-Received: by 10.55.81.2 with SMTP id f2mr20171397qkb.87.1454717417609; Fri, 05 Feb 2016 16:10:17 -0800 (PST) Received: from bigtime.com ([1.129.57.172]) by smtp.gmail.com with ESMTPSA id w66sm9079564qhc.15.2016.02.05.16.10.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Feb 2016 16:10:17 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 6 Feb 2016 11:09:23 +1100 Message-Id: <1454717370-17516-6-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1454717370-17516-1-git-send-email-rth@twiddle.net> References: <1454717370-17516-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:400d:c09::22f Cc: peter.maydell@linaro.org Subject: [Qemu-devel] [PULL 05/12] tcg: Tidy temporary allocation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In particular, make sure the memory is memset before use. Continues the increased use of TCGTemp pointers instead of integer indices where appropriate. Reviewed-by: Aurelien Jarno Signed-off-by: Richard Henderson --- tcg/tcg.c | 123 ++++++++++++++++++++++++++++---------------------------------- 1 file changed, 56 insertions(+), 67 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index ae59f60..9a836c9 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -426,32 +426,45 @@ void tcg_func_start(TCGContext *s) s->be = tcg_malloc(sizeof(TCGBackendData)); } -static inline void tcg_temp_alloc(TCGContext *s, int n) +static inline int temp_idx(TCGContext *s, TCGTemp *ts) { - if (n > TCG_MAX_TEMPS) - tcg_abort(); + ptrdiff_t n = ts - s->temps; + tcg_debug_assert(n >= 0 && n < s->nb_temps); + return n; +} + +static inline TCGTemp *tcg_temp_alloc(TCGContext *s) +{ + int n = s->nb_temps++; + tcg_debug_assert(n < TCG_MAX_TEMPS); + return memset(&s->temps[n], 0, sizeof(TCGTemp)); +} + +static inline TCGTemp *tcg_global_alloc(TCGContext *s) +{ + tcg_debug_assert(s->nb_globals == s->nb_temps); + s->nb_globals++; + return tcg_temp_alloc(s); } static int tcg_global_reg_new_internal(TCGContext *s, TCGType type, int reg, const char *name) { TCGTemp *ts; - int idx; if (TCG_TARGET_REG_BITS == 32 && type != TCG_TYPE_I32) { tcg_abort(); } - idx = s->nb_globals; - tcg_temp_alloc(s, s->nb_globals + 1); - ts = &s->temps[s->nb_globals]; + + ts = tcg_global_alloc(s); ts->base_type = type; ts->type = type; ts->fixed_reg = 1; ts->reg = reg; ts->name = name; - s->nb_globals++; tcg_regset_set_reg(s->reserved_regs, reg); - return idx; + + return temp_idx(s, ts); } void tcg_set_frame(TCGContext *s, int reg, intptr_t start, intptr_t size) @@ -491,63 +504,47 @@ int tcg_global_mem_new_internal(TCGType type, TCGv_ptr base, intptr_t offset, const char *name) { TCGContext *s = &tcg_ctx; - TCGTemp *ts, *base_ts = &s->temps[GET_TCGV_PTR(base)]; - int idx; + TCGTemp *base_ts = &s->temps[GET_TCGV_PTR(base)]; + TCGTemp *ts = tcg_global_alloc(s); + int bigendian = 0; +#ifdef HOST_WORDS_BIGENDIAN + bigendian = 1; +#endif - idx = s->nb_globals; -#if TCG_TARGET_REG_BITS == 32 - if (type == TCG_TYPE_I64) { + if (TCG_TARGET_REG_BITS == 32 && type == TCG_TYPE_I64) { + TCGTemp *ts2 = tcg_global_alloc(s); char buf[64]; - tcg_temp_alloc(s, s->nb_globals + 2); - ts = &s->temps[s->nb_globals]; - ts->base_type = type; + + ts->base_type = TCG_TYPE_I64; ts->type = TCG_TYPE_I32; - ts->fixed_reg = 0; ts->mem_allocated = 1; ts->mem_base = base_ts; -#ifdef HOST_WORDS_BIGENDIAN - ts->mem_offset = offset + 4; -#else - ts->mem_offset = offset; -#endif + ts->mem_offset = offset + bigendian * 4; pstrcpy(buf, sizeof(buf), name); pstrcat(buf, sizeof(buf), "_0"); ts->name = strdup(buf); - ts++; - ts->base_type = type; - ts->type = TCG_TYPE_I32; - ts->fixed_reg = 0; - ts->mem_allocated = 1; - ts->mem_base = base_ts; -#ifdef HOST_WORDS_BIGENDIAN - ts->mem_offset = offset; -#else - ts->mem_offset = offset + 4; -#endif + tcg_debug_assert(ts2 == ts + 1); + ts2->base_type = TCG_TYPE_I64; + ts2->type = TCG_TYPE_I32; + ts2->mem_allocated = 1; + ts2->mem_base = base_ts; + ts2->mem_offset = offset + (1 - bigendian) * 4; pstrcpy(buf, sizeof(buf), name); pstrcat(buf, sizeof(buf), "_1"); ts->name = strdup(buf); - - s->nb_globals += 2; - } else -#endif - { - tcg_temp_alloc(s, s->nb_globals + 1); - ts = &s->temps[s->nb_globals]; + } else { ts->base_type = type; ts->type = type; - ts->fixed_reg = 0; ts->mem_allocated = 1; ts->mem_base = base_ts; ts->mem_offset = offset; ts->name = name; - s->nb_globals++; } - return idx; + return temp_idx(s, ts); } -static inline int tcg_temp_new_internal(TCGType type, int temp_local) +static int tcg_temp_new_internal(TCGType type, int temp_local) { TCGContext *s = &tcg_ctx; TCGTemp *ts; @@ -561,38 +558,30 @@ static inline int tcg_temp_new_internal(TCGType type, int temp_local) ts = &s->temps[idx]; ts->temp_allocated = 1; - assert(ts->base_type == type); - assert(ts->temp_local == temp_local); + tcg_debug_assert(ts->base_type == type); + tcg_debug_assert(ts->temp_local == temp_local); } else { - idx = s->nb_temps; -#if TCG_TARGET_REG_BITS == 32 - if (type == TCG_TYPE_I64) { - tcg_temp_alloc(s, s->nb_temps + 2); - ts = &s->temps[s->nb_temps]; - ts->base_type = type; - ts->type = TCG_TYPE_I32; - ts->temp_allocated = 1; - ts->temp_local = temp_local; - ts->name = NULL; - ts++; + ts = tcg_temp_alloc(s); + if (TCG_TARGET_REG_BITS == 32 && type == TCG_TYPE_I64) { + TCGTemp *ts2 = tcg_temp_alloc(s); + ts->base_type = type; ts->type = TCG_TYPE_I32; ts->temp_allocated = 1; ts->temp_local = temp_local; - ts->name = NULL; - s->nb_temps += 2; - } else -#endif - { - tcg_temp_alloc(s, s->nb_temps + 1); - ts = &s->temps[s->nb_temps]; + + tcg_debug_assert(ts2 == ts + 1); + ts2->base_type = TCG_TYPE_I64; + ts2->type = TCG_TYPE_I32; + ts2->temp_allocated = 1; + ts2->temp_local = temp_local; + } else { ts->base_type = type; ts->type = type; ts->temp_allocated = 1; ts->temp_local = temp_local; - ts->name = NULL; - s->nb_temps++; } + idx = temp_idx(s, ts); } #if defined(CONFIG_DEBUG_TCG)