public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Correct way to make a 16-byte aligned double* for SSE vectorization?
@ 2009-12-30 21:39 Benjamin Redelings I
  2009-12-31  9:36 ` Jie Zhang
  0 siblings, 1 reply; 4+ messages in thread
From: Benjamin Redelings I @ 2009-12-30 21:39 UTC (permalink / raw)
  To: gcc-help

Hi,

     I am trying to figure out how to make a double* that is 16-byte 
aligned in the way that SSE instructions want.  Hopefully this would 
allow GCC to auto-vectorize loops in a better way.  The problem that I 
am having is that I want a pointer to an aligned double, not an aligned 
pointer to a double.

     I am compiling with these options:
% gcc -c test.C -O3 -ftree-vectorizer-verbose=3 -ffast-math

According to the output of the vectorizer, none of the three ways 
(below) of declaring an aligned pointer actually work.  They are treated 
as unaligned accesses, so presumably the location of the pointer itself 
is being aligned, but it does not point to an aligned location.  In 
contrast, if I define an aligned double, and then define a pointer to 
it, this works.  Is this recommended?

I ask, because gcc-4.5 complains about declaring a 16-byte aligned 
double, if the double is an instantiation of a template parameter. (See 
PR42555.)

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42555

Thanks for any help!

-BenRI

P.S. Here is the example code.  As is, the pointers are recognized as 
aligned.  However, if you comment out the definition of SSE_PTR and 
replace it with any of the tree other approaches, they do not work.

typedef double real;

// these two lines work (together)
typedef real aligned_real __attribute__((aligned(16)));
typedef const aligned_real* SSE_PTR;

// note of these three approaches work to define an aligned pointer in a 
single line.
//typedef const real *SSE_PTR __attribute__((aligned(16)));
//typedef const real __attribute__((aligned(16))) *SSE_PTR;
//typedef const __attribute__((aligned(16))) real *SSE_PTR;

real f(SSE_PTR __restrict__ p, SSE_PTR __restrict__ q,int n)
{
   real sum = 0;
   for(int i=0; i<n;i++)
     sum += p[i] * q[i];

   return sum;
}

-BenRI

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-01-01  0:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-30 21:39 Correct way to make a 16-byte aligned double* for SSE vectorization? Benjamin Redelings I
2009-12-31  9:36 ` Jie Zhang
2009-12-31 20:28   ` Brian Budge
     [not found]     ` <4B3D0948.5040407@ncsu.edu>
2010-01-01  0:14       ` Brian Budge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).