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

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
« runtime/lib/integers.cc ('K') | « runtime/lib/integers.cc ('k') | no next file » | 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,25 @@
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));
+ template<typename T>
+ static inline bool IsInt(int N, T value) {
+ ASSERT((0 < N) && (N < (kBitsPerByte * sizeof(T))));
Ivan Posva 2012/01/18 20:05:22 sizeof(value) is closer to the style guide: http:/
regis 2012/01/18 21:50:12 Done.
word limit = static_cast<word>(1) << (N - 1);
Ivan Posva 2012/01/18 20:05:22 You need to cast the 1 to T instead of word here.
regis 2012/01/18 21:50:12 The cast is fixed in patch 5. I have added a test.
return (-limit <= value) && (value < limit);
}
- static inline bool IsUint(int N, word value) {
- ASSERT((0 < N) && (N < kBitsPerWord));
+ template<typename T>
Ivan Posva 2012/01/18 20:05:22 ditto
regis 2012/01/18 21:50:12 Done.
+ static inline bool IsUint(int N, T value) {
+ ASSERT((0 < N) && (N < (kBitsPerByte * sizeof(T))));
word limit = static_cast<word>(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>
Ivan Posva 2012/01/18 20:05:22 ditto
regis 2012/01/18 21:50:12 Done.
+ static inline bool IsAbsoluteUint(int N, T value) {
+ ASSERT((0 < N) && (N < (kBitsPerByte * sizeof(T))));
if (value < 0) value = -value;
return IsUint(N, value);
}
« runtime/lib/integers.cc ('K') | « runtime/lib/integers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698