4

I wanted to know why the following code compiles in Visual Studio but gives a compilation error in Mingw GCC during porting. This is my first time coming in contact with __m128 type but from this link here it states

You should not access the __m128 fields directly. You can, however, see these types in the debugger. A variable of type __m128 maps to the XMM[0-7] registers.

The code base is very old and this type is being used as

Matrix m;
__m128  b0 = _mm_set_ps(b[0][0], b[1][0], b[2][0], 0);
__m128  b1 = _mm_set_ps(b[0][2], b[1][3], b[2][4], 0);

__m128  a00 = _mm_load1_ps(&a[0][0]);
__m128  a10 = _mm_load1_ps(&a[1][0]);
__m128  r1a = _mm_mul_ps(a00, b0);
__m128  r1b = _mm_mul_ps(a10, b1);
__m128  r1 = _mm_add_ps(r1a, r1b);

m[0][0] = r1.m128_f32[3];

The error that I get is

 error: request for member 'm128_f32' in 'r1', which is of non-class type '__m128 {aka __vector(4) float}'
  m[0][0] = r1.m128_f32[3];

I tried looking up this error here and here however I believe they do not apply to my case as they dealt with the C++ most vexing parse issue. Any suggestions on how I could resolve this issue would be appreciated. Thanks.

Community
  • 1
  • 1
MistyD
  • 16,373
  • 40
  • 138
  • 240

1 Answers1

2

GCC doesn't use a union for these types as VS does, the types are handled as built-in types. You can directly index a __m128, see here. This introduces a portability problem, of course. In my projects I use a wrapping class with a union and overloaded operator[] but the generated code is sub-optimal.

Community
  • 1
  • 1
rpress
  • 462
  • 3
  • 6