Close

Double float benchmark with close to C speed

A project log for L1VM

A tiny virtual machine with a 64 bit RISC CPU.

jay-tjay-t 05/18/2019 at 18:540 Comments

I wrote a benchmark calculating with double float numbers.

The benchmark on my L1VM is close to a native C program doing the same math.

Here is the L1VM benchmark source code:

(main func)
    (set int64 1 zero 0)
    (set double 1 x 23.0)
    (set double 1 y 42.0)
    (set double 1 z 7.0)
    (set double 1 a 1.0)
    (set int64 1 max 80000000Q)
    (set int64 1 one 1)
    (ASM)
    loada zero, 0, I0
    loadd x, 0, F1
    loadd y, 0, F2
    loadd z, 0, F3
    loadd a, 0, F4
    loadd a, 0, F10
    loadd y, 0, F22
    loadd x, 0, F20
    loada one, 0, I4
    loada max, 0, I5
    loada one, 0, I6
    loadl :jit, I40
    loadl :jit_end, I41
    // run jit compiler
    intr0 253, I40, I41, 0
:loop
    // call jit code
    intr0 254, I0, 0, 0
    // jump to following non-jit code
    jmp :next
:jit
    addd F10, F20, F10
    addd F10, F20, F10
    addd F10, F20, F10
    addd F10, F20, F10
    addd F10, F20, F10
    addd F10, F20, F10
    addd F10, F20, F10
    addd F10, F20, F10
    addd F10, F20, F10
    addd F10, F20, F10
    addd F10, F22, F10
    addd F10, F22, F10
    addd F10, F22, F10
    addd F10, F22, F10
    addd F10, F22, F10
    addd F10, F20, F10
    addd F10, F20, F10
    addd F10, F20, F10
    addd F10, F20, F10
    addd F10, F20, F10
    addd F10, F20, F10
    addd F10, F20, F10
    addd F10, F20, F10
    addd F10, F20, F10
    addd F10, F20, F10
    addd F10, F22, F10
    addd F10, F22, F10
    addd F10, F22, F10
    addd F10, F22, F10
:jit_end
    addd F10, F22, F10
    // store
:next
    intr0 5, F10, 0, 0
    intr0 7, 0, 0, 0
    addi I4, I6, I4
    lseqi I4, I5, I30
    jmpi I30, :loop
    intr0 5, F10, 0, 0
    intr0 7, 0, 0, 0
    intr0 255, 0, 0, 0
    (ASM_END)
(funcend)

Here is the result of the C program:

$time ./double-test >/dev/null 2>&1

real	1m3,400s
user	1m3,249s
sys	0m0,148s

And my L1VM:

$time vm/l1vm prog/jit-test-double >/dev/null 2>&1

real	1m11,828s
user	1m11,704s
sys	0m0,120s

So my VM is close to C in that case. :)

Discussions