I defined aligned floats like this
typedef __attribute((aligned(64))) float aligned_float;
And then I define aligned floats with the restrict
keyword like this
typedef aligned_float * restrict aligned_floatptr;
This works like I expect. But since I almost always want these two together I tried typedef in one line like this
typedef __attribute((aligned(64))) float * restrict aligned_floatptr2
However, this does not work. The restrict
keyword is still recognized but the alignment is not. The compiler gives me no warning however. I only realized the alignment did not work by looking at the assembly.
Why does the combined definition not work and why don't I get a warning?
You can see the assembly for Clang and GCC here.
The reason I want to do this is that I have code like this
static void kernel(float * restrict a, float * restrict b, float * restrict c, int n) {
a = __builtin_assume_aligned(a, 64);
b = __builtin_assume_aligned(b, 64);
c = __builtin_assume_aligned(c, 64);
//rest of code
}
and I have MANY variations of this. I find it more convenient to use
static void kernel(aligned_flotptr a, aligned_floatptr b, aligned_floatptr c, int n) {
//rest of code
}
I just realized that Clang does not seem to recognizing even aligned_float
. It's only GCC the recognizes it. With Clang I still need to use __builtin_assume_aligned
(or maybe #praga omp sind aligned
). On the other hand, Clang produces good code even without alignment (unaligned instructions are as fast as the aligned versions for several generations now) so it's really really with GCC that I need alignment.