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

Side by Side Diff: src/utils.h

Issue 181453002: Reset trunk to 3.24.35.4 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/unicode.cc ('k') | src/v8.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 165 }
166 166
167 167
168 // Return the smallest multiple of m which is >= x. 168 // Return the smallest multiple of m which is >= x.
169 template <typename T> 169 template <typename T>
170 inline T RoundUp(T x, intptr_t m) { 170 inline T RoundUp(T x, intptr_t m) {
171 return RoundDown<T>(static_cast<T>(x + m - 1), m); 171 return RoundDown<T>(static_cast<T>(x + m - 1), m);
172 } 172 }
173 173
174 174
175 // Increment a pointer until it has the specified alignment.
176 // This works like RoundUp, but it works correctly on pointer types where
177 // sizeof(*pointer) might not be 1.
178 template<class T>
179 T AlignUp(T pointer, size_t alignment) {
180 ASSERT(sizeof(pointer) == sizeof(uintptr_t));
181 uintptr_t pointer_raw = reinterpret_cast<uintptr_t>(pointer);
182 return reinterpret_cast<T>(RoundUp(pointer_raw, alignment));
183 }
184
185
186 template <typename T> 175 template <typename T>
187 int Compare(const T& a, const T& b) { 176 int Compare(const T& a, const T& b) {
188 if (a == b) 177 if (a == b)
189 return 0; 178 return 0;
190 else if (a < b) 179 else if (a < b)
191 return -1; 180 return -1;
192 else 181 else
193 return 1; 182 return 1;
194 } 183 }
195 184
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 T Mask(E element) const { 1082 T Mask(E element) const {
1094 // The strange typing in ASSERT is necessary to avoid stupid warnings, see: 1083 // The strange typing in ASSERT is necessary to avoid stupid warnings, see:
1095 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43680 1084 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43680
1096 ASSERT(static_cast<int>(element) < static_cast<int>(sizeof(T) * CHAR_BIT)); 1085 ASSERT(static_cast<int>(element) < static_cast<int>(sizeof(T) * CHAR_BIT));
1097 return static_cast<T>(1) << element; 1086 return static_cast<T>(1) << element;
1098 } 1087 }
1099 1088
1100 T bits_; 1089 T bits_;
1101 }; 1090 };
1102 1091
1103 // Bit field extraction.
1104 inline uint32_t unsigned_bitextract_32(int msb, int lsb, uint32_t x) {
1105 return (x >> lsb) & ((1 << (1 + msb - lsb)) - 1);
1106 }
1107
1108 inline uint64_t unsigned_bitextract_64(int msb, int lsb, uint64_t x) {
1109 return (x >> lsb) & ((static_cast<uint64_t>(1) << (1 + msb - lsb)) - 1);
1110 }
1111
1112 inline int32_t signed_bitextract_32(int msb, int lsb, int32_t x) {
1113 return (x << (31 - msb)) >> (lsb + 31 - msb);
1114 }
1115
1116 inline int signed_bitextract_64(int msb, int lsb, int x) {
1117 // TODO(jbramley): This is broken for big bitfields.
1118 return (x << (63 - msb)) >> (lsb + 63 - msb);
1119 }
1120
1121 // Check number width.
1122 inline bool is_intn(int64_t x, unsigned n) {
1123 ASSERT((0 < n) && (n < 64));
1124 int64_t limit = static_cast<int64_t>(1) << (n - 1);
1125 return (-limit <= x) && (x < limit);
1126 }
1127
1128 inline bool is_uintn(int64_t x, unsigned n) {
1129 ASSERT((0 < n) && (n < (sizeof(x) * kBitsPerByte)));
1130 return !(x >> n);
1131 }
1132
1133 template <class T>
1134 inline T truncate_to_intn(T x, unsigned n) {
1135 ASSERT((0 < n) && (n < (sizeof(x) * kBitsPerByte)));
1136 return (x & ((static_cast<T>(1) << n) - 1));
1137 }
1138
1139 #define INT_1_TO_63_LIST(V) \
1140 V(1) V(2) V(3) V(4) V(5) V(6) V(7) V(8) \
1141 V(9) V(10) V(11) V(12) V(13) V(14) V(15) V(16) \
1142 V(17) V(18) V(19) V(20) V(21) V(22) V(23) V(24) \
1143 V(25) V(26) V(27) V(28) V(29) V(30) V(31) V(32) \
1144 V(33) V(34) V(35) V(36) V(37) V(38) V(39) V(40) \
1145 V(41) V(42) V(43) V(44) V(45) V(46) V(47) V(48) \
1146 V(49) V(50) V(51) V(52) V(53) V(54) V(55) V(56) \
1147 V(57) V(58) V(59) V(60) V(61) V(62) V(63)
1148
1149 #define DECLARE_IS_INT_N(N) \
1150 inline bool is_int##N(int64_t x) { return is_intn(x, N); }
1151 #define DECLARE_IS_UINT_N(N) \
1152 template <class T> \
1153 inline bool is_uint##N(T x) { return is_uintn(x, N); }
1154 #define DECLARE_TRUNCATE_TO_INT_N(N) \
1155 template <class T> \
1156 inline T truncate_to_int##N(T x) { return truncate_to_intn(x, N); }
1157 INT_1_TO_63_LIST(DECLARE_IS_INT_N)
1158 INT_1_TO_63_LIST(DECLARE_IS_UINT_N)
1159 INT_1_TO_63_LIST(DECLARE_TRUNCATE_TO_INT_N)
1160 #undef DECLARE_IS_INT_N
1161 #undef DECLARE_IS_UINT_N
1162 #undef DECLARE_TRUNCATE_TO_INT_N
1163 1092
1164 class TypeFeedbackId { 1093 class TypeFeedbackId {
1165 public: 1094 public:
1166 explicit TypeFeedbackId(int id) : id_(id) { } 1095 explicit TypeFeedbackId(int id) : id_(id) { }
1167 int ToInt() const { return id_; } 1096 int ToInt() const { return id_; }
1168 1097
1169 static TypeFeedbackId None() { return TypeFeedbackId(kNoneId); } 1098 static TypeFeedbackId None() { return TypeFeedbackId(kNoneId); }
1170 bool IsNone() const { return id_ == kNoneId; } 1099 bool IsNone() const { return id_ == kNoneId; }
1171 1100
1172 private: 1101 private:
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 iterator end() { return container_->end(); } 1151 iterator end() { return container_->end(); }
1223 reverse_iterator rbegin() { return container_->rbegin(); } 1152 reverse_iterator rbegin() { return container_->rbegin(); }
1224 reverse_iterator rend() { return container_->rend(); } 1153 reverse_iterator rend() { return container_->rend(); }
1225 private: 1154 private:
1226 C* container_; 1155 C* container_;
1227 }; 1156 };
1228 1157
1229 } } // namespace v8::internal 1158 } } // namespace v8::internal
1230 1159
1231 #endif // V8_UTILS_H_ 1160 #endif // V8_UTILS_H_
OLDNEW
« no previous file with comments | « src/unicode.cc ('k') | src/v8.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698