BmnRoot
Loading...
Searching...
No Matches
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
24class F32vec1
25{
26 public:
28 float v;
29
30 float & operator[]( int i ){ return v;}
31 float operator[]( int i ) const { return v;}
32
34 F32vec1( const float &v0 ){
35 v = v0;
36 }
37
38 /* Conversion function */
39 operator float() const { return v; } /* Convert to __m128 */
40
41 /* Arithmetic Operators */
42
43 /* Functions */
44 //friend F32vec1 min( const F32vec1 &a, const F32vec1 &b ){ return a<b ?a :b; }
45 //friend F32vec1 max( const F32vec1 &a, const F32vec1 &b ){ return a>b ?a :b; }
46
47 /* Square Root */
48
49 /* Reciprocal( inverse) Square Root */
50 //friend F32vec1 rsqrt( const F32vec1 &a ){ return 1./sqrt(a); }
52 /* Reciprocal (inversion) */
53 friend F32vec1 rcp ( const F32vec1 &a ){ return 1./a; }
55 /* Absolute value */
56 //friend F32vec1 fabs(const F32vec1 &a){ return fabs(a); }
57
58 /* Sign */
59 //friend F32vec1 sgn(const F32vec1 &a){ return a<0 ?-1 :(a>0 ?1 :0); }
61 /* Logical */
62 /*
63 friend F32vec1 operator&( const F32vec1 &a, const F32vec1 &b ){ // mask returned
64 F32vec1 tmp;
65 int *x = (int*)&tmp;
66 int *y = (int*)&a;
67 int *z = (int*)&b;
68 x[0] = y[0] & z[0];
69 x[1] = y[1] & z[1];
70 return tmp;
71 }
72 */
73 /* Non intrinsic functions */
74
75 /* Define all operators for consistensy */
76
77 friend void operator+=( F32vec1 &a, const F32vec1 &b ){ a = a + b ; }
78 friend void operator-=( F32vec1 &a, const F32vec1 &b ){ a = a - b ; }
79 friend void operator*=( F32vec1 &a, const F32vec1 &b ){ a = a * b ; }
80 friend void operator/=( F32vec1 &a, const F32vec1 &b ){ a = a / b ; }
81
82#define _op(A,B,O) F32vec1 z; z.v = A.v O B.v; return z;
83
84// /* Comparison */
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 friend F32vec1 operator >=(const F32vec1 &a, const F32vec1 &b){ _op(a,b,>=) }
89
90// /* Logic */
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 friend F32vec1 operator ||(const F32vec1 &a, const F32vec1 &b){ _op(a,b,||) }
94#undef _op
95
96 friend F32vec1 operator !(const F32vec1 &a) {
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 F32vec1 z;
105 z[0] = (a[0]) ? b[0] : c[0];
106
107 return z;
108 }
109
110#define NotEmpty(a) bool((a)[0])
111#define Empty(a) !(bool((a)[0]))
112 friend F32vec1 bool2int( const F32vec1 &a){ // mask returned
113 return if3(a,1,0);
114 }
115
116
117
118 friend ostream & operator<<(ostream &strm, const F32vec1 &a ){
119 strm<<a[0];
120 return strm;
121 }
122
123 friend istream & operator>>(istream &strm, F32vec1 &a ){
124 float tmp;
125 strm>>tmp;
126 a = tmp;
127 return strm;
128 }
129
130} __attribute__ ((aligned(4)));;
131
132typedef F32vec1 fvec;
133const int fvecLen = 1;
134// #define fvec_true _f32vec1_true
135// #define fvec_false _f32vec1_false
136#define _fvecalignment
137
138
139namespace nsL1
140{
141 template<typename T>
142 struct vector
143 {
144 typedef std::vector<T> TStd;
145 typedef std::vector<T> TSimd;
146 };
147
149}; // namespace nsL1
150
151template<typename T>
152struct nsL1vector: public nsL1::vector<T> // just for use std::vector simultaniosly
153{
154};
155
156#endif
int i
Definition P4_F32vec4.h:22
F32vec1 fvec
const int fvecLen
nsL1vector __attribute__
#define _op(A, B, O)
friend F32vec1 rcp(const F32vec1 &a)
friend F32vec1 operator<(const F32vec1 &a, const F32vec1 &b)
friend void operator-=(F32vec1 &a, const F32vec1 &b)
friend F32vec1 operator&(const F32vec1 &a, const F32vec1 &b)
friend void operator*=(F32vec1 &a, const F32vec1 &b)
friend F32vec1 operator||(const F32vec1 &a, const F32vec1 &b)
friend istream & operator>>(istream &strm, F32vec1 &a)
friend F32vec1 bool2int(const F32vec1 &a)
friend F32vec1 if3(const F32vec1 &a, const F32vec1 &b, const F32vec1 &c)
friend void operator+=(F32vec1 &a, const F32vec1 &b)
friend ostream & operator<<(ostream &strm, const F32vec1 &a)
friend F32vec1 operator<=(const F32vec1 &a, const F32vec1 &b)
friend F32vec1 operator>=(const F32vec1 &a, const F32vec1 &b)
float operator[](int i) const
friend F32vec1 operator|(const F32vec1 &a, const F32vec1 &b)
F32vec1(const float &v0)
friend void operator/=(F32vec1 &a, const F32vec1 &b)
friend F32vec1 operator!(const F32vec1 &a)
float & operator[](int i)
friend F32vec1 operator>(const F32vec1 &a, const F32vec1 &b)
nsL1::vector< fvec >::TSimd vector_fvec
std::vector< T > TStd
std::vector< T > TSimd