Live data from Hacker News

Write Your Own Virtual Machine

justinmeiners.github.io

31–40 of 79 posts

Re: Write Your Own Virtual Machine

#34

One of my favorite techniques for implementing VMs is the "computed goto": https://eli.thegreenplace.net/2012/07/12/computed-goto-for-e... Consider this example for dispatching instructions from the article: while (running) { uint16_t op = mem_read(reg[R_PC]++) >> 12; switch (op) { case OP_ADD: {ADD, 6} break; case OP_AND: {AND, 7} break; case OP_NOT: {NOT, 7} break; case OP_BR: {BR, 7} break; ... } } That code has a…

Do you know where i can find thrse implementations in ruby or python??

Re: Write Your Own Virtual Machine

#35

Earlier quoted context omitted.

Where can I learn about techniques like that? Any recommendation would be very appreciated!

Look up work by Stefan Brunthaler, like this overview paper ("Virtual-Machine Abstraction and Optimization Techniques"): https://www.sba-research.org/wp-content/uploads/publications... Make sure to check out the references. I especially like "Ertl, M. A. and D. Gregg, The structure and performance of efficient interpreters, Journal of Instruction-Level Parallelism 5 (2003)"

There goes the weekend...

Do you know of any recent efforts to combine ML and VM optimizations ?

(I read about the VS compiler and profile-based optimizations)

Re: Write Your Own Virtual Machine

#36

One of my favorite techniques for implementing VMs is the "computed goto": https://eli.thegreenplace.net/2012/07/12/computed-goto-for-e... Consider this example for dispatching instructions from the article: while (running) { uint16_t op = mem_read(reg[R_PC]++) >> 12; switch (op) { case OP_ADD: {ADD, 6} break; case OP_AND: {AND, 7} break; case OP_NOT: {NOT, 7} break; case OP_BR: {BR, 7} break; ... } } That code has a…

Do you know where i can find thrse implementations in ruby or python??

It's "of", rather than "in"... this is probably the Python one mentioned:

https://github.com/python/cpython/blob/d7538dd5e3e04a8db22e1...

Re: Write Your Own Virtual Machine

#37
post #35

Earlier quoted context omitted.

Look up work by Stefan Brunthaler, like this overview paper ("Virtual-Machine Abstraction and Optimization Techniques"): https://www.sba-research.org/wp-content/uploads/publications... Make sure to check out the references. I especially like "Ertl, M. A. and D. Gregg, The structure and performance of efficient interpreters, Journal of Instruction-Level Parallelism 5 (2003)"

There goes the weekend... Do you know of any recent efforts to combine ML and VM optimizations ? (I read about the VS compiler and profile-based optimizations)

This one is good: http://www.tara.tcd.ie/bitstream/handle/2262/64047/Optimizin...

Though you might not think of hill climbing as "machine learning".

Re: Write Your Own Virtual Machine

#38

I like this tutorial but it should be mentioned that before implementing a virtual machine one should understand that there are many computing models and many alternative mechanisms within each of them. Implementing VM for sequential program execution is relatively easy. What is more (conceptually) difficult is concurrency, asynchronous processes etc.

Author here. Definitely agree. The intent was to write the simplest possible to VM that could run real programs. VMs are obviously a deep field of research and there are plenty more projects to learn from.

Re: Write Your Own Virtual Machine

#39

One of my favorite techniques for implementing VMs is the "computed goto": https://eli.thegreenplace.net/2012/07/12/computed-goto-for-e... Consider this example for dispatching instructions from the article: while (running) { uint16_t op = mem_read(reg[R_PC]++) >> 12; switch (op) { case OP_ADD: {ADD, 6} break; case OP_AND: {AND, 7} break; case OP_NOT: {NOT, 7} break; case OP_BR: {BR, 7} break; ... } } That code has a…

Thanks! I was not familiar with this technique. What do you think about the C++ table of function pointers towards the end? I imagine that would be slower with the additional level of indirection, but I haven't profiled or examined the assembly.
Post reply on HN