Threaded code is a technique used in the implementation of virtual machines (VMs). It avoids the overhead of calling subroutines repeatedly by 'thread

shadowofneptune / threaded-code-benchmark Public

submited by
Style Pass
2022-01-15 16:00:07

Threaded code is a technique used in the implementation of virtual machines (VMs). It avoids the overhead of calling subroutines repeatedly by 'threading' them together with jumps. This was originally done in assembly, where it is the most straightforward to implement. In C, it is harder to implement threaded code that is also performant.

These files are a test of three different techniques for produced fast threaded code. Each .c file implements a simple VM that counts to 2 billion, printing a star whenever the loop counter is evenly divisible by 200 million. The test settings can be changed in threaded_code.h. They all can be compiled and run with 'make benchmark'.

Doesn't use threaded code. This technique is often used to emulate switch statements in languages like Python. It is going to be the slowest of any of the VMs, and so acts a a control.

The equivalent in Fortran is assigned goto, but the Python VM calls it computed goto. GCC, Clang, and ICC allow for the location of a label to be stored in a variable. Since goto can only be used in local scope, the code implementing the VM instructions has to fit into one large function.

Leave a Comment
Related Posts