Commit 63ffc486 by Johannes Singler Committed by Johannes Singler

base.h: Take integer types from <tr1/cstdint>.

2009-10-02  Johannes Singler  <singler@ira.uka.de>

        * include/parallel/base.h: Take integer types from <tr1/cstdint>.
        * include/parallel/compatibility.h: Likewise.
        * include/parallel/multiseq_selection.h: Likewise.
        * include/parallel/random_shuffle.h: Likewise.
        * include/parallel/random_number.h: Likewise;
        use numeric_limits<>::digit instead of sizeof()*8.
        * include/parallel/types.h: Likewise.
        * doc/html/manual/bk01pt12ch31s03.html:
        Document dependency on stdint.h.

From-SVN: r152396
parent e6d92cec
2009-10-02 Johannes Singler <singler@ira.uka.de>
* include/parallel/base.h: Take integer types from <tr1/cstdint>.
* include/parallel/compatibility.h: Likewise.
* include/parallel/multiseq_selection.h: Likewise.
* include/parallel/random_shuffle.h: Likewise.
* include/parallel/random_number.h: Likewise;
use numeric_limits<>::digit instead of sizeof()*8.
* include/parallel/types.h: Likewise.
* doc/html/manual/bk01pt12ch31s03.html:
Document dependency on stdint.h.
2009-10-01 Phil Muldoon <pmuldoon@redhat.com> 2009-10-01 Phil Muldoon <pmuldoon@redhat.com>
* python/libstdcxx/v6/printers.py (StdListPrinter): * python/libstdcxx/v6/printers.py (StdListPrinter):
......
...@@ -17,7 +17,11 @@ In addition, hardware that supports atomic operations and a compiler ...@@ -17,7 +17,11 @@ In addition, hardware that supports atomic operations and a compiler
as <code class="literal">-march=i686</code>, as <code class="literal">-march=i686</code>,
<code class="literal">-march=native</code> or <code class="literal">-mcpu=v9</code>. See <code class="literal">-march=native</code> or <code class="literal">-mcpu=v9</code>. See
the GCC manual for more information. the GCC manual for more information.
</p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="parallel_mode.using.parallel_mode"></a>Using Parallel Mode</h3></div></div></div><p> </p>
<p>
Also, the parallel mode requires platform support for stdint.h.
</p>
</div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="parallel_mode.using.parallel_mode"></a>Using Parallel Mode</h3></div></div></div><p>
To use the libstdc++ parallel mode, compile your application with To use the libstdc++ parallel mode, compile your application with
the prerequisite flags as detailed above, and in addition the prerequisite flags as detailed above, and in addition
add <code class="constant">-D_GLIBCXX_PARALLEL</code>. This will convert all add <code class="constant">-D_GLIBCXX_PARALLEL</code>. This will convert all
......
...@@ -392,8 +392,8 @@ template<typename _Tp, typename _DifferenceTp> ...@@ -392,8 +392,8 @@ template<typename _Tp, typename _DifferenceTp>
public: public:
typedef _DifferenceTp _DifferenceType; typedef _DifferenceTp _DifferenceType;
// Better case down to uint64, than up to _DifferenceTp. // Better cast down to uint64_t, than up to _DifferenceTp.
typedef _PseudoSequenceIterator<_Tp, uint64> iterator; typedef _PseudoSequenceIterator<_Tp, uint64_t> iterator;
/** @brief Constructor. /** @brief Constructor.
* @param _M_val Element of the sequence. * @param _M_val Element of the sequence.
......
...@@ -62,7 +62,7 @@ namespace __gnu_parallel ...@@ -62,7 +62,7 @@ namespace __gnu_parallel
{ {
#if defined(__ICC) #if defined(__ICC)
template<typename _MustBeInt = int> template<typename _MustBeInt = int>
int32 __faa32(int32* __x, int32 __inc) int32_t __faa32(int32_t* __x, int32_t __inc)
{ {
asm volatile("lock xadd %0,%1" asm volatile("lock xadd %0,%1"
: "=__r" (__inc), "=__m" (*__x) : "=__r" (__inc), "=__m" (*__x)
...@@ -72,7 +72,7 @@ namespace __gnu_parallel ...@@ -72,7 +72,7 @@ namespace __gnu_parallel
} }
#if defined(__x86_64) #if defined(__x86_64)
template<typename _MustBeInt = int> template<typename _MustBeInt = int>
int64 __faa64(int64* __x, int64 __inc) int64_t __faa64(int64_t* __x, int64_t __inc)
{ {
asm volatile("lock xadd %0,%1" asm volatile("lock xadd %0,%1"
: "=__r" (__inc), "=__m" (*__x) : "=__r" (__inc), "=__m" (*__x)
...@@ -91,8 +91,8 @@ namespace __gnu_parallel ...@@ -91,8 +91,8 @@ namespace __gnu_parallel
* @param __ptr Pointer to a 32-bit signed integer. * @param __ptr Pointer to a 32-bit signed integer.
* @param __addend Value to add. * @param __addend Value to add.
*/ */
inline int32 inline int32_t
__fetch_and_add_32(volatile int32* __ptr, int32 __addend) __fetch_and_add_32(volatile int32_t* __ptr, int32_t __addend)
{ {
#if defined(__ICC) //x86 version #if defined(__ICC) //x86 version
return _InterlockedExchangeAdd((void*)__ptr, __addend); return _InterlockedExchangeAdd((void*)__ptr, __addend);
...@@ -104,7 +104,7 @@ namespace __gnu_parallel ...@@ -104,7 +104,7 @@ namespace __gnu_parallel
#elif defined(__GNUC__) #elif defined(__GNUC__)
return __sync_fetch_and_add(__ptr, __addend); return __sync_fetch_and_add(__ptr, __addend);
#elif defined(__SUNPRO_CC) && defined(__sparc) #elif defined(__SUNPRO_CC) && defined(__sparc)
volatile int32 __before, __after; volatile int32_t __before, __after;
do do
{ {
__before = *__ptr; __before = *__ptr;
...@@ -114,7 +114,7 @@ namespace __gnu_parallel ...@@ -114,7 +114,7 @@ namespace __gnu_parallel
return __before; return __before;
#else //fallback, slow #else //fallback, slow
#pragma message("slow __fetch_and_add_32") #pragma message("slow __fetch_and_add_32")
int32 __res; int32_t __res;
#pragma omp critical #pragma omp critical
{ {
__res = *__ptr; __res = *__ptr;
...@@ -130,11 +130,11 @@ namespace __gnu_parallel ...@@ -130,11 +130,11 @@ namespace __gnu_parallel
* @param __ptr Pointer to a 64-bit signed integer. * @param __ptr Pointer to a 64-bit signed integer.
* @param __addend Value to add. * @param __addend Value to add.
*/ */
inline int64 inline int64_t
__fetch_and_add_64(volatile int64* __ptr, int64 __addend) __fetch_and_add_64(volatile int64_t* __ptr, int64_t __addend)
{ {
#if defined(__ICC) && defined(__x86_64) //x86 version #if defined(__ICC) && defined(__x86_64) //x86 version
return __faa64<int>((int64*)__ptr, __addend); return __faa64<int>((int64_t*)__ptr, __addend);
#elif defined(__ECC) //IA-64 version #elif defined(__ECC) //IA-64 version
return _InterlockedExchangeAdd64((void*)__ptr, __addend); return _InterlockedExchangeAdd64((void*)__ptr, __addend);
#elif defined(__ICL) || defined(_MSC_VER) #elif defined(__ICL) || defined(_MSC_VER)
...@@ -150,7 +150,7 @@ namespace __gnu_parallel ...@@ -150,7 +150,7 @@ namespace __gnu_parallel
(defined(__i686) || defined(__pentium4) || defined(__athlon)) (defined(__i686) || defined(__pentium4) || defined(__athlon))
return __sync_fetch_and_add(__ptr, __addend); return __sync_fetch_and_add(__ptr, __addend);
#elif defined(__SUNPRO_CC) && defined(__sparc) #elif defined(__SUNPRO_CC) && defined(__sparc)
volatile int64 __before, __after; volatile int64_t __before, __after;
do do
{ {
__before = *__ptr; __before = *__ptr;
...@@ -164,7 +164,7 @@ namespace __gnu_parallel ...@@ -164,7 +164,7 @@ namespace __gnu_parallel
//#warning "please compile with -march=i686 or better" //#warning "please compile with -march=i686 or better"
#endif #endif
#pragma message("slow __fetch_and_add_64") #pragma message("slow __fetch_and_add_64")
int64 __res; int64_t __res;
#pragma omp critical #pragma omp critical
{ {
__res = *__ptr; __res = *__ptr;
...@@ -184,10 +184,12 @@ namespace __gnu_parallel ...@@ -184,10 +184,12 @@ namespace __gnu_parallel
inline _Tp inline _Tp
__fetch_and_add(volatile _Tp* __ptr, _Tp __addend) __fetch_and_add(volatile _Tp* __ptr, _Tp __addend)
{ {
if (sizeof(_Tp) == sizeof(int32)) if (sizeof(_Tp) == sizeof(int32_t))
return (_Tp)__fetch_and_add_32((volatile int32*) __ptr, (int32)__addend); return
else if (sizeof(_Tp) == sizeof(int64)) (_Tp)__fetch_and_add_32((volatile int32_t*) __ptr, (int32_t)__addend);
return (_Tp)__fetch_and_add_64((volatile int64*) __ptr, (int64)__addend); else if (sizeof(_Tp) == sizeof(int64_t))
return
(_Tp)__fetch_and_add_64((volatile int64_t*) __ptr, (int64_t)__addend);
else else
_GLIBCXX_PARALLEL_ASSERT(false); _GLIBCXX_PARALLEL_ASSERT(false);
} }
...@@ -196,10 +198,10 @@ namespace __gnu_parallel ...@@ -196,10 +198,10 @@ namespace __gnu_parallel
#if defined(__ICC) #if defined(__ICC)
template<typename _MustBeInt = int> template<typename _MustBeInt = int>
inline int32 inline int32_t
__cas32(volatile int32* __ptr, int32 __old, int32 __nw) __cas32(volatile int32_t* __ptr, int32_t __old, int32_t __nw)
{ {
int32 __before; int32_t __before;
__asm__ __volatile__("lock; cmpxchgl %1,%2" __asm__ __volatile__("lock; cmpxchgl %1,%2"
: "=a"(__before) : "=a"(__before)
: "q"(__nw), "__m"(*(volatile long long*)(__ptr)), : "q"(__nw), "__m"(*(volatile long long*)(__ptr)),
...@@ -210,10 +212,10 @@ namespace __gnu_parallel ...@@ -210,10 +212,10 @@ namespace __gnu_parallel
#if defined(__x86_64) #if defined(__x86_64)
template<typename _MustBeInt = int> template<typename _MustBeInt = int>
inline int64 inline int64_t
__cas64(volatile int64 *__ptr, int64 __old, int64 __nw) __cas64(volatile int64_t *__ptr, int64_t __old, int64_t __nw)
{ {
int64 __before; int64_t __before;
__asm__ __volatile__("lock; cmpxchgq %1,%2" __asm__ __volatile__("lock; cmpxchgq %1,%2"
: "=a"(__before) : "=a"(__before)
: "q"(__nw), "__m"(*(volatile long long*)(__ptr)), : "q"(__nw), "__m"(*(volatile long long*)(__ptr)),
...@@ -234,8 +236,8 @@ namespace __gnu_parallel ...@@ -234,8 +236,8 @@ namespace __gnu_parallel
* @param __replacement Replacement value. * @param __replacement Replacement value.
*/ */
inline bool inline bool
__compare_and_swap_32(volatile int32* __ptr, int32 __comparand, __compare_and_swap_32(volatile int32_t* __ptr, int32_t __comparand,
int32 __replacement) int32_t __replacement)
{ {
#if defined(__ICC) //x86 version #if defined(__ICC) //x86 version
return _InterlockedCompareExchange((void*)__ptr, __replacement, return _InterlockedCompareExchange((void*)__ptr, __replacement,
...@@ -277,8 +279,8 @@ namespace __gnu_parallel ...@@ -277,8 +279,8 @@ namespace __gnu_parallel
* @param __replacement Replacement value. * @param __replacement Replacement value.
*/ */
inline bool inline bool
__compare_and_swap_64(volatile int64* __ptr, int64 __comparand, __compare_and_swap_64(volatile int64_t* __ptr, int64_t __comparand,
int64 __replacement) int64_t __replacement)
{ {
#if defined(__ICC) && defined(__x86_64) //x86 version #if defined(__ICC) && defined(__x86_64) //x86 version
return __cas64<int>(__ptr, __comparand, __replacement) == __comparand; return __cas64<int>(__ptr, __comparand, __replacement) == __comparand;
...@@ -332,12 +334,14 @@ namespace __gnu_parallel ...@@ -332,12 +334,14 @@ namespace __gnu_parallel
inline bool inline bool
__compare_and_swap(volatile _Tp* __ptr, _Tp __comparand, _Tp __replacement) __compare_and_swap(volatile _Tp* __ptr, _Tp __comparand, _Tp __replacement)
{ {
if (sizeof(_Tp) == sizeof(int32)) if (sizeof(_Tp) == sizeof(int32_t))
return __compare_and_swap_32((volatile int32*) __ptr, (int32)__comparand, return __compare_and_swap_32((volatile int32_t*) __ptr,
(int32)__replacement); (int32_t)__comparand,
else if (sizeof(_Tp) == sizeof(int64)) (int32_t)__replacement);
return __compare_and_swap_64((volatile int64*) __ptr, (int64)__comparand, else if (sizeof(_Tp) == sizeof(int64_t))
(int64)__replacement); return __compare_and_swap_64((volatile int64_t*) __ptr,
(int64_t)__comparand,
(int64_t)__replacement);
else else
_GLIBCXX_PARALLEL_ASSERT(false); _GLIBCXX_PARALLEL_ASSERT(false);
} }
......
...@@ -273,7 +273,7 @@ namespace __gnu_parallel ...@@ -273,7 +273,7 @@ namespace __gnu_parallel
} }
_DifferenceType __skew = static_cast<_DifferenceType> _DifferenceType __skew = static_cast<_DifferenceType>
(static_cast<uint64>(__total) * __rank / __N - __leftsize); (static_cast<uint64_t>(__total) * __rank / __N - __leftsize);
if (__skew > 0) if (__skew > 0)
{ {
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <parallel/types.h> #include <parallel/types.h>
#include <tr1/random> #include <tr1/random>
#include <limits>
namespace __gnu_parallel namespace __gnu_parallel
{ {
...@@ -42,29 +43,29 @@ namespace __gnu_parallel ...@@ -42,29 +43,29 @@ namespace __gnu_parallel
{ {
private: private:
std::tr1::mt19937 _M_mt; std::tr1::mt19937 _M_mt;
uint64 _M_supremum; uint64_t _M_supremum;
uint64 _M_rand_sup; uint64_t _M_rand_sup;
double _M_supremum_reciprocal; double _M_supremum_reciprocal;
double _M_rand_sup_reciprocal; double _M_rand_sup_reciprocal;
// Assumed to be twice as long as the usual random number. // Assumed to be twice as long as the usual random number.
uint64 __cache; uint64_t __cache;
// Bit results. // Bit results.
int __bits_left; int __bits_left;
static uint32 static uint32_t
__scale_down(uint64 __x, __scale_down(uint64_t __x,
#if _GLIBCXX_SCALE_DOWN_FPU #if _GLIBCXX_SCALE_DOWN_FPU
uint64 /*_M_supremum*/, double _M_supremum_reciprocal) uint64_t /*_M_supremum*/, double _M_supremum_reciprocal)
#else #else
uint64 _M_supremum, double /*_M_supremum_reciprocal*/) uint64_t _M_supremum, double /*_M_supremum_reciprocal*/)
#endif #endif
{ {
#if _GLIBCXX_SCALE_DOWN_FPU #if _GLIBCXX_SCALE_DOWN_FPU
return uint32(__x * _M_supremum_reciprocal); return uint32_t(__x * _M_supremum_reciprocal);
#else #else
return static_cast<uint32>(__x % _M_supremum); return static_cast<uint32_t>(__x % _M_supremum);
#endif #endif
} }
...@@ -72,7 +73,7 @@ namespace __gnu_parallel ...@@ -72,7 +73,7 @@ namespace __gnu_parallel
/** @brief Default constructor. Seed with 0. */ /** @brief Default constructor. Seed with 0. */
_RandomNumber() _RandomNumber()
: _M_mt(0), _M_supremum(0x100000000ULL), : _M_mt(0), _M_supremum(0x100000000ULL),
_M_rand_sup(1ULL << (sizeof(uint32) * 8)), _M_rand_sup(1ULL << std::numeric_limits<uint32_t>::digits),
_M_supremum_reciprocal(double(_M_supremum) / double(_M_rand_sup)), _M_supremum_reciprocal(double(_M_supremum) / double(_M_rand_sup)),
_M_rand_sup_reciprocal(1.0 / double(_M_rand_sup)), _M_rand_sup_reciprocal(1.0 / double(_M_rand_sup)),
__cache(0), __bits_left(0) { } __cache(0), __bits_left(0) { }
...@@ -81,22 +82,22 @@ namespace __gnu_parallel ...@@ -81,22 +82,22 @@ namespace __gnu_parallel
* @param __seed Random __seed. * @param __seed Random __seed.
* @param _M_supremum Generate integer random numbers in the * @param _M_supremum Generate integer random numbers in the
* interval @__c [0,_M_supremum). */ * interval @__c [0,_M_supremum). */
_RandomNumber(uint32 __seed, uint64 _M_supremum = 0x100000000ULL) _RandomNumber(uint32_t __seed, uint64_t _M_supremum = 0x100000000ULL)
: _M_mt(__seed), _M_supremum(_M_supremum), : _M_mt(__seed), _M_supremum(_M_supremum),
_M_rand_sup(1ULL << (sizeof(uint32) * 8)), _M_rand_sup(1ULL << std::numeric_limits<uint32_t>::digits),
_M_supremum_reciprocal(double(_M_supremum) / double(_M_rand_sup)), _M_supremum_reciprocal(double(_M_supremum) / double(_M_rand_sup)),
_M_rand_sup_reciprocal(1.0 / double(_M_rand_sup)), _M_rand_sup_reciprocal(1.0 / double(_M_rand_sup)),
__cache(0), __bits_left(0) { } __cache(0), __bits_left(0) { }
/** @brief Generate unsigned random 32-bit integer. */ /** @brief Generate unsigned random 32-bit integer. */
uint32 uint32_t
operator()() operator()()
{ return __scale_down(_M_mt(), _M_supremum, _M_supremum_reciprocal); } { return __scale_down(_M_mt(), _M_supremum, _M_supremum_reciprocal); }
/** @brief Generate unsigned random 32-bit integer in the /** @brief Generate unsigned random 32-bit integer in the
interval @__c [0,local_supremum). */ interval @__c [0,local_supremum). */
uint32 uint32_t
operator()(uint64 local_supremum) operator()(uint64_t local_supremum)
{ {
return __scale_down(_M_mt(), local_supremum, return __scale_down(_M_mt(), local_supremum,
double(local_supremum * _M_rand_sup_reciprocal)); double(local_supremum * _M_rand_sup_reciprocal));
...@@ -112,7 +113,7 @@ namespace __gnu_parallel ...@@ -112,7 +113,7 @@ namespace __gnu_parallel
__bits_left -= __bits; __bits_left -= __bits;
if (__bits_left < 32) if (__bits_left < 32)
{ {
__cache |= ((uint64(_M_mt())) << __bits_left); __cache |= ((uint64_t(_M_mt())) << __bits_left);
__bits_left += 32; __bits_left += 32;
} }
return __res; return __res;
......
...@@ -100,7 +100,7 @@ template<typename _RAIter, typename _RandomNumberGenerator> ...@@ -100,7 +100,7 @@ template<typename _RAIter, typename _RandomNumberGenerator>
_BinIndex __bins_end; _BinIndex __bins_end;
/** @brief Random _M_seed for this thread. */ /** @brief Random _M_seed for this thread. */
uint32 _M_seed; uint32_t _M_seed;
/** @brief Pointer to global data. */ /** @brief Pointer to global data. */
_DRandomShufflingGlobalData<_RAIter>* _M_sd; _DRandomShufflingGlobalData<_RAIter>* _M_sd;
...@@ -372,7 +372,8 @@ template<typename _RAIter, typename _RandomNumberGenerator> ...@@ -372,7 +372,8 @@ template<typename _RAIter, typename _RandomNumberGenerator>
for (; __j < bin_cursor; ++__j) for (; __j < bin_cursor; ++__j)
_M_sd._M_bin_proc[__j] = __i; _M_sd._M_bin_proc[__j] = __i;
__pus[__i]._M_num_threads = __num_threads; __pus[__i]._M_num_threads = __num_threads;
__pus[__i]._M_seed = __rng(std::numeric_limits<uint32>::max()); __pus[__i]._M_seed =
__rng(std::numeric_limits<uint32_t>::max());
__pus[__i]._M_sd = &_M_sd; __pus[__i]._M_sd = &_M_sd;
} }
_M_starts[__num_threads] = __start; _M_starts[__num_threads] = __start;
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#define _GLIBCXX_PARALLEL_TYPES_H 1 #define _GLIBCXX_PARALLEL_TYPES_H 1
#include <cstdlib> #include <cstdlib>
#include <limits>
#include <tr1/cstdint>
namespace __gnu_parallel namespace __gnu_parallel
{ {
...@@ -108,45 +110,24 @@ namespace __gnu_parallel ...@@ -108,45 +110,24 @@ namespace __gnu_parallel
EQUAL_SPLIT EQUAL_SPLIT
}; };
/// _Integer Types.
// XXX need to use <cstdint>
/** @brief 16-bit signed integer. */
typedef short int16;
/** @brief 16-bit unsigned integer. */
typedef unsigned short uint16;
/** @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. * @brief Unsigned integer to index __elements.
* The total number of elements for each algorithm must fit into this type. * The total number of elements for each algorithm must fit into this type.
*/ */
typedef uint64 _SequenceIndex; typedef uint64_t _SequenceIndex;
/** /**
* @brief Unsigned integer to index a thread number. * @brief Unsigned integer to index a thread number.
* The maximum thread number (for each processor) must fit into this type. * The maximum thread number (for each processor) must fit into this type.
*/ */
typedef uint16 _ThreadIndex; typedef uint16_t _ThreadIndex;
// XXX atomics interface? // XXX atomics interface?
/// Longest compare-and-swappable integer type on this platform. /// Longest compare-and-swappable integer type on this platform.
typedef int64 _CASable; typedef int64_t _CASable;
// XXX numeric_limits::digits? /// Number of bits of _CASable.
/// Number of bits of ::_CASable. static const int _CASable_bits = std::numeric_limits<_CASable>::digits;
static const int _CASable_bits = sizeof(_CASable) * 8;
/// ::_CASable with the right half of bits set to 1. /// ::_CASable with the right half of bits set to 1.
static const _CASable _CASable_mask = static const _CASable _CASable_mask =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment