re PR libstdc++/35221 (libstdc++ broken)
2008-02-17 Paolo Carlini <pcarlini@suse.de> PR libstdc++/35221 * include/parallel/types.h: Reinstate integer types typedefs. * include/parallel/multiseq_selection.h: Adjust. * include/parallel/compatibility.h: Likewise. * include/parallel/random_shuffle.h: Likewise. * include/parallel/random_number.h: Likewise. * include/parallel/base.h: Likewise. From-SVN: r132380
This commit is contained in:
parent
f0a77246d3
commit
6df548d2d3
7 changed files with 77 additions and 59 deletions
|
@ -1,3 +1,13 @@
|
|||
2008-02-17 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
PR libstdc++/35221
|
||||
* include/parallel/types.h: Reinstate integer types typedefs.
|
||||
* include/parallel/multiseq_selection.h: Adjust.
|
||||
* include/parallel/compatibility.h: Likewise.
|
||||
* include/parallel/random_shuffle.h: Likewise.
|
||||
* include/parallel/random_number.h: Likewise.
|
||||
* include/parallel/base.h: Likewise.
|
||||
|
||||
2008-02-17 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
PR libstdc++/35209
|
||||
|
|
|
@ -388,8 +388,8 @@ template<typename T, typename _DifferenceTp>
|
|||
public:
|
||||
typedef _DifferenceTp difference_type;
|
||||
|
||||
// Better case down to uint64_t, than up to _DifferenceTp.
|
||||
typedef pseudo_sequence_iterator<T, uint64_t> iterator;
|
||||
// Better case down to uint64, than up to _DifferenceTp.
|
||||
typedef pseudo_sequence_iterator<T, uint64> iterator;
|
||||
|
||||
/** @brief Constructor.
|
||||
* @param val Element of the sequence.
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace __gnu_parallel
|
|||
{
|
||||
#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)
|
||||
|
@ -78,7 +78,7 @@ namespace __gnu_parallel
|
|||
}
|
||||
#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)
|
||||
|
@ -97,8 +97,8 @@ namespace __gnu_parallel
|
|||
* @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);
|
||||
|
@ -110,7 +110,7 @@ namespace __gnu_parallel
|
|||
#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;
|
||||
|
@ -120,7 +120,7 @@ namespace __gnu_parallel
|
|||
return before;
|
||||
#else //fallback, slow
|
||||
#pragma message("slow fetch_and_add_32")
|
||||
int32_t res;
|
||||
int32 res;
|
||||
#pragma omp critical
|
||||
{
|
||||
res = *ptr;
|
||||
|
@ -136,11 +136,11 @@ namespace __gnu_parallel
|
|||
* @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)
|
||||
|
@ -156,7 +156,7 @@ namespace __gnu_parallel
|
|||
(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;
|
||||
|
@ -170,7 +170,7 @@ namespace __gnu_parallel
|
|||
//#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;
|
||||
|
@ -190,10 +190,10 @@ namespace __gnu_parallel
|
|||
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);
|
||||
}
|
||||
|
@ -202,10 +202,10 @@ namespace __gnu_parallel
|
|||
#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)
|
||||
|
@ -215,10 +215,10 @@ namespace __gnu_parallel
|
|||
|
||||
#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)
|
||||
|
@ -238,7 +238,7 @@ namespace __gnu_parallel
|
|||
* @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,
|
||||
|
@ -278,7 +278,7 @@ namespace __gnu_parallel
|
|||
* @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;
|
||||
|
@ -332,10 +332,10 @@ namespace __gnu_parallel
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -264,7 +264,7 @@ namespace __gnu_parallel
|
|||
}
|
||||
|
||||
difference_type skew = static_cast<difference_type>
|
||||
(static_cast<uint64_t>(total) * rank / N - leftsize);
|
||||
(static_cast<uint64>(total) * rank / N - leftsize);
|
||||
|
||||
if (skew > 0)
|
||||
{
|
||||
|
|
|
@ -48,29 +48,29 @@ namespace __gnu_parallel
|
|||
{
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ namespace __gnu_parallel
|
|||
/** @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) { }
|
||||
|
@ -87,22 +87,22 @@ namespace __gnu_parallel
|
|||
* @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));
|
||||
|
@ -118,7 +118,7 @@ namespace __gnu_parallel
|
|||
bits_left -= bits;
|
||||
if (bits_left < 32)
|
||||
{
|
||||
cache |= ((uint64_t(mt())) << bits_left);
|
||||
cache |= ((uint64(mt())) << bits_left);
|
||||
bits_left += 32;
|
||||
}
|
||||
return res;
|
||||
|
|
|
@ -106,7 +106,7 @@ template<typename RandomAccessIterator, typename RandomNumberGenerator>
|
|||
bin_index bins_end;
|
||||
|
||||
/** @brief Random seed for this thread. */
|
||||
uint32_t seed;
|
||||
uint32 seed;
|
||||
|
||||
/** @brief Pointer to global data. */
|
||||
DRandomShufflingGlobalData<RandomAccessIterator>* sd;
|
||||
|
@ -368,7 +368,7 @@ template<typename RandomAccessIterator, typename RandomNumberGenerator>
|
|||
for (; j < bin_cursor; ++j)
|
||||
sd.bin_proc[j] = i;
|
||||
pus[i].num_threads = num_threads;
|
||||
pus[i].seed = rng(std::numeric_limits<uint32_t>::max());
|
||||
pus[i].seed = rng(std::numeric_limits<uint32>::max());
|
||||
pus[i].sd = &sd;
|
||||
}
|
||||
starts[num_threads] = start;
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
#define _GLIBCXX_PARALLEL_TYPES_H 1
|
||||
|
||||
#include <cstdlib>
|
||||
#include <tr1/cstdint>
|
||||
|
||||
namespace __gnu_parallel
|
||||
{
|
||||
|
@ -70,33 +69,42 @@ 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?
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue