-
-
Save henrygouk/44120a19d2ab3f51b010 to your computer and use it in GitHub Desktop.
Example of using AVX with asmjit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <asmjit/asmjit.h> | |
using namespace std; | |
using namespace asmjit; | |
using namespace asmjit::host; | |
int main(int argc, char **argv) | |
{ | |
JitRuntime runtime; | |
X86Assembler a(&runtime); | |
a.vmovups(ymm0, ptr(rsi)); //Load vector pointed to by second parameter | |
a.vmovups(ymm1, ptr(rdx)); //Load vector pointed to by third parameter | |
a.vaddps(ymm0, ymm0, ymm1);//Add them together | |
a.vmovups(ptr(rdi), ymm0); //Store the result in the location pointed to by first parameter | |
//a.db(0xCC); | |
a.ret(); | |
typedef void (*MyFunc)(float *, float *, float *); | |
MyFunc func = asmjit_cast<MyFunc>(a.make()); | |
float v1[] = {1, 2, 3, 4, 5, 6, 7, 8}; | |
float v2[] = {5, 5, 5, 5, 5, 5, 5, 5}; | |
float r[8]; | |
func(&r[0], &v1[0], &v2[0]); | |
for(int i = 0; i < 8; i++) | |
{ | |
cout << r[i] << " "; | |
} | |
cout << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment