From patchwork Fri Jan 11 23:42:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 211456 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A17A82C035A for ; Sat, 12 Jan 2013 10:43:33 +1100 (EST) Received: from localhost ([::1]:36816 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TtoG3-0004JL-Qm for incoming@patchwork.ozlabs.org; Fri, 11 Jan 2013 18:43:31 -0500 Received: from eggs.gnu.org ([208.118.235.92]:53246) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TtoFd-000467-DS for qemu-devel@nongnu.org; Fri, 11 Jan 2013 18:43:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TtoFY-0004KM-4U for qemu-devel@nongnu.org; Fri, 11 Jan 2013 18:43:05 -0500 Received: from mail-qc0-f169.google.com ([209.85.216.169]:55185) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TtoFX-0004KI-Vl for qemu-devel@nongnu.org; Fri, 11 Jan 2013 18:43:00 -0500 Received: by mail-qc0-f169.google.com with SMTP id t2so1489404qcq.28 for ; Fri, 11 Jan 2013 15:42:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=w3IYYmOh1kGaJAlqlfKJTqf/QeBwPCThgsI/EcgJznU=; b=u5ms3N9TZE+Us79T/rK44Sn0i4jmnpYFxwtaXRGzao0wHCDgKNMUfV76gERMt56Fs3 31S8SrQdbG6aypXyG1CDlSMpPyXCSYAkKJqtZmBbABsmQI1HyEXmWx3pEhydkWJtfI3y Xd4A+chQdvHUWntEwKUMZDWfJkvLY51K97opA1eZ++JSZ33I5r3YtNNaP53FP1owZaxO g0qOBm6iSCn1b71iTdWSTQ6VZ4kct9QUnIO/Dc8/PDlBuABjToUsCazlrjxS5QlQF/mq qsamHy8katLorZ6nlIhcm49jrpni4bSRHxtH0lOe1lHXgSdlxLGVbG4OPu5LsuJuyKvi ur/A== X-Received: by 10.49.48.113 with SMTP id k17mr74898362qen.51.1357947779502; Fri, 11 Jan 2013 15:42:59 -0800 (PST) Received: from anchor.twiddle.home.com (50-194-63-110-static.hfc.comcastbusiness.net. [50.194.63.110]) by mx.google.com with ESMTPS id ff4sm4767977qab.10.2013.01.11.15.42.57 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 11 Jan 2013 15:42:58 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 11 Jan 2013 15:42:51 -0800 Message-Id: <1357947773-31051-2-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1357947773-31051-1-git-send-email-rth@twiddle.net> References: <1357947773-31051-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.216.169 Cc: Paolo Bonzini , Aurelien Jarno Subject: [Qemu-devel] [PATCH 1/3] optimize: only write to state when clearing optimizer data 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Paolo Bonzini The next patch will add to the TCG optimizer a field that should be non-zero in the default case. Thus, replace the memset of the temps array with a loop. Only the state field has to be up-to-date, because others are not used except if the state is TCG_TEMP_COPY or TCG_TEMP_CONST. [rth: Extracted the loop to a function.] Signed-off-by: Paolo Bonzini Signed-off-by: Richard Henderson --- tcg/optimize.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index 9109b81..9d05a72 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -65,6 +65,15 @@ static void reset_temp(TCGArg temp) temps[temp].state = TCG_TEMP_UNDEF; } +/* Reset all temporaries, given that there are NB_TEMPS of them. */ +static void reset_all_temps(int nb_temps) +{ + int i; + for (i = 0; i < nb_temps; i++) { + temps[i].state = TCG_TEMP_UNDEF; + } +} + static int op_bits(TCGOpcode op) { const TCGOpDef *def = &tcg_op_defs[op]; @@ -482,7 +491,7 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, nb_temps = s->nb_temps; nb_globals = s->nb_globals; - memset(temps, 0, nb_temps * sizeof(struct tcg_temp_info)); + reset_all_temps(nb_temps); nb_ops = tcg_opc_ptr - s->gen_opc_buf; gen_args = args; @@ -768,7 +777,7 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, tmp = do_constant_folding_cond(op, args[0], args[1], args[2]); if (tmp != 2) { if (tmp) { - memset(temps, 0, nb_temps * sizeof(struct tcg_temp_info)); + reset_all_temps(nb_temps); s->gen_opc_buf[op_index] = INDEX_op_br; gen_args[0] = args[3]; gen_args += 1; @@ -861,7 +870,7 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, tmp = do_constant_folding_cond2(&args[0], &args[2], args[4]); if (tmp != 2) { if (tmp) { - memset(temps, 0, nb_temps * sizeof(struct tcg_temp_info)); + reset_all_temps(nb_temps); s->gen_opc_buf[op_index] = INDEX_op_br; gen_args[0] = args[5]; gen_args += 1; @@ -875,7 +884,7 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, && temps[args[3]].val == 0) { /* Simplify LT/GE comparisons vs zero to a single compare vs the high word of the input. */ - memset(temps, 0, nb_temps * sizeof(struct tcg_temp_info)); + reset_all_temps(nb_temps); s->gen_opc_buf[op_index] = INDEX_op_brcond_i32; gen_args[0] = args[1]; gen_args[1] = args[3]; @@ -940,7 +949,7 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, We trash everything if the operation is the end of a basic block, otherwise we only trash the output args. */ if (def->flags & TCG_OPF_BB_END) { - memset(temps, 0, nb_temps * sizeof(struct tcg_temp_info)); + reset_all_temps(nb_temps); } else { for (i = 0; i < def->nb_oargs; i++) { reset_temp(args[i]);