From patchwork Tue Apr 1 20:53:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 336155 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 94D4F140078 for ; Wed, 2 Apr 2014 07:56:21 +1100 (EST) Received: from localhost ([::1]:34352 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WV5jH-0003xw-EZ for incoming@patchwork.ozlabs.org; Tue, 01 Apr 2014 16:56:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46343) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WV5gx-0000pf-8T for qemu-devel@nongnu.org; Tue, 01 Apr 2014 16:54:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WV5gr-0007Wb-4r for qemu-devel@nongnu.org; Tue, 01 Apr 2014 16:53:55 -0400 Received: from mail-qc0-x22c.google.com ([2607:f8b0:400d:c01::22c]:33278) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WV5gr-0007WM-0J for qemu-devel@nongnu.org; Tue, 01 Apr 2014 16:53:49 -0400 Received: by mail-qc0-f172.google.com with SMTP id i8so11492992qcq.31 for ; Tue, 01 Apr 2014 13:53:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=2EGSwN/mGX4KWtU93VzlXPreGgWH3sXz9r5Sn6/auhg=; b=XDgmjuMhYiGf3zSOLz1Kr13cIvAFCt4GtvK6p1WxmiCI/3INtTiKeMmdMrSasGCqvi 7PYpcmvJDZCN91VL2jZqJCH6RLCNHv6pFdzX0jH2ic44dTAoGpKzoSHSyQOQz6MCmETE dc+AX5fFsbgY+UDGREKhLF9lD8FxLOhtnttXHE8UvM08gZbguC833kjFhHY2bIfxQDhI HwKPc5q6U+ZqBIZDP/x/XzA5Y8Z/G/4gJJ5K+JbmmqDlOiKmaIJmdq9e9dRLUFJixurD r2eSNQiJ007UnkK3MBkZ7vGyfpqDtOjePFrzVfcghjIrq1bJpfhvK/ThxsUU0W9zTmJa YnEg== X-Received: by 10.140.51.106 with SMTP id t97mr35923739qga.50.1396385628432; Tue, 01 Apr 2014 13:53:48 -0700 (PDT) Received: from pike.twiddle.home.com (50-194-63-110-static.hfc.comcastbusiness.net. [50.194.63.110]) by mx.google.com with ESMTPSA id g20sm36923963qaq.4.2014.04.01.13.53.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Apr 2014 13:53:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 1 Apr 2014 13:53:29 -0700 Message-Id: <1396385614-19267-5-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1396385614-19267-1-git-send-email-rth@twiddle.net> References: <1396385614-19267-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c01::22c Cc: peter.maydell@linaro.org Subject: [Qemu-devel] [PATCH v2 4/9] tcg: Introduce byte pointer arithmetic helpers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 f7efcb4..8df1641 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -717,6 +717,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