virtual machine efficiency

"ed_davis2" <ed_davis2@yahoo.com>
29 Dec 2004 01:49:17 -0500

          From comp.compilers

Related articles
virtual machine efficiency ed_davis2@yahoo.com (ed_davis2) (2004-12-29)
Re: virtual machine efficiency dido@imperium.ph (Rafael 'Dido' Sevilla) (2004-12-30)
Re: virtual machine efficiency anton@mips.complang.tuwien.ac.at (2004-12-30)
Re: virtual machine efficiency vbdis@aol.com (2004-12-30)
Re: virtual machine efficiency cr88192@hotmail.com (cr88192) (2004-12-30)
Re: virtual machine efficiency cfc@shell01.TheWorld.com (Chris F Clark) (2004-12-30)
Re: virtual machine efficiency lars@bearnip.com (2004-12-30)
[8 later articles]
| List of all articles for this month |

From: "ed_davis2" <ed_davis2@yahoo.com>
Newsgroups: comp.compilers,comp.lang.misc
Date: 29 Dec 2004 01:49:17 -0500
Organization: http://groups.google.com
Keywords: VM, question
Posted-Date: 29 Dec 2004 01:49:17 EST

I have developed a simple stack based virtual machine. I would like
it to be as efficient as possible, in terms of both speed and object
code size. Size, as in size of the object code the VM processes
(byte-code), and not necessarily the size of the VM.


But I've run into one of those situations where I can't figure out how
to have both.


All of the opcodes are one byte in size. Given the instruction:


push address


'push' takes one byte, and the address takes 4 bytes. If I pack
the code into a byte array, this takes 5 bytes. However, now
that means that address isn't on a word boundary. If I load
'address' using:


unsigned char *code;


operand = *(int *)code;


I incur a speed hit on many processors, and it may even fail on
others, since code probably isn't suitably aligned.


But if I use:


memcpy(&operand, code, sizeof(operand));


or


operand =
(code[pc]) |
(code[pc + 1] << 8) |
(code[pc + 2] << 16) |
(code[pc + 3] << 24);


I don't incur the miss-aligned speed hit, but it is nowhere as
fast as "operand = *(int *)code;" could be, if code were suitably
aligned.


I could make all opcodes a word in size, and make the code array an
array of integers. But that would dramatically increase the size of
the byte-code required by the VM.


Is there a way I can have both fast loading of operands, and
small byte-code size?
[Well, I suppose you could do halfword alignment, or you could split
the code into two separate sections, a list of bytes for the opcodes,
and a list of words for the operands. -John]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.