Gcc pixel alignment

Does gcc have a memory alignment pragma, akin #pragma vector aligned in the Intel compiler? I would like to tell the compiler to optimize a specific loop using aligned load / store commands. to avoid possible confusion, this is not about structured packaging.

eg:

 #if defined (__INTEL_COMPILER) #pragma vector aligned #endif for (int a = 0; a < int(N); ++a) { q10 += Ix(a,0,0)*Iy(a,1,1)*Iz(a,0,0); q11 += Ix(a,0,0)*Iy(a,0,1)*Iz(a,1,0); q12 += Ix(a,0,0)*Iy(a,0,0)*Iz(a,0,1); q13 += Ix(a,1,0)*Iy(a,0,0)*Iz(a,0,1); q14 += Ix(a,0,0)*Iy(a,1,0)*Iz(a,0,1); q15 += Ix(a,0,0)*Iy(a,0,0)*Iz(a,1,1); } 

thank

+7
optimization gcc alignment memory pragma
Apr 21 '10 at 23:20
source share
3 answers

From http://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html

 typedef double aligned_double __attribute__((aligned (16))); // Note: sizeof(aligned_double) is 8, not 16 void some_function(aligned_double *x, aligned_double *y, int n) { for (int i = 0; i < n; ++i) { // math! } } 

This will not make aligned_double 16 bytes wide. This will simply align to the 16-byte boundary, or rather, to the first in the array. Looking at the disassembly on my computer, as soon as I use the alignment directive, I begin to see many vector operations. I am currently using a computer with a Power architecture, so this is altivec code, but I think it does what you want.

(Note. I did not use double when I tested this because altivec does not support double floats.)

You can see some other examples of autovectorization using type attributes here: http://gcc.gnu.org/projects/tree-ssa/vectorization.html

+8
Apr 21 '10 at 23:40
source share

I tried your solution with g ++ version 4.5.2 (both Ubuntu and Windows) and it did not vectorize the loop.

If the alignment attribute is removed, it vectorizes the loop using unplaced loads.

If the function is built-in so that the array can be accessed directly with the pointer removed, then it is vectorized with load balancing.

In both cases, the alignment attribute prevents vectorization. This is ironic: "aligned_double * x" should have allowed vectorization, but it does the opposite.

What was the compiler that told you vectorized loops? I suspect this is not a gcc compiler?

+5
Aug 09 2018-11-11T00:
source share

Gcc has a memory alignment pragma, akin #pragma vector aligned

It seems that newer versions of GCC have __builtin_assume_aligned :

Built-in function: void * __builtin_assume_aligned (const void *exp, size_t align, ...)

This function returns its first argument and allows the compiler to assume that the returned pointer at least aligns the bytes. This inline can have two or three arguments, if it has three, the third argument must be an integer type, and if it is nonzero it means offset offset. For example:

 void *x = __builtin_assume_aligned (arg, 16); 

means that the compiler can consider x set to arg to be at least 16 bytes, and:

 void *x = __builtin_assume_aligned (arg, 32, 8); 

means that the compiler can take for x, set to arg that (char *) x - 8 is aligned by 32 bytes.

Based on some other stack overflow questions and answers around 2010, it seems that the built-in was not available in GCC 3 and early GCC 4. But I don't know where the cut-off point is.

+1
Mar 27 '17 at 6:24
source share



All Articles