Skip to content

Instantly share code, notes, and snippets.

@henrygouk
Created October 30, 2014 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrygouk/44120a19d2ab3f51b010 to your computer and use it in GitHub Desktop.
Save henrygouk/44120a19d2ab3f51b010 to your computer and use it in GitHub Desktop.
Example of using AVX with asmjit
#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