Nemeth Attila - 11 months ago 63

C++ Question

`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 Source

```
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));
}
}
```