|virtual machine efficiency firstname.lastname@example.org (ed_davis2) (2004-12-29)|
|Re: virtual machine efficiency email@example.com (Rafael 'Dido' Sevilla) (2004-12-30)|
|Re: virtual machine efficiency firstname.lastname@example.org (2004-12-30)|
|Re: virtual machine efficiency email@example.com (2004-12-30)|
|Re: virtual machine efficiency firstname.lastname@example.org (cr88192) (2004-12-30)|
|Re: virtual machine efficiency cfc@shell01.TheWorld.com (Chris F Clark) (2004-12-30)|
|Re: virtual machine efficiency email@example.com (2004-12-30)|
|[8 later articles]|
|Date:||29 Dec 2004 01:49:17 -0500|
|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' 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
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));
(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
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]
Return to the
Search the comp.compilers archives again.