PandaRoot
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 <iostream>
5 #include <cmath>
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) { _op(a, b, <=) }
86  friend F32vec1 operator>(const F32vec1 &a, const F32vec1 &b) { _op(a, b, >) }
87  friend F32vec1 operator>=(const F32vec1 &a, const F32vec1 &b) { _op(a, b, >=) }
88 
89  // /* Logic */
90  friend F32vec1 operator&(const F32vec1 &a, const F32vec1 &b) { _op(a, b, &&) }
91  friend F32vec1 operator|(const F32vec1 &a, const F32vec1 &b) { _op(a, b, ||) }
92  friend F32vec1 operator||(const F32vec1 &a, const F32vec1 &b) { _op(a, b, ||) }
93 #undef _op
94 
95  friend F32vec1 operator!(const F32vec1 &a)
96  {
97  F32vec1 z;
98  z[0] = !a[0];
99 
100  return z;
101  }
102 
103  friend F32vec1 if3(const F32vec1 &a, const F32vec1 &b, const F32vec1 &c)
104  {
105  F32vec1 z;
106  z[0] = (a[0]) ? b[0] : c[0];
107 
108  return z;
109  }
110 
111 #define NotEmpty(a) bool((a)[0])
112 #define Empty(a) !(bool((a)[0]))
113  friend F32vec1 bool2int(const F32vec1 &a)
114  { // mask returned
115  return if3(a, 1, 0);
116  }
117 
118  friend ostream &operator<<(ostream &strm, const F32vec1 &a)
119  {
120  strm << a[0];
121  return strm;
122  }
123 
124  friend istream &operator>>(istream &strm, F32vec1 &a)
125  {
126  float tmp;
127  strm >> tmp;
128  a = tmp;
129  return strm;
130  }
131 
132 } __attribute__((aligned(4)));
133 ;
134 
135 typedef F32vec1 fvec;
136 const int fvecLen = 1;
137 // #define fvec_true _f32vec1_true
138 // #define fvec_false _f32vec1_false
139 #define _fvecalignment
140 
141 namespace nsL1 {
142 template <typename T>
143 struct vector {
144  typedef std::vector<T> TStd;
145  typedef std::vector<T> TSimd;
146 };
147 
149 }; // namespace nsL1
150 
151 template <typename T>
152 struct nsL1vector : public nsL1::vector<T> // just for use std::vector simultaniosly
153 {
154 };
155 
156 #endif
friend F32vec1 operator>(const F32vec1 &a, const F32vec1 &b)
friend void operator*=(F32vec1 &a, const F32vec1 &b)
F32vec1 fvec
const int fvecLen
friend F32vec1 operator!(const F32vec1 &a)
friend void operator-=(F32vec1 &a, const F32vec1 &b)
friend ostream & operator<<(ostream &strm, const F32vec1 &a)
friend void operator+=(F32vec1 &a, const F32vec1 &b)
friend F32vec1 operator|(const F32vec1 &a, const F32vec1 &b)
friend istream & operator>>(istream &strm, F32vec1 &a)
nsL1::vector< fvec >::TSimd vector_fvec
friend F32vec1 if3(const F32vec1 &a, const F32vec1 &b, const F32vec1 &c)
unsigned int i
Definition: P4_F32vec4.h:21
#define _op(A, B, O)
friend F32vec1 rcp(const F32vec1 &a)
friend F32vec1 operator<(const F32vec1 &a, const F32vec1 &b)
float & operator[](int i)
std::vector< T > TSimd
friend F32vec1 operator &(const F32vec1 &a, const F32vec1 &b)
friend F32vec1 operator>=(const F32vec1 &a, const F32vec1 &b)
nsL1vector __attribute__
friend void operator/=(F32vec1 &a, const F32vec1 &b)
friend F32vec1 operator||(const F32vec1 &a, const F32vec1 &b)
friend F32vec1 bool2int(const F32vec1 &a)
float operator[](int i) const
friend F32vec1 operator<=(const F32vec1 &a, const F32vec1 &b)
F32vec1(const float &v0)
std::vector< T > TStd