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

Side by Side Diff: src/utils.h

Issue 8139027: Version 3.6.5 (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: '' Created 9 years, 2 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/uri.js ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // This allows conversion of 0-relative int offsets into Addresses and 106 // This allows conversion of 0-relative int offsets into Addresses and
107 // integral types. 107 // integral types.
108 template <typename T> 108 template <typename T>
109 static inline T AddressFrom(intptr_t x) { 109 static inline T AddressFrom(intptr_t x) {
110 return static_cast<T>(static_cast<T>(0) + x); 110 return static_cast<T>(static_cast<T>(0) + x);
111 } 111 }
112 112
113 113
114 // Return the largest multiple of m which is <= x. 114 // Return the largest multiple of m which is <= x.
115 template <typename T> 115 template <typename T>
116 static inline T RoundDown(T x, int m) { 116 static inline T RoundDown(T x, intptr_t m) {
117 ASSERT(IsPowerOf2(m)); 117 ASSERT(IsPowerOf2(m));
118 return AddressFrom<T>(OffsetFrom(x) & -m); 118 return AddressFrom<T>(OffsetFrom(x) & -m);
119 } 119 }
120 120
121 121
122 // Return the smallest multiple of m which is >= x. 122 // Return the smallest multiple of m which is >= x.
123 template <typename T> 123 template <typename T>
124 static inline T RoundUp(T x, int m) { 124 static inline T RoundUp(T x, intptr_t m) {
125 return RoundDown(x + m - 1, m); 125 return RoundDown<T>(static_cast<T>(x + m - 1), m);
126 } 126 }
127 127
128 128
129 template <typename T> 129 template <typename T>
130 static int Compare(const T& a, const T& b) { 130 static int Compare(const T& a, const T& b) {
131 if (a == b) 131 if (a == b)
132 return 0; 132 return 0;
133 else if (a < b) 133 else if (a < b)
134 return -1; 134 return -1;
135 else 135 else
(...skipping 16 matching lines...) Expand all
152 x = x - 1; 152 x = x - 1;
153 x = x | (x >> 1); 153 x = x | (x >> 1);
154 x = x | (x >> 2); 154 x = x | (x >> 2);
155 x = x | (x >> 4); 155 x = x | (x >> 4);
156 x = x | (x >> 8); 156 x = x | (x >> 8);
157 x = x | (x >> 16); 157 x = x | (x >> 16);
158 return x + 1; 158 return x + 1;
159 } 159 }
160 160
161 161
162 static inline uint32_t RoundDownToPowerOf2(uint32_t x) {
163 uint32_t rounded_up = RoundUpToPowerOf2(x);
164 if (rounded_up > x) return rounded_up >> 1;
165 return rounded_up;
166 }
162 167
163 template <typename T> 168
164 static inline bool IsAligned(T value, T alignment) { 169 template <typename T, typename U>
170 static inline bool IsAligned(T value, U alignment) {
165 ASSERT(IsPowerOf2(alignment)); 171 ASSERT(IsPowerOf2(alignment));
166 return (value & (alignment - 1)) == 0; 172 return (value & (alignment - 1)) == 0;
167 } 173 }
168 174
169 175
170 // Returns true if (addr + offset) is aligned. 176 // Returns true if (addr + offset) is aligned.
171 static inline bool IsAddressAligned(Address addr, 177 static inline bool IsAddressAligned(Address addr,
172 intptr_t alignment, 178 intptr_t alignment,
173 int offset) { 179 int offset = 0) {
174 intptr_t offs = OffsetFrom(addr + offset); 180 intptr_t offs = OffsetFrom(addr + offset);
175 return IsAligned(offs, alignment); 181 return IsAligned(offs, alignment);
176 } 182 }
177 183
178 184
179 // Returns the maximum of the two parameters. 185 // Returns the maximum of the two parameters.
180 template <typename T> 186 template <typename T>
181 static T Max(T a, T b) { 187 static T Max(T a, T b) {
182 return a < b ? b : a; 188 return a < b ? b : a;
183 } 189 }
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT)); 917 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT));
912 return 1 << element; 918 return 1 << element;
913 } 919 }
914 920
915 T bits_; 921 T bits_;
916 }; 922 };
917 923
918 } } // namespace v8::internal 924 } } // namespace v8::internal
919 925
920 #endif // V8_UTILS_H_ 926 #endif // V8_UTILS_H_
OLDNEW
« no previous file with comments | « src/uri.js ('k') | src/v8.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698