// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2008-2009 Gael Guennebaud // Copyright (C) 2006-2008 Benoit Jacob // // 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" // using namespace Eigen; template T ei_negate(const T& x) { return -x; } template bool areApprox(const Scalar* a, const Scalar* b, int size) { for (int i=0; i struct packet_helper { template inline Packet load(const T* from) const { return ei_pload(from); } template inline void store(T* to, const Packet& x) const { ei_pstore(to,x); } }; template struct packet_helper { template inline T load(const T* from) const { return *from; } template inline void store(T* to, const T& x) const { *to = x; } }; #define CHECK_CWISE1_IF(COND, REFOP, POP) if(COND) { \ packet_helper h; \ for (int i=0; i const complex& min(const complex& a, const complex& b) { return a.real() < b.real() ? a : b; } template<> const complex& max(const complex& a, const complex& b) { return a.real() < b.real() ? b : a; } } template void packetmath() { typedef typename ei_packet_traits::type Packet; const int PacketSize = ei_packet_traits::size; const int size = PacketSize*4; EIGEN_ALIGN_128 Scalar data1[ei_packet_traits::size*4]; EIGEN_ALIGN_128 Scalar data2[ei_packet_traits::size*4]; EIGEN_ALIGN_128 Packet packets[PacketSize*2]; EIGEN_ALIGN_128 Scalar ref[ei_packet_traits::size*4]; for (int i=0; i(); data2[i] = ei_random(); } ei_pstore(data2, ei_pload(data1)); VERIFY(areApprox(data1, data2, PacketSize) && "aligned load/store"); for (int offset=0; offset(packets[0], packets[1]); else if (offset==1) ei_palign<1>(packets[0], packets[1]); else if (offset==2) ei_palign<2>(packets[0], packets[1]); else if (offset==3) ei_palign<3>(packets[0], packets[1]); ei_pstore(data2, packets[0]); for (int i=0; i Vector; VERIFY(areApprox(ref, data2, PacketSize) && "ei_palign"); } CHECK_CWISE2(REF_ADD, ei_padd); CHECK_CWISE2(REF_SUB, ei_psub); CHECK_CWISE2(REF_MUL, ei_pmul); #ifndef EIGEN_VECTORIZE_ALTIVEC if (!ei_is_same_type::ret) CHECK_CWISE2(REF_DIV, ei_pdiv); #endif CHECK_CWISE2(std::min, ei_pmin); CHECK_CWISE2(std::max, ei_pmax); CHECK_CWISE1(ei_abs, ei_pabs); CHECK_CWISE1(ei_negate, ei_pnegate); for (int i=0; i void packetmath_real() { typedef typename ei_packet_traits::type Packet; const int PacketSize = ei_packet_traits::size; const int size = PacketSize*4; EIGEN_ALIGN_128 Scalar data1[ei_packet_traits::size*4]; EIGEN_ALIGN_128 Scalar data2[ei_packet_traits::size*4]; EIGEN_ALIGN_128 Scalar ref[ei_packet_traits::size*4]; for (int i=0; i(-1e3,1e3); data2[i] = ei_random(-1e3,1e3); } CHECK_CWISE1_IF(ei_packet_traits::HasSin, ei_sin, ei_psin); CHECK_CWISE1_IF(ei_packet_traits::HasCos, ei_cos, ei_pcos); for (int i=0; i(-87,88); data2[i] = ei_random(-87,88); } CHECK_CWISE1_IF(ei_packet_traits::HasExp, ei_exp, ei_pexp); for (int i=0; i(0,1e6); data2[i] = ei_random(0,1e6); } CHECK_CWISE1_IF(ei_packet_traits::HasLog, ei_log, ei_plog); CHECK_CWISE1_IF(ei_packet_traits::HasSqrt, ei_sqrt, ei_psqrt); } void test_packetmath() { for(int i = 0; i < g_repeat; i++) { CALL_SUBTEST( packetmath() ); CALL_SUBTEST( packetmath() ); CALL_SUBTEST( packetmath() ); CALL_SUBTEST( packetmath >() ); CALL_SUBTEST( packetmath_real() ); CALL_SUBTEST( packetmath_real() ); } }