Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(693)

Unified Diff: runtime/platform/utils.h

Issue 9112050: Simplify integer arithmetic code. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/integers.cc ('k') | runtime/vm/utils_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/platform/utils.h
===================================================================
--- runtime/platform/utils.h (revision 3410)
+++ runtime/platform/utils.h (working copy)
@@ -86,22 +86,28 @@
static uint32_t WordHash(word key);
// Check whether an N-bit two's-complement representation can hold value.
- static inline bool IsInt(int N, word value) {
- ASSERT((0 < N) && (N < kBitsPerWord));
- word limit = static_cast<word>(1) << (N - 1);
+ template<typename T>
+ static inline bool IsInt(int N, T value) {
+ ASSERT((0 < N) &&
+ (static_cast<unsigned int>(N) < (kBitsPerByte * sizeof(value))));
+ T limit = static_cast<T>(1) << (N - 1);
return (-limit <= value) && (value < limit);
}
- static inline bool IsUint(int N, word value) {
- ASSERT((0 < N) && (N < kBitsPerWord));
- word limit = static_cast<word>(1) << N;
+ template<typename T>
+ static inline bool IsUint(int N, T value) {
+ ASSERT((0 < N) &&
+ (static_cast<unsigned int>(N) < (kBitsPerByte * sizeof(value))));
+ T limit = static_cast<T>(1) << N;
return (0 <= value) && (value < limit);
}
// Check whether the magnitude of value fits in N bits, i.e., whether an
// (N+1)-bit sign-magnitude representation can hold value.
- static inline bool IsAbsoluteUint(int N, word value) {
- ASSERT((0 < N) && (N < kBitsPerWord));
+ template<typename T>
+ static inline bool IsAbsoluteUint(int N, T value) {
+ ASSERT((0 < N) &&
+ (static_cast<unsigned int>(N) < (kBitsPerByte * sizeof(value))));
if (value < 0) value = -value;
return IsUint(N, value);
}
« no previous file with comments | « runtime/lib/integers.cc ('k') | runtime/vm/utils_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698