Giter VIP home page Giter VIP logo

jitffi's Introduction

JitFFI

A fast and customizable JIT compiler for FFI (Foreign-Function Interface).

Support

Architecture Operating System Calling convention Compilers Support
x86-64 Windows Microsoft x64 MSVC, MinGW Most
x86-64 Linux System V AMD64 ABI GCC Most

Why Fast and Customizable?

The JitFFI is a compiler which compiles function info to a FFI function.

Call a function with JitFFI = Call a FFI function that JitFFI compiled. So it is fast.

It have many modes to compile, includes:

  1. Compile function-info.
  2. Compile function-info & arguments.
  3. Compile function-info & arguments & function-address. ... and more.

You can let JitFFI to compile in a mode you need. So it is customizable.

Run Example

python ./test.py -t n   # n is the num you want to run.

Compile to Static Library

python ./test.py -c

This command will create a 'libjitffi.a' file.

Usage (in C++)

JitFuncPool is a memory pool, which is executable.

JitFunc is a part of a JitFuncPool, which stands for a function.

To create JitFunc, JitFuncCreater is used.

  1. Compile to library.
  2. Using #include "jitffi.h" and import this library.

Example Code:

#include "jitffi.h"
#include <stdio.h>

double func(double v)
{
	printf("%lf\n", v);
	return v * 2;
}

int main(void)
{
	using namespace JitFFI;
	using namespace JitFFI::CurrABI;

	ArgTypeList tl = { &atu_double };

	ArgumentInfo info = GetArgInfo(atu_double, tl);

	JitFuncPool jfp(0x1000, JitFuncPool::ReadWrite);
	JitFunc jf(jfp);
	JitFuncCreater jfc(jf);

	auto f = Compile(jfc, info, func);

	double v = 3.14;
	double r;
	const void* dl[] = { &v };
	f(&r, dl);
	printf("%lf\n", r);
}

Command:

python ./test.py -c                 # Create libjitffi.a
g++ test.cpp -L. -ljitffi -o test   # Create test
./test                              # Run test

Usage (in C)

JitFFI has a header file named jitffi_c.h for C program.

All struct/class are packed with jitffi_XXX, and passed by pointer.

Only support CurrABI in C header.

JitFFI::_Platform_::atu_XX in C is jitffi_type_XX.

  1. Compile to library. (Add jitffi-c.cpp to source.)
  2. Using #include "jitffi-c.h" and import this library.

Example Code:

#include "jitffi-c.h"
#include <stdio.h>

double func(double v)
{
	printf("%lf\n", v);
	return v * 2;
}

int main(void)
{
	jitffi_argtype_ptr tl[] = { jitffi_type_double, NULL };

	jitffi_arginfo *info = jitffi_create_arginfo(jitffi_type_double, tl);

	jitffi_jfp *jfp = jitffi_create_jfp(0x1000, jitffi_readwrite);
	jitffi_jf *jf = jitffi_create_jf(jfp);
	jitffi_jfc *jfc = jitffi_create_jfc(jf);

	jitffi_f2* f = (jitffi_f2*)jitffi_compile(jfc, info, (void*)&func, NULL);

	double v = 3.14;
	double r;
	const void* dl[] = { &v };
	f(&r, dl);
	printf("%lf\n", r);

	jitffi_release_jfc(jfc);
	jitffi_release_jf(jf);
	jitffi_release_jfp(jfp);
}

Command:

python ./test.py -c               # Create libjitffi.a
gcc -c test.c                     # Create test.o
g++ test.o -L. -ljitffi -o test   # Create test
./test                            # Run test

jitffi's People

Contributors

chillmagic 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jitffi's Issues

Some Useless Codes

jitffi-ms64.cpp : 168, result of computation of two unsigned integers is also unsigned and is guaranteed to be non-negative, meaning that the assertion is useless

image

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.