Ian Lance Taylor
unread,Jan 6, 2015, 10:27:30 AM1/6/15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to minux, bdtex...@gmail.com, golang-nuts, Dan Kortschak
On Mon, Jan 5, 2015 at 8:56 PM, minux <
mi...@golang.org> wrote:
>
> I think it's the case for other languages, though. (e.g. in C/C++, if you
> get a float64 *x, you
> can't assume x is properly aligned to 16-byte. In fact, the problem is even
> worse in C/C++,
> because technically, malloc doesn't need to guarantee 16-byte alignment if
> the maximum
> alignment for C types is only 8-byte; but memory allocators in Go does
> guarantee 16-byte
> alignment if the object is > 8 byte but <= 16-byte, and 32-byte alignment if
> the object is
> larger than 16-byte)
All true but unimportant in practice. People who want to write their
own vectorized code in C use the aligned attribute on their variables
and use posix_memalign to dynamically allocate memory. Compilers like
GCC that support auto-vectorization force alignment of variables as
required. When alignment can not be forced, GCC generates code to
test the alignment at runtime and use the auto-vectorized path only
when possible.
Ian