tci rewrite
cover tci rewrite
There are a number of problems with the current interpreter:
(1) It uses direct unaligned accesses as part of the bytecode stream. This fails with SIGBUS for strict alignment hosts. This could of course be fixed to use "proper" unaligned accesses, but this would just be slow.
(2) The method by which it implements calls is non-portable, and really only works for x86.
(3) The code is full of ifdefs and TODOs that never got completed.
(4) The "registers" are in a global "tci_reg" array that implies that if threads are ever used, we'll immediately get corruption. Fixing this is complicated by the structure of the interpreter.
(5) It hasn't been updated to the "new" ldst opcodes.
To me, all of this adds up to a complete rewrite. While it might just be possible to stage such a thing in, I really don't see a way to do that cleanly. Nor am I certain it's worth the effort.
This rewrite fixes all three problems in one go:
(1) The bytecodes are encoded into a stream of uint32_t, so there are never any unaligned accesses.
(2) Use libffi. This requires a few adjustments to the generic call code, so that the parameters get layed out on the "stack" as we wish.
(3) Minimial ifdefage. My goal was to make sure that nearly all code paths are compiled, and then removed by an optimizing compiler if they're not reachable.
(4) Don't do that.
(5) Do that.
The result works on 4 hosts that I could try: x86, arm, sparc, ppc64.
The speed of emulation appears to be about the same. Measurement there seems to be within noise.
The size of both the interpreter and the bytecodes are greatly reduced.
text data bss dec hex filename
7563 0 160 7723 1e2b bld-old/ppc64-softmmu/tci.o 4313 0 8 4321 10e1 bld-new/ppc64-softmmu/tci.o
Alpha rom boot
-gen code size 64208/33430528
+gen code size 36656/33430528
PPC rom boot
-gen code size 188144/33430528
+gen code size 99776/33430528
Sparc rom boot
-gen code size 432784/33430528
+gen code size 271104/33430528
Since the patch is essentially illegible, please have a look at
git://github.com/rth7680/qemu.git tci-6
r~
Richard Henderson (3):
ppc: Disable cacheutils for the interpreter
tci: Build ffi data structures for helpers
tci: Rewrite from scratch
configure | 12 + disas/tci.c | 415 +++++++++- include/exec/cpu-all.h | 6 +- include/exec/exec-all.h | 5 +- include/exec/helper-ffi.h | 83 ++ include/exec/helper-tcg.h | 18 +- include/qemu/cache-utils.h | 2 +- include/qemu/tci.h | 171 +++++ target-i386/ops_sse_header.h | 6 + target-ppc/helper.h | 1 + tcg/tcg.c | 59 +- tcg/tci/README | 113 +-- tcg/tci/tcg-target.c | 1303 ++++++++++++++----------------- tcg/tci/tcg-target.h | 156 ++-- tci.c | 1752 ++++++++++++++---------------------------- translate-all.c | 5 +- util/cache-utils.c | 2 +- 17 files changed, 1976 insertions(+), 2133 deletions(-) create mode 100644 include/exec/helper-ffi.h create mode 100644 include/qemu/tci.h
Signature · 1 line
1.9.0
PATCH 1/3 ppc: Disable cacheutils for the interpreter
These really ought to be moved into the (unified?) tcg-ppc backend.
--- include/qemu/cache-utils.h | 2 +- util/cache-utils.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/qemu/cache-utils.h +1 -1
@@ -1,7 +1,7 @@#ifndef QEMU_CACHE_UTILS_H #define QEMU_CACHE_UTILS_H -#if defined(_ARCH_PPC) +#if defined(_ARCH_PPC) && !defined(CONFIG_TCG_INTERPRETER )#include <stdint.h> /* uintptr_t */
util/cache-utils.c +1 -1
@@ -1,7 +1,7 @@#include "qemu-common.h" #include "qemu/cache-utils.h" -#if defined(_ARCH_PPC) +#if defined(_ARCH_PPC) && !defined(CONFIG_TCG_INTERPRETER )struct qemu_cache_conf qemu_cache_conf = { .dcache_bsize =16 , .icache_bsize = 16
Signature · 1 line
1.9.0
PATCH 2/3 tci: Build ffi data structures for helpers
In reply to Richard Henderson--- configure | 12 +++++++ include/exec/helper-ffi.h | 83 ++++++++++++++++++++++++++++++++++++++++++++ include/exec/helper-tcg.h | 18 ++++++---- target-i386/ops_sse_header.h | 6 ++++ target-ppc/helper.h | 1 + tcg/tcg.c | 11 ++++++ 6 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 include/exec/helper-ffi.h
configure +12 -0
@@ -1755,6 +1755,18 @@ EOF fi ########################################## +# libffi check + +if test "$tcg_interpreter" != "no" ; then + if $pkg_config --atleast-version=3.0 libffi; then + LIBS="$LIBS `$pkg_config --libs libffi`" + QEMU_CFLAGS="$QEMU_CFLAGS `$pkg_config --cflags libffi`" + else + feature_not_found "tcg-interpreter" "Install libffi devel >= 3.0" + fi +fi + +########################################## # libseccomp check if test "$seccomp" != "no" ; then
include/exec/helper-ffi.h new file +83 -0
83 lines not on this page · raw message
include/exec/helper-tcg.h +12 -6
@@ -6,31 +6,37 @@#include <exec/helper-head.h> +#ifdef CONFIG_TCG_INTERPRETER +# define DO_CIF (NAME ) .cif = &cif_##NAME, +#else +# define DO_CIF (NAME ) +#endif +#define DEF_HELPER_FLAGS_0 (NAME ,FLAGS , ret) \ - { .func = HELPER(NAME), .name = #NAME, .flags = FLAGS, \ + { .func = HELPER(NAME), DO_CIF(NAME) .name = #NAME, .flags = FLAGS, \ .sizemask = dh_sizemask(ret, 0) },#define DEF_HELPER_FLAGS_1 (NAME ,FLAGS , ret, t1) \ - { .func = HELPER(NAME), .name = #NAME, .flags = FLAGS, \ + { .func = HELPER(NAME), DO_CIF(NAME) .name = #NAME, .flags = FLAGS, \ .sizemask = dh_sizemask(ret, 0) | dh_sizemask(t1, 1) },#define DEF_HELPER_FLAGS_2 (NAME ,FLAGS , ret, t1, t2) \ - { .func = HELPER(NAME), .name = #NAME, .flags = FLAGS, \ + { .func = HELPER(NAME), DO_CIF(NAME) .name = #NAME, .flags = FLAGS, \ .sizemask = dh_sizemask(ret, 0) | dh_sizemask(t1, 1) \ | dh_sizemask(t2, 2) },#define DEF_HELPER_FLAGS_3 (NAME ,FLAGS , ret, t1, t2, t3) \ - { .func = HELPER(NAME), .name = #NAME, .flags = FLAGS, \ + { .func = HELPER(NAME), DO_CIF(NAME) .name = #NAME, .flags = FLAGS, \ .sizemask = dh_sizemask(ret, 0) | dh_sizemask(t1, 1) \ | dh_sizemask(t2, 2) | dh_sizemask(t3, 3) },#define DEF_HELPER_FLAGS_4 (NAME ,FLAGS , ret, t1, t2, t3, t4) \ - { .func = HELPER(NAME), .name = #NAME, .flags = FLAGS, \ + { .func = HELPER(NAME), DO_CIF(NAME) .name = #NAME, .flags = FLAGS, \ .sizemask = dh_sizemask(ret, 0) | dh_sizemask(t1, 1) \ | dh_sizemask(t2, 2) | dh_sizemask(t3, 3) | dh_sizemask(t4, 4) },#define DEF_HELPER_FLAGS_5 (NAME ,FLAGS , ret, t1, t2, t3, t4, t5) \ - { .func = HELPER(NAME), .name = #NAME, .flags = FLAGS, \ + { .func = HELPER(NAME), DO_CIF(NAME) .name = #NAME, .flags = FLAGS, \ .sizemask = dh_sizemask(ret, 0) | dh_sizemask(t1, 1) \ | dh_sizemask(t2, 2) | dh_sizemask(t3, 3) | dh_sizemask(t4, 4) \ | dh_sizemask(t5, 5) },
target-i386/ops_sse_header.h +6 -0
@@ -27,13 +27,19 @@#define dh_alias_Reg ptr#define dh_alias_XMMReg ptr#define dh_alias_MMXReg ptr +#define dh_ctype_Reg Reg *#define dh_ctype_XMMReg XMMReg *#define dh_ctype_MMXReg MMXReg * +#define dh_is_signed_Reg dh_is_signed_ptr#define dh_is_signed_XMMReg dh_is_signed_ptr#define dh_is_signed_MMXReg dh_is_signed_ptr +#define dh_ffitype_Reg dh_ffitype_ptr +#define dh_ffitype_XMMReg dh_ffitype_ptr +#define dh_ffitype_MMXReg dh_ffitype_ptr + DEF_HELPER_3(glue(psrlw, SUFFIX), void, env, Reg, Reg) DEF_HELPER_3(glue(psraw, SUFFIX), void, env, Reg, Reg)DEF_HELPER_3 (glue (psllw,SUFFIX ), void, env, Reg, Reg)
target-ppc/helper.h +1 -0
@@ -103,6 +103,7 @@ DEF_HELPER_FLAGS_1(ftsqrt, TCG_CALL_NO_RWG_SE, i32, i64)#define dh_alias_avr ptr#define dh_ctype_avr ppc_avr_t *#define dh_is_signed_avr dh_is_signed_ptr +#define dh_ffitype_avr dh_ffitype_ptr DEF_HELPER_3(vaddubm, void, avr, avr, avr)DEF_HELPER_3 (vadduhm, void, avr, avr, avr)
tcg/tcg.c +11 -0
@@ -62,6 +62,10 @@#include "elf.h" +#ifdef CONFIG_TCG_INTERPRETER +#include <ffi.h> +#endif +/* Forward declarations for functions declared in tcg-target.c and used here. */ static void tcg_target_init (TCGContext *s);static void tcg_target_qemu_prologue (TCGContext *s);
@@ -309,6 +313,9 @@ void tcg_pool_reset(TCGContext *s) typedef struct TCGHelperInfo { void *func; +#ifdef CONFIG_TCG_INTERPRETER + ffi_cif *cif; +#endif const char *name; unsigned flags; unsigned sizemask;
@@ -316,6 +323,10 @@ typedef struct TCGHelperInfo {#include "exec/helper-proto.h" +#ifdef CONFIG_TCG_INTERPRETER +#include "exec/helper-ffi.h" +#endif +static const TCGHelperInfo all_helpers[] = { #include "exec/helper-tcg.h" };
Signature · 1 line
1.9.0
PATCH 3/3 tci: Rewrite from scratch
In reply to Richard HendersonUse aligned 32-bit insn units, so that we have no unaligned accesses when interpreting the bytecode stream. Encode bytecodes more efficiently. Use libffi for invoking the handlers. Provide a meaningful disassembler.
--- disas/tci.c | 415 ++++++++++- include/exec/cpu-all.h | 6 +- include/exec/exec-all.h | 5 +- include/qemu/tci.h | 171 +++++ tcg/tcg.c | 54 +- tcg/tci/README | 113 ++- tcg/tci/tcg-target.c | 1303 +++++++++++++++-------------------- tcg/tci/tcg-target.h | 156 ++--- tci.c | 1752 ++++++++++++++++------------------------------- translate-all.c | 5 +- 10 files changed, 1852 insertions(+), 2128 deletions(-) create mode 100644 include/qemu/tci.h
disas/tci.c +387 -28
@@ -19,41 +19,400 @@#include "disas/bfd.h" #include "tcg/tcg.h" +#include "qemu/tci.h" -/* Disassemble TCI bytecode. */ -int print_insn_tci (bfd_vma addr,disassemble_info *info) + +#define O (OPC ) [TCI_##OPC] = #OPC + +static const char *const opcode_name[1 <<LEN_OP ] = { +O (invalid), +O (add), +O (sub), +O (mul), +O (divu), +O (remu), +O (divs), +O (rems), +O (and), +O (ior), +O (xor), +O (andc), +O (iorc), +O (xorc), +O (nand), +O (nior), +O (shl), +O (shr4), +O (sar4), +O (rol4), +O (ror4), +O (shr8), +O (sar8), +O (rol8), +O (ror8), +O (cmp4eq), +O (cmp4ne), +O (cmp4lt), +O (cmp4le), +O (cmp4gt), +O (cmp4ge), +O (cmp4ltu), +O (cmp4leu), +O (cmp4gtu), +O (cmp4geu), +O (cmp8eq), +O (cmp8ne), +O (cmp8lt), +O (cmp8le), +O (cmp8gt), +O (cmp8ge), +O (cmp8ltu), +O (cmp8leu), +O (cmp8gtu), +O (cmp8geu), +O (qst1), +O (qst2_le), +O (qst2_be), +O (qst4_le), +O (qst4_be), +O (qst8_le), +O (qst8_be), +O (movc), +O (deposit), +O (concat4), +O (sxt1), +O (sxt2), +O (sxt4), +O (zxt1), +O (zxt2), +O (zxt4), +O (bswap2), +O (bswap4), +O (bswap8), +O (qld1u), +O (qld1s), +O (qld2u_le), +O (qld2u_be), +O (qld2s_le), +O (qld2s_be), +O (qld4u_le), +O (qld4u_be), +O (qld4s_le), +O (qld4s_be), +O (qld8_le), +O (qld8_be), +O (b), +O (bc), +O (exit), +O (call0), +O (call4), +O (call8), +O (setc), +O (st1), +O (st2), +O (st4), +O (st8), +O (ld1u), +O (ld1s), +O (ld2u), +O (ld2s), +O (ld4u), +O (ld4s), +O (ld8), +O (cmppeq), +O (cmppne), +O (cmpplt), +O (cmpple), +O (cmppgt), +O (cmppge), +O (cmppltu), +O (cmppleu), +O (cmppgtu), +O (cmppgeu), +O (add2), +O (sub2), +O (mulu2), +O (muls2), +}; + +#undef O + +static char const reg_names[8 ][4 ] = { +"a" ,"b" ,"c" ,"d" ,"e" ,"f" ,"vp" ,"sp" , +}; + +static inline const char *get_r (int n) { -int length; -uint8_t byte; -int status; -TCGOpcode op; - - status = info->read_memory_func (addr, &byte,1 , info); -if (status !=0 ) { - info->memory_error_func (status, addr, info); -return -1 ; +assert (n <8 ); +return ®_names[n][0 ]; +} + +static inline uint64_t concat4 (uint32_t xv,uint32_t yv) +{ +return (uint64_t )xv <<32 | yv; +} + +static inline void *concatp (int32_t xv,int32_t yv) +{ +if (sizeof (void *) ==8 ) { +return (void *)(uintptr_t )concat4 (xv, yv); } - op = byte; +return (void *)(uintptr_t )yv; +} + +/* Disassemble TCI bytecode. */ +int print_insn_tci (bfd_vma baddr,disassemble_info *info) +{ +/* These are host address. Dispense with the indirection. */ +uint32_t *addr = (uint32_t *)(uintptr_t )baddr; +uint32_t *orig_addr = addr; +char buf1[16 ], buf2[16 ]; +const char *name, *r, *w, *x, *y; +int ri, wi, xi, yi; +int32_t xv, yv; +uint32_t insn; +TCIOp opc; + + insn = *addr++; + + opc =extract32 (insn,POS_OP ,LEN_OP ); + ri =extract32 (insn,POS_R ,LEN_R ); + wi =extract32 (insn,POS_W ,LEN_W ); + xi =extract32 (insn,POS_X ,LEN_X ); + yi =extract32 (insn,POS_Y ,LEN_Y ); + + name = opcode_name[opc]; + r = reg_names[ri]; + w = reg_names[wi]; - addr++; - status = info->read_memory_func (addr, &byte,1 , info); -if (status !=0 ) { - info->memory_error_func (status, addr, info); -return -1 ; +if (xi <8 ) { + x = reg_names[xi]; + xv =0xdeadbeef ; + }else { +if (xi ==8 ) { + xv = (int32_t )*addr++; + }else { + xv = xi -BIAS_X ; + } +snprintf (buf1,sizeof (buf1),"%d" , xv); + x = buf1; } - length = byte; -if (op >= tcg_op_defs_max) { - info->fprintf_func (info->stream,"illegal opcode %d" , op); +if (yi <8 ) { + y = reg_names[yi]; + yv =0xdeadbeef ; }else { -const TCGOpDef *def = &tcg_op_defs[op]; -int nb_oargs = def->nb_oargs; -int nb_iargs = def->nb_iargs; -int nb_cargs = def->nb_cargs; -/* TODO: Improve disassembler output. */ - info->fprintf_func (info->stream,"%s\to=%d i=%d c=%d" , - def->name, nb_oargs, nb_iargs, nb_cargs); +if (yi ==8 ) { + yv = (int32_t )*addr++; + }else { + yv = yi -BIAS_Y ; + } +snprintf (buf2,sizeof (buf2),"%d" , yv); + y = buf2; + } + +switch (opc) { +case TCI_cmp4eq: +case TCI_cmp4ne: +case TCI_cmp4lt: +case TCI_cmp4le: +case TCI_cmp4gt: +case TCI_cmp4ge: +case TCI_cmp4ltu: +case TCI_cmp4leu: +case TCI_cmp4gtu: +case TCI_cmp4geu: +case TCI_cmp8eq: +case TCI_cmp8ne: +case TCI_cmp8lt: +case TCI_cmp8le: +case TCI_cmp8gt: +case TCI_cmp8ge: +case TCI_cmp8ltu: +case TCI_cmp8leu: +case TCI_cmp8gtu: +case TCI_cmp8geu: + info->fprintf_func (info->stream,"%-10s%s,%s" , name, x, y); +break ; + +case TCI_qst8_le: +case TCI_qst8_be: +if (TCG_TARGET_REG_BITS ==32 ) { + info->fprintf_func (info->stream,"%-10s[%s,%s]=%s:%s" , + name, w, y, r, x); +break ; + } +/* FALLTHRU */ +case TCI_qst1: +case TCI_qst2_le: +case TCI_qst2_be: +case TCI_qst4_le: +case TCI_qst4_be: + info->fprintf_func (info->stream,"%-10s[%s,%s]=%s" , name, w, y, x); +break ; + +case TCI_qld8_le: +case TCI_qld8_be: +if (TCG_TARGET_REG_BITS ==32 ) { + info->fprintf_func (info->stream,"%-10s%s:%s=[%s,%s]" , + name, w, r, x, y); +break ; + } +/* FALLTHRU */ +case TCI_qld1u: +case TCI_qld1s: +case TCI_qld2u_le: +case TCI_qld2u_be: +case TCI_qld2s_le: +case TCI_qld2s_be: +case TCI_qld4u_le: +case TCI_qld4u_be: +case TCI_qld4s_le: +case TCI_qld4s_be: + info->fprintf_func (info->stream,"%-10s%s=[%s,%s]" , name, r, x, y); +break ; + +case TCI_deposit: +assert (yi >=8 ); + info->fprintf_func (info->stream,"%-10s%s=%s,%d,%d,%s" , + name, r, w, yv >>6 , yv &0x3f , x); +break ; + +case TCI_concat4: +if (xi >=8 && yi >=8 ) { +/* Special case R = X:Y as MOV. */ + info->fprintf_func (info->stream,"%-10s%s=0x%016" PRIx64, +"mov" , r,concat4 (xv, yv)); + }else { + info->fprintf_func (info->stream,"%-10s%s=%s:%s" , name, r, x, y); + } +break ; + +case TCI_ior: +if (xi ==BIAS_X ) { +/* Special case R = 0 | Y as MOV. */ + info->fprintf_func (info->stream,"%-10s%s=%s" ,"mov" , r, y); +break ; + } +/* FALLTHRU */ +case TCI_add: +case TCI_sub: +case TCI_mul: +case TCI_divu: +case TCI_remu: +case TCI_divs: +case TCI_rems: +case TCI_and: +case TCI_xor: +case TCI_andc: +case TCI_iorc: +case TCI_xorc: +case TCI_nand: +case TCI_nior: +case TCI_shl: +case TCI_shr4: +case TCI_sar4: +case TCI_rol4: +case TCI_ror4: +case TCI_shr8: +case TCI_sar8: +case TCI_rol8: +case TCI_ror8: +case TCI_movc: + info->fprintf_func (info->stream,"%-10s%s=%s,%s" , name, r, x, y); +break ; + +case TCI_sxt1: +case TCI_sxt2: +case TCI_sxt4: +case TCI_zxt1: +case TCI_zxt2: +case TCI_zxt4: +case TCI_bswap2: +case TCI_bswap4: +case TCI_bswap8: + info->fprintf_func (info->stream,"%-10s%s=%s" , name, r, y); +break ; + +case TCI_b: +/* Special case B with Y extention word as GOTO. */ +if (yi ==8 ) { + name ="goto" ; + } +/* FALLTHRU */ +case TCI_bc: +assert (yi >=8 ); + info->fprintf_func (info->stream,"%-10s%p" , name, addr + yv); +break ; + +case TCI_exit: +case TCI_call0: +assert (xi >=8 && yi >=8 ); + info->fprintf_func (info->stream,"%-10s%p" , name,concatp (xv, yv)); +break ; +case TCI_call8: +assert (xi >=8 && yi >=8 ); +if (TCG_TARGET_REG_BITS ==32 ) { + info->fprintf_func (info->stream,"%-10s%s:%s=%p" , + name, w, r,concatp (xv, yv)); +break ; + } +/* FALLTHRU */ +case TCI_call4: +assert (xi >=8 && yi >=8 ); + info->fprintf_func (info->stream,"%-10s%s=%p" , + name, r,concatp (xv, yv)); +break ; + +case TCI_setc: + info->fprintf_func (info->stream,"%-10s%s" , name, r); +break ; + +case TCI_st1: +case TCI_st2: +case TCI_st4: +case TCI_st8: + info->fprintf_func (info->stream,"%-10s[%s+%s]=%s" , name, w, y, x); +break ; + +case TCI_ld1u: +case TCI_ld1s: +case TCI_ld2u: +case TCI_ld2s: +case TCI_ld4u: +case TCI_ld4s: +case TCI_ld8: + info->fprintf_func (info->stream,"%-10s%s=[%s+%s]" , name, r, w, y); +break ; + +case TCI_cmppeq: +case TCI_cmppne: +case TCI_cmpplt: +case TCI_cmpple: +case TCI_cmppgt: +case TCI_cmppge: +case TCI_cmppltu: +case TCI_cmppleu: +case TCI_cmppgtu: +case TCI_cmppgeu: + info->fprintf_func (info->stream,"%-10s%s:%s,%s:%s" , name, w, r, x, y); +break ; + +case TCI_mulu2: +case TCI_muls2: + info->fprintf_func (info->stream,"%-10s%s:%s=%s,%s" , name, w, r, x, y); +break ; + +case TCI_add2: +case TCI_sub2: + info->fprintf_func (info->stream,"%-10s%s:%s=%s:%s,%s:%s" , + name, w, r, w, r, x, y); +break ; + +case TCI_invalid: +default : + info->fprintf_func (info->stream,"illegal opcode %d" , opc); } -return length; +return (addr - orig_addr) * (sizeof (*addr)); }
include/exec/cpu-all.h +3 -3
@@ -199,20 +199,20 @@ extern unsigned long reserved_va;#endif /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ -#define g2h (x) ((void *)((unsigned long)(target_ulong)(x) + GUEST_BASE)) +#define g2h (x) ((void *)(uintptr_t)(x) + GUEST_BASE)#if HOST_LONG_BITS <=TARGET_VIRT_ADDR_SPACE_BITS #define h2g_valid (x) 1#else #define h2g_valid (x) ({ \ - unsigned long __guest = (unsigned long)(x) - GUEST_BASE; \ + uintptr_t __guest = (uintptr_t)(x) - GUEST_BASE; \ (__guest < (1ul << TARGET_VIRT_ADDR_SPACE_BITS)) && \ (!RESERVED_VA || (__guest < RESERVED_VA)); \ })#endif #define h2g_nocheck (x) ({ \ - unsigned long __ret = (unsigned long)(x) - GUEST_BASE; \ + uintptr_t __ret = (uintptr_t)(x) - GUEST_BASE; \ (abi_ulong)__ret; \ })
include/exec/exec-all.h +3 -2
@@ -218,8 +218,9 @@ void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr);#if defined(CONFIG_TCG_INTERPRETER )static inline void tb_set_jmp_target1 (uintptr_t jmp_addr,uintptr_t addr) { -/* patch the branch destination */ - *(uint32_t *)jmp_addr = addr - (jmp_addr +4 ); +intptr_t disp = (intptr_t )(addr - jmp_addr -4 ) /4 ; +assert (disp == (int32_t )disp); + *(int32_t *)jmp_addr = disp;/* no need to flush icache explicitly */ }#elif defined(_ARCH_PPC)
include/qemu/tci.h new file +171 -0
171 lines not on this page · raw message
tcg/tcg.c +36 -18
81 lines not on this page · raw message
tcg/tci/README +41 -72
123 lines not on this page · raw message
tcg/tci/tcg-target.c +570 -733
1,446 lines not on this page · raw message
tcg/tci/tcg-target.h +60 -96
205 lines not on this page · raw message
tci.c +577 -1175
512 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.9.0
Part of the diff is not shown here. View the raw message.
Quoted 12 lines · Richard Henderson
There are a number of problems with the current interpreter:
(1) It uses direct unaligned accesses as part of the bytecode stream. This fails with SIGBUS for strict alignment hosts. This could of course be fixed to use "proper" unaligned accesses, but this would just be slow.
(2) The method by which it implements calls is non-portable, and really only works for x86.
(3) The code is full of ifdefs and TODOs that never got completed.
Quoted 7 lines
(4) The "registers" are in a global "
tci_reg" array that implies that if threads are ever used, we'll immediately get corruption. Fixing this is complicated by the structure of the interpreter.(5) It hasn't been updated to the "new" ldst opcodes.
To me, all of this adds up to a complete rewrite.
Does the TCG interpreter actually have any interesting uses to merit our carrying it around, maintaining it and (in this case) rewriting it? Mostly I just see it when people accidentally configure it and I have to say "don't do that, you really want the native TCG backend".
thanks
-- PMM
Quoted 19 lines · Peter Maydell
Quoted 18 lines · Richard Henderson
There are a number of problems with the current interpreter:
(1) It uses direct unaligned accesses as part of the bytecode stream. This fails with SIGBUS for strict alignment hosts. This could of course be fixed to use "proper" unaligned accesses, but this would just be slow.
(2) The method by which it implements calls is non-portable, and really only works for x86.
(3) The code is full of ifdefs and TODOs that never got completed.
(4) The "registers" are in a global "
tci_reg" array that implies that if threads are ever used, we'll immediately get corruption. Fixing this is complicated by the structure of the interpreter.(5) It hasn't been updated to the "new" ldst opcodes.
Quoted 7 lines
Quoted 1 line
To me, all of this adds up to a complete rewrite.
Does the TCG interpreter actually have any interesting uses to merit our carrying it around, maintaining it and (in this case) rewriting it? Mostly I just see it when people accidentally configure it and I have to say "don't do that, you really want the native TCG backend".
The only interesting use I can think of is pure portability to otherwise unsupported hosts. Rare these days, but there are still some kicking.
When do folks accidentally configure it?
r~
Quoted 9 lines · Richard Henderson
Quoted 5 lines · Peter Maydell
Does the TCG interpreter actually have any interesting uses to merit our carrying it around, maintaining it and (in this case) rewriting it? Mostly I just see it when people accidentally configure it and I have to say "don't do that, you really want the native TCG backend".
The only interesting use I can think of is pure portability to otherwise unsupported hosts. Rare these days, but there are still some kicking.
Hosts we care about enough to want to run QEMU really slowly but not enough to write a TCG backend for?
Quoted 1 line
When do folks accidentally configure it?
Last one I saw was somebody reading an out of date set of wiki configuration instructions that were for building a KVM QEMU on AArch64 back before the TCG backend arrived. [incidentally that's a problem that would be better solved by allowing TCG to be disabled completely.]
I think possibly also some people read the configure help and don't realise that --enable-tcg-interpreter actually means --disable-sensible-tcg-backend...
thanks
-- PMM
Quoted 2 lines · Peter Maydell
Hosts we care about enough to want to run QEMU really slowly but not enough to write a TCG backend for?
A fair point. I suppose we should port the x86 backend to win64 at some point...
Quoted 3 lines
I think possibly also some people read the configure help and don't realise that --enable-tcg-interpreter actually means --disable-sensible-tcg-backend...
Ah, yeah, there's that. If we decide to keep tci, perhaps we should rename the option to --disable-tcg-native?
r~