OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef PLATFORM_GLOBALS_H_ | 5 #ifndef PLATFORM_GLOBALS_H_ |
6 #define PLATFORM_GLOBALS_H_ | 6 #define PLATFORM_GLOBALS_H_ |
7 | 7 |
8 // __STDC_FORMAT_MACROS has to be defined before including <inttypes.h> to | 8 // __STDC_FORMAT_MACROS has to be defined before including <inttypes.h> to |
9 // enable platform independent printf format specifiers. | 9 // enable platform independent printf format specifiers. |
10 #ifndef __STDC_FORMAT_MACROS | 10 #ifndef __STDC_FORMAT_MACROS |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 const int kBitsPerWord = kWordSize * kBitsPerByte; | 274 const int kBitsPerWord = kWordSize * kBitsPerByte; |
275 | 275 |
276 // System-wide named constants. | 276 // System-wide named constants. |
277 const intptr_t KB = 1024; | 277 const intptr_t KB = 1024; |
278 const intptr_t KBLog2 = 10; | 278 const intptr_t KBLog2 = 10; |
279 const intptr_t MB = KB * KB; | 279 const intptr_t MB = KB * KB; |
280 const intptr_t MBLog2 = KBLog2 + KBLog2; | 280 const intptr_t MBLog2 = KBLog2 + KBLog2; |
281 const intptr_t GB = MB * KB; | 281 const intptr_t GB = MB * KB; |
282 const intptr_t GBLog2 = MBLog2 + KBLog2; | 282 const intptr_t GBLog2 = MBLog2 + KBLog2; |
283 | 283 |
| 284 const intptr_t KBInWords = KB >> kWordSizeLog2; |
| 285 const intptr_t KBInWordsLog2 = KBLog2 - kWordSizeLog2; |
| 286 const intptr_t MBInWords = KB * KBInWords; |
| 287 const intptr_t MBInWordsLog2 = KBLog2 + KBInWordsLog2; |
| 288 const intptr_t GBInWords = MB * KBInWords; |
| 289 const intptr_t GBInWordsLog2 = MBLog2 + KBInWordsLog2; |
| 290 |
| 291 // Helpers to round memory sizes to human readable values. |
| 292 inline intptr_t RoundWordsToKB(intptr_t size_in_words) { |
| 293 return (size_in_words + (KBInWords >> 1)) >> KBInWordsLog2; |
| 294 } |
| 295 inline intptr_t RoundWordsToMB(intptr_t size_in_words) { |
| 296 return (size_in_words + (MBInWords >> 1)) >> MBInWordsLog2; |
| 297 } |
| 298 inline intptr_t RoundWordsToGB(intptr_t size_in_words) { |
| 299 return (size_in_words + (GBInWords >> 1)) >> GBInWordsLog2; |
| 300 } |
| 301 |
284 const intptr_t kIntptrOne = 1; | 302 const intptr_t kIntptrOne = 1; |
285 const intptr_t kIntptrMin = (kIntptrOne << (kBitsPerWord - 1)); | 303 const intptr_t kIntptrMin = (kIntptrOne << (kBitsPerWord - 1)); |
286 const intptr_t kIntptrMax = ~kIntptrMin; | 304 const intptr_t kIntptrMax = ~kIntptrMin; |
287 | 305 |
288 // Time constants. | 306 // Time constants. |
289 const int kMillisecondsPerSecond = 1000; | 307 const int kMillisecondsPerSecond = 1000; |
290 const int kMicrosecondsPerMillisecond = 1000; | 308 const int kMicrosecondsPerMillisecond = 1000; |
291 const int kMicrosecondsPerSecond = (kMicrosecondsPerMillisecond * | 309 const int kMicrosecondsPerSecond = (kMicrosecondsPerMillisecond * |
292 kMillisecondsPerSecond); | 310 kMillisecondsPerSecond); |
293 const int kNanosecondsPerMicrosecond = 1000; | 311 const int kNanosecondsPerMicrosecond = 1000; |
294 const int kNanosecondsPerMillisecond = (kNanosecondsPerMicrosecond * | 312 const int kNanosecondsPerMillisecond = (kNanosecondsPerMicrosecond * |
295 kMicrosecondsPerMillisecond); | 313 kMicrosecondsPerMillisecond); |
296 const int kNanosecondsPerSecond = (kNanosecondsPerMicrosecond * | 314 const int kNanosecondsPerSecond = (kNanosecondsPerMicrosecond * |
297 kMicrosecondsPerSecond); | 315 kMicrosecondsPerSecond); |
298 | 316 |
| 317 // Helpers to round micro second times to human understandable values. |
| 318 inline double RoundMicrosecondsToSeconds(int64_t micros) { |
| 319 const int k1M = 1000000; // Converting us to secs. |
| 320 return static_cast<double>(micros + (k1M >> 1)) / k1M; |
| 321 } |
| 322 inline double RoundMicrosecondsToMilliseconds(int64_t micros) { |
| 323 const int k1K = 1000; // Conversting us to ms. |
| 324 return static_cast<double>(micros + (k1K >> 1)) / k1K; |
| 325 } |
| 326 |
299 // A macro to disallow the copy constructor and operator= functions. | 327 // A macro to disallow the copy constructor and operator= functions. |
300 // This should be used in the private: declarations for a class. | 328 // This should be used in the private: declarations for a class. |
301 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ | 329 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ |
302 private: \ | 330 private: \ |
303 TypeName(const TypeName&); \ | 331 TypeName(const TypeName&); \ |
304 void operator=(const TypeName&) | 332 void operator=(const TypeName&) |
305 | 333 |
306 | 334 |
307 // A macro to disallow all the implicit constructors, namely the default | 335 // A macro to disallow all the implicit constructors, namely the default |
308 // constructor, copy constructor and operator= functions. This should be | 336 // constructor, copy constructor and operator= functions. This should be |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 // N.B.: As the GCC manual states, "[s]ince non-static C++ methods | 489 // N.B.: As the GCC manual states, "[s]ince non-static C++ methods |
462 // have an implicit 'this' argument, the arguments of such methods | 490 // have an implicit 'this' argument, the arguments of such methods |
463 // should be counted from two, not one." | 491 // should be counted from two, not one." |
464 #define PRINTF_ATTRIBUTE(string_index, first_to_check) \ | 492 #define PRINTF_ATTRIBUTE(string_index, first_to_check) \ |
465 __attribute__((__format__(__printf__, string_index, first_to_check))) | 493 __attribute__((__format__(__printf__, string_index, first_to_check))) |
466 #else | 494 #else |
467 #define PRINTF_ATTRIBUTE(string_index, first_to_check) | 495 #define PRINTF_ATTRIBUTE(string_index, first_to_check) |
468 #endif | 496 #endif |
469 | 497 |
470 #endif // PLATFORM_GLOBALS_H_ | 498 #endif // PLATFORM_GLOBALS_H_ |
OLD | NEW |