float test

#include <immintrin.h> #include <iostream> #include <chrono> #include <random> int main() { size_t lenght{ 1024 * 1024 * 64 }; float* a{ new float[lenght] }; float* b{ new float[lenght] }; float* c{ new float[lenght] }; float* r{ new float[lenght] }; std::mt19937_64 rng{ std::random_device{}() }; std::uniform_real_distribution<float> dist{ 0, 1 }; for (size_t i{ 0 }; i < lenght; ++i) { a[i] = dist(rng); b[i] = dist(rng); c[i] = dist(rng); } const float* ap = a; const float* bp = a; const float* cp = a; auto start{ std::chrono::high_resolution_clock::now() }; for (size_t i{ 0 }; i < lenght; i += 8) { __m256 ar = _mm256_load_ps(&ap[i]); __m256 br = _mm256_load_ps(&ap[i]); __m256 cr = _mm256_load_ps(&ap[i]); __m256 h = _mm256_fmadd_ps(ar, br, cr); _mm256_store_ps(&r[i], h); } auto end{ std::chrono::high_resolution_clock::now() }; std::cout << "Time: " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms."; delete[] a; delete[] b; delete[] c; delete[] r; std::getchar(); return 0; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.