From patchwork Fri Oct 20 23:19:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 116546 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp2224119qgn; Fri, 20 Oct 2017 16:26:43 -0700 (PDT) X-Received: by 10.55.15.42 with SMTP id z42mr9423224qkg.181.1508542002997; Fri, 20 Oct 2017 16:26:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508542002; cv=none; d=google.com; s=arc-20160816; b=JNbqf09s1FfciMNZFJvCh+P1+9ZDVx5VC+QpZrvR5bTNfX+HubhHjUexSZ85MAX5/f fwNNx9QPznABHeeD99Ak44Tt+EtL1exIrYIivQZtKBZ7X6E7fXmm/5WBXul7m/G1KpqC hQeadPLM12aqaGX4AXDW23LvOeWBpBA42uih3FdpXLTOam6sJ5M1MkaelzaiGyvC46u0 BiQO9pmkMUnJrc5yMNVkvtZLWou7V92OPjHnEy81DpuKcZ1HYSqc8sK+WVgjIYhWEu2Z 0Gc7ewCDzDAkRDRo0VX1RnXx8DTcBB5uaZ5XLhDCCJrMIG4w9mq0E5bRUM1bwPODLnMe g4Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=6Cea3ZwIgqGR0ikYypu8xyy8LUMvO1iRCow79pbvw6Q=; b=eXY2PxUmNdj/VGaBOgc4toPs4wgDM8dMqYlGdtnTUXLqBF/OuVgOL3t58IeHG4D8lQ an2sdYHFNzb5Kq66CVUvo4c0joAqGAuNUBl0IpFEzvEfUT537tsY5oFzV4P44pVtsMId WOj5Hbcc3WAwXuxPJnSlsNsYWrgVoqs07okPIRqFhNnE7GnO+At/6hhm1hpHAVzDJQTL yvFoAxPQVNIhbZy0sVImK2mMCtSMTHdUcfFFSdIUOts1FYkRsP2hPm3VzVrywomusS1T O5EI1O6GCabiZjjXfkLpLeo+k7ALAyzsrICNdi09AArj1ko4I/uYWQNH18aNiaH8gVay 9eIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=c/N6lgm2; 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 e126si1641738qkd.77.2017.10.20.16.26.42 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 20 Oct 2017 16:26:42 -0700 (PDT) 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=c/N6lgm2; 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]:56002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5gga-0002cb-TD for patch@linaro.org; Fri, 20 Oct 2017 19:26:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5gap-0005uN-T0 for qemu-devel@nongnu.org; Fri, 20 Oct 2017 19:20:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e5gao-0007bF-Ud for qemu-devel@nongnu.org; Fri, 20 Oct 2017 19:20:43 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:47093) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e5gao-0007b1-OM for qemu-devel@nongnu.org; Fri, 20 Oct 2017 19:20:42 -0400 Received: by mail-pf0-x242.google.com with SMTP id p87so13073074pfj.3 for ; Fri, 20 Oct 2017 16:20:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6Cea3ZwIgqGR0ikYypu8xyy8LUMvO1iRCow79pbvw6Q=; b=c/N6lgm2EYcfKXCDCY+ePejf9oCBRpP8Rqufw7nIy0hrLyZ/skqEk61lpJhrJ4mFAA XryDpkiTLukU9oPiU4LqPk5YWf5HEBzaOdgh2pduzUY4xQZs2jRu9sf03Qddya07vGXS gV8T84WoHa8E1tz2OT5W6+iN35SR0nP+HOtb4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6Cea3ZwIgqGR0ikYypu8xyy8LUMvO1iRCow79pbvw6Q=; b=RV75gVmtcrchMYlzbga+aj8KayeOrzOqWcmKsDhi6FPskGAJnOdtvCXUf3ttVfCkzZ ofrdTWYvEA+j1LYM+qNTkTgQJxIoMBs439UqpgJcbE5olmK11Xjkqok0Q1HJmM50fzf0 hbmy7Qt+JuxGX3D1p7j4prsQc9rLSpccwc8QUHkjAUldJ0pGJvxIlw60uvr0hkB9FMtf Cr8ozafEQQkiUoMg/AUbc6q7ITYIH6upxqeb9hkzXe+qORYC3K8EFt0bZGX9HDB+QNll xpGK0B6WpnKmP8ZiHHFZBl9NZUlxMHcBS7gOqhsTJkB0RRrlAw67NUywedX6qyXcZiaG 7McA== X-Gm-Message-State: AMCzsaVTb4ENoQ5LV7naCrZOgKz5jOGSlTHIzNQnCDJ/awlVwqhkz8Pw 1g3aJlsZRdJabac1/sNE0u/HUQitsvU= X-Google-Smtp-Source: ABhQp+Rdwb3GVroXkEKajvjyytRxn7QPD1wyNVTX0bcF8kxb9C0NOCpcHiHtC3+2VuJYTUo1hhcchw== X-Received: by 10.84.162.204 with SMTP id o12mr5212172plg.230.1508541641549; Fri, 20 Oct 2017 16:20:41 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-165-104.tukw.qwest.net. [97.113.165.104]) by smtp.gmail.com with ESMTPSA id a17sm3532594pfk.173.2017.10.20.16.20.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Oct 2017 16:20:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 20 Oct 2017 16:19:41 -0700 Message-Id: <20171020232023.15010-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171020232023.15010-1-richard.henderson@linaro.org> References: <20171020232023.15010-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::242 Subject: [Qemu-devel] [PATCH v7 10/52] tcg: Avoid loops against variable bounds 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: pbonzini@redhat.com, cota@braap.org, f4bug@amsat.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson 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. Reviewed-by: Emilio G. Cota Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- tcg/tcg.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) -- 2.13.6 Reviewed-by: Philippe Mathieu-Daudé diff --git a/tcg/tcg.c b/tcg/tcg.c index d08e34a9d8..840e65c0d4 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1159,23 +1159,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; } @@ -2277,9 +2270,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); } } @@ -2289,9 +2282,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