Stop trying to align vtkm types. Read the full comments on why.

Using alignment on basic types when vtkm only targetted Linux/BSD/OSX was
'okay' because of how the alignment operators worked, but potential was going
to cause issues in the long run if we failed to detect the correct size and the
compiler was than forced to not use intrinsics.

Now with adding windows support we have run into another problem. Basically
using an alignment operator on a typedef means that the type must never
be passed by value, but must always be passed by reference. The reason for
this is that passing by value doesn't respect alignment requirements, and
can cause very subtle errors or crashes.

A really good read for people more interested in these problems:

http://eigen.tuxfamily.org/dox/group__TopicPassingByValue.html
http://eigen.tuxfamily.org/dox-devel/group__DenseMatrixManipulation__Alignement.html
This commit is contained in:
Robert Maynard 2014-05-19 14:27:37 -04:00
parent 552a8ab160
commit 763949351f

@ -107,16 +107,6 @@ typedef unsigned long long UInt64Type;
#error Could not find a 64-bit integer.
#endif
//for windows support we need a macro to wrap the alignment call,
//since for windows you need declspec(align)
#ifdef _MSC_VER
# define VTKM_ALIGN_BEGIN(size) __declspec(align(size))
# define VTKM_ALIGN_END(size)
#else //we presume clang or gcc
# define VTKM_ALIGN_BEGIN(size)
# define VTKM_ALIGN_END(size) __attribute__((aligned(size)))
#endif
//-----------------------------------------------------------------------------
template<int Size>
@ -441,13 +431,11 @@ protected:
};
/// Vector2 corresponds to a 2-tuple
namespace internal
{ typedef VTKM_ALIGN_BEGIN(VTKM_ALIGNMENT_TWO_SCALAR) vtkm::Tuple<vtkm::Scalar,2> Vector2 VTKM_ALIGN_END(VTKM_ALIGNMENT_TWO_SCALAR); }
typedef internal::Vector2 Vector2;
typedef vtkm::Tuple<vtkm::Scalar,2> Vector2;
/// Id2 corresponds to a 2-dimensional index
typedef VTKM_ALIGN_BEGIN(VTKM_SIZE_ID) vtkm::Tuple<vtkm::Id,2> Id2 VTKM_ALIGN_END(VTKM_SIZE_ID);
typedef vtkm::Tuple<vtkm::Id,2> Id2;
template<typename T>
class Tuple<T,3>
@ -522,7 +510,11 @@ protected:
};
/// Vector3 corresponds to a 3-tuple
typedef VTKM_ALIGN_BEGIN(VTKM_SIZE_SCALAR) vtkm::Tuple<vtkm::Scalar,3> Vector3 VTKM_ALIGN_END(VTKM_SIZE_SCALAR);
typedef vtkm::Tuple<vtkm::Scalar,3> Vector3;
/// Id3 corresponds to a 3-dimensional index for 3d arrays. Note that
/// the precision of each index may be less than vtkm::Id.
typedef vtkm::Tuple<vtkm::Id,3> Id3;
template<typename T>
class Tuple<T,4>
@ -602,13 +594,9 @@ protected:
};
/// Vector4 corresponds to a 4-tuple
typedef VTKM_ALIGN_BEGIN(VTKM_ALIGNMENT_FOUR_SCALAR) vtkm::Tuple<vtkm::Scalar,4> Vector4 VTKM_ALIGN_END(VTKM_ALIGNMENT_FOUR_SCALAR);
typedef vtkm::Tuple<vtkm::Scalar,4> Vector4;
/// Id3 corresponds to a 3-dimensional index for 3d arrays. Note that
/// the precision of each index may be less than vtkm::Id.
typedef VTKM_ALIGN_BEGIN(VTKM_SIZE_ID) vtkm::Tuple<vtkm::Id,3> Id3 VTKM_ALIGN_END(VTKM_SIZE_ID);
/// Initializes and returns a Vector2.
VTKM_EXEC_CONT_EXPORT vtkm::Vector2 make_Vector2(vtkm::Scalar x,
vtkm::Scalar y)