Skip to content

Instantly share code, notes, and snippets.

@Hydrotoast
Created December 25, 2012 12:49
Show Gist options
  • Save Hydrotoast/4373015 to your computer and use it in GitHub Desktop.
Save Hydrotoast/4373015 to your computer and use it in GitHub Desktop.
#include <iostream>
#include "emmintrin.h"
using namespace std;
int main(int argc, char* argv[]) {
const LENGTH = 1 << 10;
const SSE_LENGTH = LENGTH >> 2;
// Set constant vectors
__m128i A = _mm_set1_epi32(1);
__m128i B = _mm_set1_epi32(2);
// Allocate result array and cast as vector
unsigned int* C = (unsigned int*) _aligned_malloc(LENGTH * sizeof(unsigned int), 32);
__m128i* result = (__m128i*) C;
// Process vectorized addition: four items will be set per cycle
for (size_t i = 0; i < SSE_LENGTH; i += 4)
result[i] = _mm_add_epi32(A, B);
// Print the result array
for (size_t i = 0; i < LENGTH; ++i)
cout << C[i] << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment