Created
September 16, 2015 20:14
-
-
Save quasilyte/d7cf5cec1af8673da254 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source | |
z = 100 | |
x = 4 | |
y = 10 | |
x = x + y | |
z = z + y | |
// stack based: | |
push 100 | |
push 10 | |
dup | |
push 4 | |
add | |
add | |
// => 6 instruction fetces (costy) | |
// => (+ 1 4 1 4 1 1 4 1 1) => 18 size in bytes | |
// we can replace {add,add} with n-add like: | |
n-add 2 | |
// then it will take 5 fetches, but byte size will be 20 | |
// register based: | |
// z:0, x:1, y:2 | |
n-set-const { | |
i(0 100) | |
i(1 4) | |
i(2 10) | |
} | |
n-left-add { | |
i(1 2) | |
i(0 1) | |
} | |
// => 2 instruction fetches (cheaper) | |
// => (+ 1 1 4 4 1 4 4 1 4 4 1 1 4 4 1 4 4) 47 size in bytes | |
// o t i i t i i t i i o t i i t i i | |
// o -- operation byte | |
// t -- operand types descriptor | |
// i -- int32 operand |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment