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

Side by Side Diff: src/utils.h

Issue 1072333002: Fix some -Werror=sign-compare errors (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « no previous file | test/cctest/test-cpu-profiler.cc » ('j') | test/cctest/test-cpu-profiler.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_UTILS_H_ 5 #ifndef V8_UTILS_H_
6 #define V8_UTILS_H_ 6 #define V8_UTILS_H_
7 7
8 #include <limits.h> 8 #include <limits.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 23 matching lines...) Expand all
34 inline bool CStringEquals(const char* s1, const char* s2) { 34 inline bool CStringEquals(const char* s1, const char* s2) {
35 return (s1 == s2) || (s1 != NULL && s2 != NULL && strcmp(s1, s2) == 0); 35 return (s1 == s2) || (s1 != NULL && s2 != NULL && strcmp(s1, s2) == 0);
36 } 36 }
37 37
38 38
39 // X must be a power of 2. Returns the number of trailing zeros. 39 // X must be a power of 2. Returns the number of trailing zeros.
40 inline int WhichPowerOf2(uint32_t x) { 40 inline int WhichPowerOf2(uint32_t x) {
41 DCHECK(base::bits::IsPowerOfTwo32(x)); 41 DCHECK(base::bits::IsPowerOfTwo32(x));
42 int bits = 0; 42 int bits = 0;
43 #ifdef DEBUG 43 #ifdef DEBUG
44 int original_x = x; 44 uint32_t original_x = x;
45 #endif 45 #endif
46 if (x >= 0x10000) { 46 if (x >= 0x10000) {
47 bits += 16; 47 bits += 16;
48 x >>= 16; 48 x >>= 16;
49 } 49 }
50 if (x >= 0x100) { 50 if (x >= 0x100) {
51 bits += 8; 51 bits += 8;
52 x >>= 8; 52 x >>= 8;
53 } 53 }
54 if (x >= 0x10) { 54 if (x >= 0x10) {
55 bits += 4; 55 bits += 4;
56 x >>= 4; 56 x >>= 4;
57 } 57 }
58 switch (x) { 58 switch (x) {
59 default: UNREACHABLE(); 59 default: UNREACHABLE();
60 case 8: bits++; // Fall through. 60 case 8: bits++; // Fall through.
61 case 4: bits++; // Fall through. 61 case 4: bits++; // Fall through.
62 case 2: bits++; // Fall through. 62 case 2: bits++; // Fall through.
63 case 1: break; 63 case 1: break;
64 } 64 }
65 DCHECK_EQ(1 << bits, original_x); 65 DCHECK_EQ(static_cast<uint32_t>(1) << bits, original_x);
66 return bits; 66 return bits;
67 } 67 }
68 68
69 69
70 // X must be a power of 2. Returns the number of trailing zeros. 70 // X must be a power of 2. Returns the number of trailing zeros.
71 inline int WhichPowerOf2_64(uint64_t x) { 71 inline int WhichPowerOf2_64(uint64_t x) {
72 DCHECK(base::bits::IsPowerOfTwo64(x)); 72 DCHECK(base::bits::IsPowerOfTwo64(x));
73 int bits = 0; 73 int bits = 0;
74 #ifdef DEBUG 74 #ifdef DEBUG
75 uint64_t original_x = x; 75 uint64_t original_x = x;
(...skipping 14 matching lines...) Expand all
90 bits += 4; 90 bits += 4;
91 x >>= 4; 91 x >>= 4;
92 } 92 }
93 switch (x) { 93 switch (x) {
94 default: UNREACHABLE(); 94 default: UNREACHABLE();
95 case 8: bits++; // Fall through. 95 case 8: bits++; // Fall through.
96 case 4: bits++; // Fall through. 96 case 4: bits++; // Fall through.
97 case 2: bits++; // Fall through. 97 case 2: bits++; // Fall through.
98 case 1: break; 98 case 1: break;
99 } 99 }
100 DCHECK_EQ(1L << bits, original_x); 100 DCHECK_EQ(static_cast<uint64_t>(1) << bits, original_x);
101 return bits; 101 return bits;
102 } 102 }
103 103
104 104
105 inline int MostSignificantBit(uint32_t x) { 105 inline int MostSignificantBit(uint32_t x) {
106 static const int msb4[] = {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4}; 106 static const int msb4[] = {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4};
107 int nibble = 0; 107 int nibble = 0;
108 if (x & 0xffff0000) { 108 if (x & 0xffff0000) {
109 nibble += 16; 109 nibble += 16;
110 x >>= 16; 110 x >>= 16;
(...skipping 1599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 // Takes the address of the limit variable in order to find out where 1710 // Takes the address of the limit variable in order to find out where
1711 // the top of stack is right now. 1711 // the top of stack is right now.
1712 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit); 1712 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit);
1713 return limit; 1713 return limit;
1714 } 1714 }
1715 1715
1716 } // namespace internal 1716 } // namespace internal
1717 } // namespace v8 1717 } // namespace v8
1718 1718
1719 #endif // V8_UTILS_H_ 1719 #endif // V8_UTILS_H_
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-cpu-profiler.cc » ('j') | test/cctest/test-cpu-profiler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698