aboutsummaryrefslogtreecommitdiff
path: root/src/indirect/vectors-pseudo.hh
blob: a5cca83a28b8aeef3be57c445ddc938c471875fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <cmath>
#include <cstdlib>
using namespace std;

template<typename T>
struct vec_t {
  size_t const D = 2;
  typedef T scalar_t;
  typedef T impl_t;
  impl_t v[D];
  
  static inline size_t size()
  {
    return D;
  }
  
  inline vec_t ()
  {
  }
  inline vec_t (scalar_t const& a)
  {
    for (size_t d=0; d<D; ++d) v[d]=a;
  }
  
  inline operator impl_t ()
  {
    return v;
  }
  
  inline scalar_t operator[] (size_t const d) const
  {
    return v[d];
  }
  
  static inline vec_t load (scalar_t const& a)
  {
    vec_t r;
    for (size_t d=0; d<D; ++d) r.v[d]=(&a)[d];
    return r;
  }
  static inline vec_t loadu (scalar_t const& a)
  {
    return load(a);
  }
  // Load a vector from memory that may or may not be aligned, as
  // decided by the offset and the vector size
  static inline vec_t loadu_maybe (int const off, scalar_t const& p)
  {
    return load(a);
  }
  static inline vec_t loadu_maybe3 (int const off0, int const off1,
                                    int const off2,
                                    scalar_t const& p)
  {
    return load(a);
  }
  inline void store (scalar_t& p) const
  {
    for (size_t d=0; d<D; ++d) (&p)[d]=v[d];
  }
  inline void storeu (scalar_t& p) const
  {
    store(p);
  }
  inline void store_nta (scalar_t& p) const
  {
    store(p);
  }
  inline void store_nta_partial_lo (scalar_t& p, size_t const cnt) const
  {
    for (size_t d=0; d<cnt; ++d) (&p)[d]=v[d];
  }
  inline void store_nta_partial_hi (scalar_t& p, size_t const cnt) const
  {
    for (size_t d=D-cnt; d<D; ++d) (&p)[d]=v[d];
  }
  
  inline vec_t operator+ () const
  {
    vec_t r=*this;
    for (size_t d=0; d<D; ++d) r.v[d]=+v[d];
    return r;
  }
  inline vec_t operator- () const
  {
    vec_t r=*this;
    for (size_t d=0; d<D; ++d) r.v[d]=-v[d];
    return r;
  }
  inline vec_t operator+ (vec_t const& x) const
  {
    vec_t r=*this;
    return r+=x;
  }
  inline vec_t operator- (vec_t const& x) const
  {
    vec_t r=*this;
    return r-=x;
  }
  inline vec_t operator* (vec_t const& x) const
  {
    vec_t r=*this;
    return r*=x;
  }
  inline vec_t operator/ (vec_t const& x) const
  {
    vec_t r=*this;
    return r/=x;
  }
  inline vec_t& operator+= (vec_t const& x)
  {
    for (size_t d=0; d<D; ++d) v[d]+=x.v[d];
    return *this;
  }
  inline vec_t& operator-= (vec_t const& x)
  {
    for (size_t d=0; d<D; ++d) v[d]-=x.v[d];
    return *this;
  }
  inline vec_t& operator*= (vec_t const& x)
  {
    for (size_t d=0; d<D; ++d) v[d]*=x.v[d];
    return *this;
  }
  inline vec_t& operator/= (vec_t const& x)
  {
    for (size_t d=0; d<D; ++d) v[d]/=x.v[d];
    return *this;
  }
};

template<typename T>
vec_t<T> exp (vec_t<T> const& x)
{
  vec_t r;
  for (size_t d=0; d<D; ++d) r.v[d]=exp(x.v[d]);
  return r;
}
template<typename T>
vec_t<T> fabs (vec_t<T> const& x)
{
  vec_t r;
  for (size_t d=0; d<D; ++d) r.v[d]=fabs(x.v[d]);
  return r;
}
template<typename T>
vec_t<T> fmax (vec_t<T> const& x, vec_t<T> const& y)
{
  vec_t r;
  for (size_t d=0; d<D; ++d) r.v[d]=fmax(x.v[d],y.v[d]);
  return r;
}
template<typename T>
vec_t<T> fmin (vec_t<T> const& x, vec_t<T> const& y)
{
  vec_t r;
  for (size_t d=0; d<D; ++d) r.v[d]=fmin(x.v[d],y.v[d]);
  return r;
}
template<typename T>
vec_t<T> ifthen (bool const b, vec_t<T> const& x, vec_t<T> const& y)
{
  return b ? x : y;
}
vec_t<T> log (vec_t<T> const& x)
{
  vec_t r;
  for (size_t d=0; d<D; ++d) r.v[d]=log(x.v[d]);
  return r;
}
template<typename T>
vec_t<T> pow (vec_t<T> const& x, typename vec_t<T>::scalar_t const& a)
{
  vec_t r;
  for (size_t d=0; d<D; ++d) r.v[d]=pow(x.v[d],a);
  return r;
}
vec_t<T> sqrt (vec_t<T> const& x)
{
  vec_t r;
  for (size_t d=0; d<D; ++d) r.v[d]=sqrt(x.v[d]);
  return r;
}