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