[Bug 293] New: Utilize assert (ptr == (ptr & -align)) to assume alignment
gdc-bugzilla at gdcproject.org
gdc-bugzilla at gdcproject.org
Thu Jun 21 15:35:33 UTC 2018
https://bugzilla.gdcproject.org/show_bug.cgi?id=293
Bug ID: 293
Summary: Utilize assert (ptr == (ptr & -align)) to assume
alignment
Product: GDC
Version: 8,x
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: Normal
Component: gdc
Assignee: ibuclaw at gdcproject.org
Reporter: araspik at protonmail.com
This is a feature request.
GCC provides __builtin_assume_aligned to let the programmer inform the compiler
that a pointer is aligned. Some pointer alignment code I am using is not making
sense to the compiler, and so it is not using aligned SSE movement instructions
when possible. Here is my alignment (pseudo)code (note that I have excluded
casting pointers to arithmetic types and back):
len = -dst & 0xf; // Gets amount needed to align to 16 bytes
if (len) {
if (len & 1) {
*cast(ubyte*)dst = *cast(ubyte*)src;
dst++;
src++;
assert ((dst & 1) == 0); // This should work to assume X-byte alignment
}
...
}
// This should work, and the compiler should assume it's true even when asserts
are not being compiled.
assert ((dst & 0xf) == 0); // Now aligned.
assert ((dst & -0x10) == dst); // Same thing.
// I have to do this instead:
dst &= 0xf;
struct void16 {void[16] data;} // Example SSE register optimization
*cast(void16*)dst = *cast(void16*)src; // Should use movdqa and move into dst
aligned
// Does not work via asserts.
This could be used as a global assumption optimization.
GDC arguments (note that no AVX, but SSE 4.2):
gdc -march=native -mtune=native -frelease -Ofast
Additionally, I have excluded Phobos, enabled static compilation, and disabled
PIC and moduleinfo.
--
You are receiving this mail because:
You are watching all bug changes.
More information about the D.gnu
mailing list