Home » U++ TheIDE » U++ TheIDE: Compiling, Linking, Debugging of your packages » How to link assembler compiled file
Re: How to link assembler compiled file [message #61689 is a reply to message #61688] |
Sat, 24 May 2025 20:12  |
frederik.dumarey
Messages: 30 Registered: December 2021 Location: Belgium
|
Member |
|
|
Quote:
Just to be sure, are you aware there are intrinsics for these?
Yes, I do, and for those interested, I have a small example of it here:
#include <iostream>
#include <immintrin.h>
int main(int argc, const char *argv[])
{
alignas(32) float a[8] = {1.0f, 2.0f, 3.0f, 4.0f, 1.5f, 2.5f, 3.5f, 4.5f};
alignas(32) float b[8] = {5.0f, 6.0f, 7.0f, 8.0f, 5.5f, 6.5f, 7.5f, 8.5f};
//load data in AVX registers
__m256 vec_a = _mm256_load_ps(a);
__m256 vec_b = _mm256_load_ps(b);
//multiply elements
__m256 vec_mul = _mm256_mul_ps(vec_a, vec_b);
//horizontal add to compute the sum of all elements
__m256 temp = _mm256_hadd_ps(vec_mul, vec_mul);
temp = _mm256_hadd_ps(temp, temp);
//extract 128 lower bits and sum
__m128 low = _mm256_castps256_ps128 (temp);
__m128 high = _mm256_extractf128_ps (temp,1);
__m128 sum = _mm_add_ps (low, high);
//extract the final result
float result = _mm_cvtss_f32 (sum);
std::cout << "Dot product: " << result << std::endl;
return 0;
}
Regards,
Frederik Dumarey
Belgium
|
|
|
Goto Forum:
Current Time: Mon Jun 16 06:00:57 CEST 2025
Total time taken to generate the page: 0.04441 seconds
|