summaryrefslogtreecommitdiffstats
path: root/openmp/runtime/src/kmp_sched.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'openmp/runtime/src/kmp_sched.cpp')
-rw-r--r--openmp/runtime/src/kmp_sched.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/openmp/runtime/src/kmp_sched.cpp b/openmp/runtime/src/kmp_sched.cpp
index 5a421d700ad..a09aa868173 100644
--- a/openmp/runtime/src/kmp_sched.cpp
+++ b/openmp/runtime/src/kmp_sched.cpp
@@ -244,12 +244,11 @@ __kmp_for_static_init(
trip_count = *pupper - *plower + 1;
} else if (incr == -1) {
trip_count = *plower - *pupper + 1;
+ } else if ( incr > 0 ) {
+ // upper-lower can exceed the limit of signed type
+ trip_count = (UT)(*pupper - *plower) / incr + 1;
} else {
- if ( incr > 1 ) { // the check is needed for unsigned division when incr < 0
- trip_count = (*pupper - *plower) / incr + 1;
- } else {
- trip_count = (*plower - *pupper) / ( -incr ) + 1;
- }
+ trip_count = (UT)(*plower - *pupper) / (-incr) + 1;
}
if ( __kmp_env_consistency_check ) {
@@ -447,8 +446,11 @@ __kmp_dist_for_static_init(
trip_count = *pupper - *plower + 1;
} else if(incr == -1) {
trip_count = *plower - *pupper + 1;
+ } else if ( incr > 0 ) {
+ // upper-lower can exceed the limit of signed type
+ trip_count = (UT)(*pupper - *plower) / incr + 1;
} else {
- trip_count = (ST)(*pupper - *plower) / incr + 1; // cast to signed to cover incr<0 case
+ trip_count = (UT)(*plower - *pupper) / (-incr) + 1;
}
*pstride = *pupper - *plower; // just in case (can be unused)
@@ -514,8 +516,11 @@ __kmp_dist_for_static_init(
trip_count = *pupperDist - *plower + 1;
} else if(incr == -1) {
trip_count = *plower - *pupperDist + 1;
+ } else if ( incr > 1 ) {
+ // upper-lower can exceed the limit of signed type
+ trip_count = (UT)(*pupperDist - *plower) / incr + 1;
} else {
- trip_count = (ST)(*pupperDist - *plower) / incr + 1;
+ trip_count = (UT)(*plower - *pupperDist) / (-incr) + 1;
}
KMP_DEBUG_ASSERT( trip_count );
switch( schedule ) {
@@ -684,8 +689,11 @@ __kmp_team_static_init(
trip_count = upper - lower + 1;
} else if(incr == -1) {
trip_count = lower - upper + 1;
+ } else if ( incr > 0 ) {
+ // upper-lower can exceed the limit of signed type
+ trip_count = (UT)(upper - lower) / incr + 1;
} else {
- trip_count = (ST)(upper - lower) / incr + 1; // cast to signed to cover incr<0 case
+ trip_count = (UT)(lower - upper) / (-incr) + 1;
}
if( chunk < 1 )
chunk = 1;
OpenPOWER on IntegriCloud