9 #ifndef ALIHLTTPCCAMATH_H
10 #define ALIHLTTPCCAMATH_H
12 #include "AliHLTTPCCADef.h"
18 #if defined(HLTCA_STANDALONE)
25 #include <xmmintrin.h>
35 template<
typename T>
static inline T Min (
const T &x,
const T &y ) {
return std::min( x, y ); }
36 template<
typename T>
static inline T Max (
const T &x,
const T &y ) {
return std::max( x, y ); }
37 template<
typename T>
static inline T Sqrt(
const T &x ) {
return std::sqrt( x ); }
38 template<
typename T>
static inline T RSqrt(
const T &x ) {
const T one = 1.;
return one / std::sqrt( x ); }
39 template<
typename T>
typename Vc::Vector<T> RSqrt(
const Vc::Vector<T> &x) {
return Vc::rsqrt( x ); }
40 template<
typename T>
static inline T Abs (
const T &x ) {
return std::abs( x ); }
41 template<
typename T>
static inline T Log (
const T &x ) {
return std::log( x ); }
42 template<
typename T>
static inline T Log10(
const T &x ) {
return std::log10( x ); }
43 template<
typename T>
static inline T Sin (
const T &x ) {
return std::sin( x ); }
44 template<
typename T>
static inline T Cos (
const T &x ) {
return std::cos( x ); }
45 template<
typename T>
static T Reciprocal(
const T &x );
46 template<
typename T>
typename Vc::Vector<T> Reciprocal(
const Vc::Vector<T> &x) {
return Vc::reciprocal( x ); }
47 template<
typename T>
static T ApproxSqrt(
const T &x );
49 template<
typename T>
static T AtomicMax( T
volatile *addr, T val );
53 template<
typename T>
static typename FiniteReturnTypeHelper<T>::R Finite(
const T &x );
54 template<
typename T>
typename Vc::Vector<T>::Mask Finite(
const Vc::Vector<T> &x) {
return Vc::isfinite( x ); }
56 template<
typename T>
static T Round(
const T &x ) {
return round( x ); }
58 template<
typename T>
static inline T Recip(
const T &x ) {
return T( 1 ) / x; }
59 template<
typename T>
static T ATan2(
const T &y,
const T &x ) {
return atan2( y, x ); }
60 template<
typename T>
static T ASin(
const T &x ) {
return asin( x ); }
63 float Copysign(
float x,
float y );
64 static inline float TwoPi() {
return 6.283185307179586f; }
65 static inline float Pi() {
return 3.1415926535897f; }
68 template<
typename T>
static T ACos(
const T &x ) {
return (Pi()/2.f - asin( x )); }
71 int AtomicExch(
int volatile *addr,
int val );
72 int AtomicAdd (
int volatile *addr,
int val );
73 int AtomicMin (
int volatile *addr,
int val );
77 #if defined( HLTCA_STANDALONE )
78 #define choice(c1,c2,c3) c2
80 #define choice(c1,c2,c3) c3
86 template<>
inline float Reciprocal<float>(
const float &x )
91 template<>
inline double Reciprocal<double>(
const double &x )
97 template<>
inline float RSqrt<float>(
const float &x )
104 :
"+m"( r ),
"=x"( tmp )
110 template<>
inline float ApproxSqrt<float>(
const float &x )
115 "add $0x1fc00000,%0\n\t"
122 inline int CAMath::Nint(
float x )
127 if ( x + 0.5f ==
float( i ) && i & 1 ) i--;
130 if ( x - 0.5f ==
float( i ) && i & 1 ) i++;
137 template<>
inline bool Finite<float>(
const float &x )
140 x < std::numeric_limits<float>::infinity() && -x < std::numeric_limits<float>::infinity(),
144 template<>
inline bool Finite<double>(
const double &x )
147 x < std::numeric_limits<double>::infinity() && -x < std::numeric_limits<double>::infinity(),
151 template<>
inline float Round<float>(
const float &x ) {
return static_cast<float>( Nint( x ) ); }
153 template<>
inline float ATan2<float>(
const float &y,
const float &x )
155 return choice( atan2f( y, x ), atan2( y, x ), TMath::ATan2( y, x ) );
158 template<>
inline float ASin(
const float &x )
160 return choice( asinf( x ), asin( x ), TMath::ASin( x ) );
166 inline float CAMath::Copysign(
float x,
float y )
168 x = CAMath::Abs( x );
169 return ( y >= 0 ) ? x : -x;
173 inline float CAMath::Tan(
float x )
175 return choice( tanf( x ), tan( x ), TMath::Tan( x ) );
180 #include <tbb/atomic.h>
182 inline int CAMath::AtomicExch(
int volatile *addr,
int val )
184 tbb::atomic<int> &a = *
reinterpret_cast<tbb::atomic<int> *
>(
const_cast<int *
>( addr ) );
185 return a.fetch_and_store( val );
188 inline int CAMath::AtomicAdd (
int volatile *addr,
int val )
190 tbb::atomic<int> &a = *
reinterpret_cast<tbb::atomic<int> *
>(
const_cast<int *
>( addr ) );
191 return a.fetch_and_add( val );
196 template<>
inline int AtomicMax<int>(
int volatile *addr,
int val )
198 tbb::atomic<int> &a = *
reinterpret_cast<tbb::atomic<int> *
>(
const_cast<int *
>( addr ) );
201 while ( old != a.compare_and_swap( val, old ) ) {
211 template<>
inline unsigned int AtomicMax<unsigned int>(
unsigned int volatile *addr,
unsigned int val )
213 tbb::atomic<unsigned int> &a = *
reinterpret_cast<tbb::atomic<unsigned int> *
>(
const_cast<unsigned int *
>( addr ) );
214 unsigned int old = a;
216 while ( old != a.compare_and_swap( val, old ) ) {
227 inline int CAMath::AtomicMin (
int volatile *addr,
int val )
229 tbb::atomic<int> &a = *
reinterpret_cast<tbb::atomic<int> *
>(
const_cast<int *
>( addr ) );
232 while ( old != a.compare_and_swap( val, old ) ) {