]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/tracking-ca/AliHLTTPCCAMath.h
A tracker update: significant clean up, reorganise of the data structures, p-p track...
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCAMath.h
CommitLineData
00d07bcd 1//-*- Mode: C++ -*-
2// @(#) $Id: AliHLTTPCCARow.h 27042 2008-07-02 12:06:02Z richterm $
3
4//* This file is property of and copyright by the ALICE HLT Project *
5//* ALICE Experiment at CERN, All rights reserved. *
6//* See cxx source for full Copyright notice *
7
8#ifndef ALIHLTTPCCAMATH_H
9#define ALIHLTTPCCAMATH_H
10
11#include "AliHLTTPCCADef.h"
12
13#if defined(HLTCA_STANDALONE) || defined(HLTCA_GPUCODE)
14#include <math.h>
15#else
16#include "TMath.h"
17#endif
18
19/**
20 * @class ALIHLTTPCCAMath
21 *
22 *
23 */
24class AliHLTTPCCAMath
25{
26public:
27 GPUd() static Float_t Min(Float_t x, Float_t y);
28 GPUd() static Float_t Max(Float_t x, Float_t y);
29 GPUd() static Int_t Min(Int_t x, Int_t y);
30 GPUd() static Int_t Max(Int_t x, Int_t y);
31 GPUd() static Float_t Sqrt(Float_t x );
32 GPUd() static Float_t Abs(Float_t x );
33 GPUd() static Double_t Abs(Double_t x );
34 GPUd() static Int_t Abs(Int_t x );
35 GPUd() static Float_t ASin(Float_t x );
36 GPUd() static Float_t ATan2( Float_t y, Float_t x );
37 GPUd() static Float_t Sin( Float_t x );
38 GPUd() static Float_t Cos( Float_t x );
39 GPUd() static Float_t Tan( Float_t x );
40 GPUd() static Float_t Copysign( Float_t x, Float_t y );
41 GPUd() static Float_t TwoPi(){ return 6.28319; }
42 GPUd() static Float_t Pi(){ return 3.1415926535897; }
43 GPUd() static Int_t Nint(Float_t x );
44 GPUd() static Bool_t Finite(Float_t x );
45
46 GPUd() static Int_t atomicExch( Int_t *addr, Int_t val);
47 GPUd() static Int_t atomicAdd ( Int_t *addr, Int_t val);
48 GPUd() static Int_t atomicMax ( Int_t *addr, Int_t val);
49 GPUd() static Int_t atomicMin ( Int_t *addr, Int_t val);
50 GPUd() static Int_t mul24( Int_t a, Int_t b );
51 GPUd() static Float_t fmul_rz( Float_t a, Float_t b );
52};
53
54typedef AliHLTTPCCAMath CAMath;
55
56
57#if defined( HLTCA_GPUCODE )
58#define choice(c1,c2,c3) c1
59#elif defined( HLTCA_STANDALONE )
60#define choice(c1,c2,c3) c2
61#else
62#define choice(c1,c2,c3) c3
63#endif
64
65
66GPUd() inline Int_t AliHLTTPCCAMath::Nint(Float_t x)
67{
68#if defined(HLTCA_STANDALONE) || defined( HLTCA_GPUCODE )
4687b8fc 69 Int_t i;
00d07bcd 70 if (x >= 0) {
71 i = int(x + 0.5);
72 if (x + 0.5 == Float_t(i) && i & 1) i--;
73 } else {
74 i = int(x - 0.5);
75 if (x - 0.5 == Float_t(i) && i & 1) i++;
76 }
77 return i;
78#else
79 return TMath::Nint(x);
80#endif
81}
82
83GPUd() inline Bool_t AliHLTTPCCAMath::Finite(Float_t x)
84{
85 return choice( 1, finite(x), finite(x) );
86}
87
88GPUd() inline Float_t AliHLTTPCCAMath::ATan2(Float_t y, Float_t x)
89{
90 return choice(atan2f(y,x), atan2(y,x), TMath::ATan2(y,x) );
91}
92
93
94GPUd() inline Float_t AliHLTTPCCAMath::Copysign(Float_t x, Float_t y)
95{
96#if defined( HLTCA_GPUCODE )
97 return copysignf(x,y);
98#else
99 x = CAMath::Abs(x);
100 return (y>=0) ?x : -x;
101#endif
102}
103
104
105GPUd() inline Float_t AliHLTTPCCAMath::Sin(Float_t x)
106{
107 return choice( sinf(x), sin(x), TMath::Sin(x) );
108}
109
110GPUd() inline Float_t AliHLTTPCCAMath::Cos(Float_t x)
111{
112 return choice( cosf(x), cos(x), TMath::Cos(x) );
113}
114
115GPUd() inline Float_t AliHLTTPCCAMath::Tan(Float_t x)
116{
117 return choice( tanf(x), tan(x), TMath::Tan(x) );
118}
119
120GPUd() inline Float_t AliHLTTPCCAMath::Min(Float_t x, Float_t y)
121{
122 return choice( fminf(x,y), (x<y ?x :y), TMath::Min(x,y) );
123}
124
125GPUd() inline Float_t AliHLTTPCCAMath::Max(Float_t x, Float_t y)
126{
127 return choice( fmaxf(x,y), (x>y ?x :y), TMath::Max(x,y) );
128}
129
130GPUd() inline Int_t AliHLTTPCCAMath::Min(Int_t x, Int_t y)
131{
132 return choice( min(x,y), (x<y ?x :y), TMath::Min(x,y) );
133}
134
135GPUd() inline Int_t AliHLTTPCCAMath::Max(Int_t x, Int_t y)
136{
137 return choice( max(x,y), (x>y ?x :y), TMath::Max(x,y) );
138}
139
140GPUd() inline Float_t AliHLTTPCCAMath::Sqrt(Float_t x )
141{
142 return choice( sqrtf(x), sqrt(x), TMath::Sqrt(x) );
143}
144
145GPUd() inline Float_t AliHLTTPCCAMath::Abs(Float_t x )
146{
147 return choice( fabsf(x), fabs(x), TMath::Abs(x) );
148}
149
150GPUd() inline Double_t AliHLTTPCCAMath::Abs(Double_t x )
151{
152 return choice( fabs(x), fabs(x), TMath::Abs(x) );
153}
154
155GPUd() inline Int_t AliHLTTPCCAMath::Abs(Int_t x )
156{
157 return choice( abs(x), (x>=0 ?x :-x), TMath::Abs(x) );
158}
159
160GPUd() inline Float_t AliHLTTPCCAMath::ASin(Float_t x )
161{
162 return choice( asinf(x), asin(x), TMath::ASin(x) );
163}
164
165
166GPUd() inline Int_t AliHLTTPCCAMath::mul24( Int_t a, Int_t b )
167{
168 return choice( __mul24(a,b), a*b, a*b );
169}
170
171GPUd() inline Float_t AliHLTTPCCAMath::fmul_rz( Float_t a, Float_t b )
172{
173 return choice( __fmul_rz(a,b), a*b, a*b );
174}
175
176
177GPUd() inline Int_t AliHLTTPCCAMath::atomicExch( Int_t *addr, Int_t val)
178{
179#if defined( HLTCA_GPUCODE )
180 return ::atomicExch(addr, val );
181#else
182 Int_t old = *addr;
183 *addr = val;
184 return old;
185#endif
186}
187
188GPUd() inline Int_t AliHLTTPCCAMath::atomicAdd ( Int_t *addr, Int_t val)
189{
190#if defined( HLTCA_GPUCODE )
191 return ::atomicAdd(addr, val );
192#else
193 Int_t old = *addr;
194 *addr += val;
195 return old;
196#endif
197}
198
199GPUd() inline Int_t AliHLTTPCCAMath::atomicMax ( Int_t *addr, Int_t val)
200{
201#if defined( HLTCA_GPUCODE )
202 return ::atomicMax(addr, val );
203#else
204 Int_t old = *addr;
205 if( *addr< val ) *addr = val;
206 return old;
207#endif
208}
209
210GPUd() inline Int_t AliHLTTPCCAMath::atomicMin ( Int_t *addr, Int_t val)
211{
212#if defined( HLTCA_GPUCODE )
213 return ::atomicMin(addr, val );
214#else
215 Int_t old = *addr;
216 if( *addr> val ) *addr = val;
217 return old;
218#endif
219}
220
221#undef CHOICE
222
223#endif