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

Side by Side Diff: src/utils.h

Issue 15943002: v8 typed arrays: add DataView type (Closed)
Patch Set: v8 typed arrays: add DataView type, v2 Created 7 years, 6 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 } 239 }
240 240
241 241
242 inline int StrLength(const char* string) { 242 inline int StrLength(const char* string) {
243 size_t length = strlen(string); 243 size_t length = strlen(string);
244 ASSERT(length == static_cast<size_t>(static_cast<int>(length))); 244 ASSERT(length == static_cast<size_t>(static_cast<int>(length)));
245 return static_cast<int>(length); 245 return static_cast<int>(length);
246 } 246 }
247 247
248 248
249 template <typename T>
250 inline void Swizzle(T* value) {
251 char* start = reinterpret_cast<char*>(value);
252 char* end = start + sizeof(*value) - 1;
253 while (start < end) {
254 char t = *start;
255 *start++ = *end;
256 *end-- = t;
257 }
258 }
259
260
261 enum Endianness {
262 kLittleEndian, // _Not_ LITTLE_ENDIAN, clashes with endian.h.
263 kBigEndian
264 };
265
266
267 inline enum Endianness GetEndianness() {
Dmitry Lomov (no reviews) 2013/06/03 13:09:04 This belongs to cpu.h. Should be a #define with po
bnoordhuis 2013/06/03 13:48:12 I'll move it but is turning it into a macro necess
Dmitry Lomov (no reviews) 2013/06/03 14:42:49 Explicitly define expected endianness using V8_TAR
268 // Constant-folded by the compiler.
269 const union {
270 uint8_t u8[2];
271 uint16_t u16;
272 } u = {
273 { 1, 0 }
274 };
275 return u.u16 == 1 ? kLittleEndian : kBigEndian;
276 }
277
278
279 inline bool IsLittleEndian() {
280 return GetEndianness() == kLittleEndian;
281 }
282
283
284 inline bool IsBigEndian() {
285 return GetEndianness() == kBigEndian;
286 }
287
288
249 // ---------------------------------------------------------------------------- 289 // ----------------------------------------------------------------------------
250 // BitField is a help template for encoding and decode bitfield with 290 // BitField is a help template for encoding and decode bitfield with
251 // unsigned content. 291 // unsigned content.
252 292
253 template<class T, int shift, int size, class U> 293 template<class T, int shift, int size, class U>
254 class BitFieldBase { 294 class BitFieldBase {
255 public: 295 public:
256 // A type U mask of bit field. To use all bits of a type U of x bits 296 // A type U mask of bit field. To use all bits of a type U of x bits
257 // in a bitfield without compiler warnings we have to compute 2^x 297 // in a bitfield without compiler warnings we have to compute 2^x
258 // without using a shift count of x in the computation. 298 // without using a shift count of x in the computation.
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 1149
1110 // Every compiled stub starts with this id. 1150 // Every compiled stub starts with this id.
1111 static const int kStubEntryId = 5; 1151 static const int kStubEntryId = 5;
1112 1152
1113 int id_; 1153 int id_;
1114 }; 1154 };
1115 1155
1116 } } // namespace v8::internal 1156 } } // namespace v8::internal
1117 1157
1118 #endif // V8_UTILS_H_ 1158 #endif // V8_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698