[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 21/51] tcg: Use offsets not indices for TCGv_*
From: |
Richard Henderson |
Subject: |
[Qemu-devel] [PULL 21/51] tcg: Use offsets not indices for TCGv_* |
Date: |
Wed, 25 Oct 2017 11:35:05 +0200 |
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é <address@hidden>
Reviewed-by: Emilio G. Cota <address@hidden>
Signed-off-by: Richard Henderson <address@hidden>
---
tcg/tcg.h | 64 ++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 33 insertions(+), 31 deletions(-)
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
--
2.13.6
- [Qemu-devel] [PULL 07/51] tcg: Return NULL temp for TCG_CALL_DUMMY_ARG, (continued)
- [Qemu-devel] [PULL 07/51] tcg: Return NULL temp for TCG_CALL_DUMMY_ARG, Richard Henderson, 2017/10/25
- [Qemu-devel] [PULL 08/51] tcg: Introduce temp_arg, export temp_idx, Richard Henderson, 2017/10/25
- [Qemu-devel] [PULL 11/51] tcg: Change temp_allocate_frame arg to TCGTemp, Richard Henderson, 2017/10/25
- [Qemu-devel] [PULL 09/51] tcg: Use per-temp state data in liveness, Richard Henderson, 2017/10/25
- [Qemu-devel] [PULL 10/51] tcg: Avoid loops against variable bounds, Richard Henderson, 2017/10/25
- [Qemu-devel] [PULL 12/51] tcg: Remove unused TCG_CALL_DUMMY_TCGV, Richard Henderson, 2017/10/25
- [Qemu-devel] [PULL 15/51] tcg: Push tcg_ctx into tcg_gen_callN, Richard Henderson, 2017/10/25
- [Qemu-devel] [PULL 14/51] tcg: Push tcg_ctx into generator functions, Richard Henderson, 2017/10/25
- [Qemu-devel] [PULL 13/51] tcg: Use per-temp state data in optimize, Richard Henderson, 2017/10/25
- [Qemu-devel] [PULL 18/51] tcg: Remove GET_TCGV_* and MAKE_TCGV_*, Richard Henderson, 2017/10/25
- [Qemu-devel] [PULL 21/51] tcg: Use offsets not indices for TCGv_*,
Richard Henderson <=
- [Qemu-devel] [PULL 17/51] tcg: Introduce temp_tcgv_{i32,i64,ptr}, Richard Henderson, 2017/10/25
- [Qemu-devel] [PULL 24/51] tcg: Include CF_COUNT_MASK in CF_HASH_MASK, Richard Henderson, 2017/10/25
- [Qemu-devel] [PULL 16/51] tcg: Introduce tcgv_{i32, i64, ptr}_{arg, temp}, Richard Henderson, 2017/10/25
- [Qemu-devel] [PULL 23/51] tcg: Add CPUState cflags_next_tb, Richard Henderson, 2017/10/25
- [Qemu-devel] [PULL 22/51] tcg: define CF_PARALLEL and use it for TB hashing along with CF_COUNT_MASK, Richard Henderson, 2017/10/25
- [Qemu-devel] [PULL 20/51] qom: Introduce CPUClass.tcg_initialize, Richard Henderson, 2017/10/25
- [Qemu-devel] [PULL 19/51] tcg: Remove TCGV_EQUAL*, Richard Henderson, 2017/10/25
- [Qemu-devel] [PULL 26/51] target/arm: check CF_PARALLEL instead of parallel_cpus, Richard Henderson, 2017/10/25
- [Qemu-devel] [PULL 27/51] target/hppa: check CF_PARALLEL instead of parallel_cpus, Richard Henderson, 2017/10/25