dm-jitaux is a Rust-based JIT compiler using modified auxtools, dmasm and Inkwell LLVM wrapper for boosting Byond DM performance without any hassle!

Overview

WIP PRs Welcome

dm-jitaux

dm-jitaux is a Rust-based JIT compiler using modified auxtools, dmasm and Inkwell LLVM wrapper for boosting Byond DM performance without any hassle (such as rewriting/refactroing your DM code).

Implementation status

Roadmap

  • PoC ✔️
  • Deoptimization ✔️
  • Sleeping proc deoptimization
  • Calls ✔️
  • Virtual calls ✔️
  • Type probing deoptimization
  • Heterogenous instruction optimization
  • JITed-to-JITed direct calls
  • Tiering
  • Branch / Call counting
  • Sleeping proc support

Opcodes

OpCode Status
GetVar SetCache, Field, Src, Local
SetVar SetCache, Field, Local
Add Float
Sub Float
Tg Float
Tl Float
Tge Float
Tle Float
AugAdd Float
AugSub Float
Teq ✔️
Ret ✔️
End ✔️
Test ✔️
Jz ✔️
JmpOr ✔️
JmpAnd ✔️
Jmp ✔️
PushInt ✔️
PushVal ✔️
GetFlag ✔️
Pop ✔️
IsNull ✔️
Not ✔️
Mul Float
CallGlobal No sleep deopt
Call StaticProc, DynamicProc, No sleep deopt
CallStatement StaticProc, DynamicProc, No sleep deopt
Abs ✔️

Dependencies

These instructions were taken directly from tgstation's rust-g documentation.

The Rust compiler:

  1. Install the Rust compiler's dependencies (primarily the system linker):

  2. Use the Rust installer, or another Rust installation method, or run the following:

    curl https://sh.rustup.rs -sSfo rustup-init.sh
    chmod +x rustup-init.sh
    # Nightly toolchain is required
    ./rustup-init.sh

    Alternatively without saving

    # Nightly toolchain is required
    curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly
  3. Set the default compiler to 32-bit:

    # Clone the `dm-jitaux` repository to a directory of your choice
    git clone https://github.com/ss220-space/dm-jitaux.git
    # in the `dm-jitaux` directory...
    cd dm-jitaux
    # Linux
    rustup target add i686-unknown-linux-gnu
    # Windows
    rustup target add i686-pc-windows-msvc
    
    # Clone the `auxtools` repository to a parent directory of dm-jitaux
    cd ..
    git clone https://github.com/ss220-space/auxtools.git --branch dm-jitaux
    # in the `auxtools` directory...
    cd auxtools
    # Linux
    rustup target add i686-unknown-linux-gnu
    # Windows
    rustup target add i686-pc-windows-msvc

System libraries:

  • Ubuntu and Debian users run:

    sudo dpkg --add-architecture i386
    sudo apt-get update
    sudo apt-get install zlib1g-dev:i386 libssl-dev:i386 pkg-config:i386
    sudo apt-get install gcc-multilib g++-multilib
  • Other Linux distributions install the appropriate 32-bit development and 32-bit runtime packages.

Building

LLVM

Windows

CMake required, can be downloaded from cmake.org

You need to build LLVM 12.0.0 on Windows with x32 target and MD CRT linking

Note: It takes 30-60 minutes to compile, 23 GB of free disk space

Download from LLVM github releases

# Unpack to path without spaces 
tar -xJf llvm-12.0.0.src.tar.xz
# Create build directory
mkdir build
cd build
# Configure 
cmake -DCMAKE_INSTALL_PREFIX=C:/LLVM -DLLVM_USE_CRT_DEBUG=MD -DLLVM_TARGETS_TO_BUILD="X86" -Thost=x86 -A Win32 ../llvm-12.0.0.src/
# Build
cmake --build .
# Install to CMAKE_INSTALL_PREFIX
cmake --build . --target install

Full guide: Building LLVM with CMake

Debian

sudo apt install llvm-12-dev:i386

Other

Checkout this for more info.

Compiling

Windows

# PowerShell
$env:LLVM_SYS_120_PREFIX = "C:\LLVM" # LLVM prefix specified before
cargo build --target i686-pc-windows-msvc
cargo test --target i686-pc-windows-msvc -- --test-threads=1

Linux

cargo build --target i686-unknown-linux-gnu
BYOND_PATH="~/byond" cargo test --target i686-unknown-linux-gnu -- --test-threads=1

See also

DM Opcode relative frequency table

opcode_counts.txt

License

dm-jitaux is licensed under the AGPL-3.0 License. See LICENSE for more details.

You might also like...
sblade or switchblade it's a multitool in one capable of doing simple analysis with any type of data, attempting to speed up ethical hacking activities

sblade or switchblade it's a multitool in one capable of doing simple analysis with any type of data, attempting to speed up ethical hacking activities

Use explicit container types with Scrypto! Leverage the Rust compiler's type checking to increase security and productivity when developing Radix blueprints.

Scrypto Static Types Use explicit container types with Scrypto! Leverage the Rust compiler's type checking to increase security and productivity when

Compiler & Interpreter for the (rather new and very experimental) Y programming language.

Y Lang Why would anyone build a new (and rather experimental) language with no real world use case. Design Y (pronounced as why) is based on the idea

Build fast, reward everyone, and scale without friction.
Build fast, reward everyone, and scale without friction.

Scrypto Language for building DeFi apps on Radix. Terminology Package: A collection of blueprints, compiled and published as a single unit. Blueprint:

proc macros for generating mut and non-mut methods without duplicating code

mwt Hey! You! Read this before using! mwt was thrown together pretty quickly for personal use, because I couldn't find an existing crate that does thi

An optimising Brainf*ck to x86-64 assembly compiler written in Rust

brainfrsk 2 An optimising Brainf*ck to x86-64 assembly compiler. This compiler can produce optimised binaries for macOS (Sytem V calling convention) b

The official zeta compiler
The official zeta compiler

Torq What makes Torq the goto language for creating CLI's? Smaller Executables Inbuilt argument and flag parser Your code will work anywhere in any OS

The nightly_crimes!{} macro commits horrible crimes to allow you to enable nightly features on the stable compiler.

The nightly_crimes!{} macro commits horrible crimes to allow you to enable nightly features on the stable compiler.

Comments
  • Optimize code-generation for deoptimizations using LLVM stack-maps

    Optimize code-generation for deoptimizations using LLVM stack-maps

    Now deopts uses LLVM StackMap feature This reduces the impact of deopt points on code size

    StackMap allows us to dump real variable locations at a given program point, allowing to read it manually from assigned registers/indirect inside deopt code, instead of packing values into arrays in deopt-calling code

    opened by semoro 1
  • Added GitHub Actions CI

    Added GitHub Actions CI

    Actions (Linux only, Windows action is just stub):

    • Build image with LLVM 13.0.1 (may be triggered manual);
    • Next: Build image with Rust (may be triggered manual or by LLVM image (re-)builded successful);
    • Next: Build DMJit in 3 ways:
    1. Manual, with specific BYOND version;
    2. On push commit in main branch or Rust image (re-)builded successful, with hardcoded BYOND version (514.1569);
    3. On pull-request opened, reopened, synchronize, labeled, unlabeled if PR contains "verified" label, with hardcoded BYOND version (514.1569);

    p.s. Needs replace in uses, racer396/dmjit to ss220-space/dmjit in.github/workflows/linux_build_dmjit_auto.yaml, .github/workflows/linux_build_dmjit_manual.yaml, .github/workflows/linux_build_dmjit_pullrequest.yaml

    opened by Racer396 0
  • Fix invalid assertion in variable_termination_pass

    Fix invalid assertion in variable_termination_pass

    It was incorrectly assumed that fix-point loop can always solve into stable solution, In fact, as 'Undecided' solution is higher priority then 'Present', phi loops will not reach fix-point

    Example: 0: Source 1: Phi[0, 1]

    On first pass we have decision for 1: Present vs Undecided, and Undecided wins

    opened by semoro 0
Releases(v0.1.0)
  • v0.1.0(Dec 5, 2021)

Owner
SS220
Space Station 13 Project
SS220
JIT compiler and runtime for a toy language, using Cranelift

Hello! This is a simple demo that JIT-compiles a toy language, using Cranelift. It uses the new JIT interface in development here. JIT takes care of m

Bytecode Alliance 468 Jan 7, 2023
An example of Brainf*** JIT-compiler with only the standard library.

jit-compiler An example of Brainf*** JIT-compiler with only the standard library. Prerequisite Rust(1.56.0-nightly or later, but it must work kind of

Akihito KIRISAKI 18 Jan 22, 2022
🦜 A hassle-free, highly performant, host it yourself Discord music bot built with Serenity in Rust. Powered by youtube-dl and Genius.

?? A hassle-free, highly performant and fast evolving Discord music bot built with Serenity in Rust. Deployment Usage Just create a bot account, copy

Miguel Mano 82 Dec 14, 2022
The 峨眉 (EMei) JIT/AOT backend framework.

emei The 峨眉 (EMei) JIT/AOT backend framework. Support Instructions x86_64 mov mov mov_zero_extend_bit8/16 mov_sign_extend_bit8/16/32 mov_rev movs(is m

Lyzh 14 Apr 11, 2022
HTTP microservice using Axum and Reqwest to request the Google Translate TTS endpoint without rate limits

HTTP microservice using Axum and Reqwest to request the Google Translate TTS endpoint without rate limits

Gnome! 5 Oct 5, 2022
Provides a wrapper to deserialize clap app using serde.

clap-serde Provides a wrapper to deserialize clap app using serde. API Reference toml const CLAP_TOML: &'static str = r#" name = "app_clap_serde" vers

null 17 Jan 9, 2023
Cloud-Based Microservice Performance Profiling Tool

Revelio Systems Revelio Systems is a student startup sponsored by UT Austin's Inventors Program in partnership with Trend Micro. Team: Tejas Saboo, So

Tejas Saboo 1 Feb 24, 2022
Simple library to host lv2 plugins. Is not meant to support any kind of GUI.

lv2-host-minimal Simple library to host lv2 plugins. Is not meant to support any kind of GUI. Host fx plugins (audio in, audio out) Set parameters Hos

Cody Bloemhard 11 Aug 31, 2022
Adds size optimizations to any Perseus app automatically.

Perseus Size Optimization Plugin WARNING: Until Perseus #66 is fixed, this plugin can actually increase overall binary size! Once that issue is fixed

arctic_hen7 6 Aug 14, 2022
Auto launch any application or executable at startup

Auto Launch Auto launch any application or executable at startup. Supports Windows, Mac (via AppleScript or Launch Agent), and Linux. How does it work

GyDi 38 Dec 27, 2022