PandaRoot
PSEUDO_F64vec1.h
Go to the documentation of this file.
1 #ifndef L1Algo_PSEUDO_F64vec1_H
2 #define L1Algo_PSEUDO_F64vec1_H
3 
4 #include <iostream>
5 #include <cmath>
6 #include "vec_arithmetic.h"
7 
8 /**********************************
9  *
10  * Vector of four doubles
11  *
12  **********************************/
13 
14 class F64vec1 {
15  public:
16  double v[1];
17 
18  double &operator[](int i) { return ((double *)&v)[i]; }
19  double operator[](int i) const { return ((double *)&v)[i]; }
20 
21  F64vec1() {}
22  F64vec1(const F64vec1 &a) { v[0] = a.v[0]; }
23  F64vec1(const double &a) { v[0] = a; }
24 
25  friend double min(double x, double y) { return x < y ? x : y; }
26  friend double max(double x, double y) { return x < y ? y : x; }
27  friend double asgnb(double x, double y) { return y >= 0 ? fabs(x) : -fabs(x); }
28  friend double rsqrt(double x) { return 1. / sqrt(x); }
29  friend double rcp(double x) { return 1. / x; }
30  friend double sgn(double x) { return x >= 0 ? 1 : -1; }
31 
32 #define _f2(A, B, F) \
33  F64vec1 z; \
34  z.v[0] = F(A.v[0], B.v[0]); \
35  return z;
36 #define _f1(A, F) \
37  F64vec1 z; \
38  z.v[0] = F(A.v[0]); \
39  return z;
40 #define _op(A, B, O) \
41  F64vec1 z; \
42  z.v[0] = A.v[0] O B.v[0]; \
43  return z;
44 
45  /* Arithmetic Operators */
46  friend F64vec1 operator+(const F64vec1 &a, const F64vec1 &b) { _op(a, b, +) }
47  friend F64vec1 operator-(const F64vec1 &a, const F64vec1 &b) { _op(a, b, -) }
48  friend F64vec1 operator*(const F64vec1 &a, const F64vec1 &b) { _op(a, b, *) }
49  friend F64vec1 operator/(const F64vec1 &a, const F64vec1 &b) { _op(a, b, /) }
50 
51  /* Functions */
52  friend F64vec1 min(const F64vec1 &a, const F64vec1 &b) { _f2(a, b, min) }
53  friend F64vec1 max(const F64vec1 &a, const F64vec1 &b) { _f2(a, b, max) }
54  friend F64vec1 asgnb(const F64vec1 &a, const F64vec1 &b) { _f2(a, b, asgnb) }
55  friend F64vec1 sqrt(const F64vec1 &a) { _f1(a, sqrt) }
56  friend F64vec1 rsqrt(const F64vec1 &a) { _f1(a, rsqrt) }
57  friend F64vec1 rcp(const F64vec1 &a) { _f1(a, rcp) }
58  friend F64vec1 fabs(const F64vec1 &a) { _f1(a, fabs) }
59  friend F64vec1 sgn(const F64vec1 &a) { _f1(a, sgn) }
60  friend F64vec1 exp(const F64vec1 &a) { _f1(a, exp) }
61  friend F64vec1 log(const F64vec1 &a) { _f1(a, log) }
62  friend F64vec1 sin(const F64vec1 &a) { _f1(a, sin) }
63  friend F64vec1 cos(const F64vec1 &a) { _f1(a, cos) }
64 #undef _f1
65 #undef _f2
66 #undef _op
67 
68  /* Define all operators for consistensy */
69 
70  vec_arithmetic(F64vec1, double);
71 
72  friend std::ostream &operator<<(std::ostream &strm, const F64vec1 &a)
73  {
74  strm << a[0];
75  return strm;
76  }
77 
78  friend std::istream &operator>>(std::istream &strm, F64vec1 &a)
79  {
80  double tmp;
81  strm >> tmp;
82  a = tmp;
83  return strm;
84  }
85 
86 }; // __attribute__ ((aligned(16)));;
87 
88 typedef F64vec1 fvec;
89 const int fvecLen = 1;
90 typedef double fscal;
91 
92 //#define fvec_true _f32vec1_true
93 //#define fvec_false _f32vec1_false
94 #define _fvecalignment
95 
96 #endif
friend F64vec1 operator/(const F64vec1 &a, const F64vec1 &b)
friend F64vec1 max(const F64vec1 &a, const F64vec1 &b)
friend std::ostream & operator<<(std::ostream &strm, const F64vec1 &a)
F64vec1(const F64vec1 &a)
F64vec1 fvec
F64vec1(const double &a)
#define _op(A, B, O)
friend double rsqrt(double x)
friend double sgn(double x)
double v[1]
vec_arithmetic(F64vec1, double)
friend F64vec1 cos(const F64vec1 &a)
const int fvecLen
#define _f2(A, B, F)
friend F64vec1 operator*(const F64vec1 &a, const F64vec1 &b)
unsigned int i
Definition: P4_F32vec4.h:21
double & operator[](int i)
friend std::istream & operator>>(std::istream &strm, F64vec1 &a)
friend F64vec1 log(const F64vec1 &a)
friend F64vec1 min(const F64vec1 &a, const F64vec1 &b)
friend F64vec1 sgn(const F64vec1 &a)
friend double max(double x, double y)
friend double asgnb(double x, double y)
friend F64vec1 exp(const F64vec1 &a)
friend F64vec1 fabs(const F64vec1 &a)
friend F64vec1 sin(const F64vec1 &a)
friend F64vec1 rcp(const F64vec1 &a)
double operator[](int i) const
friend F64vec1 rsqrt(const F64vec1 &a)
friend double min(double x, double y)
friend F64vec1 operator+(const F64vec1 &a, const F64vec1 &b)
friend F64vec1 operator-(const F64vec1 &a, const F64vec1 &b)
double fscal
friend F64vec1 asgnb(const F64vec1 &a, const F64vec1 &b)
friend F64vec1 sqrt(const F64vec1 &a)
#define _f1(A, F)
friend double rcp(double x)