A.nechi - 2 months ago 7x

C Question

I' trying to create some macros that are somehow similar to SIMD intrinsics. And the reason why I want to create these macros is that I'm working with a simulator called "Gem5" that does not support SIMD.

Well, first of all, i created a structure that defines a vector of 4 packed single precision floating point elements like so:

`typedef struct`

{

float vec1;

float vec2;

float vec3;

float vec4;

} __m128 __attribute__((aligned(16)));

then I've created the ADD macro:

`#define __M128_MM_ADD_PS(dest, a,b) \`

{ \

(dest)->vec1 = (a)->vec1 + (b)->vec1; \

(dest)->vec2 = (a)->vec2 + (b)->vec2; \

(dest)->vec3 = (a)->vec3 + (b)->vec3; \

(dest)->vec4 = (a)->vec4 + (b)->vec4; \

}

and another macro for storing the results in a float array:

`#define __M128_MM_MOVA_PS(dest, a) \`

{ \

dest[0] = a->vec1; \

dest[1] = a->vec2; \

dest[2] = a->vec3; \

dest[3] = a->vec4; \

}

and to them I've declared the variables as

`void foo(){`

__m128 bfly0_rv, x_n2_vec, x_N2_vec;

float *x;

__M128_MM_ADD_PS(bfly0_rv,x_n2_vec,x_N2_vec);

__M128_MM_MOVA_PS(&x[n2],bfly0_rv);

}

and I'm getting these kind of error messages:

for the ADD macro

(dest)->vec4 = (a)->vec4 + (b)->vec4;

for the storing macro

dest[3] = a->vec4;

Anyone could have an idea about that?

Answer

All of your macros will work with pointers to `__m128`

, but you pass just `__m128`

not `__m128 *`

. Just replace `->`

with `.`

inside macros or prepend macro arguments with `&`

:

```
__M128_MM_ADD_PS(&bfly0_rv, &x_n2_vec, &x_N2_vec);
__M128_MM_MOVA_PS(&x[n2], &bfly0_rv);
```

Also don't forget to enclose `dest`

and `a`

in braces in `__M128_MM_MOVA_PS`

.

P.S. It would be better to use `do { ... } while(0)`

instead of `{ ... }`

in macro definitions.

Source (Stackoverflow)

Comments