[PPL-devel] [GIT] ppl/ppl(master): Exploit new helper function least_significant_one_mask(),
Enea Zaffanella
zaffanella at cs.unipr.it
Sat Feb 25 16:14:06 CET 2012
Module: ppl/ppl
Branch: master
Commit: 73aee8ff7b811416d25b4c54344fbaa214ea7804
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=73aee8ff7b811416d25b4c54344fbaa214ea7804
Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date: Sat Feb 25 16:11:07 2012 +0100
Exploit new helper function least_significant_one_mask(),
thereby avoiding unary minus on unsigned integer values.
Detected by ECLAIR service utypflag.
---
src/CO_Tree.inlines.hh | 19 ++++++++++---------
1 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/src/CO_Tree.inlines.hh b/src/CO_Tree.inlines.hh
index ece7ab0..0032029 100644
--- a/src/CO_Tree.inlines.hh
+++ b/src/CO_Tree.inlines.hh
@@ -679,7 +679,7 @@ CO_Tree::tree_iterator::tree_iterator(CO_Tree& tree1, dimension_type i1)
PPL_ASSERT(tree.reserved_size != 0);
PPL_ASSERT(i1 <= tree.reserved_size + 1);
i = i1;
- offset = i & -i;
+ offset = least_significant_one_mask(i);
PPL_ASSERT(OK());
}
@@ -703,9 +703,7 @@ inline CO_Tree::tree_iterator&
CO_Tree::tree_iterator::operator=(const iterator& itr) {
PPL_ASSERT(itr != tree.end());
i = tree.dfs_index(itr);
- offset = i;
- // This assumes two's complement encoding.
- offset &= -i;
+ offset = least_significant_one_mask(i);
return *this;
}
@@ -762,9 +760,10 @@ CO_Tree::tree_iterator::follow_left_children_with_value() {
p -= (offset - 1);
while (*p == unused_index)
++p;
- PPL_ASSERT(p >= tree.indexes);
- i = static_cast<dimension_type>(p - tree.indexes);
- offset = i & -i;
+ ptrdiff_t distance = p - tree.indexes;
+ PPL_ASSERT(distance >= 0);
+ i = static_cast<dimension_type>(distance);
+ offset = least_significant_one_mask(i);
PPL_ASSERT(OK());
}
@@ -776,8 +775,10 @@ CO_Tree::tree_iterator::follow_right_children_with_value() {
p += (offset - 1);
while (*p == unused_index)
--p;
- i = static_cast<dimension_type>(p - tree.indexes);
- offset = i & -i;
+ ptrdiff_t distance = p - tree.indexes;
+ PPL_ASSERT(distance >= 0);
+ i = static_cast<dimension_type>(distance);
+ offset = least_significant_one_mask(i);
PPL_ASSERT(OK());
}
More information about the PPL-devel
mailing list