Received: from eggs.gnu.org ([2001:4830:134:3::10]:59231) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WjzhQ-0004jb-3A for qemu-devel@nongnu.org; Mon, 12 May 2014 19:32:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WjzhJ-0005mv-LJ for qemu-devel@nongnu.org; Mon, 12 May 2014 19:32:00 -0400 Received: from mail-qa0-x229.google.com ([2607:f8b0:400d:c00::229]:34156) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WjzhJ-0005mY-Hq for qemu-devel@nongnu.org; Mon, 12 May 2014 19:31:53 -0400 Received: by mail-qa0-f41.google.com with SMTP id dc16so7885901qab.28 for ; Mon, 12 May 2014 16:31:53 -0700 (PDT) Sender: Richard Henderson From: Richard Henderson Date: Mon, 12 May 2014 16:30:52 -0700 Message-Id: <1399937474-6530-5-git-send-email-rth@twiddle.net> In-Reply-To: <1399937474-6530-1-git-send-email-rth@twiddle.net> References: <1399937474-6530-1-git-send-email-rth@twiddle.net> Subject: [Qemu-devel] [PULL 04/26] tcg: Introduce byte pointer arithmetic helpers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- tcg/tcg.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tcg/tcg.h b/tcg/tcg.h index a6a2d06..d38c92d 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -724,6 +724,51 @@ TCGv_i32 tcg_const_local_i32(int32_t val); TCGv_i64 tcg_const_local_i64(int64_t val); /** + * tcg_ptr_byte_diff + * @a, @b: addresses to be differenced + * + * There are many places within the TCG backends where we need a byte + * difference between two pointers. While this can be accomplished + * with local casting, it's easy to get wrong -- especially if one is + * concerned with the signedness of the result. + * + * This version relies on GCC's void pointer arithmetic to get the + * correct result. + */ + +static inline ptrdiff_t tcg_ptr_byte_diff(void *a, void *b) +{ + return a - b; +} + +/** + * tcg_pcrel_diff + * @s: the tcg context + * @target: address of the target + * + * Produce a pc-relative difference, from the current code_ptr + * to the destination address. + */ + +static inline ptrdiff_t tcg_pcrel_diff(TCGContext *s, void *target) +{ + return tcg_ptr_byte_diff(target, s->code_ptr); +} + +/** + * tcg_current_code_size + * @s: the tcg context + * + * Compute the current code size within the translation block. + * This is used to fill in qemu's data structures for goto_tb. + */ + +static inline size_t tcg_current_code_size(TCGContext *s) +{ + return tcg_ptr_byte_diff(s->code_ptr, s->code_buf); +} + +/** * tcg_qemu_tb_exec: * @env: CPUArchState * for the CPU * @tb_ptr: address of generated code for the TB to execute -- 1.9.0