Skip to content

Instantly share code, notes, and snippets.

@ButchDean
Created December 29, 2016 04:54
Show Gist options
  • Save ButchDean/fc8c19b20120b3bc4e9b1fb5ea7d1372 to your computer and use it in GitHub Desktop.
Save ButchDean/fc8c19b20120b3bc4e9b1fb5ea7d1372 to your computer and use it in GitHub Desktop.
SSE test/sample code from Game Engine Architecture by Jason Gregory
#include <cstdio>
#include <xmmintrin.h>
__m128 addWithAssembly(const __m128 a, const __m128 b)
{
__asm addps xmm0, xmm1
}
__m128 addWithIntrinsics(const __m128 a, const __m128 b)
{
return _mm_add_ps(a, b);
}
void testSSE()
{
__declspec(align(16)) float A[4];
__declspec(align(16)) float B[4] = { 8.0f, 6.0f, 4.0f, 2.0f };
__declspec(align(16)) float C[4];
__declspec(align(16)) float D[4];
__m128 a = _mm_set_ps(2.0f, 4.0f, 6.0f, 8.0f);
__m128 b = _mm_load_ps(&B[0]);
__m128 c = addWithAssembly(a, b);
__m128 d = addWithIntrinsics(a, b);
_mm_store_ps(&A[0], a);
_mm_store_ps(&B[0], b);
_mm_store_ps(&C[0], c);
_mm_store_ps(&D[0], d);
printf("a = %g %g %g %g\n", A[0], A[1], A[2], A[3]);
printf("b = %g %g %g %g\n", B[0], B[1], B[2], B[3]);
printf("c = %g %g %g %g\n", C[0], C[1], C[2], C[3]);
printf("a = %g %g %g %g\n", D[0], D[1], D[2], D[3]);
}
int main()
{
testSSE();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment