Browse Source

GCC 4.4 compatibility: workarounds for strict-aliasing fascism.

These four cover most (but not all) warnings when compiling in Release
mode. Now all the tests pass, but the warnings signalize that something
could go bad somewhere else. However, only one drastic solution comes to
my mind at this time -- disabling strict aliasing completely
`-fno-strict-aliasing`. Don't know performance impact of that.
Vladimír Vondruš 13 years ago
parent
commit
48bb1f1cb0
  1. 12
      src/Math/Matrix3.h
  2. 12
      src/Math/Matrix4.h

12
src/Math/Matrix3.h

@ -244,7 +244,13 @@ template<class T> class Matrix3: public Matrix<3, T> {
* @todo extract 2x2 matrix and multiply directly? (benchmark that)
*/
inline Vector2<T> transformVector(const Vector2<T>& vector) const {
/* Workaround for GCC 4.4 strict-aliasing fascism */
#ifndef CORRADE_GCC44_COMPATIBILITY
return ((*this)*Vector3<T>(vector, T(0))).xy();
#else
const auto v = (*this)*Vector3<T>(vector, T(0));
return v.xy();
#endif
}
/**
@ -257,7 +263,13 @@ template<class T> class Matrix3: public Matrix<3, T> {
* @see DualComplex::transformPoint(), Matrix4::transformPoint()
*/
inline Vector2<T> transformPoint(const Vector2<T>& vector) const {
/* Workaround for GCC 4.4 strict-aliasing fascism */
#ifndef CORRADE_GCC44_COMPATIBILITY
return ((*this)*Vector3<T>(vector, T(1))).xy();
#else
const auto v = (*this)*Vector3<T>(vector, T(1));
return v.xy();
#endif
}
MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(3, 3, Matrix3<T>)

12
src/Math/Matrix4.h

@ -401,7 +401,13 @@ template<class T> class Matrix4: public Matrix<4, T> {
* @todo extract 3x3 matrix and multiply directly? (benchmark that)
*/
inline Vector3<T> transformVector(const Vector3<T>& vector) const {
/* Workaround for GCC 4.4 strict-aliasing fascism */
#ifndef CORRADE_GCC44_COMPATIBILITY
return ((*this)*Vector4<T>(vector, T(0))).xyz();
#else
const auto v = (*this)*Vector4<T>(vector, T(0));
return v.xyz();
#endif
}
/**
@ -414,7 +420,13 @@ template<class T> class Matrix4: public Matrix<4, T> {
* @see DualQuaternion::transformPoint(), Matrix3::transformPoint()
*/
inline Vector3<T> transformPoint(const Vector3<T>& vector) const {
/* Workaround for GCC 4.4 strict-aliasing fascism */
#ifndef CORRADE_GCC44_COMPATIBILITY
return ((*this)*Vector4<T>(vector, T(1))).xyz();
#else
const auto v = (*this)*Vector4<T>(vector, T(1));
return v.xyz();
#endif
}
MAGNUM_RECTANGULARMATRIX_SUBCLASS_IMPLEMENTATION(4, 4, Matrix4<T>)

Loading…
Cancel
Save