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

Side by Side Diff: runtime/platform/utils.h

Issue 23604024: Fix a compiler bug caused by Utils::IsPowerOfTwo treating zero as a power of two. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 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 | « no previous file | runtime/vm/flow_graph_optimizer.cc » ('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 (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_UTILS_H_ 5 #ifndef PLATFORM_UTILS_H_
6 #define PLATFORM_UTILS_H_ 6 #define PLATFORM_UTILS_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "platform/globals.h" 9 #include "platform/globals.h"
10 10
(...skipping 12 matching lines...) Expand all
23 } 23 }
24 24
25 template<typename T> 25 template<typename T>
26 static inline T Abs(T x) { 26 static inline T Abs(T x) {
27 if (x < 0) return -x; 27 if (x < 0) return -x;
28 return x; 28 return x;
29 } 29 }
30 30
31 template<typename T> 31 template<typename T>
32 static inline bool IsPowerOfTwo(T x) { 32 static inline bool IsPowerOfTwo(T x) {
33 return (x & (x - 1)) == 0; 33 return ((x & (x - 1)) == 0) && (x != 0);
34 } 34 }
35 35
36 template<typename T> 36 template<typename T>
37 static inline int ShiftForPowerOfTwo(T x) { 37 static inline int ShiftForPowerOfTwo(T x) {
38 ASSERT(IsPowerOfTwo(x)); 38 ASSERT(IsPowerOfTwo(x));
39 int num_shifts = 0; 39 int num_shifts = 0;
40 while (x > 1) { 40 while (x > 1) {
41 num_shifts++; 41 num_shifts++;
42 x = x >> 1; 42 x = x >> 1;
43 } 43 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 #include "platform/utils_linux.h" 189 #include "platform/utils_linux.h"
190 #elif defined(TARGET_OS_MACOS) 190 #elif defined(TARGET_OS_MACOS)
191 #include "platform/utils_macos.h" 191 #include "platform/utils_macos.h"
192 #elif defined(TARGET_OS_WINDOWS) 192 #elif defined(TARGET_OS_WINDOWS)
193 #include "platform/utils_win.h" 193 #include "platform/utils_win.h"
194 #else 194 #else
195 #error Unknown target os. 195 #error Unknown target os.
196 #endif 196 #endif
197 197
198 #endif // PLATFORM_UTILS_H_ 198 #endif // PLATFORM_UTILS_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/flow_graph_optimizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698