OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // though. | 47 // though. |
48 static inline int ArithmeticShiftRight(int x, int s) { | 48 static inline int ArithmeticShiftRight(int x, int s) { |
49 return x >> s; | 49 return x >> s; |
50 } | 50 } |
51 | 51 |
52 | 52 |
53 // Compute the 0-relative offset of some absolute value x of type T. | 53 // Compute the 0-relative offset of some absolute value x of type T. |
54 // This allows conversion of Addresses and integral types into | 54 // This allows conversion of Addresses and integral types into |
55 // 0-relative int offsets. | 55 // 0-relative int offsets. |
56 template <typename T> | 56 template <typename T> |
57 static inline int OffsetFrom(T x) { | 57 static inline intptr_t OffsetFrom(T x) { |
58 return x - static_cast<T>(0); | 58 return x - static_cast<T>(0); |
59 } | 59 } |
60 | 60 |
61 | 61 |
62 // Compute the absolute value of type T for some 0-relative offset x. | 62 // Compute the absolute value of type T for some 0-relative offset x. |
63 // This allows conversion of 0-relative int offsets into Addresses and | 63 // This allows conversion of 0-relative int offsets into Addresses and |
64 // integral types. | 64 // integral types. |
65 template <typename T> | 65 template <typename T> |
66 static inline T AddressFrom(int x) { | 66 static inline T AddressFrom(intptr_t x) { |
67 return static_cast<T>(0) + x; | 67 return static_cast<T>(0) + x; |
68 } | 68 } |
69 | 69 |
70 | 70 |
71 // Return the largest multiple of m which is <= x. | 71 // Return the largest multiple of m which is <= x. |
72 template <typename T> | 72 template <typename T> |
73 static inline T RoundDown(T x, int m) { | 73 static inline T RoundDown(T x, int m) { |
74 ASSERT(IsPowerOf2(m)); | 74 ASSERT(IsPowerOf2(m)); |
75 return AddressFrom<T>(OffsetFrom(x) & -m); | 75 return AddressFrom<T>(OffsetFrom(x) & -m); |
76 } | 76 } |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 #endif | 545 #endif |
546 while (dest < limit) { | 546 while (dest < limit) { |
547 *dest++ = static_cast<sinkchar>(*src++); | 547 *dest++ = static_cast<sinkchar>(*src++); |
548 } | 548 } |
549 } | 549 } |
550 | 550 |
551 | 551 |
552 } } // namespace v8::internal | 552 } } // namespace v8::internal |
553 | 553 |
554 #endif // V8_UTILS_H_ | 554 #endif // V8_UTILS_H_ |
OLD | NEW |