Skip to content

Commit

Permalink
Reduce recursion depth for less error clutter
Browse files Browse the repository at this point in the history
If something doesn't compile the compiler will show the call sequence
that lead to the issue. Since the previous implementation used a many
function calls before instantiating the test function template, these
call traces were really long (especially, because they all contained
long type lists). Now, the call stack is a lot flatter (as flat as
possible, I hope), making it easier to go through compiler error
messages.

Clean up some of the code to make it more consistent and easier to
extend.

Signed-off-by: Matthias Kretz <kretz@kde.org>
  • Loading branch information
mattkretz committed Dec 17, 2015
1 parent d416a23 commit 9cae962
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 133 deletions.
41 changes: 22 additions & 19 deletions tests/math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/*}}}*/
using namespace Vc;

using RealTypes = concat<RealVectors, RealSimdArrays>;
using AllTypes = concat<AllVectors, AllSimdArrays>;

// fix isfinite and isnan {{{1
#ifdef isfinite
#undef isfinite
Expand All @@ -43,9 +46,9 @@ using namespace Vc;
#undef isnan
#endif

// testAbs{{{1
TEST_TYPES(V, testAbs, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST, int_v, short_v, SimdArray<int, 8>,
SimdArray<int, 2>, SimdArray<int, 7>))
// abs {{{1
TEST_TYPES(V, testAbs, (concat<RealTypes, int_v, short_v, SimdArray<int, 8>,
SimdArray<int, 2>, SimdArray<int, 7>>))
{
for (int i = 0; i < 0x7fff - int(V::size()); ++i) {
V a = V::IndexesFromZero() + i;
Expand All @@ -60,7 +63,7 @@ TEST_TYPES(V, testAbs, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST, int_v, short_v, Simd
}
}

TEST_TYPES(V, testTrunc, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
TEST_TYPES(V, testTrunc, (RealTypes)) //{{{1
{
typedef typename V::EntryType T;
for (size_t i = 0; i < 100000 / V::Size; ++i) {
Expand All @@ -73,7 +76,7 @@ TEST_TYPES(V, testTrunc, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
COMPARE(Vc::trunc(x), reference) << ", x = " << x;
}

TEST_TYPES(V, testFloor, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
TEST_TYPES(V, testFloor, (RealTypes)) //{{{1
{
typedef typename V::EntryType T;
for (size_t i = 0; i < 100000 / V::Size; ++i) {
Expand All @@ -86,7 +89,7 @@ TEST_TYPES(V, testFloor, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
COMPARE(Vc::floor(x), reference) << ", x = " << x;
}

TEST_TYPES(V, testCeil, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
TEST_TYPES(V, testCeil, (RealTypes)) //{{{1
{
typedef typename V::EntryType T;
for (size_t i = 0; i < 100000 / V::Size; ++i) {
Expand All @@ -99,7 +102,7 @@ TEST_TYPES(V, testCeil, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
COMPARE(Vc::ceil(x), reference) << ", x = " << x;
}

TEST_TYPES(V, testExp, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
TEST_TYPES(V, testExp, (RealTypes)) //{{{1
{
UnitTest::setFuzzyness<float>(1);
UnitTest::setFuzzyness<double>(2);
Expand All @@ -112,7 +115,7 @@ TEST_TYPES(V, testExp, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
COMPARE(Vc::exp(V::Zero()), V::One());
}

TEST_TYPES(V, testMax, (ALL_VECTORS, SIMD_ARRAY_LIST)) //{{{1
TEST_TYPES(V, testMax, (AllTypes)) //{{{1
{
typedef typename V::EntryType T;
VectorMemoryHelper<V> mem(3);
Expand All @@ -129,15 +132,15 @@ TEST_TYPES(V, testMax, (ALL_VECTORS, SIMD_ARRAY_LIST)) //{{{1
COMPARE(Vc::max(a, b), c);
}

TEST_TYPES(V, testSqrt, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
TEST_TYPES(V, testSqrt, (RealTypes)) //{{{1
{
V data = V::IndexesFromZero();
V reference = V::generate([&](int i) { return std::sqrt(data[i]); });

FUZZY_COMPARE(Vc::sqrt(data), reference);
}

TEST_TYPES(V, testRSqrt, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
TEST_TYPES(V, testRSqrt, (RealTypes)) //{{{1
{
typedef typename V::EntryType T;
for (size_t i = 0; i < 1024 / V::Size; ++i) {
Expand All @@ -147,7 +150,7 @@ TEST_TYPES(V, testRSqrt, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
}
}

TEST_TYPES(V, testReciprocal, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
TEST_TYPES(V, testReciprocal, (RealTypes)) //{{{1
{
typedef typename V::EntryType T;
UnitTest::setFuzzyness<float>(1.258295e+07);
Expand All @@ -168,7 +171,7 @@ TEST_TYPES(V, testReciprocal, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
}
}

TEST_TYPES(V, isNegative, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
TEST_TYPES(V, isNegative, (RealTypes)) //{{{1
{
typedef typename V::EntryType T;
VERIFY(isnegative(V::One()).isEmpty());
Expand All @@ -177,7 +180,7 @@ TEST_TYPES(V, isNegative, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
VERIFY(isnegative(V(T(-0.))).isFull());
}

TEST_TYPES(V, testInf, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
TEST_TYPES(V, testInf, (RealTypes)) //{{{1
{
typedef typename V::EntryType T;
const T one = 1;
Expand All @@ -197,7 +200,7 @@ TEST_TYPES(V, testInf, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
VERIFY(none_of(Vc::isinf(nan)));
}

TEST_TYPES(V, testNaN, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
TEST_TYPES(V, testNaN, (RealTypes)) //{{{1
{
typedef typename V::EntryType T;
typedef typename V::IndexType I;
Expand All @@ -216,7 +219,7 @@ TEST_TYPES(V, testNaN, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
VERIFY(all_of(Vc::isnan(nan)));
}

TEST_TYPES(V, testRound, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
TEST_TYPES(V, testRound, (RealTypes)) //{{{1
{
typedef typename V::EntryType T;
enum {
Expand All @@ -243,7 +246,7 @@ TEST_TYPES(V, testRound, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
}
}

TEST_TYPES(V, testExponent, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
TEST_TYPES(V, testExponent, (RealTypes)) //{{{1
{
typedef typename V::EntryType T;
Vc::array<T, 32> input;
Expand Down Expand Up @@ -287,7 +290,7 @@ TEST_TYPES(V, testExponent, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1

template<typename T> struct _ExponentVector { typedef int_v Type; };

TEST_TYPES(V, testFrexp, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
TEST_TYPES(V, testFrexp, (RealTypes)) //{{{1
{
typedef typename V::EntryType T;
using ExpV = typename V::IndexType;
Expand Down Expand Up @@ -338,7 +341,7 @@ TEST_TYPES(V, testFrexp, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
}
}

TEST_TYPES(V, testLdexp, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
TEST_TYPES(V, testLdexp, (RealTypes)) //{{{1
{
typedef typename V::EntryType T;
using ExpV = typename V::IndexType;
Expand All @@ -352,7 +355,7 @@ TEST_TYPES(V, testLdexp, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1

#include "ulp.h"
// copysign {{{1
TEST_TYPES(V, testCopysign, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST))
TEST_TYPES(V, testCopysign, (RealTypes))
{
const V x = V::Random();
const V y = -x;
Expand Down
4 changes: 2 additions & 2 deletions tests/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ template<typename V, typename I> void FloatRandom()
}
}

template <> void testRandom<float_v>::operator()()
template <> void testRandom<float_v>::run()
{
FloatRandom<float_v, SimdArray<int, float_v::size()>>();
}
template <> void testRandom<double_v>::operator()()
template <> void testRandom<double_v>::run()
{
FloatRandom<double_v, SimdArray<int, double_v::size()>>();
}
Expand Down
13 changes: 11 additions & 2 deletions tests/typelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

template <typename... Ts> struct Typelist;
// concat {{{
template <typename A, typename B, typename... More> struct concat_impl;
template <typename... More> struct concat_impl;
/**
* Concatenate two type arguments into a single Typelist.
*/
template <typename... Ts> using concat = typename concat_impl<Ts...>::type;

// concat implementation:
template <typename A> struct concat_impl<A> {
using type = A;
};
template <typename A, typename B> struct concat_impl<A, B> {
using type = Typelist<A, B>;
};
Expand Down Expand Up @@ -81,8 +84,12 @@ template <typename A, typename B>
using outer_product = typename outer_product_impl<A, B>::type;
// }}}
// extract_type_impl {{{
struct TypelistSentinel;
template <std::size_t N, bool N_less_4, bool N_larger_32, typename... Ts>
struct extract_type_impl;
struct extract_type_impl
{
using type = TypelistSentinel;
};
template <typename T0, typename... Ts> struct extract_type_impl<0, true, false, T0, Ts...>
{
using type = T0;
Expand Down Expand Up @@ -196,6 +203,8 @@ template <typename... Ts> struct Typelist
{
template <std::size_t N>
using at = typename extract_type_impl<N, (N < 4), (N >= 32), Ts...>::type;

static constexpr std::size_t size() { return sizeof...(Ts); }
};

// }}}
Expand Down
2 changes: 1 addition & 1 deletion tests/ulp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "unittest.h"

TEST_TYPES(V, testUlpDiff, (REAL_VECTORS, SIMD_REAL_ARRAY_LIST)) //{{{1
TEST_TYPES(V, testUlpDiff, (concat<RealVectors, RealSimdArrays>)) //{{{1
{
typedef typename V::EntryType T;

Expand Down
Loading

0 comments on commit 9cae962

Please sign in to comment.