This bugzilla service is closed. All entries have been migrated to
Bug 1331 - Alignment on 16 bytes, whereas AVX requires 32?
Summary: Alignment on 16 bytes, whereas AVX requires 32?
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - general (show other bugs)
Version: 3.3 (current stable)
Hardware: x86 - AVX Windows
: Highest Crash
Assignee: Nobody
Depends on:
Blocks: 3.3
  Show dependency treegraph
Reported: 2016-10-19 14:44 UTC by Thijs Withaar
Modified: 2019-12-04 16:27 UTC (History)
3 users (show)


Description Thijs Withaar 2016-10-19 14:44:24 UTC
Using Eigen 3.3rc1 on windows 7, 64 bit with Visual Studio 2013,
and /arch:AVX

EIGEN_IDEAL_MAX_ALIGN_BYTES is defined as 32 when AVX is enabled.

Somehow in 

aligned_malloc() still takes the code path given by EIGEN_MALLOC_ALREADY_ALIGNED
which results in 16-byte aligned memory.

This results in a crash in an line like
Eigen::VectorXd x = Eigen::VectorXd::Zero(n)
which traces down to a pstore.

Could it be that line 52 of Memory.h should read:

instead of:
Comment 1 Christoph Hertzberg 2016-10-20 13:56:20 UTC
I'm not sure, especially since the gcc and clang paths have the same condition (i.e. `== 16`). And as far as I remember the essential unit tests all work with gcc and clang and AVX enabled (currently I'm on a non-AVX cpu, I'll try that when I get home).
Comment 2 Gael Guennebaud 2016-10-24 20:27:55 UTC
This is strange because EIGEN_MALLOC_ALREADY_ALIGNED is defined only if EIGEN_DEFAULT_ALIGN_BYTES == 16 (Memory.h, line 52), and in Macros.h line 772 we have:


so in your case, EIGEN_DEFAULT_ALIGN_BYTES should be defined to 32, and thus EIGEN_MALLOC_ALREADY_ALIGNED would be disabled.

Are you sure you are using 3.3rc1? Could you check the value of EIGEN_DEFAULT_ALIGN_BYTES?
Comment 3 Thijs Withaar 2016-10-25 13:39:58 UTC
Using your suggestions:

was set correctly (32) for the static lib of which the code is part.
The application itself, however, did not have the AVX instruction set enabled.
This caused the functions in the .lib to use the non-32 byte version of the allocation routines.
Comment 4 Nobody 2019-12-04 16:27:26 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance:

Note You need to log in before you can comment on or make changes to this bug.