Skip to content

Instantly share code, notes, and snippets.

@andresfelipemendez
Last active February 8, 2018 22:15
Show Gist options
  • Save andresfelipemendez/0950bf41399f531630c43e88bace62ab to your computer and use it in GitHub Desktop.
Save andresfelipemendez/0950bf41399f531630c43e88bace62ab to your computer and use it in GitHub Desktop.
cl /arch:SSE3 main.cpp && main.exe
#include <string>
#include <array>
#include <memory>
#include <iostream>
using namespace std;
#include <intrin.h>
string get_cpu_name()
{
uint32_t data[4] = {0};
_asm
{
cpuid;
mov data[0], ebx;
mov data[4], edx;
mov data[8], ecx;
}
return string((const char*)data);
}
void assembler()
{
cout << "CPU is " << get_cpu_name() << endl;
float f1[] = { 1.f, 2.f, 3.f, 4.f };
float f2[] = { 5.f, 4.f, 3.f, 2.f };
float result[4] = {0.f};
_asm
{
movups xmm1, f1;
movups xmm2, f2;
mulps xmm1, xmm2;
movups result, xmm1;
}
for(size_t i = 0; i < 4; i++)
{
cout << result[i] << "\t";
}
cout << "\n";
int d, c;
_asm
{
mov eax, 1;
cpuid;
mov d, edx;
mov c, ecx;
}
if((d & (1 << 26)) != 0)
cout << "SSE2 is supported\n";
if((c & 1 ) != 0)
cout << "SSE3 is supported\n";
if((c & (1 << 19)) != 0)
cout << "SSE4.1 is supported\n";
if((c & (1 << 10)) != 0)
cout << "SSE4.2 is supported\n";
}
void instrinsics()
{
auto a = _mm_set_ps(1,2,3,4);
auto b = _mm_set_ps(5,3,2,1);
auto c = _mm_add_ps(a,b);
float f = c.m128_f32[0];
for(int i = 0; i < 4; ++i){
cout << c.m128_f32[i] << " ";
}
cout << '\n';
}
int main()
{
assembler();
instrinsics();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment