From: Richard Henderson <rth@twiddle.net>
To: qemu-devel@nongnu.org
Cc: av1474@comtv.ru
Subject: [Qemu-devel] [PATCH 26/26] tcg-ppc: Streamline USE_DIRECT_JUMP
Date: Thu, 1 May 2014 08:44:47 -0700 [thread overview]
Message-ID: <1398959087-23590-27-git-send-email-rth@twiddle.net> (raw)
In-Reply-To: <1398959087-23590-1-git-send-email-rth@twiddle.net>
With the TCG_REG_RA base, we can form any 2G displacement for 64-bit,
which means we only need 4 insns for the 64-bit target instead of 7.
Generate the mtctr and brctr insns once during translation and not
part of ppc_tb_set_jmp_target. This means we can update only 2 insns,
and we can arrange to do that update atomically.
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
tcg/ppc/tcg-target.c | 56 +++++++++++++++++++++++++++++++++++++++++-----------
translate-all.c | 2 ++
2 files changed, 47 insertions(+), 11 deletions(-)
diff --git a/tcg/ppc/tcg-target.c b/tcg/ppc/tcg-target.c
index 7d4fd3e..4aec848 100644
--- a/tcg/ppc/tcg-target.c
+++ b/tcg/ppc/tcg-target.c
@@ -1244,11 +1244,41 @@ static void tcg_out_brcond2 (TCGContext *s, const TCGArg *args,
void ppc_tb_set_jmp_target(uintptr_t jmp_addr, uintptr_t addr)
{
- TCGContext s;
+ tcg_insn_unit insn1, insn2;
+ uint64_t pair;
+
+ if (in_range_b(addr - jmp_addr)) {
+ insn1 = B | ((addr - jmp_addr) & 0x3fffffc);
+ insn2 = NOP;
+ } else if (TCG_TARGET_REG_BITS == 32 || addr == (int32_t)addr) {
+ insn1 = ADDIS | TAI(TCG_REG_TMP1, 0, addr >> 16);
+ insn2 = ORI | TAI(TCG_REG_R0, TCG_REG_TMP1, addr);
+ } else {
+ intptr_t diff = addr - (uintptr_t)tb_ret_addr;
+ int16_t lo = diff;
+ int32_t hi = diff - lo;
+
+ assert(hi + lo == diff);
+ insn1 = ADDIS | TAI(TCG_REG_TMP1, TCG_REG_RA, hi >> 16);
+ insn2 = ADDI | TAI(TCG_REG_R0, TCG_REG_TMP1, lo);
+ }
+
+#ifdef HOST_WORDS_BIGENDIAN
+ pair = (uint64_t)insn1 << 32 | insn2;
+#else
+ pair = (uint64_t)insn2 << 32 | insn1;
+#endif
+
+ if (TCG_TARGET_REG_BITS == 64) {
+ *(uint64_t *)jmp_addr = pair;
+ } else {
+ /* In 32-bit mode, we've got to use the fpu to
+ atomically store 8 bytes. */
+ /* ??? With gcc 4.8+, we could use __atomic_store. */
+ __asm volatile("stfdx %0,0,%1" : : "f"(pair), "r"(jmp_addr));
+ }
- s.code_buf = s.code_ptr = (tcg_insn_unit *)jmp_addr;
- tcg_out_b(&s, 0, (tcg_insn_unit *)addr);
- flush_icache_range(jmp_addr, jmp_addr + tcg_current_code_size(&s));
+ flush_icache_range(jmp_addr, jmp_addr + 8);
}
static void tcg_out_call(TCGContext *s, tcg_insn_unit *target)
@@ -1848,14 +1878,18 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args,
tcg_out_b(s, 0, tb_ret_addr);
break;
case INDEX_op_goto_tb:
- if (s->tb_jmp_offset) {
- /* Direct jump method. */
- s->tb_jmp_offset[args[0]] = tcg_current_code_size(s);
- s->code_ptr += 7;
- } else {
- /* Indirect jump method. */
- tcg_abort();
+ assert(s->tb_jmp_offset != NULL);
+ /* Direct jump method. */
+ /* Align the two insns so we can update them atomically. */
+ if ((intptr_t)s->code_ptr & 4) {
+ tcg_out32(s, NOP);
}
+ s->tb_jmp_offset[args[0]] = tcg_current_code_size(s);
+ /* Max 2 insns to compose address into R0. */
+ s->code_ptr += 2;
+ /* Branch to the address computed. */
+ tcg_out32(s, MTSPR | RS(TCG_REG_R0) | CTR);
+ tcg_out32(s, BCCTR | BO_ALWAYS);
s->tb_next_offset[args[0]] = tcg_current_code_size(s);
break;
case INDEX_op_br:
diff --git a/translate-all.c b/translate-all.c
index 5549a85..6bd8fe8 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -466,6 +466,8 @@ static inline PageDesc *page_find(tb_page_addr_t index)
host cpu, as used by the TCG implementation of goto_tb. */
#if defined(__x86_64__)
# define MAX_CODE_GEN_BUFFER_SIZE (2ul * 1024 * 1024 * 1024)
+#elif defined(_ARCH_PPC)
+# define MAX_CODE_GEN_BUFFER_SIZE (2ul * 1024 * 1024 * 1024)
#elif defined(__sparc__)
# define MAX_CODE_GEN_BUFFER_SIZE (2ul * 1024 * 1024 * 1024)
#elif defined(__aarch64__)
--
1.9.0
next prev parent reply other threads:[~2014-05-01 15:46 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-01 15:44 [Qemu-devel] [PATCH 00/26] Merge ppc32/ppc64 tcg backends Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 01/26] tcg-ppc: Use uintptr_t in ppc_tb_set_jmp_target Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 02/26] tcg-ppc64: Avoid some hard-codings of TCG_TYPE_I64 Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 03/26] tcg-ppc64: Move functions around Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 04/26] tcg-ppc64: Relax register restrictions in tcg_out_mem_long Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 05/26] tcg-ppc64: Use tcg_out_{ld, st, cmp} internally Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 06/26] tcg-ppc64: Make TCG_AREG0 and TCG_REG_CALL_STACK enum constants Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 07/26] tcg-ppc64: Move call macros out of tcg-target.h Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 08/26] tcg-ppc64: Fix TCG_TARGET_CALL_STACK_OFFSET Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 09/26] tcg-ppc64: Better parameterize the stack frame Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 10/26] tcg-ppc64: Use the correct test in tcg_out_call Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 11/26] tcg-ppc64: Support the ppc64 elfv2 ABI Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 12/26] tcg-ppc64: Adjust tcg_out_call for ELFv2 Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 13/26] tcg-ppc64: Merge 32-bit ABIs into the prologue / frame code Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 14/26] tcg-ppc64: Fix sub2 implementation Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 15/26] tcg-ppc64: Begin merging ppc32 with ppc64 Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 16/26] tcg-ppc64: Merge ppc32 brcond2, setcond2, muluh Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 17/26] tcg-ppc64: Merge ppc32 qemu_ld/st Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 18/26] tcg-ppc64: Merge ppc32 register usage Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 19/26] tcg-ppc64: Support mulsh_i32 Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 20/26] tcg-ppc64: Merge ppc32 shifts Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 21/26] tcg-ppc: Remove the backend Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 22/26] tcg-ppc: Rename the tcg/ppc64 backend Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 23/26] qemu/osdep: Remove the need for qemu_init_auxval Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 24/26] tcg-ppc: Merge cache-utils into the backend Richard Henderson
2014-05-01 15:44 ` [Qemu-devel] [PATCH 25/26] tcg-ppc64: Use the return address as a base pointer Richard Henderson
2014-05-01 15:44 ` Richard Henderson [this message]
2014-05-02 14:56 ` [Qemu-devel] [PATCH 00/26] Merge ppc32/ppc64 tcg backends Tom Musta
2014-05-02 16:30 ` Ulrich Weigand
2014-05-02 16:43 ` Richard Henderson
2014-05-05 20:32 ` Tom Musta
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=1398959087-23590-27-git-send-email-rth@twiddle.net \
--to=rth@twiddle.net \
--cc=av1474@comtv.ru \
--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).