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