From patchwork Wed Oct 25 09:35:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 117066 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp646082qgn; Wed, 25 Oct 2017 02:52:18 -0700 (PDT) X-Google-Smtp-Source: ABhQp+T/R4xLiY/3bKXLMPZuXjuKQVWEhDUVjTwLCWEoly4M/H4RxruXuDCvB2VNjMf58cHA16r6 X-Received: by 10.129.99.85 with SMTP id x82mr12471004ywb.225.1508925138633; Wed, 25 Oct 2017 02:52:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508925138; cv=none; d=google.com; s=arc-20160816; b=Q1aoKFiAcRjAq7gHBHxhWGwZ2a6d56vZfiuzRcZBV1ae/9Ry+2Rdx2iUmFnPMoT/2R ZxcVcOfBwCuhKie1Jf92PJ0qr3nNfn84Aljb0wjqR/0VjmU++UNTDiI+GQHBWUcJ5rr6 elatqq5AuhkFpL0uUKisCAFPwNYjIE+R2YSgRUmbuPAsulAFyqeFLTU4Wcn3OyBpQCqd F9C1znu8H/O1vYTAum96yvTbLHEaBaFrgkC3+FWlhKaEnVp/CEyTrshA0LvGgSGEhmeC 3Uqi1HeIiVD39tSdS31ZZqEh+y7+juYh5O3YLnsv6ffSZzVaJz4rdfdFE946OqiIGUC1 oF5g== 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=+ZKfmpIeCuGmQ/ukqNE48h4VaJZW/yPbDvg/tr7lBLk=; b=T95NVBbMkkNYPB0hjIiOUUwB7okduHrTMAcIB5KsQiXVJdRebCrpbJC+VWEOl89YZp +2UFJMxYyayaWH+b/z4z2AHV5BQr2vMGpvu1vWP2S7IcanF6dVvXbwIwrBgrxsADY+Ak iWCUG6jKU9cebCzCRAPby7WZMIxmdKqC64ybGzVd3hJWuk4h1iAG0Em5LazDCMQtPg5C yoZB8YKVIbvOEqqzCe3JOlT/vHqxKnF0EspO82PRKBfVASy9ofeKNLHN7dOSCBJ2AOC4 irptuiwuslUrrUrlqBOX1HAdGJmevgQ1z20fRa3WZxSoSz7pPV+DYsnaGryPQdUZQZ5a fbIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MnH4uiBO; 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 d15si384086ywb.775.2017.10.25.02.52.18 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 25 Oct 2017 02:52:18 -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=MnH4uiBO; 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]:47373 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7IME-0005LA-4B for patch@linaro.org; Wed, 25 Oct 2017 05:52:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45631) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7I6Z-0008KU-W6 for qemu-devel@nongnu.org; Wed, 25 Oct 2017 05:36:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e7I6Y-0008Fu-58 for qemu-devel@nongnu.org; Wed, 25 Oct 2017 05:36:07 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:47225) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e7I6X-0008DO-Ta for qemu-devel@nongnu.org; Wed, 25 Oct 2017 05:36:06 -0400 Received: by mail-wm0-x244.google.com with SMTP id r196so622442wmf.2 for ; Wed, 25 Oct 2017 02:36:05 -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=+ZKfmpIeCuGmQ/ukqNE48h4VaJZW/yPbDvg/tr7lBLk=; b=MnH4uiBOviH86ztQwOvIHPzvIGKNilGsI4fJiVSYC2JZ6Y/L+7Lwx2Ny7RGf58lT7B N1Ugt0Dpb657EN9Nfn/eMQAbdfcgcB9nzdTbXymzHgh4CrtVGpGOW6VOUzpgS7OW7EWK 1QXmyJrhkQID4FyfmjKuvS+zhtOk2dNcj8IwE= 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=+ZKfmpIeCuGmQ/ukqNE48h4VaJZW/yPbDvg/tr7lBLk=; b=knw4zt34b96V7dje/ylkHCblGK55YjFy7dIMgyP3mhl8R8PqicaHTC/O8jmnW7GNfL GH+M4QSrPtEz8wbF0KxipT/RVeHzfU4LuEueXX4XZGjxgJ9vmlnQcT6NC4MAlUm8yV6A iI1w8g1yEC3uBlvvTsIKDCH9nTRkeAE8QLWHHX7s0nS6LcQwNQL4fgZI+OqKwDfRCErm XyWho+kOw2MH0+3Qw1HPNIvDVvZDueSoEocFH0mi/reHzLGRbOThrEuZcrPmdGV7Awdw jftU4vJ9TZU7dPr4h6D3JB0QnDiLeVQij9ovtE5L+57oV1kVlh9n63ecGr9qgcS9OJoa 5V/g== X-Gm-Message-State: AMCzsaWmXhLpC2ydRavRM6l7NVP6cAoXVqmxJRuZoSJ03Dzd3ciUEJpW MYzu/hye6EMZoMH01nO0qwLsWZxRq1w= X-Received: by 10.28.213.143 with SMTP id m137mr1072754wmg.67.1508924164691; Wed, 25 Oct 2017 02:36:04 -0700 (PDT) Received: from cloudburst.twiddle.net ([62.168.35.107]) by smtp.gmail.com with ESMTPSA id v23sm2751025wmh.8.2017.10.25.02.36.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Oct 2017 02:36:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 25 Oct 2017 11:35:05 +0200 Message-Id: <20171025093535.10175-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171025093535.10175-1-richard.henderson@linaro.org> References: <20171025093535.10175-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: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PULL 21/51] tcg: Use offsets not indices for TCGv_* 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Using the offset of a temporary, relative to TCGContext, rather than its index means that we don't use 0. That leaves offset 0 free for a NULL representation without having to leave index 0 unused. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Emilio G. Cota Signed-off-by: Richard Henderson --- tcg/tcg.h | 64 ++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 31 deletions(-) -- 2.13.6 diff --git a/tcg/tcg.h b/tcg/tcg.h index 8f692bc6cf..c85786fb47 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -428,14 +428,14 @@ typedef TCGv_ptr TCGv_env; #error Unhandled TARGET_LONG_BITS value #endif -/* Dummy definition to avoid compiler warnings. */ -#define TCGV_UNUSED_I32(x) (x = (TCGv_i32)-1) -#define TCGV_UNUSED_I64(x) (x = (TCGv_i64)-1) -#define TCGV_UNUSED_PTR(x) (x = (TCGv_ptr)-1) +/* See the comment before tcgv_i32_temp. */ +#define TCGV_UNUSED_I32(x) (x = (TCGv_i32)NULL) +#define TCGV_UNUSED_I64(x) (x = (TCGv_i64)NULL) +#define TCGV_UNUSED_PTR(x) (x = (TCGv_ptr)NULL) -#define TCGV_IS_UNUSED_I32(x) ((x) == (TCGv_i32)-1) -#define TCGV_IS_UNUSED_I64(x) ((x) == (TCGv_i64)-1) -#define TCGV_IS_UNUSED_PTR(x) ((x) == (TCGv_ptr)-1) +#define TCGV_IS_UNUSED_I32(x) ((x) == (TCGv_i32)NULL) +#define TCGV_IS_UNUSED_I64(x) ((x) == (TCGv_i64)NULL) +#define TCGV_IS_UNUSED_PTR(x) ((x) == (TCGv_ptr)NULL) /* call flags */ /* Helper does not read globals (either directly or through an exception). It @@ -453,8 +453,8 @@ typedef TCGv_ptr TCGv_env; #define TCG_CALL_NO_RWG_SE (TCG_CALL_NO_RWG | TCG_CALL_NO_SE) #define TCG_CALL_NO_WG_SE (TCG_CALL_NO_WG | TCG_CALL_NO_SE) -/* used to align parameters */ -#define TCG_CALL_DUMMY_ARG ((TCGArg)(-1)) +/* Used to align parameters. See the comment before tcgv_i32_temp. */ +#define TCG_CALL_DUMMY_ARG ((TCGArg)0) /* Conditions. Note that these are laid out for easy manipulation by the functions below: @@ -701,62 +701,64 @@ static inline size_t temp_idx(TCGTemp *ts) static inline TCGArg temp_arg(TCGTemp *ts) { - return temp_idx(ts); + return (uintptr_t)ts; } static inline TCGTemp *arg_temp(TCGArg a) { - return a == TCG_CALL_DUMMY_ARG ? NULL : &tcg_ctx.temps[a]; + return (TCGTemp *)(uintptr_t)a; } -static inline size_t arg_index(TCGArg a) +/* Using the offset of a temporary, relative to TCGContext, rather than + its index means that we don't use 0. That leaves offset 0 free for + a NULL representation without having to leave index 0 unused. */ +static inline TCGTemp *tcgv_i32_temp(TCGv_i32 v) { - return a; -} - -static inline TCGArg tcgv_i32_arg(TCGv_i32 t) -{ - return (intptr_t)t; + uintptr_t o = (uintptr_t)v; + TCGTemp *t = (void *)&tcg_ctx + o; + tcg_debug_assert(offsetof(TCGContext, temps[temp_idx(t)]) == o); + return t; } -static inline TCGArg tcgv_i64_arg(TCGv_i64 t) +static inline TCGTemp *tcgv_i64_temp(TCGv_i64 v) { - return (intptr_t)t; + return tcgv_i32_temp((TCGv_i32)v); } -static inline TCGArg tcgv_ptr_arg(TCGv_ptr t) +static inline TCGTemp *tcgv_ptr_temp(TCGv_ptr v) { - return (intptr_t)t; + return tcgv_i32_temp((TCGv_i32)v); } -static inline TCGTemp *tcgv_i32_temp(TCGv_i32 t) +static inline TCGArg tcgv_i32_arg(TCGv_i32 v) { - return arg_temp(tcgv_i32_arg(t)); + return temp_arg(tcgv_i32_temp(v)); } -static inline TCGTemp *tcgv_i64_temp(TCGv_i64 t) +static inline TCGArg tcgv_i64_arg(TCGv_i64 v) { - return arg_temp(tcgv_i64_arg(t)); + return temp_arg(tcgv_i64_temp(v)); } -static inline TCGTemp *tcgv_ptr_temp(TCGv_ptr t) +static inline TCGArg tcgv_ptr_arg(TCGv_ptr v) { - return arg_temp(tcgv_ptr_arg(t)); + return temp_arg(tcgv_ptr_temp(v)); } static inline TCGv_i32 temp_tcgv_i32(TCGTemp *t) { - return (TCGv_i32)temp_idx(t); + (void)temp_idx(t); /* trigger embedded assert */ + return (TCGv_i32)((void *)t - (void *)&tcg_ctx); } static inline TCGv_i64 temp_tcgv_i64(TCGTemp *t) { - return (TCGv_i64)temp_idx(t); + return (TCGv_i64)temp_tcgv_i32(t); } static inline TCGv_ptr temp_tcgv_ptr(TCGTemp *t) { - return (TCGv_ptr)temp_idx(t); + return (TCGv_ptr)temp_tcgv_i32(t); } #if TCG_TARGET_REG_BITS == 32