Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define SIMDPP_ARCH_X86_SSE4_1 true
- #include <simdpp/simd.h>
- #include <iostream>
- #include <chrono>
- //example where i got this from
- //https://github.com/p12tic/libsimdpp/tree/2e5c0464a8069310d7eb3048e1afa0e96e08f344
- // Initializes vector to store values
- void init_vector(float* a, float* b, size_t size) {
- for (int i=0; i<size; i++) {
- a[i] = i * 1.0;
- b[i] = (size * 1.0) - i - 1;
- }
- }
- using namespace simdpp;
- int main() {
- //1048576
- const unsigned long SIZE = 4 * 150000;
- float vec_a[SIZE];
- float vec_b[SIZE];
- float result[SIZE];
- ///////////////////////////*/
- //LibSIMDpp
- //*
- auto t1 = std::chrono::high_resolution_clock::now();
- init_vector(vec_a, vec_b, SIZE);
- for (int i=0; i<SIZE; i+=4) {
- float32<4> xmmA = load(vec_a + i); //loads 4 floats into xmmA
- float32<4> xmmB = load(vec_b + i); //loads 4 floats into xmmB
- float32<4> xmmC = add(xmmA, xmmB); //Vector add of xmmA and xmmB
- store(result + i, xmmC); //Store result into the vector
- }
- auto t2 = std::chrono::high_resolution_clock::now();
- std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count()
- << " milliseconds\n";
- //*/
- ///////////////////////////*/
- //standard
- //*
- init_vector(vec_a, vec_b, SIZE);
- t1 = std::chrono::high_resolution_clock::now();
- for (auto i = 0; i < SIZE; i++) {
- result[i] = vec_a[i] + vec_b[i];
- }
- t2 = std::chrono::high_resolution_clock::now();
- std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count()
- << " milliseconds\n";
- //*/
- int i = 0;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement