AsmJit是一个完整的JIT(Just-I-Time,运行时刻)的针对C++语言的汇编器,可以生成兼容x86和x64架构的原生代码,不仅支持整个x86/x64的指令集(包括传统的MMX和最新的AVX2指令集),而且提供了一套可以在编译时刻进行语义检查的API。
AsmJit的使用也没有任何的限制,适用于多媒体,虚拟机的后端,远程代码生成等等。
特性
完全支持x86/x64指令集(包括MMX,SSEx,AVX1/2,BMI,XOP,FMA3和FMA4)
底层次和高层次的代码生成概念
内置检测处理器特性功能
实现虚拟内存的管理,类似于malloc和free
强大的日志记录和错误处理能力
体积小,可直接嵌入项目,编译后的体积在150至200kb之间
独立性强,不需要依赖其他任何的库(包括STL和RTTI)
环境
1. 操作系统
BSD系列
Liux
Mac
Widows
2. C++编译器
BorladC++
Clag
GCC
MiGW
MSVC
其他的在”build.h”中文件中定义过的编译器
3. 后端
X86
X64
软件简介引自:https://www.cblogs.com/larexixi/p/5021641.html
// Create simple DWORD memory copy fuctio for 32 bit x86 platform:// (for AsmJit versio 0.8+)//// void ASMJIT_CDECL memcpy32(UIt32* dst, cost UIt32* src, SysUIt le);// AsmJit library#iclude <AsmJit/AsmJitAssembler.h>#iclude <AsmJit/AsmJitVM.h>// C library - pritf#iclude <stdio.h>usig amespace AsmJit;// This is type of fuctio we will geerate typedef void (*MemCpy32F)(UIt32*, cost UIt32*, SysUIt);it mai(it argc, char* argv[]){ // ========================================================================== // Part 1: // Create Assembler Assembler a; // Costats cost it arg_offset = 8; // Argumets offset (STDCALL EBP) cost it arg_size = 12; // Argumets size // Labels Label L_Loop; Label L_Exit; // Prolog a.push(ebp); a.mov(ebp, esp); a.push(esi); a.push(edi); // Fetch argumets a.mov(edi, dword_ptr(ebp, arg_offset + 0)); // get dst a.mov(esi, dword_ptr(ebp, arg_offset + 4)); // get src a.mov(ecx, dword_ptr(ebp, arg_offset + 8)); // get le // exit if legth is zero a.jz(&L_Exit); // Bid L_Loop label to here a.bid(&L_Loop); a.mov(eax, dword_ptr(esi)); a.mov(dword_ptr(edi), eax); a.add(esi, 4); a.add(edi, 4); // Loop util ecx is ot zero a.dec(ecx); a.jz(&L_Loop); // Exit a.bid(&L_Exit); // Epilog a.pop(edi); a.pop(esi); a.mov(esp, ebp); a.pop(ebp); // Retur a.ret(); // ========================================================================== // ========================================================================== // Part 2: // Make JIT fuctio MemCpy32F f = fuctio_cast<MemCpy32F>(a.make()); // Esure that everythig is ok if (!f) { pritf("Error makig jit fuctio (%u).\", a.error()); retur 1; } // Create some data UIt32 dst[128]; UIt32 src[128]; // Call JIT fuctio f(dst, src, 128); // If you do't eed the fuctio aymore, it should be freed MemoryMaager::global()->free((void*)f); // ========================================================================== retur 0;}
评论