18
18
#include " kmp_str.h"
19
19
#include " kmp_collapse.h"
20
20
21
- #include < cmath>
22
-
23
21
#if OMPT_SUPPORT
24
22
#include " ompt-specific.h"
25
23
#endif
26
24
27
25
// OMPTODO: different style of comments (see kmp_sched)
28
26
// OMPTODO: OMPT/OMPD
29
27
28
+ // avoid inadevertently using a library based abs
29
+ template <typename T> T __kmp_abs (const T val) {
30
+ return (val < 0 ) ? -val: val;
31
+ }
32
+ kmp_uint32 __kmp_abs (const kmp_uint32 val) { return val; }
33
+ kmp_uint64 __kmp_abs (const kmp_uint64 val) { return val; }
34
+
30
35
// ----------------------------------------------------------------------------
31
36
// Common functions for working with rectangular and non-rectangular loops
32
37
// ----------------------------------------------------------------------------
33
38
34
- template <typename T> int sign (T val) { return (T (0 ) < val) - (val < T (0 )); }
39
+ template <typename T> int __kmp_sign (T val) { return (T (0 ) < val) - (val < T (0 )); }
35
40
36
41
// ----------Loop canonicalization---------------------------------------------
37
42
@@ -131,7 +136,7 @@ kmp_loop_nest_iv_t kmp_calculate_trip_count_XX(
131
136
// kmp_loop_nest_iv_t anyway
132
137
bounds->trip_count =
133
138
static_cast <kmp_loop_nest_iv_t >(bounds->ub0 - bounds->lb0 ) /
134
- std::abs (bounds->step ) +
139
+ __kmp_abs (bounds->step ) +
135
140
1 ;
136
141
}
137
142
} else if (bounds->comparison == comparison_t ::comp_greater_or_eq) {
@@ -144,7 +149,7 @@ kmp_loop_nest_iv_t kmp_calculate_trip_count_XX(
144
149
// kmp_loop_nest_iv_t anyway
145
150
bounds->trip_count =
146
151
static_cast <kmp_loop_nest_iv_t >(bounds->lb0 - bounds->ub0 ) /
147
- std::abs (bounds->step ) +
152
+ __kmp_abs (bounds->step ) +
148
153
1 ;
149
154
}
150
155
} else {
@@ -658,16 +663,16 @@ void kmp_calc_new_bounds_XX(
658
663
T old_lb1 = bbounds.lb1 ;
659
664
T old_ub1 = bbounds.ub1 ;
660
665
661
- if (sign (old_lb1) != sign (old_ub1)) {
666
+ if (__kmp_sign (old_lb1) != __kmp_sign (old_ub1)) {
662
667
// With this shape we can adjust to a rectangle:
663
668
bbounds.lb1 = 0 ;
664
669
bbounds.ub1 = 0 ;
665
670
} else {
666
671
// get upper and lower bounds to be parallel
667
672
// with values in the old range.
668
- // Note: std:: abs didn't work here.
669
- if (((sign ( old_lb1) == - 1 ) && (old_lb1 < old_ub1)) ||
670
- ((sign ( old_lb1) == 1 ) && (old_lb1 > old_ub1))) {
673
+ // Note: abs didn't work here.
674
+ if (((old_lb1 < 0 ) && (old_lb1 < old_ub1)) ||
675
+ ((old_lb1 > 0 ) && (old_lb1 > old_ub1))) {
671
676
bbounds.lb1 = old_ub1;
672
677
} else {
673
678
bbounds.ub1 = old_lb1;
@@ -804,13 +809,13 @@ kmp_calc_number_of_iterations_XX(const bounds_infoXX_template<T> *bounds,
804
809
iterations =
805
810
(static_cast <T>(original_ivs[ind]) - bounds->lb0 -
806
811
bounds->lb1 * static_cast <T>(original_ivs[bounds->outer_iv ])) /
807
- std::abs (bounds->step );
812
+ __kmp_abs (bounds->step );
808
813
} else {
809
814
KMP_DEBUG_ASSERT (bounds->comparison == comparison_t ::comp_greater_or_eq);
810
815
iterations = (bounds->lb0 +
811
816
bounds->lb1 * static_cast <T>(original_ivs[bounds->outer_iv ]) -
812
817
static_cast <T>(original_ivs[ind])) /
813
- std::abs (bounds->step );
818
+ __kmp_abs (bounds->step );
814
819
}
815
820
816
821
return iterations;
0 commit comments