Received: from eggs.gnu.org ([2001:4830:134:3::10]:52719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c76Fe-0000m4-KM for qemu-devel@nongnu.org; Wed, 16 Nov 2016 14:52:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c76Fc-00076c-1u for qemu-devel@nongnu.org; Wed, 16 Nov 2016 14:52:10 -0500 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:33922) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c76Fb-00075y-T3 for qemu-devel@nongnu.org; Wed, 16 Nov 2016 14:52:08 -0500 Received: by mail-wm0-x242.google.com with SMTP id g23so14616880wme.1 for ; Wed, 16 Nov 2016 11:52:07 -0800 (PST) Sender: Richard Henderson From: Richard Henderson Date: Wed, 16 Nov 2016 20:51:41 +0100 Message-Id: <1479325910-9060-6-git-send-email-rth@twiddle.net> In-Reply-To: <1479325910-9060-1-git-send-email-rth@twiddle.net> References: <1479325910-9060-1-git-send-email-rth@twiddle.net> Subject: [Qemu-devel] [RFC 05/14] tcg: Avoid loops against variable bounds List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aurelien@aurel32.net, peter.maydell@linaro.org Copy s->nb_globals or s->nb_temps to a local variable for the purposes of iteration. This should allow the compiler to use low-overhead looping constructs on some hosts. Signed-off-by: Richard Henderson --- tcg/tcg.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index b186b38..840c8b5 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -882,23 +882,16 @@ void tcg_gen_callN(TCGContext *s, void *func, TCGArg ret, static void tcg_reg_alloc_start(TCGContext *s) { - int i; + int i, n; TCGTemp *ts; - for(i = 0; i < s->nb_globals; i++) { + + for (i = 0, n = s->nb_globals; i < n; i++) { ts = &s->temps[i]; - if (ts->fixed_reg) { - ts->val_type = TEMP_VAL_REG; - } else { - ts->val_type = TEMP_VAL_MEM; - } + ts->val_type = (ts->fixed_reg ? TEMP_VAL_REG : TEMP_VAL_MEM); } - for(i = s->nb_globals; i < s->nb_temps; i++) { + for (n = s->nb_temps; i < n; i++) { ts = &s->temps[i]; - if (ts->temp_local) { - ts->val_type = TEMP_VAL_MEM; - } else { - ts->val_type = TEMP_VAL_DEAD; - } + ts->val_type = (ts->temp_local ? TEMP_VAL_MEM : TEMP_VAL_DEAD); ts->mem_allocated = 0; ts->fixed_reg = 0; } @@ -2046,9 +2039,9 @@ static void temp_save(TCGContext *s, TCGTemp *ts, TCGRegSet allocated_regs) temporary registers needs to be allocated to store a constant. */ static void save_globals(TCGContext *s, TCGRegSet allocated_regs) { - int i; + int i, n; - for (i = 0; i < s->nb_globals; i++) { + for (i = 0, n = s->nb_globals; i < n; i++) { temp_save(s, &s->temps[i], allocated_regs); } } @@ -2058,9 +2051,9 @@ static void save_globals(TCGContext *s, TCGRegSet allocated_regs) temporary registers needs to be allocated to store a constant. */ static void sync_globals(TCGContext *s, TCGRegSet allocated_regs) { - int i; + int i, n; - for (i = 0; i < s->nb_globals; i++) { + for (i = 0, n = s->nb_globals; i < n; i++) { TCGTemp *ts = &s->temps[i]; tcg_debug_assert(ts->val_type != TEMP_VAL_REG || ts->fixed_reg -- 2.7.4