From: Richard Henderson <rth@twiddle.net>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org
Subject: [Qemu-devel] [PATCH v2 4/9] tcg: Introduce byte pointer arithmetic helpers
Date: Tue, 1 Apr 2014 13:53:29 -0700 [thread overview]
Message-ID: <1396385614-19267-5-git-send-email-rth@twiddle.net> (raw)
In-Reply-To: <1396385614-19267-1-git-send-email-rth@twiddle.net>
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
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
--
1.9.0
next prev parent reply other threads:[~2014-04-01 20:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-01 20:53 [Qemu-devel] [PATCH v2 0/9] tcg: tidy the type of code_ptr Richard Henderson
2014-04-01 20:53 ` [Qemu-devel] [PATCH v2 1/9] exec-all.h: Use stl_p to avoid undefined behaviour patching x86 jumps Richard Henderson
2014-04-01 20:53 ` [Qemu-devel] [PATCH v2 2/9] tcg: Avoid stores to unaligned addresses Richard Henderson
2014-04-01 20:53 ` [Qemu-devel] [PATCH v2 3/9] tcg: Avoid undefined behaviour patching code at " Richard Henderson
2014-04-01 20:53 ` Richard Henderson [this message]
2014-04-01 20:53 ` [Qemu-devel] [PATCH v2 5/9] tcg: Define tcg_insn_unit for code pointers Richard Henderson
2014-04-01 20:53 ` [Qemu-devel] [PATCH v2 6/9] tcg-i386: Define TCG_TARGET_INSN_UNIT_SIZE Richard Henderson
2014-04-01 20:53 ` [Qemu-devel] [PATCH v2 7/9] tcg-ppc64: " Richard Henderson
2014-04-01 21:12 ` Peter Maydell
2014-04-01 21:31 ` Richard Henderson
2014-04-01 20:53 ` [Qemu-devel] [PATCH v2 8/9] tcg-ppc: " Richard Henderson
2014-04-01 20:53 ` [Qemu-devel] [PATCH v2 9/9] tcg-sparc: " Richard Henderson
2014-04-01 21:15 ` [Qemu-devel] [PATCH v2 0/9] tcg: tidy the type of code_ptr Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1396385614-19267-5-git-send-email-rth@twiddle.net \
--to=rth@twiddle.net \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).