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

« back to all changes in this revision

Viewing changes to scalar/writemaskedvector.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) 2009-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_SCALAR_WRITEMASKEDVECTOR_H
 
21
#define VC_SCALAR_WRITEMASKEDVECTOR_H
 
22
 
 
23
namespace Vc
 
24
{
 
25
namespace Scalar
 
26
{
 
27
 
 
28
template<typename T> class WriteMaskedVector
 
29
{
 
30
    friend class Vector<T>;
 
31
    typedef typename Vector<T>::Mask Mask;
 
32
    typedef typename Vector<T>::EntryType EntryType;
 
33
    public:
 
34
        //prefix
 
35
        Vc_ALWAYS_INLINE Vector<T> &operator++() { if (mask) ++vec->m_data; return *vec; }
 
36
        Vc_ALWAYS_INLINE Vector<T> &operator--() { if (mask) --vec->m_data; return *vec; }
 
37
        //postfix
 
38
        Vc_ALWAYS_INLINE Vector<T> operator++(int) { if (mask) vec->m_data++; return *vec; }
 
39
        Vc_ALWAYS_INLINE Vector<T> operator--(int) { if (mask) vec->m_data--; return *vec; }
 
40
 
 
41
        Vc_ALWAYS_INLINE Vector<T> &operator+=(Vector<T> x) { if (mask) vec->m_data += x.m_data; return *vec; }
 
42
        Vc_ALWAYS_INLINE Vector<T> &operator-=(Vector<T> x) { if (mask) vec->m_data -= x.m_data; return *vec; }
 
43
        Vc_ALWAYS_INLINE Vector<T> &operator*=(Vector<T> x) { if (mask) vec->m_data *= x.m_data; return *vec; }
 
44
        Vc_ALWAYS_INLINE Vector<T> &operator/=(Vector<T> x) { if (mask) vec->m_data /= x.m_data; return *vec; }
 
45
 
 
46
        Vc_ALWAYS_INLINE Vector<T> &operator=(Vector<T> x) {
 
47
            vec->assign(x, mask);
 
48
            return *vec;
 
49
        }
 
50
 
 
51
        Vc_ALWAYS_INLINE Vector<T> &operator+=(EntryType x) { if (mask) vec->m_data += x; return *vec; }
 
52
        Vc_ALWAYS_INLINE Vector<T> &operator-=(EntryType x) { if (mask) vec->m_data -= x; return *vec; }
 
53
        Vc_ALWAYS_INLINE Vector<T> &operator*=(EntryType x) { if (mask) vec->m_data *= x; return *vec; }
 
54
        Vc_ALWAYS_INLINE Vector<T> &operator/=(EntryType x) { if (mask) vec->m_data /= x; return *vec; }
 
55
 
 
56
        Vc_ALWAYS_INLINE Vector<T> &operator=(EntryType x) {
 
57
            vec->assign(Vector<T>(x), mask);
 
58
            return *vec;
 
59
        }
 
60
 
 
61
        template<typename F> Vc_ALWAYS_INLINE void call(const F &f) const {
 
62
            vec->call(f, mask);
 
63
        }
 
64
        template<typename F> Vc_ALWAYS_INLINE void call(F &f) const {
 
65
            vec->call(f, mask);
 
66
        }
 
67
        template<typename F> Vc_ALWAYS_INLINE Vector<T> apply(const F &f) const {
 
68
            if (mask) {
 
69
                return Vector<T>(f(vec->m_data));
 
70
            } else {
 
71
                return *vec;
 
72
            }
 
73
        }
 
74
        template<typename F> Vc_ALWAYS_INLINE Vector<T> apply(F &f) const {
 
75
            if (mask) {
 
76
                return Vector<T>(f(vec->m_data));
 
77
            } else {
 
78
                return *vec;
 
79
            }
 
80
        }
 
81
    private:
 
82
        Vc_ALWAYS_INLINE WriteMaskedVector(Vector<T> *v, Mask k) : vec(v), mask(k) {}
 
83
        Vector<T> *const vec;
 
84
        Mask mask;
 
85
};
 
86
 
 
87
} // namespace Scalar
 
88
} // namespace Vc
 
89
#endif // VC_SCALAR_WRITEMASKEDVECTOR_H