~ubuntu-branches/ubuntu/raring/vc/raring-proposed

« back to all changes in this revision

Viewing changes to sse/debug.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-03-08 12:50:59 UTC
  • Revision ID: package-import@ubuntu.com-20130308125059-2vpu3hm02kgrqv96
Tags: upstream-0.7.0
ImportĀ upstreamĀ versionĀ 0.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  This file is part of the Vc library.
 
2
 
 
3
    Copyright (C) 2011-2012 Matthias Kretz <kretz@kde.org>
 
4
 
 
5
    Vc is free software: you can redistribute it and/or modify
 
6
    it under the terms of the GNU Lesser General Public License as
 
7
    published by the Free Software Foundation, either version 3 of
 
8
    the License, or (at your option) any later version.
 
9
 
 
10
    Vc is distributed in the hope that it will be useful, but
 
11
    WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
    GNU Lesser General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU Lesser General Public
 
16
    License along with Vc.  If not, see <http://www.gnu.org/licenses/>.
 
17
 
 
18
*/
 
19
 
 
20
#ifndef VC_SSE_DEBUG_H
 
21
#define VC_SSE_DEBUG_H
 
22
 
 
23
#ifndef NDEBUG
 
24
#include "types.h"
 
25
#include <iostream>
 
26
#include <iomanip>
 
27
#endif
 
28
 
 
29
namespace Vc
 
30
{
 
31
namespace SSE
 
32
{
 
33
 
 
34
#ifdef NDEBUG
 
35
class DebugStream
 
36
{
 
37
    public:
 
38
        DebugStream(const char *, const char *, int) {}
 
39
        template<typename T> inline DebugStream &operator<<(const T &) { return *this; }
 
40
};
 
41
#else
 
42
class DebugStream
 
43
{
 
44
    private:
 
45
        template<typename T, typename V> static void printVector(V _x)
 
46
        {
 
47
            enum { Size = sizeof(V) / sizeof(T) };
 
48
            union { V v; T m[Size]; } x = { _x };
 
49
            std::cerr << '[' << std::setprecision(24) << x.m[0];
 
50
            for (int i = 1; i < Size; ++i) {
 
51
                std::cerr << ", " << std::setprecision(24) << x.m[i];
 
52
            }
 
53
            std::cerr << ']';
 
54
        }
 
55
    public:
 
56
        DebugStream(const char *func, const char *file, int line)
 
57
        {
 
58
            std::cerr << "\033[1;40;33mDEBUG: " << file << ':' << line << ' ' << func << ' ';
 
59
        }
 
60
 
 
61
        template<typename T> DebugStream &operator<<(const T &x) { std::cerr << x; return *this; }
 
62
 
 
63
        DebugStream &operator<<(__m128 x) {
 
64
            printVector<float, __m128>(x);
 
65
            return *this;
 
66
        }
 
67
        DebugStream &operator<<(__m128d x) {
 
68
            printVector<double, __m128d>(x);
 
69
            return *this;
 
70
        }
 
71
        DebugStream &operator<<(__m128i x) {
 
72
            printVector<unsigned int, __m128i>(x);
 
73
            return *this;
 
74
        }
 
75
 
 
76
        ~DebugStream()
 
77
        {
 
78
            std::cerr << "\033[0m" << std::endl;
 
79
        }
 
80
};
 
81
#endif
 
82
 
 
83
#define VC_DEBUG ::Vc::SSE::DebugStream(__PRETTY_FUNCTION__, __FILE__, __LINE__)
 
84
 
 
85
} // namespace SSE
 
86
} // namespace Vc
 
87
 
 
88
#endif // VC_SSE_DEBUG_H