Is this a proper way to extract a byte from a NEON uint8x16_t vector?

  arm64, armv7, c++, simd

I am a beginner to NEON intrinsics, and I wanted to work with uint8x16_t and also uint8x16x4_t.
While working with it I came across a situation, where I wanted to extract a byte from a uint8x16_t. Being naive to the details I accidentally began extracting bytes from it using the [] operator at runtime. But my compiler CLANG happily compiled the code, gave no errors or warnings and I got the desired output.

I searched through the ARM reference guides and I never seemed to find any reference on using the [] operator on a uint8x16_t vector, after all it’s a 128 bit register and not an array!? (Please correct me if I’m wrong).

Therefore, to bring light to the issue, I tracked the origin of the vector uint8x16_t in the header file arm_neon.h and I found this:

typedef __attribute__((neon_vector_type(16))) uint8_t uint8x16_t;
  • How is this stored in computer memory ?

  • Why am I able to use the [] operator on it directly, where I should
    be using:

    uint8_t fetch(uint8x16_t *r, int index) {
    unsigned char u[16];
    vst1q_u8(u, *r);
    return u[index];

    instead of:

    uint8_t fetch(uint8x16_t *r, int index){
    return (*r)[index];
    } // This is much faster in performance!

Every help will be greatly appreciated!

Source: StackOverflow C++