{
#if defined(__ICC)
template<typename must_be_int = int>
- int32_t faa32(int32_t* x, int32_t inc)
+ int32 faa32(int32* x, int32 inc)
{
asm volatile("lock xadd %0,%1"
: "=r" (inc), "=m" (*x)
}
#if defined(__x86_64)
template<typename must_be_int = int>
- int64_t faa64(int64_t* x, int64_t inc)
+ int64 faa64(int64* x, int64 inc)
{
asm volatile("lock xadd %0,%1"
: "=r" (inc), "=m" (*x)
* @param ptr Pointer to a 32-bit signed integer.
* @param addend Value to add.
*/
- inline int32_t
- fetch_and_add_32(volatile int32_t* ptr, int32_t addend)
+ inline int32
+ fetch_and_add_32(volatile int32* ptr, int32 addend)
{
#if defined(__ICC) //x86 version
return _InterlockedExchangeAdd((void*)ptr, addend);
#elif defined(__GNUC__)
return __sync_fetch_and_add(ptr, addend);
#elif defined(__SUNPRO_CC) && defined(__sparc)
- volatile int32_t before, after;
+ volatile int32 before, after;
do
{
before = *ptr;
return before;
#else //fallback, slow
#pragma message("slow fetch_and_add_32")
- int32_t res;
+ int32 res;
#pragma omp critical
{
res = *ptr;
* @param ptr Pointer to a 64-bit signed integer.
* @param addend Value to add.
*/
- inline int64_t
- fetch_and_add_64(volatile int64_t* ptr, int64_t addend)
+ inline int64
+ fetch_and_add_64(volatile int64* ptr, int64 addend)
{
#if defined(__ICC) && defined(__x86_64) //x86 version
- return faa64<int>((int64_t*)ptr, addend);
+ return faa64<int>((int64*)ptr, addend);
#elif defined(__ECC) //IA-64 version
return _InterlockedExchangeAdd64((void*)ptr, addend);
#elif defined(__ICL) || defined(_MSC_VER)
(defined(__i686) || defined(__pentium4) || defined(__athlon))
return __sync_fetch_and_add(ptr, addend);
#elif defined(__SUNPRO_CC) && defined(__sparc)
- volatile int64_t before, after;
+ volatile int64 before, after;
do
{
before = *ptr;
//#warning "please compile with -march=i686 or better"
#endif
#pragma message("slow fetch_and_add_64")
- int64_t res;
+ int64 res;
#pragma omp critical
{
res = *ptr;
inline T
fetch_and_add(volatile T* ptr, T addend)
{
- if (sizeof(T) == sizeof(int32_t))
- return (T)fetch_and_add_32((volatile int32_t*) ptr, (int32_t)addend);
- else if (sizeof(T) == sizeof(int64_t))
- return (T)fetch_and_add_64((volatile int64_t*) ptr, (int64_t)addend);
+ if (sizeof(T) == sizeof(int32))
+ return (T)fetch_and_add_32((volatile int32*) ptr, (int32)addend);
+ else if (sizeof(T) == sizeof(int64))
+ return (T)fetch_and_add_64((volatile int64*) ptr, (int64)addend);
else
_GLIBCXX_PARALLEL_ASSERT(false);
}
#if defined(__ICC)
template<typename must_be_int = int>
- inline int32_t
- cas32(volatile int32_t* ptr, int32_t old, int32_t nw)
+ inline int32
+ cas32(volatile int32* ptr, int32 old, int32 nw)
{
- int32_t before;
+ int32 before;
__asm__ __volatile__("lock; cmpxchgl %1,%2"
: "=a"(before)
: "q"(nw), "m"(*(volatile long long*)(ptr)), "0"(old)
#if defined(__x86_64)
template<typename must_be_int = int>
- inline int64_t
- cas64(volatile int64_t *ptr, int64_t old, int64_t nw)
+ inline int64
+ cas64(volatile int64 *ptr, int64 old, int64 nw)
{
- int64_t before;
+ int64 before;
__asm__ __volatile__("lock; cmpxchgq %1,%2"
: "=a"(before)
: "q"(nw), "m"(*(volatile long long*)(ptr)), "0"(old)
* @param replacement Replacement value.
*/
inline bool
- compare_and_swap_32(volatile int32_t* ptr, int32_t comparand, int32_t replacement)
+ compare_and_swap_32(volatile int32* ptr, int32 comparand, int32 replacement)
{
#if defined(__ICC) //x86 version
return _InterlockedCompareExchange((void*)ptr, replacement,
* @param replacement Replacement value.
*/
inline bool
- compare_and_swap_64(volatile int64_t* ptr, int64_t comparand, int64_t replacement)
+ compare_and_swap_64(volatile int64* ptr, int64 comparand, int64 replacement)
{
#if defined(__ICC) && defined(__x86_64) //x86 version
return cas64<int>(ptr, comparand, replacement) == comparand;
inline bool
compare_and_swap(volatile T* ptr, T comparand, T replacement)
{
- if (sizeof(T) == sizeof(int32_t))
- return compare_and_swap_32((volatile int32_t*) ptr, (int32_t)comparand, (int32_t)replacement);
- else if (sizeof(T) == sizeof(int64_t))
- return compare_and_swap_64((volatile int64_t*) ptr, (int64_t)comparand, (int64_t)replacement);
+ if (sizeof(T) == sizeof(int32))
+ return compare_and_swap_32((volatile int32*) ptr, (int32)comparand, (int32)replacement);
+ else if (sizeof(T) == sizeof(int64))
+ return compare_and_swap_64((volatile int64*) ptr, (int64)comparand, (int64)replacement);
else
_GLIBCXX_PARALLEL_ASSERT(false);
}
{
private:
std::tr1::mt19937 mt;
- uint64_t supremum;
- uint64_t RAND_SUP;
+ uint64 supremum;
+ uint64 RAND_SUP;
double supremum_reciprocal;
double RAND_SUP_REC;
// Assumed to be twice as long as the usual random number.
- uint64_t cache;
+ uint64 cache;
// Bit results.
int bits_left;
- static uint32_t
- scale_down(uint64_t x,
+ static uint32
+ scale_down(uint64 x,
#if _GLIBCXX_SCALE_DOWN_FPU
- uint64_t /*supremum*/, double supremum_reciprocal)
+ uint64 /*supremum*/, double supremum_reciprocal)
#else
- uint64_t supremum, double /*supremum_reciprocal*/)
+ uint64 supremum, double /*supremum_reciprocal*/)
#endif
{
#if _GLIBCXX_SCALE_DOWN_FPU
- return uint32_t(x * supremum_reciprocal);
+ return uint32(x * supremum_reciprocal);
#else
- return static_cast<uint32_t>(x % supremum);
+ return static_cast<uint32>(x % supremum);
#endif
}
/** @brief Default constructor. Seed with 0. */
random_number()
: mt(0), supremum(0x100000000ULL),
- RAND_SUP(1ULL << (sizeof(uint32_t) * 8)),
+ RAND_SUP(1ULL << (sizeof(uint32) * 8)),
supremum_reciprocal(double(supremum) / double(RAND_SUP)),
RAND_SUP_REC(1.0 / double(RAND_SUP)),
cache(0), bits_left(0) { }
* @param seed Random seed.
* @param supremum Generate integer random numbers in the
* interval @c [0,supremum). */
- random_number(uint32_t seed, uint64_t supremum = 0x100000000ULL)
+ random_number(uint32 seed, uint64 supremum = 0x100000000ULL)
: mt(seed), supremum(supremum),
- RAND_SUP(1ULL << (sizeof(uint32_t) * 8)),
+ RAND_SUP(1ULL << (sizeof(uint32) * 8)),
supremum_reciprocal(double(supremum) / double(RAND_SUP)),
RAND_SUP_REC(1.0 / double(RAND_SUP)),
cache(0), bits_left(0) { }
/** @brief Generate unsigned random 32-bit integer. */
- uint32_t
+ uint32
operator()()
{ return scale_down(mt(), supremum, supremum_reciprocal); }
/** @brief Generate unsigned random 32-bit integer in the
interval @c [0,local_supremum). */
- uint32_t
- operator()(uint64_t local_supremum)
+ uint32
+ operator()(uint64 local_supremum)
{
return scale_down(mt(), local_supremum,
double(local_supremum * RAND_SUP_REC));
bits_left -= bits;
if (bits_left < 32)
{
- cache |= ((uint64_t(mt())) << bits_left);
+ cache |= ((uint64(mt())) << bits_left);
bits_left += 32;
}
return res;
#define _GLIBCXX_PARALLEL_TYPES_H 1
#include <cstdlib>
-#include <tr1/cstdint>
namespace __gnu_parallel
{
inline bool
is_parallel(const parallelism __p) { return __p != sequential; }
- /// Integer Types.
- using std::tr1::int16_t;
- using std::tr1::uint16_t;
+ // XXX need to use <cstdint>
+ /** @brief 16-bit signed integer. */
+ typedef short int16;
- using std::tr1::int32_t;
- using std::tr1::uint32_t;
+ /** @brief 16-bit unsigned integer. */
+ typedef unsigned short uint16;
- using std::tr1::int64_t;
- using std::tr1::uint64_t;
+ /** @brief 32-bit signed integer. */
+ typedef int int32;
+
+ /** @brief 32-bit unsigned integer. */
+ typedef unsigned int uint32;
+
+ /** @brief 64-bit signed integer. */
+ typedef long long int64;
+
+ /** @brief 64-bit unsigned integer. */
+ typedef unsigned long long uint64;
/**
* @brief Unsigned integer to index elements.
* The total number of elements for each algorithm must fit into this type.
*/
- typedef uint64_t sequence_index_t;
+ typedef uint64 sequence_index_t;
/**
* @brief Unsigned integer to index a thread number.
* The maximum thread number (for each processor) must fit into this type.
*/
- typedef uint16_t thread_index_t;
+ typedef uint16 thread_index_t;
// XXX atomics interface?
/**
* @brief Longest compare-and-swappable integer type on this platform.
*/
- typedef int64_t lcas_t;
+ typedef int64 lcas_t;
// XXX numeric_limits::digits?
/**