By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,849 Members | 2,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,849 IT Pros & Developers. It's quick & easy.

Questions on creating a virtual machine: Operations

P: n/a
Hi there! I'm in the process of writing a virtual machine for my script
language, and I'm trying to determine the best way of handling operations on
different types of data. My language supports floats, ints, and unsigned
ints for numerical data. I have implemented the basic "assembly-ish" version
of the language, but I can't seem to make up my mind on how to do numerical
operations, like comparisons and mathematical functions. Should I have
separate opcodes for each datatype (like iadd, uadd, fadd for ints, uints
and floats) or should I have a single operation for all types and let C++
handle the type conversions? This vm will be used in my games, so it needs
to be fast.

Any thoughts? And perhaps any other general recommendations when it comes to
writing a vm?

Help will be very appreciated.
Yours,
Morten Aune Lyrstad
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Morten Aune Lyrstad" <wa****@spam.ever> wrote in message
news:sV******************@news4.e.nsc.no...
Hi there! I'm in the process of writing a virtual machine for my script
language, and I'm trying to determine the best way of handling operations on different types of data. My language supports floats, ints, and unsigned
ints for numerical data. I have implemented the basic "assembly-ish" version of the language, but I can't seem to make up my mind on how to do numerical operations, like comparisons and mathematical functions. Should I have
separate opcodes for each datatype (like iadd, uadd, fadd for ints, uints
and floats) or should I have a single operation for all types and let C++
handle the type conversions? This vm will be used in my games, so it needs
to be fast.

Any thoughts? And perhaps any other general recommendations when it comes to writing a vm?

Help will be very appreciated.
Yours,
Morten Aune Lyrstad

If performance is your goal, it would seem that separate op codes for each
type/operation
would be best, since you would avoid the extra run-time operation of
decoding the actual
values.

Jul 22 '05 #2

P: n/a
Thank you for your quick response.
Your answer was wat I thought it would be. However: You talk about decoding
overhead: Currently the actual type of the variable is stored as well (I
need to delete string memory on exit). Would this have any effect on your
evaluation?

Yours,
Morten Aune Lyrstad
Jul 22 '05 #3

P: n/a

"Morten Aune Lyrstad" <wa****@spam.ever> wrote in message
news:P6******************@news4.e.nsc.no...
Thank you for your quick response.
Your answer was wat I thought it would be. However: You talk about decoding overhead: Currently the actual type of the variable is stored as well (I
need to delete string memory on exit). Would this have any effect on your
evaluation?

Yours,
Morten Aune Lyrstad


Morten,

Its a bit hard to say without examining the code. However, I'm sure you can
always
right specialized/customized functions for dealing with specific types which
would outperform
the general purpose approach. Its all a trade-off, runtime performance
against code
complexity ( well not quite complexity, but you'd have more cases to code
and to test).
(one idea that has just sprung into my head is that you might use templates
so your effort
in coding would be reduced somewhat, but you would still get the runtime
performance advantage. ).

You really need to benchmark alternatives, its ok for me to say one approach
is bound to
be faster than the other, but I'm not saying how much, if the difference is
marginal, you
might want to look at the general approach since this is likely to be less
complicated to
get right.

good luck!

dave

Jul 22 '05 #4

P: n/a
Thank you very much! Especially for the template function suggestion.
Genious! I hadn't thought of that :-) I'll continue on my current road then,
with separate operations for each datatype.
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.