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