by cwaffles on 4/20/23, 2:32 PM with 27 comments
by asicsp on 4/20/23, 3:00 PM
by kibwen on 4/20/23, 2:56 PM
by cmrdporcupine on 4/20/23, 4:06 PM
C compilers do a pretty good job of optimizing these into something pretty efficient, and I imagine it helps that the size of the case values is constant, and it can be turned by the compiler into either a jump table lookup or an unrolled jmp depending on size, etc.
Rust enums, in contrast, can be variable sized at match time. And the elements can be nested a few levels deep. The obvious way to write an opcode execution loop in Rust -- a pattern match over an enum of opcodes -- I'm curious if this can be made to perform as well as in C/C++.
(I've been writing a virtual machine interpreter loop and so have a modest interest in seeing how this kind of thing, though I'm not optimizing for performance yet, so)
Don't see any explicit mention of this in this document.
by cwaffles on 4/20/23, 2:33 PM
by peoplearepeople on 4/20/23, 3:55 PM