Nemeth Attila Nemeth Attila - 1 month ago 6
C++ Question

How to multply two float arrays using sse?

void sse_mul_float(float* a, float* b, int N)
{
int nb_iters = N / 4;

__m128* l = (__m128*)a;
__m128* r = (__m128*)b;

for (int i = 0; i < nb_iters; ++i, ++l, ++r)
_mm_store_ps(l, _mm_mul_ps (l, r));
}


I would like to multiply elements of one float array with another one and I would like to store the results in the first array

I am getting this error:
cannot convert ‘__m128* {aka __vector(4) float*}’ to ‘__m128 {aka __vector(4) float}’ for argument ‘1’ to ‘__m128 _mm_mul_ps(__m128, __m128)’

Answer
void sse_mul_float(float* a, float* b, int N)                                                                                                                                                                          
{          
  int nb_iters = N / sizeof(float);                                                                                                                                                                                         

  float c;
  __m128* l = (__m128*)a;                                                                                                                                                                                      
  __m128* r = (__m128*)b;


  for (int i = 0; i < nb_iters; ++i, ++l, ++r)
  {
      _mm_store_ps(&a[i*4], _mm_mul_ps(*l, *r));
  }

}
Comments