From cb71dc4bbfe3c4dd49603872a960aff1a841e561 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 7 Jan 2009 22:20:03 +0000 Subject: [PATCH] Add a vectorization_logic unit test for assign and sum. Need to add dot and more tests, but it seems I've already found some room for improvement in sum. --- test/CMakeLists.txt | 1 + test/vectorization_logic.cpp | 100 +++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 test/vectorization_logic.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0fac20915..706ff7e1a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -160,6 +160,7 @@ ei_add_test(nomalloc) ei_add_test(mixingtypes) ei_add_test(packetmath) ei_add_test(unalignedassert) +ei_add_test(vectorization_logic) ei_add_test(basicstuff) ei_add_test(linearstructure) ei_add_test(cwiseop) diff --git a/test/vectorization_logic.cpp b/test/vectorization_logic.cpp new file mode 100644 index 000000000..2f54189a9 --- /dev/null +++ b/test/vectorization_logic.cpp @@ -0,0 +1,100 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. Eigen itself is part of the KDE project. +// +// Copyright (C) 2008 Gael Guennebaud +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see . + +#include "main.h" +#include + +template +bool test_assign(const Dst&, const Src&, int vectorization, int unrolling) +{ + return ei_assign_traits::Vectorization==vectorization + && ei_assign_traits::Unrolling==unrolling; +} + +template +bool test_sum(const Xpr&, int vectorization, int unrolling) +{ + return ei_sum_traits::Vectorization==vectorization + && ei_sum_traits::Unrolling==unrolling; +} + +void test_vectorization_logic() +{ + +#ifdef EIGEN_VECTORIZE + + VERIFY(test_assign(Vector4f(),Vector4f(), + InnerVectorization,CompleteUnrolling)); + VERIFY(test_assign(Vector4f(),Vector4f()+Vector4f(), + InnerVectorization,CompleteUnrolling)); + VERIFY(test_assign(Vector4f(),Vector4f().cwise() * Vector4f(), + InnerVectorization,CompleteUnrolling)); + + VERIFY(test_assign(Matrix4f(),Matrix4f(), + InnerVectorization,CompleteUnrolling)); + VERIFY(test_assign(Matrix4f(),Matrix4f()+Matrix4f(), + InnerVectorization,CompleteUnrolling)); + VERIFY(test_assign(Matrix4f(),Matrix4f().cwise() * Matrix4f(), + InnerVectorization,CompleteUnrolling)); + + VERIFY(test_assign(Matrix(),Matrix()+Matrix(), + InnerVectorization,InnerUnrolling)); + + VERIFY(test_assign(Matrix(),Matrix()+Matrix(), + NoVectorization,InnerUnrolling)); + + VERIFY(test_assign(Matrix(),Matrix().cwise() / Matrix(), + LinearVectorization,CompleteUnrolling)); + + VERIFY(test_assign(Matrix(),Matrix()+Matrix(), + NoVectorization,InnerUnrolling)); + + VERIFY(test_assign(Matrix(),Matrix().block<4,4>(2,3)+Matrix().block<4,4>(10,4), + NoVectorization,CompleteUnrolling)); + + VERIFY(test_assign(MatrixXf(10,10),MatrixXf(20,20).block(10,10,2,3), + SliceVectorization,NoUnrolling)); + + + VERIFY(test_sum(VectorXf(10), + LinearVectorization,NoUnrolling)); + + VERIFY(test_sum(Matrix(), + LinearVectorization,CompleteUnrolling)); + + VERIFY(test_sum(Matrix(), + LinearVectorization,NoUnrolling)); + + VERIFY(test_sum(Matrix().block<4,4>(1,2), + NoVectorization,CompleteUnrolling)); + + VERIFY(test_sum(Matrix().block<8,1>(1,2), + LinearVectorization,CompleteUnrolling)); + + VERIFY(test_sum(Matrix(), + NoVectorization,CompleteUnrolling)); + +#endif // EIGEN_VECTORIZE + +}