Advertisement
Guest User

Untitled

a guest
Mar 1st, 2019
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1.  
  2. #define SIMDPP_ARCH_X86_SSE4_1 true
  3. #include <simdpp/simd.h>
  4. #include <iostream>
  5. #include <chrono>
  6. //example where i got this from
  7. //https://github.com/p12tic/libsimdpp/tree/2e5c0464a8069310d7eb3048e1afa0e96e08f344
  8.  
  9. // Initializes vector to store values
  10. void init_vector(float* a, float* b, size_t size) {
  11.     for (int i=0; i<size; i++) {
  12.         a[i] = i * 1.0;
  13.         b[i] = (size * 1.0) - i - 1;
  14.     }
  15. }
  16.  
  17.  
  18.  
  19. using namespace simdpp;
  20. int main() {
  21.     //1048576
  22.     const unsigned long SIZE = 4 * 150000;
  23.  
  24.     float vec_a[SIZE];
  25.     float vec_b[SIZE];
  26.     float result[SIZE];
  27.  
  28. ///////////////////////////*/
  29. //LibSIMDpp
  30.     //*
  31.     auto t1 = std::chrono::high_resolution_clock::now();
  32.  
  33.     init_vector(vec_a, vec_b, SIZE);
  34.     for (int i=0; i<SIZE; i+=4) {
  35.         float32<4> xmmA = load(vec_a + i);  //loads 4 floats into xmmA
  36.         float32<4> xmmB = load(vec_b + i);  //loads 4 floats into xmmB
  37.         float32<4> xmmC = add(xmmA, xmmB);  //Vector add of xmmA and xmmB
  38.         store(result + i, xmmC);            //Store result into the vector
  39.     }
  40.  
  41.     auto t2 = std::chrono::high_resolution_clock::now();
  42.  
  43.     std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count()
  44.               << " milliseconds\n";
  45.     //*/
  46.  
  47.  
  48. ///////////////////////////*/
  49. //standard
  50.     //*
  51.     init_vector(vec_a, vec_b, SIZE);
  52.     t1 = std::chrono::high_resolution_clock::now();
  53.  
  54.     for (auto i = 0; i < SIZE; i++) {
  55.         result[i] = vec_a[i]  + vec_b[i];
  56.     }
  57.  
  58.     t2 = std::chrono::high_resolution_clock::now();
  59.  
  60.     std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count()
  61.               << " milliseconds\n";
  62.     //*/
  63.  
  64.  
  65.     int i = 0;
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement