2 // ************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project *
4 // ALICE Experiment at CERN, All rights reserved. *
5 // See cxx source for full Copyright notice *
7 //*************************************************************************
9 #ifndef ALIHLTTPCCAMATH_H
10 #define ALIHLTTPCCAMATH_H
12 #include "AliHLTTPCCADef.h"
14 #if defined(HLTCA_STANDALONE) || defined(HLTCA_GPUCODE)
21 * @class ALIHLTTPCCAMath
28 GPUd() static float2 MakeFloat2(float x, float y );
30 GPUd() static Float_t Min(Float_t x, Float_t y);
31 GPUd() static Float_t Max(Float_t x, Float_t y);
32 GPUd() static Int_t Min(Int_t x, Int_t y);
33 GPUd() static Int_t Max(Int_t x, Int_t y);
34 GPUd() static Float_t Sqrt(Float_t x );
35 GPUd() static Float_t Abs(Float_t x );
36 GPUd() static Double_t Abs(Double_t x );
37 GPUd() static Int_t Abs(Int_t x );
38 GPUd() static Float_t ASin(Float_t x );
39 GPUd() static Float_t ATan2( Float_t y, Float_t x );
40 GPUd() static Float_t Sin( Float_t x );
41 GPUd() static Float_t Cos( Float_t x );
42 GPUd() static Float_t Tan( Float_t x );
43 GPUd() static Float_t Copysign( Float_t x, Float_t y );
44 GPUd() static Float_t TwoPi(){ return 6.28319; }
45 GPUd() static Float_t Pi(){ return 3.1415926535897; }
46 GPUd() static Int_t Nint(Float_t x );
47 GPUd() static Bool_t Finite(Float_t x );
49 GPUd() static Int_t AtomicExch( Int_t *addr, Int_t val);
50 GPUd() static Int_t AtomicAdd ( Int_t *addr, Int_t val);
51 GPUd() static Int_t AtomicMax ( Int_t *addr, Int_t val);
52 GPUd() static Int_t AtomicMin ( Int_t *addr, Int_t val);
53 GPUd() static Int_t Mul24( Int_t a, Int_t b );
54 GPUd() static Float_t FMulRZ( Float_t a, Float_t b );
57 typedef AliHLTTPCCAMath CAMath;
60 #if defined( HLTCA_GPUCODE )
61 #define choice(c1,c2,c3) c1
62 #elif defined( HLTCA_STANDALONE )
63 #define choice(c1,c2,c3) c2
65 #define choice(c1,c2,c3) c3
68 GPUd() inline float2 AliHLTTPCCAMath::MakeFloat2(float x, float y )
70 #if !defined( HLTCA_GPUCODE )
74 return make_float2(x,y);
79 GPUd() inline Int_t AliHLTTPCCAMath::Nint(Float_t x)
81 #if defined(HLTCA_STANDALONE) || defined( HLTCA_GPUCODE )
85 if (x + 0.5 == Float_t(i) && i & 1) i--;
88 if (x - 0.5 == Float_t(i) && i & 1) i++;
92 return TMath::Nint(x);
96 GPUd() inline Bool_t AliHLTTPCCAMath::Finite(Float_t x)
98 return choice( 1, finite(x), finite(x) );
101 GPUd() inline Float_t AliHLTTPCCAMath::ATan2(Float_t y, Float_t x)
103 return choice(atan2f(y,x), atan2(y,x), TMath::ATan2(y,x) );
107 GPUd() inline Float_t AliHLTTPCCAMath::Copysign(Float_t x, Float_t y)
109 #if defined( HLTCA_GPUCODE )
110 return copysignf(x,y);
113 return (y>=0) ?x : -x;
118 GPUd() inline Float_t AliHLTTPCCAMath::Sin(Float_t x)
120 return choice( sinf(x), sin(x), TMath::Sin(x) );
123 GPUd() inline Float_t AliHLTTPCCAMath::Cos(Float_t x)
125 return choice( cosf(x), cos(x), TMath::Cos(x) );
128 GPUd() inline Float_t AliHLTTPCCAMath::Tan(Float_t x)
130 return choice( tanf(x), tan(x), TMath::Tan(x) );
133 GPUd() inline Float_t AliHLTTPCCAMath::Min(Float_t x, Float_t y)
135 return choice( fminf(x,y), (x<y ?x :y), TMath::Min(x,y) );
138 GPUd() inline Float_t AliHLTTPCCAMath::Max(Float_t x, Float_t y)
140 return choice( fmaxf(x,y), (x>y ?x :y), TMath::Max(x,y) );
143 GPUd() inline Int_t AliHLTTPCCAMath::Min(Int_t x, Int_t y)
145 return choice( min(x,y), (x<y ?x :y), TMath::Min(x,y) );
148 GPUd() inline Int_t AliHLTTPCCAMath::Max(Int_t x, Int_t y)
150 return choice( max(x,y), (x>y ?x :y), TMath::Max(x,y) );
153 GPUd() inline Float_t AliHLTTPCCAMath::Sqrt(Float_t x )
155 return choice( sqrtf(x), sqrt(x), TMath::Sqrt(x) );
158 GPUd() inline Float_t AliHLTTPCCAMath::Abs(Float_t x )
160 return choice( fabsf(x), fabs(x), TMath::Abs(x) );
163 GPUd() inline Double_t AliHLTTPCCAMath::Abs(Double_t x )
165 return choice( fabs(x), fabs(x), TMath::Abs(x) );
168 GPUd() inline Int_t AliHLTTPCCAMath::Abs(Int_t x )
170 return choice( abs(x), (x>=0 ?x :-x), TMath::Abs(x) );
173 GPUd() inline Float_t AliHLTTPCCAMath::ASin(Float_t x )
175 return choice( asinf(x), asin(x), TMath::ASin(x) );
179 GPUd() inline Int_t AliHLTTPCCAMath::Mul24( Int_t a, Int_t b )
181 return choice( __mul24(a,b), a*b, a*b );
184 GPUd() inline Float_t AliHLTTPCCAMath::FMulRZ( Float_t a, Float_t b )
186 return choice( __fmul_rz(a,b), a*b, a*b );
190 GPUd() inline Int_t AliHLTTPCCAMath::AtomicExch( Int_t *addr, Int_t val)
192 #if defined( HLTCA_GPUCODE )
193 return ::atomicExch(addr, val );
201 GPUd() inline Int_t AliHLTTPCCAMath::AtomicAdd ( Int_t *addr, Int_t val)
203 #if defined( HLTCA_GPUCODE )
204 return ::atomicAdd(addr, val );
212 GPUd() inline Int_t AliHLTTPCCAMath::AtomicMax ( Int_t *addr, Int_t val)
214 #if defined( HLTCA_GPUCODE )
215 return ::atomicMax(addr, val );
218 if( *addr< val ) *addr = val;
223 GPUd() inline Int_t AliHLTTPCCAMath::AtomicMin ( Int_t *addr, Int_t val)
225 #if defined( HLTCA_GPUCODE )
226 return ::atomicMin(addr, val );
229 if( *addr> val ) *addr = val;