Tag Archive for 'zcode'

Updated opcode format for ZCODE VM

Changes from previous version:

  • I removed 128-bit math from specifications – it is potentially a big pain to implement, and adds unneccessary overhead to opcode decoding
  • I removed fixed point math – it’s essentially just using integers and typecasting trancedental functions from floating point to integer.
  • Make scheme nicer
  • Included the fact that you actually need to specify memory operation size (what a waste, the extra field is only 2 bits, I might change this)

Currently opcode decoding is done, and I’m going to add operations to virtual machine now. I might work on some “paperwork” these days, and fix up a lot of documentation on the VM, compiler, and OS.

opcformat_v2
(yeah, it is poster size)

HybriC progress

I’ve been working on HybriC! I added constant expression evaulator, more syntax features (arrays, stuff), and actual code generator now. Right now it just generates code, but soon it will also built optimization tree, simplify it, and then output resulting code. It will compile very fast bytecode.

Some examples of how it compiles stuff right now (I picked ones without obvious optimizations that would be cut down by optimization tree anyway):
R0 = 100;
R1 = 200;
R2 = 300;

zap all; //this will mark all registers as "not important"

R0 = (R0 + R1*R1) * (R1*R1 + R2*R2);
compiles into:
MOV R0,100
MOV R1,200
MOV R2,300
MUL R1,R1
ADD R0,R1
MUL R1,R1
MUL R2,R2
ADD R1,R2
MUL R0,R1

And this:
F0 = 100.0;
F1 = 200.0;
F2 = 300;

R31 = F0 * (R1 + R2);
into this (it preserves F0, F1, F2 – these are registers 0, 1, 2, but they are treated as if they have floating point value. Typecasting is automatic, and done by the VM):
MOV F0,float 100.00
MOV F1,float 200.00
MOV R2,300
MOV R3,R1
ADD R3,R2
MOV F2,F0
MUL F2,R3
MOV R31,F2

Registers can be important and unimportant – value of important register will be preserved at all costs. Registers R0 and F0 are the same physical register, except when you write “F0″ you mean that you want to treat data inside the register as floating point value.