tcg/interpreter: Add TCG + interpreter for bytecode (virtual machine)
Hello
The patch following this mail adds a new code generator to qemu. It includes a README file with more details.
Comments and contributions to complete it are welcome.
Regards
Stefan Weil
PATCH 1/1 tcg, tci: Add TCG and interpreter for bytecode (virtual machine)
This is an initial and highly experimental version of a new code generator which does not create native code (so it will not depend on the host running qemu when it is finished). It creates bytecode which is interpreted.
The current version can run the bios code, a simple hello world and the linux-user testcode for the i386 and x86_64 targets on x86_64 hosts.
Some additional information is in tcg/bytecode/README which is part of the patch.
Please send patches / enhancements based on my latest version from git://repo.or.cz/qemu/ar7.git.
--- Makefile.target | 1 + configure | 24 +- dyngen-exec.h | 4 +- target-i386/exec.h | 4 + tcg/bytecode/README | 64 +++ tcg/bytecode/tcg-target.c | 937 ++++++++++++++++++++++++++++++++++++++++++++ tcg/bytecode/tcg-target.h | 151 +++++++ tcg/tcg.c | 16 +- tcg/tcg.h | 4 +- tcg/tci.c | 952 +++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 2148 insertions(+), 9 deletions(-) create mode 100644 tcg/bytecode/README create mode 100644 tcg/bytecode/tcg-target.c create mode 100644 tcg/bytecode/tcg-target.h create mode 100644 tcg/tci.c
Makefile.target +1 -0
@@ -33,6 +33,7 @@ all: $(PROGS) # cpu emulator library libobj-y = exec.o translate-all.o cpu-exec.o translate.o libobj-y += tcg/tcg.o +libobj-$(CONFIG_TCG_INTERPRETER) += tcg/tci.o libobj-$(CONFIG_SOFTFLOAT) += fpu/softfloat.o libobj-$(CONFIG_NOSOFTFLOAT) += fpu/softfloat-native.o libobj-y += op_helper.o helper.o
configure +21 -3
@@ -195,6 +195,7 @@ linux_aio="" gprof="no" debug_tcg="no" +tcg_interpreter="no" debug="no" strip_opt="yes" bigendian="no"
@@ -471,6 +472,10 @@ for opt do ;; --enable-kvm) kvm="yes" ;; + --disable-tcg-interpreter) tcg_interpreter="no" + ;; + --enable-tcg-interpreter) tcg_interpreter="yes" + ;; --enable-profiler) profiler="yes" ;; --enable-cocoa)
@@ -673,6 +678,7 @@ echo " --disable-bluez disable bluez stack connectivity" echo " --enable-bluez enable bluez stack connectivity" echo " --disable-kvm disable KVM acceleration support" echo " --enable-kvm enable KVM acceleration support" +echo " --enable-tcg-interpreter enable TCG with bytecode interpreter TCI" echo " --disable-nptl disable usermode NPTL support" echo " --enable-nptl enable usermode NPTL support" echo " --enable-system enable all system emulation targets"
@@ -1764,6 +1770,7 @@ echo "IO thread $io_thread" echo "Linux AIO support $linux_aio" echo "Install blobs $blobs" echo "KVM support $kvm" +echo "TCG interpreter $tcg_interpreter" echo "fdt support $fdt" echo "preadv support $preadv" echo "fdatasync $fdatasync"
@@ -1796,8 +1803,14 @@ case "$cpu" in ARCH=arm ;; *) - echo "Unsupported CPU = $cpu" - exit 1 + if test "$tcg_interpreter" = "yes" ; then + echo "Unsupported CPU = $cpu, will use TCG with TCI (experimental)" + ARCH=unknown + echo "CONFIG_TCG_INTERPRETER=y" >> $config_host_mak + else + echo "Unsupported CPU = $cpu, try --enable-tcg-interpreter" + exit 1 + fi ;; esac echo "ARCH=$ARCH" >> $config_host_mak
@@ -1959,6 +1972,9 @@ fi if test "$fdt" = "yes" ; then echo "CONFIG_FDT=y" >> $config_host_mak fi +if test "$tcg_interpreter" = "yes" ; then + echo "CONFIG_TCG_INTERPRETER=y" >> $config_host_mak +fi if test "$need_offsetof" = "yes" ; then echo "CONFIG_NEED_OFFSETOF=y" >> $config_host_mak fi
@@ -2331,7 +2347,9 @@ fi cflags="" ldflags="" -if test "$ARCH" = "sparc64" ; then +if test "$tcg_interpreter" = "yes"; then + cflags="-I\$(SRC_PATH)/tcg/bytecode $cflags" +elif test "$ARCH" = "sparc64" ; then cflags="-I\$(SRC_PATH)/tcg/sparc $cflags" else cflags="-I\$(SRC_PATH)/tcg/\$(ARCH) $cflags"
dyngen-exec.h +3 -1
@@ -48,7 +48,9 @@ extern int fprintf(FILE *, const char *, ...);extern int fputs (const char *,FILE *);extern int printf (const char *, ...); -#if defined(__i386__) +#if defined(CONFIG_TCG_INTERPRETER ) +/* The TCG interpreter does not use special registers. */ +#elif defined(__i386__)#define AREG0 "ebp"#define AREG1 "ebx"#define AREG2 "esi"
target-i386/exec.h +4 -0
@@ -28,7 +28,11 @@#include "cpu-defs.h" +#if defined(CONFIG_TCG_INTERPRETER ) +extern struct CPUX86State *env; +#else register struct CPUX86State *env asm(AREG0); +#endif #include "qemu-common.h" #include "qemu-log.h"
tcg/bytecode/README new file +64 -0
64 lines not on this page · raw message
tcg/bytecode/tcg-target.c new file +937 -0
937 lines not on this page · raw message
tcg/bytecode/tcg-target.h new file +151 -0
151 lines not on this page · raw message
tcg/tcg.c +12 -4
@@ -155,6 +155,12 @@ int gen_new_label(void)return idx; } +/* Forward declarations for functions which may be used in tcg-target.c. */ +static char *tcg_get_arg_str_idx (TCGContext *s,char *buf,int buf_size, +int idx); +static TCGHelperInfo *tcg_find_helper (TCGContext *s,tcg_target_ulong val); +static const char *const cond_name[10 ]; +#include "tcg-target.c" /* pool based memory allocation */
@@ -696,13 +702,15 @@ static void tcg_reg_alloc_start(TCGContext *s)static char *tcg_get_arg_str_idx (TCGContext *s,char *buf,int buf_size,int idx) { -TCGTemp *ts; +TCGTemp *ts =NULL ; - ts = &s->temps[idx]; -if (idx < s->nb_globals) { +if (idx >=0 && idx < s->nb_temps) { + ts = &s->temps[idx]; + } +if (ts && idx < s->nb_globals) {pstrcpy (buf, buf_size, ts->name); }else { -if (ts->temp_local) +if (ts && ts->temp_local)snprintf (buf, buf_size,"loc%d" , idx - s->nb_globals);else snprintf (buf, buf_size,"tmp%d" , idx - s->nb_globals);
tcg/tcg.h +3 -1
@@ -457,7 +457,9 @@ const TCGArg *tcg_gen_code_op(TCGContext *s, int opc, const TCGArg *args1, unsigned int dead_iargs);extern uint8_t code_gen_prologue[]; -#if defined(_ARCH_PPC) && !defined(_ARCH_PPC64) +#if defined(CONFIG_TCG_INTERPRETER ) +unsigned long tcg_qemu_tb_exec (uint8_t *tb_ptr); +#elif defined(_ARCH_PPC) && !defined(_ARCH_PPC64)#define tcg_qemu_tb_exec (tb_ptr) \ ((long REGPARM __attribute__ ((longcall)) (*)(void *))code_gen_prologue)(tb_ptr)#else
tcg/tci.c new file +952 -0
952 lines not on this page · raw message
Signature · 1 line
1.5.6.5
Re: [Qemu-devel] [PATCH] tcg, tci: Add TCG and interpreter for bytecode (virtual machine)
Quoted 9 lines · Stefan Weil
This is an initial and highly experimental version of a new code generator which does not create native code (so it will not depend on the host running qemu when it is finished). It creates bytecode which is interpreted.
The current version can run the bios code, a simple hello world and the linux-user testcode for the i386 and
x86_64targets onx86_64hosts.
Quoted 5 lines
Some additional information is in tcg/bytecode/README which is part of the patch.
Please send patches / enhancements based on my latest version from
git://repo.or.cz/qemu/ar7.git.
Nice. When the interpreter works, it should be unconditional for targets that are not supported by TCG.
tcg/bytecode/README line 11
Quoted 2 lines
tcg/bytecode/README new file +2
-0+QEMU can create native code for some hosts (arm, hppa, i386, ppc, ppc64, +sparc, x86_64). For others, inoffical host support was written (s390).
unofficial
Quoted 2 lines
+static const int tcg_target_call_oarg_regs[2] = {
+ // TODO: ppc64 only uses one register. Why do others use two?
To pass a 64 bit return value in two 32 bit registers?
tcg/bytecode/tcg-target.c line 230
Quoted 5 lines
tcg/bytecode/tcg-target.c new file +3
-0+static const char *const tcg_target_reg_names[TCG_TARGET_NB_REGS ] = { +#if TCG_TARGET_NB_REGS == 16 || TCG_TARGET_NB_REGS == 32 + "r16",
Table overflow.
Re: [Qemu-devel] [PATCH] tcg, tci: Add TCG and interpreter for bytecode (virtual machine)
Quoted 40 lines · Blue Swirl
Quoted 9 lines · Stefan Weil
This is an initial and highly experimental version of a new code generator which does not create native code (so it will not depend on the host running qemu when it is finished). It creates bytecode which is interpreted.
The current version can run the bios code, a simple hello world and the linux-user testcode for the i386 and
x86_64targets onx86_64hosts.Quoted 6 lines
Some additional information is in tcg/bytecode/README which is part of the patch.
Please send patches / enhancements based on my latest version from
git://repo.or.cz/qemu/ar7.git.Nice. When the interpreter works, it should be unconditional for targets that are not supported by TCG.
tcg/bytecode/README line 11
Quoted 3 lines
tcg/bytecode/README new file +2
-0+QEMU can create native code for some hosts (arm, hppa, i386, ppc, ppc64, +sparc, x86_64). For others, inoffical host support was written (s390).unofficial
tcg/bytecode/tcg-target.c line 206
Quoted 3 lines
tcg/bytecode/tcg-target.c new file +2
-0+static const int tcg_target_call_oarg_regs[2 ] = { +// TODO: ppc64 only uses one register. Why do others use two? To pass a 64 bit return value in two 32 bit registers?
Quoted 2 lines
+static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
Quoted 10 lines
Review
Quoted 6 lines
(quoted diff) +2
-0+#if TCG_TARGET_NB_REGS == 16 || TCG_TARGET_NB_REGS == 32 + "r16",Table overflow.
Thanks. Fixed in git://repo.or.cz/qemu/ar7.git
Re: [Qemu-devel] [PATCH] tcg, tci: Add TCG and interpreter for bytecode (virtual machine)
In reply to Stefan WeilQuoted 2 lines · Stefan Weil
Please send patches / enhancements based on my latest version from
git://repo.or.cz/qemu/ar7.git.
Just bug reports for now, unfortunately...
exec-all.h defines 'USE_DIRECT_JUMP' based on the host architecture, which is not relevant under TCI. Also, a tb_set_jmp_target1() implementation is needed for TCI.
I think tcg_out64() belongs in tcg.c along with tcg_out8/16/32(). There are places where the x86_64, ppc64 and s390 TCG targets call out32() twice, which should be replaced with a single call to out64().
tcg_out16(), tcg_out32() and tcg_out64(), etc. rely on the code buffer pointer being aligned on those architectures that require alignment... We'd need definitions of these in terms of stw_p(), stl_p() and stq_p() for TCI... Is there any reason to preserve the old definitions?
(BTW, there's no 'ldul' macro, so perhaps one should be added, although the names in that set of macros and functions are rather unclear, so perhaps some more descriptive naming could be used for new code.)
Cheers,
Signature · 1 line
Stuart Brady
Re: [Qemu-devel] [PATCH] tcg, tci: Add TCG and interpreter for bytecode (virtual machine)
Quoted 9 lines · Stuart Brady
Quoted 2 lines · Stefan Weil
Please send patches / enhancements based on my latest version from
git://repo.or.cz/qemu/ar7.git.Just bug reports for now, unfortunately...
exec-all.hdefines 'USE_DIRECT_JUMP' based on the host architecture, which is not relevant under TCI. Also, atb_set_jmp_target1()implementation is needed for TCI.
Done. Tested with mips / mipsel host.
Quoted 4 lines
I think
tcg_out64()belongs intcg.calong with tcg_out8/16/32(). There are places where thex86_64, ppc64 and s390 TCG targets callout32()twice, which should be replaced with a single call toout64().
This is still to be done.
Quoted 11 lines
tcg_out16(),tcg_out32()andtcg_out64(), etc. rely on the code buffer pointer being aligned on those architectures that require alignment... We'd need definitions of these in terms ofstw_p(),stl_p()andstq_p()for TCI... Is there any reason to preserve the old definitions?(BTW, there's no 'ldul' macro, so perhaps one should be added, although the names in that set of macros and functions are rather unclear, so perhaps some more descriptive naming could be used for new code.)
Cheers,
Here is a status update:
A basic test of tcg + interpreter which includes system emulation (pc bios) and linux user mode (simple hello) now works for i386, x86_64, mips and mipsel hosts with i386 and x86_64 guests. Endianess and 32/64 bit issues should be fixed now. Alignment is still to be done (my test platforms don't need it).
So it is finally possible again to run qemu on mips hosts, and any 32 or 64 bit host should be able to run qemu, too. Of course the interpreted code is not fast - in my test on an emulated mips malta machine it is even terribly slow.
git://repo.or.cz/qemu/ar7.git contains the latest changes.
If the maintainers want to integrate tci in the official qemu, I can prepare the patches needed to add bytecode generator and interpreter and tcg host support for any host.
Cheers,
Stefan Weil
Re: [Qemu-devel] [PATCH] tcg, tci: Add TCG and interpreter for bytecode (virtual machine)
Quoted 40 lines · Stefan Weil
Quoted 9 lines · Stuart Brady
Quoted 2 lines · Stefan Weil
Please send patches / enhancements based on my latest version from
git://repo.or.cz/qemu/ar7.git.Just bug reports for now, unfortunately...
exec-all.hdefines 'USE_DIRECT_JUMP' based on the host architecture, which is not relevant under TCI. Also, atb_set_jmp_target1()implementation is needed for TCI.Done. Tested with mips / mipsel host.
Quoted 4 lines
I think
tcg_out64()belongs intcg.calong with tcg_out8/16/32(). There are places where thex86_64, ppc64 and s390 TCG targets callout32()twice, which should be replaced with a single call toout64().This is still to be done.
Quoted 11 lines
tcg_out16(),tcg_out32()andtcg_out64(), etc. rely on the code buffer pointer being aligned on those architectures that require alignment... We'd need definitions of these in terms ofstw_p(),stl_p()andstq_p()for TCI... Is there any reason to preserve the old definitions?(BTW, there's no 'ldul' macro, so perhaps one should be added, although the names in that set of macros and functions are rather unclear, so perhaps some more descriptive naming could be used for new code.)
Cheers,
Here is a status update:
A basic test of tcg + interpreter which includes system emulation (pc bios) and linux user mode (simple hello) now works for i386,
x86_64, mips and mipsel hosts with i386 andx86_64guests. Endianess and 32/64 bit issues should be fixed now. Alignment is still to be done (my test platforms don't need it).So it is finally possible again to run qemu on mips hosts, and any 32 or 64 bit host should be able to run qemu, too. Of course the interpreted code is not fast - in my test on an emulated mips malta machine it is even terribly slow.
Quoted 6 lines
git://repo.or.cz/qemu/ar7.gitcontains the latest changes.If the maintainers want to integrate tci in the official qemu, I can prepare the patches needed to add bytecode generator and interpreter and tcg host support for any host.
I'm, at the very least, will definitely look at it.
Signature · 1 line
mailto:[email protected]
Re: [Qemu-devel] [PATCH] tcg, tci: Add TCG and interpreter for bytecode (virtual machine)
In reply to Stefan WeilQuoted 6 lines · Stefan Weil
Quoted 5 lines · Stuart Brady
Quoted 2 lines · Stefan Weil
Please send patches / enhancements based on my latest version from
git://repo.or.cz/qemu/ar7.git.Just bug reports for now, unfortunately...
[..snip..]
Quoted 5 lines
git://repo.or.cz/qemu/ar7.gitcontains the latest changes.If the maintainers want to integrate tci in the official qemu, I can prepare the patches needed to add bytecode generator and interpreter and tcg host support for any host.
I've looked at the code, and the problem with helpers is essentially unsolved, if only things were as simple as casting things to `helper_function' and expecting it will work, not that it's _that_ much more complex, but stil..
Signature · 1 line
mailto:[email protected]
Re: [Qemu-devel] [PATCH] tcg, tci: Add TCG and interpreter for bytecode (virtual machine)
Quoted 13 lines · malc
Quoted 5 lines · Stefan Weil
Quoted 4 lines · Stuart Brady
Quoted 2 lines · Stefan Weil
Please send patches / enhancements based on my latest version from
git://repo.or.cz/qemu/ar7.git.Just bug reports for now, unfortunately...
[..snip..]
Quoted 2 lines
git://repo.or.cz/qemu/ar7.gitcontains the latest changes.
Quoted 8 lines
Quoted 3 lines
If the maintainers want to integrate tci in the official qemu, I can prepare the patches needed to add bytecode generator and interpreter and tcg host support for any host.
I've looked at the code, and the problem with helpers is essentially unsolved, if only things were as simple as casting things to `helper_function' and expecting it will work, not that it's _that_ much more complex, but still..
Hello Malc,
I read your comments on the possible ABI problems.
Nevertheless, as far as I could see all existing TCG hosts simply use fixed registers when calling helper functions.
So the same approach should work for TCI, too.
At least it is possible to run complete operating systems using this approach.
What do you think would be needed to get a first stage of TCI integrated in QEMU master?
Regards,
Stefan
Re: [Qemu-devel] [PATCH] tcg, tci: Add TCG and interpreter for bytecode (virtual machine)
Quoted 23 lines · Stefan Weil
Quoted 13 lines · malc
Quoted 5 lines · Stefan Weil
Quoted 4 lines · Stuart Brady
Quoted 2 lines · Stefan Weil
Please send patches / enhancements based on my latest version from
git://repo.or.cz/qemu/ar7.git.Just bug reports for now, unfortunately...
[..snip..]
Quoted 2 lines
git://repo.or.cz/qemu/ar7.gitcontains the latest changes.Quoted 8 lines
Quoted 3 lines
If the maintainers want to integrate tci in the official qemu, I can prepare the patches needed to add bytecode generator and interpreter and tcg host support for any host.
I've looked at the code, and the problem with helpers is essentially unsolved, if only things were as simple as casting things to `helper_function' and expecting it will work, not that it's _that_ much more complex, but still..
Quoted 6 lines
Hello Malc,
I read your comments on the possible ABI problems.
Nevertheless, as far as I could see all existing TCG hosts simply use fixed registers when calling helper functions.
The problem, as i explained earlier, is that TCI doesn't take types of the parameters into considerations and this will break SVR4 PPC ABI for instance, since long long arguments are "aligned". Please read this for details:
http://marc.info/?l=qemu-devel&m=125535217403861&w=2
Quoted 9 lines
So the same approach should work for TCI, too.
At least it is possible to run complete operating systems using this approach.
What do you think would be needed to get a first stage of TCI integrated in QEMU master?
Fixing the aforementioned problem first, then convincing someone to commit it. I'd guess that having qemu/tci run on something we do not have TCG support for would imrpove the odds.
Signature · 1 line
mailto:[email protected]
Re: [Qemu-devel] [PATCH] tcg, tci: Add TCG and interpreter for bytecode (virtual machine)
In reply to Stefan WeilQuoted 6 lines · Stefan Weil
Quoted 3 lines · Stuart Brady
exec-all.hdefines 'USE_DIRECT_JUMP' based on the host architecture, which is not relevant under TCI. Also, atb_set_jmp_target1()implementation is needed for TCI.Done. Tested with mips / mipsel host.
I think the #ifdef CONFIG_TCG_INTERPRETER sections belong before the arch-specific sections. :-)
Quoted 1 line
Alignment is still to be done (my test platforms don't need it).
I will do this at some point if nobody beats me to it. :-)
BTW, I'm wondering about certain places that require host-specific code... for example:
* qemu-lock.h, which is used by cpu_exec() for the tb lock and by cpu_unlink_tb() for non-NPTL hosts.
* The generic cpu_get_real_ticks() doesn't seem great... I suppose the MIPS version using clock() might be more appropriate?
Apart from this, I suppose user mode emulation simply has to depend on host-specific code for signal handling... :-(
I gather INDEX_op_call handling could be improved? Presumably that's really just a matter of casting to the right type of function pointer when making each call?
Cheers,
Signature · 1 line
Stuart Brady
Re: [Qemu-devel] [PATCH] tcg, tci: Add TCG and interpreter for bytecode (virtual machine)
Quoted 24 lines · Stuart Brady
Quoted 6 lines · Stefan Weil
Quoted 3 lines · Stuart Brady
exec-all.hdefines 'USE_DIRECT_JUMP' based on the host architecture, which is not relevant under TCI. Also, atb_set_jmp_target1()implementation is needed for TCI.Done. Tested with mips / mipsel host.
I think the #ifdef
CONFIG_TCG_INTERPRETERsections belong before the arch-specific sections. :-)Quoted 1 line
Alignment is still to be done (my test platforms don't need it).
I will do this at some point if nobody beats me to it. :-)
BTW, I'm wondering about certain places that require host-specific code... for example:
*
qemu-lock.h, which is used bycpu_exec()for the tb lock and bycpu_unlink_tb()for non-NPTL hosts.* The generic
cpu_get_real_ticks()doesn't seem great... I suppose the MIPS version usingclock()might be more appropriate?
Quoted 6 lines
Apart from this, I suppose user mode emulation simply has to depend on host-specific code for signal handling... :-(
I gather
INDEX_op_callhandling could be improved? Presumably that's really just a matter of casting to the right type of function pointer when making each call?
No it's not, given that there are ABIs with argument alignment and the fact that information about the types doesn't exist at the point of op_call things just aren't that simple.
Signature · 1 line
mailto:[email protected]
Re: [Qemu-devel] [PATCH] tcg, tci: Add TCG and interpreter for bytecode (virtual machine)
Quoted 5 lines · malc
yOn Mon, 12 Oct 2009, Stuart Brady wrote:
No it's not, given that there are ABIs with argument alignment and the fact that information about the types doesn't exist at the point of
op_callthings just aren't that simple.
Huh? If you're using a function pointer with the *correct* type, I hardly see how that's not sufficient.
Yes, I did notice that the information doesn't exist at that point, (in fact I did so before the previous time that you pointed this out).
Cheers,
Signature · 1 line
Stuart Brady
Re: [Qemu-devel] [PATCH] tcg, tci: Add TCG and interpreter for bytecode (virtual machine)
Quoted 9 lines · Stuart Brady
Quoted 5 lines · malc
yOn Mon, 12 Oct 2009, Stuart Brady wrote:
No it's not, given that there are ABIs with argument alignment and the fact that information about the types doesn't exist at the point of
op_callthings just aren't that simple.Huh? If you're using a function pointer with the *correct* type, I hardly see how that's not sufficient.
Let me give you an example:
tcg$ cat << eof | gcc-4.4.1 -O -o - -S -x c -
Quoted 10 lines
unsigned long long moo1 (int dummy, unsigned long long a)
{ return ((unsigned long) (a >> 32)) | (a << 32); }unsigned long long moo2 (int dummy1, int dummy2, unsigned long long a)
{ return ((unsigned long) (a >> 32)) | (a << 32); }eof
.file ""
.gnu_attribute 4, 1
.gnu_attribute 8, 1
.gnu_attribute 12, 2
.section ".text"
.align 2
.globl moo1
.type moo1, @function
moo1:
mr 3,6
mr 4,5
blr
.size moo1, .-moo1
.align 2
.globl moo2
.type moo2, @function
moo2:
mr 3,6
mr 4,5
blr
.size moo2, .-moo2
.ident "GCC: (GNU) 4.4.1"
.section .note.GNU-stack,"",@progbitstcg$ uname -mo
ppc GNU/Linux
I hope it's self explanatory.
Quoted 6 lines
Yes, I did notice that the information doesn't exist at that point, (in fact I did so before the previous time that you pointed this out).
Cheers,
Signature · 1 line
mailto:[email protected]
Re: [Qemu-devel] [PATCH] tcg, tci: Add TCG and interpreter for bytecode (virtual machine)
Quoted 5 lines · malc
Quoted 3 lines · Stuart Brady
Quoted 2 lines · malc
yOn Mon, 12 Oct 2009, Stuart Brady wrote:
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
No it's not, given that there are ABIs with argument alignment and the fact that information about the types doesn't exist at the point of
op_callthings just aren't that simple.Huh? If you're using a function pointer with the *correct* type, I hardly see how that's not sufficient.
Let me give you an example:
[..snip overcomplication..]
Quoted 5 lines
tcg$ uname -mo
ppc GNU/LinuxI hope it's self explanatory.
~$ gcc-4.4.1 -O2 -o - -S -x c - <<eof
Quoted 6 lines
unsigned long long moo1 (int dummy, unsigned long long a)
{ asm ("# dummy is %0" : : "r" (dummy)); return a; }
Quoted 6 lines
unsigned long long moo2 (int dummy1, int dummy2, unsigned long long a)
{ asm ("# dummy1 is %0, dummy2 is %1" : : "r" (dummy1), "r" (dummy2)); return a; } .file ""
.gnu_attribute 4, 1
.gnu_attribute 8, 1
.gnu_attribute 12, 2
.section ".text"
.align 2
.globl moo1
.type moo1, @function
moo1:
#APP
# 3 "<stdin>" 1
# dummy is 3
# 0 "" 2
#NO_APP
mr 3,5
mr 4,6
blr
.size moo1, .-moo1
.align 2
.globl moo2
.type moo2, @function
moo2:
#APP
# 9 "<stdin>" 1
# dummy1 is 3, dummy2 is 4
# 0 "" 2
#NO_APP
mr 3,5
mr 4,6
blr
.size moo2, .-moo2
.ident "GCC: (GNU) 4.4.1"
.section .note.GNU-stack,"",@progbits(BTW 64 bit values are returned in r3 r4 pair under SV4 ABI rules)
And a quote from SVR4abippc.pdf itself:
The following algorithm specifies where argument data is passed for the C language. For this purpose, consider the arguments as ordered from left (First argument) to right, although the order of evaluation of the arguments is unspecified. In this algorithm, fr contains the number of the next available Floating-point register, gr contains the number of the next available general purpose register, and starg is the address of the next available stack argument word.
INITIALIZE:
Set fr=1, gr=3, and starg to the address of parameter word 1.
SCAN:
If there are no more arguments, terminate. Otherwise, select one of the following depending on the type of the next argument:
DOUBLE_OR_FLOAT:
If fr>8 (that is, there are no more available Flating-point registers), go to OTHER. Otherwise, load the argument value into Floating-point register fr, set fr to fr+1, and go to SCAN.
SIMPLE_ARG:
A SIMPLE_ARG is one of the following:
. One of the simple integer types no more than 32 bits
wide (char, short, int, long, enum), or
. A pointer to an object of any type, or
. A struct, union, or long double, any of which shall
be treated as a pointer to the object, or to a copy of the object where necessary to enforce call-by-value semantics. Only if the caller can ascertain that the object is "constant" can it pass a pointer to the object itself.
If gr>10, go to OTHER. Otherwise, load the argument value into general register gr, set gr to gr+1, and go to SCAN. Values shorter than 32 bits are sign-extended or zero-extended, depending on whether they are signed or unsigned.
LONG_LONG:
Note that implementations are not required to support a long long data type, but if they do, the following treatment is required. If gr>9, go to OTHER. If gr is even, set gr to gr+1. Load the lower- addressed word of the long long into gr and the higher-addressed word into gr+1, set gr to gr+2, and go to SCAN.
Signature · 1 line
mailto:[email protected]
Re: [Qemu-devel] [PATCH] tcg, tci: Add TCG and interpreter for bytecode (virtual machine)
In reply to malcQuoted 7 lines · malc
Quoted 2 lines · Stuart Brady
Huh? If you're using a function pointer with the *correct* type, I hardly see how that's not sufficient.
Let me give you an example:
[snip]
*Mind boggles* :-)
You seem to be ignoring the words "correct type" in all of my sentences. My suggestion was to give op_call handling the information it that needs iff TCI is used. Yes, the code in tcg_gen_callN() is clearly not appropriate for TCI, although I'd somehow missed the fact that it may also need to be changed in future to support other new TCG back-ends.
I'm quite aware that functions must be invoked using the *correct type* of function pointer, though. Perhaps I wasn't specific enough in what I said, but please, I'm not completely clueless... :-)
Cheers,
Signature · 1 line
Stuart Brady
Re: [Qemu-devel] [PATCH] tcg, tci: Add TCG and interpreter for bytecode (virtual machine)
Quoted 18 lines · Stuart Brady
Quoted 7 lines · malc
Quoted 2 lines · Stuart Brady
Huh? If you're using a function pointer with the *correct* type, I hardly see how that's not sufficient.
Let me give you an example:
[snip]
*Mind boggles* :-)
You seem to be ignoring the words "correct type" in all of my sentences. My suggestion was to give
op_callhandling the information it that needs iff TCI is used. Yes, the code intcg_gen_callN()is clearly not appropriate for TCI, although I'd somehow missed the fact that it may also need to be changed in future to support other new TCG back-ends.
Quoted 3 lines
I'm quite aware that functions must be invoked using the *correct type* of function pointer, though. Perhaps I wasn't specific enough in what I said, but please, I'm not completely clueless... :-)
Are you thinking of a giant switch here, or what?
Signature · 1 line
mailto:[email protected]
Re: [Qemu-devel] [PATCH] tcg, tci: Add TCG and interpreter for bytecode (virtual machine)
Quoted 7 lines · malc
Quoted 3 lines · Stuart Brady
I'm quite aware that functions must be invoked using the *correct type* of function pointer, though. Perhaps I wasn't specific enough in what I said, but please, I'm not completely clueless... :-)
Are you thinking of a giant switch here, or what?
Yes.
Cheers,
Signature · 1 line
Stuart Brady
Am 28.09.2009 18:50, schrieb Stefan Weil:
Quoted 9 lines
Hello
The patch following this mail adds a new code generator to qemu. It includes a README file with more details.
Comments and contributions to complete it are welcome.
Regards
Stefan Weil
Hello,
The latest version of the TCG interpreter ("TCI") runs QEMU system emulation booting 32 or 64 bit x86 or mips linux on 32 or 64 bit x86 hosts.
x86 bios boot also works on arm hosts (real hardware) and mips hosts (qemu malta emulation).
Compilation was tested for powerpc host, too.
The code is available from http://repo.or.cz/w/qemu/ar7.git, see also
http://repo.or.cz/w/qemu/ar7.git/blob_plain/master:/tcg/bytecode/README
Of course I can also send patches to the list if people want integration in qemu master.
I am still looking for new test environments, especially hosts which are still unsupported by qemu.
Regards
Stefan Weil
Quoted 6 lines · Stefan Weil
Hello
The patch following this mail adds a new code generator to qemu. It includes a README file with more details.
Comments and contributions to complete it are welcome.
Could you compare the performance of TCG and TCI? I suppose that TCG is still faster, but by how much?
(I know TCI still needs a lot of optimization, but lets compare TCG and TCI with assumption that TCI is already matured)
Thanks,
J