473,378 Members | 1,156 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Questions on creating a virtual machine: Operations

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
4 1236

"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
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

81
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there...
10
by: VB Programmer | last post by:
1. Is there an ASP.NET 2.0 version available yet? 2. Is there a VB.NET version available? 3. How do I install the source version on my dev machine (I have SQL Server 2000, VS.NET, IIS, etc...)...
3
by: Phil Lee | last post by:
Hi, I have a few questions regarding web services in .NET 2 1) Why, when I run code analysis do I get a source controlled files named {guid}/codeanalysislog.xml...
12
by: mohan | last post by:
Hi All, How to implement virtual concept in c. TIA Mohan
7
by: Philippe Poulard | last post by:
Hi, RefleX 0.1.3, a general-purpose XML Virtual Machine, is available here : http://reflex.gforge.inria.fr/ In this release, you'll find tutorials for mapping SQL to arbitrary complex XML...
4
by: Shawnk | last post by:
This post is intended to verify that true value semantics DO NOT EXIST for the Enum class (relative to boolean operations). If this is true then (thus and therefore) you can not design state...
10
by: John Salerno | last post by:
Ok, this is completely unnecessary so I don't intend to get into stuff that's beyond my skill, but I'm wondering how simple it would be to use Python to create a server that runs on my computer so...
17
by: Jess | last post by:
Hello, If I have a class that has virtual but non-pure declarations, like class A{ virtual void f(); }; Then is A still an abstract class? Do I have to have "virtual void f() = 0;"...
11
by: Alexander Adam | last post by:
Hi there! I've got a few (more generic) questions for those C++ experts out there. 1. I am trying to store any kind of data (custom PODs, numbers, strings etc.) within some kind of stream...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.