4

Does NEON support aliasing of the vector data types with their scalar components?

E.g.(Intel SSE)

typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__));

The above will allow me to do:

__m128i* somePtr;
somePtr++;//advance to the next block

Aliasing a la Intel it will allow to advance my pointer to the next block I want to process without managing extra counts and indexes.

celavek
  • 5,575
  • 6
  • 41
  • 69

3 Answers3

2

The __may_alias__ attribute on __m128i should be viewed as a work-around which makes it possible to write strict-aliasing-correct code even though Intel completely screwed up the signatures of some of the SEE load/store intrinsics. (The 8-byte loading _mm_loadl_epi64(const __m128i*) is the most hilarious example, but there are others). ARM got their intrinsics right, so __may_alias__ isn't needed.

Just use pointers to the element type, and use explicit loads and stores. In my experience that leads to better code being generated, and is probably also more portable. (Does the ARM C language spec even allow pointers to NEON types? I wouldn't be surprised if they didn't).

fgp
  • 8,126
  • 1
  • 17
  • 18
1

NEON intrinsics implementation does NOT support aliasing of the vector data types with their scalar components.

celavek
  • 5,575
  • 6
  • 41
  • 69
0

GCC supports a bunch of intrinsics when you specify -mfpu_neon. One of the ones you'd be interested in, I'm guessing, is int32x4_t. More info about all the types available can be found on the ARM site.

Goz
  • 61,365
  • 24
  • 124
  • 204
  • I know about the intrinsics and the available vector types. I'm interested in aliasing of the types. The int32x4_t you mention will enda up as a struct containing 2 doubles similar to struct some {double __private1, __private2;};(you can check that in the arm_neon.h header). With Intel SSE if I have an array of unsigned 16 bit values for example and a pointer to that array using the type described in the question I can safely do __m128i* nameAlias = (__m128i*)myArray; I'm not sure I can do that with the ARM types; I could not find anything in the documentation about that. – celavek Aug 26 '11 at 13:36
  • I could certainly try to force the conversion but I'm interested to know if that is safe and\or supported by the implementation of those intrinsics and vector types. – celavek Aug 26 '11 at 13:38
  • int32x4_t is declared just like __m128i (`typedef __builtin_neon_si int32x4_t __attribute__ ((__vector_size__ (16)));`) but without the `__may_alias__` attribute. My best guess is that you will run into problems doing what you want to do, but I am unsure so will leave this as a comment rather than a full answer. – James Greenhalgh Aug 26 '11 at 14:09