CbmRoot
L1/vectors/PSEUDO_F32vec1.h
Go to the documentation of this file.
1 #ifndef CBM_KF_F32vec1_H
2 #define CBM_KF_F32vec1_H
3 
4 #include <cmath>
5 #include <iostream>
6 
7 /**********************************
8  *
9  * Vector of one single float
10  *
11  **********************************/
12 
13 // const union
14 // {
15 // int i[1];
16 // float m;
17 // }
18 // __f32vec1_true_cheat = {0xFFFFFFFF},
19 // __f32vec1_false_cheat = {0x00000000};
20 
21 // #define _f32vec1_true ((F32vec1)__f32vec1_true_cheat.m)
22 // #define _f32vec1_false ((F32vec1)__f32vec1_false_cheat.m)
23 
24 class F32vec1 {
25 public:
26  float v;
27 
28  float& operator[](int i) { return v; }
29  float operator[](int i) const { return v; }
30 
31  F32vec1() {}
32  F32vec1(const float& v0) { v = v0; }
33 
34  /* Conversion function */
35  operator float() const { return v; } /* Convert to __m128 */
36 
37  /* Arithmetic Operators */
38 
39  /* Functions */
40  //friend F32vec1 min( const F32vec1 &a, const F32vec1 &b ){ return a<b ?a :b; }
41  //friend F32vec1 max( const F32vec1 &a, const F32vec1 &b ){ return a>b ?a :b; }
42 
43  /* Square Root */
44 
45  /* Reciprocal( inverse) Square Root */
46  //friend F32vec1 rsqrt( const F32vec1 &a ){ return 1./sqrt(a); }
47 
48  /* Reciprocal (inversion) */
49  friend F32vec1 rcp(const F32vec1& a) { return 1. / a; }
50 
51  /* Absolute value */
52  //friend F32vec1 fabs(const F32vec1 &a){ return fabs(a); }
53 
54  /* Sign */
55  //friend F32vec1 sgn(const F32vec1 &a){ return a<0 ?-1 :(a>0 ?1 :0); }
56 
57  /* Logical */
58  /*
59  friend F32vec1 operator&( const F32vec1 &a, const F32vec1 &b ){ // mask returned
60  F32vec1 tmp;
61  int *x = (int*)&tmp;
62  int *y = (int*)&a;
63  int *z = (int*)&b;
64  x[0] = y[0] & z[0];
65  x[1] = y[1] & z[1];
66  return tmp;
67  }
68  */
69  /* Non intrinsic functions */
70 
71  /* Define all operators for consistensy */
72 
73  friend void operator+=(F32vec1& a, const F32vec1& b) { a = a + b; }
74  friend void operator-=(F32vec1& a, const F32vec1& b) { a = a - b; }
75  friend void operator*=(F32vec1& a, const F32vec1& b) { a = a * b; }
76  friend void operator/=(F32vec1& a, const F32vec1& b) { a = a / b; }
77 
78 #define _op(A, B, O) \
79  F32vec1 z; \
80  z.v = A.v O B.v; \
81  return z;
82 
83  // /* Comparison */
84  friend F32vec1 operator<(const F32vec1& a, const F32vec1& b) { _op(a, b, <) }
85  friend F32vec1 operator<=(const F32vec1& a, const F32vec1& b) {
86  _op(a, b, <=)
87  }
88  friend F32vec1 operator>(const F32vec1& a, const F32vec1& b) { _op(a, b, >) }
89  friend F32vec1 operator>=(const F32vec1& a, const F32vec1& b) {
90  _op(a, b, >=)
91  }
92 
93  // /* Logic */
94  friend F32vec1 operator&(const F32vec1& a, const F32vec1& b) { _op(a, b, &&) }
95  friend F32vec1 operator|(const F32vec1& a, const F32vec1& b) { _op(a, b, ||) }
96  friend F32vec1 operator||(const F32vec1& a, const F32vec1& b) {
97  _op(a, b, ||)
98  }
99 #undef _op
100 
101  friend F32vec1 operator!(const F32vec1& a) {
102  F32vec1 z;
103  z[0] = !a[0];
104 
105  return z;
106  }
107 
108  friend F32vec1 if3(const F32vec1& a, const F32vec1& b, const F32vec1& c) {
109  F32vec1 z;
110  z[0] = (a[0]) ? b[0] : c[0];
111 
112  return z;
113  }
114 
115 #define NotEmpty(a) bool((a)[0])
116 #define Empty(a) !(bool((a)[0]))
117  friend F32vec1 bool2int(const F32vec1& a) { // mask returned
118  return if3(a, 1, 0);
119  }
120 
121 
122  friend ostream& operator<<(ostream& strm, const F32vec1& a) {
123  strm << a[0];
124  return strm;
125  }
126 
127  friend istream& operator>>(istream& strm, F32vec1& a) {
128  float tmp;
129  strm >> tmp;
130  a = tmp;
131  return strm;
132  }
133 
134 } __attribute__((aligned(4)));
135 ;
136 
137 typedef F32vec1 fvec;
138 const int fvecLen = 1;
139 // #define fvec_true _f32vec1_true
140 // #define fvec_false _f32vec1_false
141 #define _fvecalignment
142 
143 
144 namespace nsL1 {
145  template<typename T>
146  struct vector {
147  typedef std::vector<T> TStd;
148  typedef std::vector<T> TSimd;
149  };
150 
152 }; // namespace nsL1
153 
154 template<typename T>
155 struct nsL1vector :
156  public nsL1::vector<T> // just for use std::vector simultaniosly
157 {};
158 
159 #endif
nsL1
Definition: L1/vectors/PSEUDO_F32vec1.h:144
F32vec1::operator<
friend F32vec1 operator<(const F32vec1 &a, const F32vec1 &b)
Definition: L1/vectors/PSEUDO_F32vec1.h:88
_op
#define _op(A, B, O)
Definition: L1/vectors/PSEUDO_F32vec1.h:57
F32vec1::operator||
friend F32vec1 operator||(const F32vec1 &a, const F32vec1 &b)
Definition: L1/vectors/PSEUDO_F32vec1.h:100
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
F32vec1::operator>>
friend istream & operator>>(istream &strm, F32vec1 &a)
Definition: L1/vectors/PSEUDO_F32vec1.h:131
F32vec1::operator*=
friend void operator*=(F32vec1 &a, const F32vec1 &b)
Definition: L1/vectors/PSEUDO_F32vec1.h:79
F32vec1::operator<=
friend F32vec1 operator<=(const F32vec1 &a, const F32vec1 &b)
Definition: L1/vectors/PSEUDO_F32vec1.h:89
F32vec1::operator-=
friend void operator-=(F32vec1 &a, const F32vec1 &b)
Definition: L1/vectors/PSEUDO_F32vec1.h:78
F32vec1::operator!
friend F32vec1 operator!(const F32vec1 &a)
Definition: L1/vectors/PSEUDO_F32vec1.h:105
F32vec1::v
float v
Definition: L1/vectors/PSEUDO_F32vec1.h:30
__attribute__
nsL1vector __attribute__
fvecLen
const int fvecLen
Definition: L1/vectors/PSEUDO_F32vec1.h:138
F32vec1::operator>
friend F32vec1 operator>(const F32vec1 &a, const F32vec1 &b)
Definition: L1/vectors/PSEUDO_F32vec1.h:92
F32vec1::operator<<
friend ostream & operator<<(ostream &strm, const F32vec1 &a)
Definition: L1/vectors/PSEUDO_F32vec1.h:126
F32vec1::operator+=
friend void operator+=(F32vec1 &a, const F32vec1 &b)
Definition: L1/vectors/PSEUDO_F32vec1.h:77
F32vec1::operator>=
friend F32vec1 operator>=(const F32vec1 &a, const F32vec1 &b)
Definition: L1/vectors/PSEUDO_F32vec1.h:93
F32vec1::bool2int
friend F32vec1 bool2int(const F32vec1 &a)
Definition: L1/vectors/PSEUDO_F32vec1.h:121
fvec
F32vec1 fvec
Definition: L1/vectors/PSEUDO_F32vec1.h:135
F32vec1::operator&
friend F32vec1 operator&(const F32vec1 &a, const F32vec1 &b)
Definition: L1/vectors/PSEUDO_F32vec1.h:98
nsL1::vector_fvec
nsL1::vector< fvec >::TSimd vector_fvec
Definition: L1/vectors/PSEUDO_F32vec1.h:151
nsL1::vector::TSimd
std::vector< T > TSimd
Definition: L1/vectors/PSEUDO_F32vec1.h:148
F32vec1::operator/=
friend void operator/=(F32vec1 &a, const F32vec1 &b)
Definition: L1/vectors/PSEUDO_F32vec1.h:80
F32vec1::operator|
friend F32vec1 operator|(const F32vec1 &a, const F32vec1 &b)
Definition: L1/vectors/PSEUDO_F32vec1.h:99
nsL1::vector::TStd
std::vector< T > TStd
Definition: L1/vectors/PSEUDO_F32vec1.h:147
F32vec1
Definition: L1/vectors/PSEUDO_F32vec1.h:24
nsL1::vector
Definition: L1/vectors/PSEUDO_F32vec1.h:146
F32vec1::rcp
friend F32vec1 rcp(const F32vec1 &a)
Definition: L1/vectors/PSEUDO_F32vec1.h:53
F32vec1::operator[]
float & operator[](int i)
Definition: L1/vectors/PSEUDO_F32vec1.h:32
nsL1vector
Definition: L1/vectors/PSEUDO_F32vec1.h:157
F32vec1::F32vec1
F32vec1()
Definition: L1/vectors/PSEUDO_F32vec1.h:35
F32vec1::if3
friend F32vec1 if3(const F32vec1 &a, const F32vec1 &b, const F32vec1 &c)
Definition: L1/vectors/PSEUDO_F32vec1.h:112