GithubHelp home page GithubHelp logo

becavalier / brainfuck-jit-interpreter Goto Github PK

View Code? Open in Web Editor NEW
37.0 4.0 6.0 1.77 MB

A handwritten Brainfuck JIT interpreter, mainly used for demonstration.

License: MIT License

Brainfuck 45.15% Makefile 0.65% C++ 46.86% Python 7.34%

brainfuck-jit-interpreter's Introduction

brainfuck-jit-interpreter

A handwritten Brainfuck JIT interpreter, mainly used for demonstration purposes.

How to use?

* Please make sure you have installed python 3.75 or above and clang++ / g++.

# run interpreter (with JIT or not).
make && ./interpreter ./bfs/HELLO_WORLD.bf [--jit]
# run benchmark.
make benchmark suite=mandelbrot  

Limitations of this program:

  • No exception-handling support.
  • No thread-safe guaranteed.
  • No fine-tuning of the generated assembly code.
  • Only implemented a simple stdout buffer.
  • The amount of consecutive "+", "-", "<" and ">" showing up in the source code cannot exceed 255, for "]", cannot exceed 23.
  • Only support X86-64 on macOS and Linux.

Benchmark Result

  • [System] macOS 10.14.6
  • [Compiler] Apple LLVM version 10.0.1 (clang-1001.0.46.4)
  • [Optimization Level] -O2

IO Intensive Case

Benchmark for 10 seconds: (higher score is better)
   12950 .out_interpreter
   35928 .out_jit (win)

Computing Intensive Case

Benchmark Result: (lower time is better)
    13.018s interpreter
     0.885s jit (win)

Sidenote

The actual performance of the interpreter that compiled with a higher-level optimization flag (-O2 / -O3) may be higher than the performance of the JIT compiler in some specific situations.

Because we don't have too much fine-tuning on the machine code generated by the JIT compiler, for example, too much emitted jmp may suffer the program from branch prediction penalty, no execution flow analysis may cause the JIT compiler to emit more instructions than the program really needs, etc. But in the contrast, the advanced C/C++ compilers are really good at generating highly optimized machine code even the program may suffer from a small wrong branch prediction penalty. So, whether the performance of the JIT compiler would be better than the interpreter, it depends on the real cases.

But anyway, we (JIT) win the game in the two cases of the benchmark suite :)

brainfuck-jit-interpreter's People

Contributors

becavalier avatar wjwoffline avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.