Unexpressed loading / saving in gcc extension

I need to access unbalanced values ​​using the GCC vector extension

The program below crashes - both in clang and gcc

typedef int __attribute__((vector_size(16))) int4;
typedef int __attribute__((vector_size(16),aligned(4))) *int4p;

int main()
{
        int v[64] __attribute__((aligned(16))) = {};
        int4p ptr = reinterpret_cast<int4p>(&v[7]);
        int4 val = *ptr;
}

However, if I change

typedef int __attribute__((vector_size(16),aligned(4))) *int4p;

to

typedef int __attribute__((vector_size(16),aligned(4))) int4u;
typedef int4u *int4up;

The generated assembly code is correct (using uncluttered load) - both in clang and in gcc.

What is wrong with a single definition or what will I skip? Could this be the same error in both clang and gcc?

Note: this happens in both clang and gcc

+4
source share
1 answer

TL DR

, pointee. vector_size , aligned. , GCC, Clang.

GCC, § 6.33.1 ( ):

aligned ()

( ) . [...]

, , - , . ,

typedef int __attribute__((vector_size(16),aligned(4))) *int4p;

T, * T, :

  • * T - 16- (16 ).
  • T - , 4- ( * T, ).

§ 6.49 ( ):

SIMD, , . , x86 MMX, 3DNow! SSE .

. typedef:

typedef int v4si __attribute__ ((vector_size (16)));

int , , . , , v4si 16 int. 32- int 4 4 , foo - V4SI.

vector_size , ​​ , . , , .

Demo

#include <stdio.h>

typedef int __attribute__((aligned(128))) * batcrazyptr;
struct batcrazystruct{
    batcrazyptr ptr;
};

int main()
{
    printf("Ptr:    %zu\n", sizeof(batcrazyptr));
    printf("Struct: %zu\n", sizeof(batcrazystruct));
}

:

Ptr:    8
Struct: 128

batcrazyptr ptr , .

, typedef, int4u. , typedef.

+6

Source: https://habr.com/ru/post/1668227/


All Articles