Browse Source

GCC 4.5 compatibility: GCC badly optimizes Matrix4::rotation*().

Redone in a way that the unit test passes.
Vladimír Vondruš 14 years ago
parent
commit
af915b2716
  1. 6
      src/Math/Matrix.h
  2. 13
      src/Math/Matrix4.h

6
src/Math/Matrix.h

@ -248,6 +248,9 @@ template<size_t size, class T> class Matrix {
return Matrix<size, T>(first, next...);
}
#ifdef MAGNUM_GCC45_COMPATIBILITY
protected:
#endif
/* Used internally instead of [][], because GCC does some heavy
optimalization in release mode which breaks it */
inline T& operator()(size_t col, size_t row) {
@ -257,6 +260,9 @@ template<size_t size, class T> class Matrix {
return _data[col*size+row];
}
#ifdef MAGNUM_GCC45_COMPATIBILITY
private:
#endif
T _data[size*size];
};

13
src/Math/Matrix4.h

@ -120,18 +120,31 @@ template<class T> class Matrix4: public Matrix<4, T> {
/** @brief Rotation and scaling part of the matrix */
inline Matrix3<T> rotationScaling() const {
#ifndef MAGNUM_GCC45_COMPATIBILITY /* GCC 4.5 badly optimizes this */
return Matrix3<T>::from(
(*this)[0].xyz(),
(*this)[1].xyz(),
(*this)[2].xyz());
#else
return Matrix3<T>(
(*this)(0, 0), (*this)(0, 1), (*this)(0, 2),
(*this)(1, 0), (*this)(1, 1), (*this)(1, 2),
(*this)(2, 0), (*this)(2, 1), (*this)(2, 2));
#endif
}
/** @brief Rotation part of the matrix */
inline Matrix3<T> rotation() const {
return Matrix3<T>::from(
#ifndef MAGNUM_GCC45_COMPATIBILITY /* GCC 4.5 badly optimizes this */
(*this)[0].xyz().normalized(),
(*this)[1].xyz().normalized(),
(*this)[2].xyz().normalized());
#else
Vector3<T>((*this)(0, 0), (*this)(0, 1), (*this)(0, 2)).normalized(),
Vector3<T>((*this)(1, 0), (*this)(1, 1), (*this)(1, 2)).normalized(),
Vector3<T>((*this)(2, 0), (*this)(2, 1), (*this)(2, 2)).normalized());
#endif
}
MAGNUM_MATRIX_SUBCLASS_IMPLEMENTATION(Matrix4, Vector4, 4)

Loading…
Cancel
Save