BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
PSEUDO_F32vec4.h
Go to the documentation of this file.
1#ifndef L1Algo_PSEUDO_F32vec4_H
2#define L1Algo_PSEUDO_F32vec4_H
3
5
6#include <cmath>
7#include <iostream>
9/**********************************
10 *
11 * Vector of four floats
12 *
13 **********************************/
14
15float min(float x, float y);
16float max(float x, float y);
17float asgnb(float x, float y);
18float rsqrt(float x);
19float rcp(float x);
20float sgn(float x);
21
22class F32vec4
24
25 public:
26 float v[4];
27
28 float& operator[](int i) { return ((float*)&v)[i]; }
29 float operator[](int i) const { return ((float*)&v)[i]; }
30
32 F32vec4(const F32vec4& a)
33 {
34 v[0] = a.v[0];
35 v[1] = a.v[1];
36 v[2] = a.v[2];
37 v[3] = a.v[3];
38 }
39 F32vec4(const float& a)
40 {
41 v[0] = a;
42 v[1] = a;
43 v[2] = a;
44 v[3] = a;
45 }
46
47 F32vec4(const float& f0, const float& f1, const float& f2, const float& f3)
48 {
49 v[0] = f0;
50 v[1] = f1;
51 v[2] = f2;
52 v[3] = f3;
53 }
55#define _f2(A, B, F) \
56 F32vec4 z; \
57 z.v[0] = F(A.v[0], B.v[0]); \
58 z.v[1] = F(A.v[1], B.v[1]); \
59 z.v[2] = F(A.v[2], B.v[2]); \
60 z.v[3] = F(A.v[3], B.v[3]); \
61 return z;
62#define _f1(A, F) \
63 F32vec4 z; \
64 z.v[0] = F(A.v[0]); \
65 z.v[1] = F(A.v[1]); \
66 z.v[2] = F(A.v[2]); \
67 z.v[3] = F(A.v[3]); \
68 return z;
69#define _op(A, B, O) \
70 F32vec4 z; \
71 z.v[0] = A.v[0] O B.v[0]; \
72 z.v[1] = A.v[1] O B.v[1]; \
73 z.v[2] = A.v[2] O B.v[2]; \
74 z.v[3] = A.v[3] O B.v[3]; \
75 return z;
76
77 /* Arithmetic Operators */
78 friend F32vec4 operator+(const F32vec4& a, const F32vec4& b) { _op(a, b, +) }
79 friend F32vec4 operator-(const F32vec4& a, const F32vec4& b) { _op(a, b, -) }
80 friend F32vec4 operator*(const F32vec4& a, const F32vec4& b) { _op(a, b, *) }
81 friend F32vec4 operator/(const F32vec4& a, const F32vec4& b) { _op(a, b, /) }
82
83 /* Comparison */
84 friend F32vec4 operator<(const F32vec4& a, const F32vec4& b) { _op(a, b, <) }
85 friend F32vec4 operator<=(const F32vec4& a, const F32vec4& b) { _op(a, b, <=) }
86 friend F32vec4 operator>(const F32vec4& a, const F32vec4& b) { _op(a, b, >) }
87 friend F32vec4 operator>=(const F32vec4& a, const F32vec4& b) { _op(a, b, >=) }
88
89 /* Logic */
90 friend F32vec4 operator&(const F32vec4& a, const F32vec4& b) { _op(a, b, &&) }
91 friend F32vec4 operator|(const F32vec4& a, const F32vec4& b) { _op(a, b, ||) }
92 friend F32vec4 operator||(const F32vec4& a, const F32vec4& b) { _op(a, b, ||) }
93
94 friend F32vec4 operator!(const F32vec4& a)
95 {
97 z[0] = !a[0];
98 z[1] = !a[1];
99 z[2] = !a[2];
100 z[3] = !a[3];
101
102 return z;
105 friend F32vec4 if3(const F32vec4& a, const F32vec4& b, const F32vec4& c)
108 z[0] = (a[0]) ? b[0] : c[0];
109 z[1] = (a[1]) ? b[1] : c[1];
110 z[2] = (a[2]) ? b[2] : c[2];
111 z[3] = (a[3]) ? b[3] : c[3];
113 return z;
116#define NotEmpty(a) bool((a)[0]) | bool((a)[1]) | bool((a)[2]) | bool((a)[3])
117#define Empty(a) !(bool((a)[0]) | bool((a)[1]) | bool((a)[2]) | bool((a)[3]))
118 // bool NotEmpty(const F32vec4 &a) { return a[0]||a[1]||a[2]||a[3]; }
119 // bool Empty(const F32vec4 &a) { return !(a[0]||a[1]||a[2]||a[3]); } // optimize
120 friend F32vec4 bool2int(const F32vec4& a)
121 { // mask returned
122 return if3(a, 1, 0);
123 }
124
125 /* Functions */
126 friend float min(float x, float y) { return x < y ? x : y; }
127 friend float max(float x, float y) { return x < y ? y : x; }
128 friend float asgnb(float x, float y) { return y >= 0 ? fabs(x) : -fabs(x); }
129 friend float rsqrt(float x) { return 1. / sqrt(x); }
130 friend float rcp(float x) { return 1. / x; }
131 friend float sgn(float x) { return x >= 0 ? 1 : -1; }
132
133 friend F32vec4 min(const F32vec4& a, const F32vec4& b) { _f2(a, b, min) }
134 friend F32vec4 max(const F32vec4& a, const F32vec4& b) { _f2(a, b, max) }
135 friend F32vec4 asgnb(const F32vec4& a, const F32vec4& b) { _f2(a, b, asgnb) }
136 friend F32vec4 sqrt(const F32vec4& a) { _f1(a, sqrt) }
137 friend F32vec4 rsqrt(const F32vec4& a) { _f1(a, rsqrt) }
138 friend F32vec4 rcp(const F32vec4& a) { _f1(a, rcp) }
139 friend F32vec4 fabs(const F32vec4& a) { _f1(a, fabs) }
140 friend F32vec4 sgn(const F32vec4& a) { _f1(a, sgn) }
141 friend F32vec4 exp(const F32vec4& a) { _f1(a, exp) }
142 friend F32vec4 log(const F32vec4& a) { _f1(a, log) }
143 friend F32vec4 sin(const F32vec4& a) { _f1(a, sin) }
144 friend F32vec4 cos(const F32vec4& a){_f1(a, cos)}
145#undef _f1
146#undef _f2
147#undef _op
148
149 /* Define all operators for consistensy */
150
152
153 friend ostream& operator<<(ostream& strm, const F32vec4& a)
154 {
155 strm << a[0] << " " << a[1] << " " << a[2] << " " << a[3];
156 return strm;
157 }
158
159 friend istream& operator>>(istream& strm, F32vec4& a)
160 {
161 float tmp;
162 strm >> tmp;
163 a = tmp;
164 return strm;
165 }
166
167} __attribute__((aligned(16)));
168;
169
170typedef F32vec4 fvec;
171typedef float fscal;
172const int fvecLen = 4;
173// #define fvec_true _f32vec4_true
174// #define fvec_false _f32vec4_false
175#define _fvecalignment
176
177namespace nsL1
178{
179template<typename T>
180struct vector
181{
182 typedef std::vector<T> TStd;
183 typedef std::vector<T> TSimd;
184};
185
187}; // namespace nsL1
188
189template<typename T>
190struct nsL1vector : public nsL1::vector<T> // just for use std::vector simultaniosly
191{};
192
193#endif
float fscal
Definition P4_F32vec4.h:232
const int fvecLen
Definition P4_F32vec4.h:233
int i
Definition P4_F32vec4.h:22
#define if3(a, b, c)
Definition P4_F32vec4.h:148
F32vec4 fvec
Definition P4_F32vec4.h:231
#define _f2(A, B, F)
nsL1vector __attribute__
float asgnb(float x, float y)
float sgn(float x)
float rsqrt(float x)
#define _f1(A, F)
float rcp(float x)
#define _op(A, B, O)
float min(float x, float y)
float max(float x, float y)
F32vec4(const float &a)
friend F32vec4 operator>(const F32vec4 &a, const F32vec4 &b)
float & operator[](int i)
friend F32vec4 sgn(const F32vec4 &a)
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
friend F32vec4 operator|(const F32vec4 &a, const F32vec4 &b)
friend F32vec4 rcp(const F32vec4 &a)
__m128 v
Definition P4_F32vec4.h:46
friend F32vec4 operator||(const F32vec4 &a, const F32vec4 &b)
float operator[](int i) const
friend F32vec4 sin(const F32vec4 &a)
friend F32vec4 if3(const F32vec4 &a, const F32vec4 &b, const F32vec4 &c)
friend F32vec4 operator-(const F32vec4 &a, const F32vec4 &b)
friend F32vec4 fabs(const F32vec4 &a)
Definition P4_F32vec4.h:97
friend F32vec4 bool2int(const F32vec4 &a)
friend F32vec4 rsqrt(const F32vec4 &a)
friend F32vec4 asgnb(const F32vec4 &a, const F32vec4 &b)
friend F32vec4 operator<=(const F32vec4 &a, const F32vec4 &b)
friend float asgnb(float x, float y)
friend F32vec4 operator&(const F32vec4 &a, const F32vec4 &b)
F32vec4(const float &f0, const float &f1, const float &f2, const float &f3)
friend float sgn(float x)
friend F32vec4 operator<(const F32vec4 &a, const F32vec4 &b)
F32vec4(const F32vec4 &a)
friend F32vec4 operator>=(const F32vec4 &a, const F32vec4 &b)
friend ostream & operator<<(ostream &strm, const F32vec4 &a)
friend F32vec4 operator*(const F32vec4 &a, const F32vec4 &b)
friend F32vec4 exp(const F32vec4 &a)
friend float rsqrt(float x)
friend F32vec4 operator+(const F32vec4 &a, const F32vec4 &b)
vec_arithmetic(F32vec4, float)
friend F32vec4 operator/(const F32vec4 &a, const F32vec4 &b)
friend F32vec4 sqrt(const F32vec4 &a)
Definition P4_F32vec4.h:79
friend F32vec4 log(const F32vec4 &a)
friend float rcp(float x)
friend F32vec4 operator!(const F32vec4 &a)
friend float min(float x, float y)
friend float max(float x, float y)
friend F32vec4 cos(const F32vec4 &a)
friend istream & operator>>(istream &strm, F32vec4 &a)
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
nsL1::vector< fvec >::TSimd vector_fvec
std::vector< T > TStd
std::vector< T > TSimd