various minor improvements
parent
a1da52f589
commit
526467da0e
|
@ -53,7 +53,16 @@ template <typename T> inline bool atomicCompareAndExchangePtr(T **v, T *newValue
|
|||
inline bool atomicCompareAndExchange(volatile int32_t *v, int32_t newValue, int32_t oldValue) {
|
||||
#if defined(WIN32)
|
||||
return InterlockedCompareExchange(
|
||||
reint32_terpret_cast<volatile int32_t *>(v), newValue, oldValue) == oldValue;
|
||||
reinterpret_cast<volatile int32_t *>(v), newValue, oldValue) == oldValue;
|
||||
#else
|
||||
return __sync_bool_compare_and_swap(v, oldValue, newValue);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool atomicCompareAndExchange(volatile int64_t *v, int64_t newValue, int64_t oldValue) {
|
||||
#if defined(WIN64)
|
||||
return InterlockedCompareExchange64(
|
||||
reinterpret_cast<volatile int64_t *>(v), newValue, oldValue) == oldValue;
|
||||
#else
|
||||
return __sync_bool_compare_and_swap(v, oldValue, newValue);
|
||||
#endif
|
||||
|
@ -71,7 +80,23 @@ inline float atomicAdd(volatile float *val, float delta) {
|
|||
#endif
|
||||
oldVal.f = *val;
|
||||
newVal.f = oldVal.f + delta;
|
||||
} while (atomicCompareAndExchange((volatile int32_t *) val, newVal.i, oldVal.i) != oldVal.i);
|
||||
} while (!atomicCompareAndExchange((volatile int32_t *) val, newVal.i, oldVal.i));
|
||||
return newVal.f;
|
||||
}
|
||||
|
||||
inline double atomicAdd(volatile double *val, double delta) {
|
||||
/* Atomic FP addition from PBRT */
|
||||
union bits { double f; int64_t i; };
|
||||
bits oldVal, newVal;
|
||||
do {
|
||||
// On IA64/x64, adding a PAUSE instruction in compare/exchange loops
|
||||
// is recommended to improve performance. (And it does!)
|
||||
#if (defined(__i386__) || defined(__amd64__))
|
||||
__asm__ __volatile__ ("pause\n");
|
||||
#endif
|
||||
oldVal.f = *val;
|
||||
newVal.f = oldVal.f + delta;
|
||||
} while (!atomicCompareAndExchange((volatile int64_t *) val, newVal.i, oldVal.i));
|
||||
return newVal.f;
|
||||
}
|
||||
|
||||
|
|
|
@ -164,6 +164,8 @@ public:
|
|||
inline const aabb_type &getAABB() const { return m_aabb; }
|
||||
/// Return the depth of the constructed KD-tree
|
||||
inline size_t getDepth() const { return m_depth; }
|
||||
/// Return the size of the kd-tree
|
||||
inline size_t getSize() const { return m_nodes.size(); }
|
||||
|
||||
/// Construct the KD-tree hierarchy
|
||||
void build() {
|
||||
|
|
|
@ -261,7 +261,16 @@ public:
|
|||
*this = temp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/// Compute the trace of a square matrix
|
||||
inline Float trace() const {
|
||||
BOOST_STATIC_ASSERT(M == N);
|
||||
Float sum = 0;
|
||||
for (int i=0; i<M; ++i)
|
||||
sum += m[i][i];
|
||||
return sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Compute the LU decomposition of a matrix
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue