diff --git a/include/ceres/internal/port.h b/include/ceres/internal/port.h index 1193fcfcb..f4dcaee7b 100644 --- a/include/ceres/internal/port.h +++ b/include/ceres/internal/port.h @@ -33,9 +33,8 @@ // This file needs to compile as c code. #ifdef __cplusplus - +#include #include "ceres/internal/config.h" -#include "Eigen/Core" #if defined(CERES_TR1_MEMORY_HEADER) #include #else @@ -57,7 +56,6 @@ using std::shared_ptr; // what case we're in and write macros that do the right thing. #ifdef CERES_USE_CXX11 namespace port_constants { - static constexpr size_t kMaxAlignBytes = // Work around a GCC 4.8 bug // (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56019) where @@ -67,22 +65,7 @@ static constexpr size_t kMaxAlignBytes = #else alignof(std::max_align_t); #endif - -static constexpr bool kShouldAlignMatrix = 16 <= kMaxAlignBytes; -static constexpr size_t kAlignment = kShouldAlignMatrix ? 16 : 1; - -static constexpr int kEigenAlignmentHint = - kShouldAlignMatrix ? Eigen::AutoAlign : Eigen::DontAlign; } // namespace port_constants - -#define CERES_ALIGNMENT_SPECIFIER alignas(::ceres::port_constants::kAlignment) -#define CERES_MATRIX_ALIGN_HINT ::ceres::port_constants::kEigenAlignmentHint - -#else // !CXX_11 - -#define CERES_ALIGNMENT_SPECIFIER -#define CERES_MATRIX_ALIGN_HINT Eigen::DontAlign - #endif } // namespace ceres diff --git a/include/ceres/jet.h b/include/ceres/jet.h index 8515be844..1e95eaa56 100644 --- a/include/ceres/jet.h +++ b/include/ceres/jet.h @@ -228,8 +228,23 @@ struct Jet { T a; // The infinitesimal part. - // See ceres/include/internal/port.h for meaning of the #defines here. - CERES_ALIGNMENT_SPECIFIER Eigen::Matrix v; + + // We allocate Jets on the stack and other places they + // might not be aligned to 16-byte boundaries. If we have C++11, we + // can specify their alignment anyway, and thus can safely enable + // vectorization on those matrices; in C++99, we are out of luck. Figure out + // what case we're in and do the right thing. +#ifndef CERES_USE_CXX11 + // fall back to safe version: + Eigen::Matrix v; +#else + static constexpr bool kShouldAlignMatrix = + 16 <= ::ceres::port_constants::kMaxAlignBytes; + static constexpr int kAlignHint = kShouldAlignMatrix ? + Eigen::AutoAlign : Eigen::DontAlign; + static constexpr size_t kAlignment = kShouldAlignMatrix ? 16 : 1; + alignas(kAlignment) Eigen::Matrix v; +#endif }; // Unary +