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