Cleanup: put i_maxmin members and ___kmp_size_type into traits_t

Put the duplicated i_maxmin into traits_t by adding new members max_value and
min_value. Put ___kmp_size_type into traits_t by adding member type_size.

Differential Revision: https://reviews.llvm.org/D28847

llvm-svn: 293316
This commit is contained in:
Jonathan Peyton 2017-01-27 18:09:22 +00:00
parent 3061e3e454
commit 12313d44cf
3 changed files with 27 additions and 79 deletions

View File

@ -49,34 +49,6 @@
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
// template for type limits
template< typename T >
struct i_maxmin {
static const T mx;
static const T mn;
};
template<>
struct i_maxmin< int > {
static const int mx = 0x7fffffff;
static const int mn = 0x80000000;
};
template<>
struct i_maxmin< unsigned int > {
static const unsigned int mx = 0xffffffff;
static const unsigned int mn = 0x00000000;
};
template<>
struct i_maxmin< long long > {
static const long long mx = 0x7fffffffffffffffLL;
static const long long mn = 0x8000000000000000LL;
};
template<>
struct i_maxmin< unsigned long long > {
static const unsigned long long mx = 0xffffffffffffffffLL;
static const unsigned long long mn = 0x0000000000000000LL;
};
//-------------------------------------------------------------------------
#if KMP_STATIC_STEAL_ENABLED #if KMP_STATIC_STEAL_ENABLED
// replaces dispatch_private_info{32,64} structures and dispatch_private_info{32,64}_t types // replaces dispatch_private_info{32,64} structures and dispatch_private_info{32,64}_t types
@ -612,7 +584,6 @@ __kmp_dispatch_init(
typedef typename traits_t< T >::unsigned_t UT; typedef typename traits_t< T >::unsigned_t UT;
typedef typename traits_t< T >::signed_t ST; typedef typename traits_t< T >::signed_t ST;
typedef typename traits_t< T >::floating_t DBL; typedef typename traits_t< T >::floating_t DBL;
static const int ___kmp_size_type = sizeof( UT );
int active; int active;
T tc; T tc;
@ -688,7 +659,7 @@ __kmp_dispatch_init(
} else { } else {
pr->nomerge = FALSE; pr->nomerge = FALSE;
} }
pr->type_size = ___kmp_size_type; // remember the size of variables pr->type_size = traits_t<T>::type_size; // remember the size of variables
if ( kmp_ord_lower & schedule ) { if ( kmp_ord_lower & schedule ) {
pr->ordered = TRUE; pr->ordered = TRUE;
schedule = (enum sched_type)(((int)schedule) - (kmp_ord_lower - kmp_sch_lower)); schedule = (enum sched_type)(((int)schedule) - (kmp_ord_lower - kmp_sch_lower));
@ -869,7 +840,7 @@ __kmp_dispatch_init(
//pr->pfields.parm3 = 0; // it's not used in static_steal //pr->pfields.parm3 = 0; // it's not used in static_steal
pr->u.p.parm4 = (id + 1) % nproc; // remember neighbour tid pr->u.p.parm4 = (id + 1) % nproc; // remember neighbour tid
pr->u.p.st = st; pr->u.p.st = st;
if ( ___kmp_size_type > 4 ) { if ( traits_t<T>::type_size > 4 ) {
// AC: TODO: check if 16-byte CAS available and use it to // AC: TODO: check if 16-byte CAS available and use it to
// improve performance (probably wait for explicit request // improve performance (probably wait for explicit request
// before spending time on this). // before spending time on this).
@ -1438,9 +1409,6 @@ __kmp_dispatch_next(
typedef typename traits_t< T >::unsigned_t UT; typedef typename traits_t< T >::unsigned_t UT;
typedef typename traits_t< T >::signed_t ST; typedef typename traits_t< T >::signed_t ST;
typedef typename traits_t< T >::floating_t DBL; typedef typename traits_t< T >::floating_t DBL;
#if ( KMP_STATIC_STEAL_ENABLED )
static const int ___kmp_size_type = sizeof( UT );
#endif
// This is potentially slightly misleading, schedule(runtime) will appear here even if the actual runtme schedule // This is potentially slightly misleading, schedule(runtime) will appear here even if the actual runtme schedule
// is static. (Which points out a disadavantage of schedule(runtime): even when static scheduling is used it costs // is static. (Which points out a disadavantage of schedule(runtime): even when static scheduling is used it costs
@ -1607,7 +1575,7 @@ __kmp_dispatch_next(
trip = pr->u.p.tc - 1; trip = pr->u.p.tc - 1;
if ( ___kmp_size_type > 4 ) { if ( traits_t<T>::type_size > 4 ) {
// use lock for 8-byte and CAS for 4-byte induction // use lock for 8-byte and CAS for 4-byte induction
// variable. TODO (optional): check and use 16-byte CAS // variable. TODO (optional): check and use 16-byte CAS
kmp_lock_t * lck = th->th.th_dispatch->th_steal_lock; kmp_lock_t * lck = th->th.th_dispatch->th_steal_lock;
@ -2224,7 +2192,7 @@ __kmp_dispatch_next(
if ( (ST)num_done == th->th.th_team_nproc - 1 ) { if ( (ST)num_done == th->th.th_team_nproc - 1 ) {
#if ( KMP_STATIC_STEAL_ENABLED ) #if ( KMP_STATIC_STEAL_ENABLED )
if( pr->schedule == kmp_sch_static_steal && ___kmp_size_type > 4 ) { if( pr->schedule == kmp_sch_static_steal && traits_t<T>::type_size > 4 ) {
int i; int i;
kmp_info_t **other_threads = team->t.t_threads; kmp_info_t **other_threads = team->t.t_threads;
// loop complete, safe to destroy locks used for stealing // loop complete, safe to destroy locks used for stealing
@ -2400,14 +2368,14 @@ __kmp_dist_get_bounds(
// Check/correct bounds if needed // Check/correct bounds if needed
if( incr > 0 ) { if( incr > 0 ) {
if( *pupper < *plower ) if( *pupper < *plower )
*pupper = i_maxmin< T >::mx; *pupper = traits_t<T>::max_value;
if( plastiter != NULL ) if( plastiter != NULL )
*plastiter = *plower <= upper && *pupper > upper - incr; *plastiter = *plower <= upper && *pupper > upper - incr;
if( *pupper > upper ) if( *pupper > upper )
*pupper = upper; // tracker C73258 *pupper = upper; // tracker C73258
} else { } else {
if( *pupper > *plower ) if( *pupper > *plower )
*pupper = i_maxmin< T >::mn; *pupper = traits_t<T>::min_value;
if( plastiter != NULL ) if( plastiter != NULL )
*plastiter = *plower >= upper && *pupper < upper - incr; *plastiter = *plower >= upper && *pupper < upper - incr;
if( *pupper < upper ) if( *pupper < upper )

View File

@ -188,12 +188,7 @@ typedef double kmp_real64;
// template for debug prints specification ( d, u, lld, llu ), and to obtain // template for debug prints specification ( d, u, lld, llu ), and to obtain
// signed/unsigned flavors of a type // signed/unsigned flavors of a type
template< typename T > template< typename T >
struct traits_t { struct traits_t { };
typedef T signed_t;
typedef T unsigned_t;
typedef T floating_t;
static char const * spec;
};
// int // int
template<> template<>
struct traits_t< signed int > { struct traits_t< signed int > {
@ -201,6 +196,9 @@ typedef double kmp_real64;
typedef unsigned int unsigned_t; typedef unsigned int unsigned_t;
typedef double floating_t; typedef double floating_t;
static char const * spec; static char const * spec;
static const signed_t max_value = 0x7fffffff;
static const signed_t min_value = 0x80000000;
static const int type_size = sizeof(signed_t);
}; };
// unsigned int // unsigned int
template<> template<>
@ -209,6 +207,9 @@ typedef double kmp_real64;
typedef unsigned int unsigned_t; typedef unsigned int unsigned_t;
typedef double floating_t; typedef double floating_t;
static char const * spec; static char const * spec;
static const unsigned_t max_value = 0xffffffff;
static const unsigned_t min_value = 0x00000000;
static const int type_size = sizeof(unsigned_t);
}; };
// long long // long long
template<> template<>
@ -217,6 +218,9 @@ typedef double kmp_real64;
typedef unsigned long long unsigned_t; typedef unsigned long long unsigned_t;
typedef long double floating_t; typedef long double floating_t;
static char const * spec; static char const * spec;
static const signed_t max_value = 0x7fffffffffffffffLL;
static const signed_t min_value = 0x8000000000000000LL;
static const int type_size = sizeof(signed_t);
}; };
// unsigned long long // unsigned long long
template<> template<>
@ -225,6 +229,9 @@ typedef double kmp_real64;
typedef unsigned long long unsigned_t; typedef unsigned long long unsigned_t;
typedef long double floating_t; typedef long double floating_t;
static char const * spec; static char const * spec;
static const unsigned_t max_value = 0xffffffffffffffffLL;
static const unsigned_t min_value = 0x0000000000000000LL;
static const int type_size = sizeof(unsigned_t);
}; };
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
#endif // __cplusplus #endif // __cplusplus

View File

@ -33,33 +33,6 @@
#include "ompt-specific.h" #include "ompt-specific.h"
#endif #endif
// template for type limits
template< typename T >
struct i_maxmin {
static const T mx;
static const T mn;
};
template<>
struct i_maxmin< int > {
static const int mx = 0x7fffffff;
static const int mn = 0x80000000;
};
template<>
struct i_maxmin< unsigned int > {
static const unsigned int mx = 0xffffffff;
static const unsigned int mn = 0x00000000;
};
template<>
struct i_maxmin< long long > {
static const long long mx = 0x7fffffffffffffffLL;
static const long long mn = 0x8000000000000000LL;
};
template<>
struct i_maxmin< unsigned long long > {
static const unsigned long long mx = 0xffffffffffffffffLL;
static const unsigned long long mn = 0x0000000000000000LL;
};
//-------------------------------------------------------------------------
#ifdef KMP_DEBUG #ifdef KMP_DEBUG
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// template for debug prints specification ( d, u, lld, llu ) // template for debug prints specification ( d, u, lld, llu )
@ -295,13 +268,13 @@ __kmp_for_static_init(
*pupper = *plower + big_chunk_inc_count - incr; *pupper = *plower + big_chunk_inc_count - incr;
if ( incr > 0 ) { if ( incr > 0 ) {
if( *pupper < *plower ) if( *pupper < *plower )
*pupper = i_maxmin< T >::mx; *pupper = traits_t<T>::max_value;
if( plastiter != NULL ) if( plastiter != NULL )
*plastiter = *plower <= old_upper && *pupper > old_upper - incr; *plastiter = *plower <= old_upper && *pupper > old_upper - incr;
if ( *pupper > old_upper ) *pupper = old_upper; // tracker C73258 if ( *pupper > old_upper ) *pupper = old_upper; // tracker C73258
} else { } else {
if( *pupper > *plower ) if( *pupper > *plower )
*pupper = i_maxmin< T >::mn; *pupper = traits_t<T>::min_value;
if( plastiter != NULL ) if( plastiter != NULL )
*plastiter = *plower >= old_upper && *pupper < old_upper - incr; *plastiter = *plower >= old_upper && *pupper < old_upper - incr;
if ( *pupper < old_upper ) *pupper = old_upper; // tracker C73258 if ( *pupper < old_upper ) *pupper = old_upper; // tracker C73258
@ -511,7 +484,7 @@ __kmp_dist_for_static_init(
// Check/correct bounds if needed // Check/correct bounds if needed
if( incr > 0 ) { if( incr > 0 ) {
if( *pupperDist < *plower ) if( *pupperDist < *plower )
*pupperDist = i_maxmin< T >::mx; *pupperDist = traits_t<T>::max_value;
if( plastiter != NULL ) if( plastiter != NULL )
*plastiter = *plower <= upper && *pupperDist > upper - incr; *plastiter = *plower <= upper && *pupperDist > upper - incr;
if( *pupperDist > upper ) if( *pupperDist > upper )
@ -522,7 +495,7 @@ __kmp_dist_for_static_init(
} }
} else { } else {
if( *pupperDist > *plower ) if( *pupperDist > *plower )
*pupperDist = i_maxmin< T >::mn; *pupperDist = traits_t<T>::min_value;
if( plastiter != NULL ) if( plastiter != NULL )
*plastiter = *plower >= upper && *pupperDist < upper - incr; *plastiter = *plower >= upper && *pupperDist < upper - incr;
if( *pupperDist < upper ) if( *pupperDist < upper )
@ -580,7 +553,7 @@ __kmp_dist_for_static_init(
*pupper = *plower + chunk_inc_count - incr; *pupper = *plower + chunk_inc_count - incr;
if( incr > 0 ) { if( incr > 0 ) {
if( *pupper < *plower ) if( *pupper < *plower )
*pupper = i_maxmin< T >::mx; *pupper = traits_t<T>::max_value;
if( plastiter != NULL ) if( plastiter != NULL )
if( *plastiter != 0 && !(*plower <= upper && *pupper > upper - incr) ) if( *plastiter != 0 && !(*plower <= upper && *pupper > upper - incr) )
*plastiter = 0; *plastiter = 0;
@ -588,7 +561,7 @@ __kmp_dist_for_static_init(
*pupper = upper;//tracker C73258 *pupper = upper;//tracker C73258
} else { } else {
if( *pupper > *plower ) if( *pupper > *plower )
*pupper = i_maxmin< T >::mn; *pupper = traits_t<T>::min_value;
if( plastiter != NULL ) if( plastiter != NULL )
if( *plastiter != 0 && !(*plower >= upper && *pupper < upper - incr) ) if( *plastiter != 0 && !(*plower >= upper && *pupper < upper - incr) )
*plastiter = 0; *plastiter = 0;
@ -729,12 +702,12 @@ __kmp_team_static_init(
// Correct upper bound if needed // Correct upper bound if needed
if( incr > 0 ) { if( incr > 0 ) {
if( *p_ub < *p_lb ) // overflow? if( *p_ub < *p_lb ) // overflow?
*p_ub = i_maxmin< T >::mx; *p_ub = traits_t<T>::max_value;
if( *p_ub > upper ) if( *p_ub > upper )
*p_ub = upper; // tracker C73258 *p_ub = upper; // tracker C73258
} else { // incr < 0 } else { // incr < 0
if( *p_ub > *p_lb ) if( *p_ub > *p_lb )
*p_ub = i_maxmin< T >::mn; *p_ub = traits_t<T>::min_value;
if( *p_ub < upper ) if( *p_ub < upper )
*p_ub = upper; // tracker C73258 *p_ub = upper; // tracker C73258
} }