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

Side by Side Diff: src/utils.h

Issue 15943002: v8 typed arrays: add DataView type (Closed)
Patch Set: Created 7 years, 7 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
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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 232 }
233 233
234 234
235 inline int StrLength(const char* string) { 235 inline int StrLength(const char* string) {
236 size_t length = strlen(string); 236 size_t length = strlen(string);
237 ASSERT(length == static_cast<size_t>(static_cast<int>(length))); 237 ASSERT(length == static_cast<size_t>(static_cast<int>(length)));
238 return static_cast<int>(length); 238 return static_cast<int>(length);
239 } 239 }
240 240
241 241
242 template <typename T>
243 inline void Swizzle(T* value) {
244 char* start = reinterpret_cast<char*>(value);
245 char* end = start + sizeof(*value) - 1;
246 while (start < end) {
247 char t = *start;
248 *start++ = *end;
249 *end-- = t;
250 }
251 }
252
253
254 enum Endianness {
255 kLittleEndian, // _Not_ LITTLE_ENDIAN, clashes with endian.h.
256 kBigEndian
257 };
258
259
260 inline enum Endianness GetEndianness() {
261 // Constant-folded by the compiler.
262 const union {
263 uint8_t u8[2];
264 uint16_t u16;
265 } u = {
266 { 1, 0 }
267 };
268 return u.u16 == 1 ? kLittleEndian : kBigEndian;
269 }
270
271
272 inline bool IsLittleEndian() {
273 return GetEndianness() == kLittleEndian;
274 }
275
276
277 inline bool IsBigEndian() {
278 return GetEndianness() == kBigEndian;
279 }
280
281
242 // ---------------------------------------------------------------------------- 282 // ----------------------------------------------------------------------------
243 // BitField is a help template for encoding and decode bitfield with 283 // BitField is a help template for encoding and decode bitfield with
244 // unsigned content. 284 // unsigned content.
245 285
246 template<class T, int shift, int size, class U> 286 template<class T, int shift, int size, class U>
247 class BitFieldBase { 287 class BitFieldBase {
248 public: 288 public:
249 // A type U mask of bit field. To use all bits of a type U of x bits 289 // A type U mask of bit field. To use all bits of a type U of x bits
250 // in a bitfield without compiler warnings we have to compute 2^x 290 // in a bitfield without compiler warnings we have to compute 2^x
251 // without using a shift count of x in the computation. 291 // without using a shift count of x in the computation.
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 1142
1103 // Every compiled stub starts with this id. 1143 // Every compiled stub starts with this id.
1104 static const int kStubEntryId = 5; 1144 static const int kStubEntryId = 5;
1105 1145
1106 int id_; 1146 int id_;
1107 }; 1147 };
1108 1148
1109 } } // namespace v8::internal 1149 } } // namespace v8::internal
1110 1150
1111 #endif // V8_UTILS_H_ 1151 #endif // V8_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698