aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/MatrixStorage.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2008-04-25 15:46:18 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2008-04-25 15:46:18 +0000
commita451835bce179a999cddedc3c9dab49e421968eb (patch)
treedf3fed6cf99e2bd9cf362e6e3800c284f115c31b /Eigen/src/Core/MatrixStorage.h
parent30d47b5250240d2313d1473adb6f6dd47c5d685a (diff)
Make the explicit vectorization much more flexible:
- support dynamic sizes - support arbitrary matrix size when the matrix can be seen as a 1D array (except for fixed size matrices where the size in Bytes must be a factor of 16, this is to allow compact storage of a vector of matrices) Note that the explict vectorization is still experimental and far to be completely tested.
Diffstat (limited to 'Eigen/src/Core/MatrixStorage.h')
-rw-r--r--Eigen/src/Core/MatrixStorage.h40
1 files changed, 31 insertions, 9 deletions
diff --git a/Eigen/src/Core/MatrixStorage.h b/Eigen/src/Core/MatrixStorage.h
index cca4414d3..c8ee7a62c 100644
--- a/Eigen/src/Core/MatrixStorage.h
+++ b/Eigen/src/Core/MatrixStorage.h
@@ -49,6 +49,28 @@ template <typename T, int Size> struct ei_aligned_array<T,Size,false>
T array[Size];
};
+template<typename T>
+T* ei_aligned_malloc(size_t size)
+{
+ #ifdef EIGEN_VECTORIZE
+ if (ei_packet_traits<T>::size>1)
+ return static_cast<T*>(_mm_malloc(sizeof(T)*size, 16));
+ else
+ #endif
+ return new T[size];
+}
+
+template<typename T>
+void ei_aligned_free(T* ptr)
+{
+ #ifdef EIGEN_VECTORIZE
+ if (ei_packet_traits<T>::size>1)
+ _mm_free(ptr);
+ else
+ #endif
+ delete[] ptr;
+}
+
// purely fixed-size matrix
template<typename T, int Size, int _Rows, int _Cols> class ei_matrix_storage
{
@@ -127,7 +149,7 @@ template<typename T> class ei_matrix_storage<T, Dynamic, Dynamic, Dynamic>
int m_cols;
public:
ei_matrix_storage(int size, int rows, int cols)
- : m_data(new T[size]), m_rows(rows), m_cols(cols) {}
+ : m_data(ei_aligned_malloc<T>(size)), m_rows(rows), m_cols(cols) {}
~ei_matrix_storage() { delete[] m_data; }
int rows(void) const {return m_rows;}
int cols(void) const {return m_cols;}
@@ -135,8 +157,8 @@ template<typename T> class ei_matrix_storage<T, Dynamic, Dynamic, Dynamic>
{
if(size != m_rows*m_cols)
{
- delete[] m_data;
- m_data = new T[size];
+ ei_aligned_free(m_data);
+ m_data = ei_aligned_malloc<T>(size);
}
m_rows = rows;
m_cols = cols;
@@ -151,7 +173,7 @@ template<typename T, int _Rows> class ei_matrix_storage<T, Dynamic, _Rows, Dynam
T *m_data;
int m_cols;
public:
- ei_matrix_storage(int size, int, int cols) : m_data(new T[size]), m_cols(cols) {}
+ ei_matrix_storage(int size, int, int cols) : m_data(ei_aligned_malloc<T>(size)), m_cols(cols) {}
~ei_matrix_storage() { delete[] m_data; }
static int rows(void) {return _Rows;}
int cols(void) const {return m_cols;}
@@ -159,8 +181,8 @@ template<typename T, int _Rows> class ei_matrix_storage<T, Dynamic, _Rows, Dynam
{
if(size != _Rows*m_cols)
{
- delete[] m_data;
- m_data = new T[size];
+ ei_aligned_free(m_data);
+ m_data = ei_aligned_malloc<T>(size);
}
m_cols = cols;
}
@@ -174,7 +196,7 @@ template<typename T, int _Cols> class ei_matrix_storage<T, Dynamic, Dynamic, _Co
T *m_data;
int m_rows;
public:
- ei_matrix_storage(int size, int rows, int) : m_data(new T[size]), m_rows(rows) {}
+ ei_matrix_storage(int size, int rows, int) : m_data(ei_aligned_malloc<T>(size)), m_rows(rows) {}
~ei_matrix_storage() { delete[] m_data; }
int rows(void) const {return m_rows;}
static int cols(void) {return _Cols;}
@@ -182,8 +204,8 @@ template<typename T, int _Cols> class ei_matrix_storage<T, Dynamic, Dynamic, _Co
{
if(size != m_rows*_Cols)
{
- delete[] m_data;
- m_data = new T[size];
+ ei_aligned_free(m_data);
+ m_data = ei_aligned_malloc<T>(size);
}
m_rows = rows;
}