Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Virtual Machine

Name: Anonymous 2011-09-01 1:28

Hello /prague/

I'm working on implementing a virtual machine of my own design. I started by writing the ALU, and I decided that it should operate on 32 bit words. It allows for many of the basic functions (NOT, AND, OR, XOR, >>, <<, +, -, *, /).

I am entirely new to designing machines (I'm a college sophomore.) and I ran into the problem of representation of floating point data. Is this implemented directly into the hardware of computers, or does software manipulate words to create floating point number manipulation higher up?

Name: Anonymous 2011-09-01 1:37

either would work. If it can be done in hardware it should be though. Doing floating point computation in software will take over 9000 times longer.

Name: Anonymous 2011-09-01 1:48

CPUs have had native floating point support for decades now. These days it is only implemented in software to meet special requirements, and rarely at that because most use cases (reproducibility, strict error checking, stricter rounding) can be achieved with a thin wrapper around hardware (see: Java).

Name: Anonymous 2011-09-01 14:14

>>3
Thank you. I just did some reading on IEEE 754, and it seems like that would be fairly easy to imitate.

Here is my only concern. My ALU takes two words and a byte representation of any of the above functions and performs that function upon the two words. How would the ALU distinguish between floating-point data and non-floating-point data? Would I have to write sets of functions for each and rely on the processor to send the right data to the ALU?

Name: Anonymous 2011-09-01 14:24

>>4
How would the ALU distinguish between floating-point data and non-floating-point data?
It can't if you're not using a dynamically-typed language. But I really wouldn't consider using one for implementing a VM.

Name: Anonymous 2011-09-01 14:32

For a VM I think the best language is C or something that let's you manipulate data on bit level.
That avoids problems like the one >>4 points out.

Name: Anonymous 2011-09-01 14:50

>>6
I'm using Java, so manipulation isn't really an issue.
The issue is that the ALU receives two 32 bit words and doesn't know whether the words should represent floating-point numbers or integers, it just knows that I passed it those words and a byte signifying that it should perform the add command.

I want to know how computer engineers/various wizards solve this issue. Should I implement a floating-point add and an integer add command, and then add each of those functions to the VM's machine code?

Name: Anonymous 2011-09-01 15:00

I think you're doing it wrong. You really shouldn't have an ALU interface called by the other parts of the processor.
What you need to do is to create instructions such as:
- Clear floating-point register;
- Clear integer register;
- Add integer immediate to floating-pointer register;
- Add floating-point immediate to floating-pointer register;
- Add integer immediate to integer register;
- Add floating-point immediate to integer register.

Name: Anonymous 2011-09-01 15:35

didnt we have this thread like 2 days ago

Name: Anonymous 2011-09-01 15:36

>>9
No. That previous thread was shit.

Name: VIPPER 2011-09-01 16:30

>>7
You use separate instructions to operate on floating point data. Atleast thats how its on x86.

Name: Anonymous 2011-09-01 18:38

>>8
Perhaps that's a problem. My CPU is designed to only have 1 register... It's just a toy though.

The processor emulator will be able to interpret and execute those instructions, it's just that I wanted to organize the code used to execute those instructions, so I wrote an ALU emulator. IF they organize it that way in real machines, why not on the VM?

>>11
That's what I was hoping to hear, and how I started implementing it. Thanks.

Name: Anonymous 2011-09-02 11:37

>>12
The processor emulator will be able to interpret and execute those instructions, it's just that I wanted to organize the code used to execute those instructions, so I wrote an ALU emulator. IF they organize it that way in real machines, why not on the VM?
Think about it this way: you have an ALU in the underlying processor, why not use it? It's both much more efficient and easier to do so. Real processors embark ALU only because they can't rely on any underlying hardware for computation.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List