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

Side by Side Diff: src/utils.h

Issue 219213003: Fixed power-of-2 predicates, excluding 0. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 6 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 | Annotate | Revision Log
« no previous file with comments | « src/objects.cc ('k') | src/x64/lithium-codegen-x64.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 25 matching lines...) Expand all
36 #include "allocation.h" 36 #include "allocation.h"
37 #include "checks.h" 37 #include "checks.h"
38 #include "globals.h" 38 #include "globals.h"
39 39
40 namespace v8 { 40 namespace v8 {
41 namespace internal { 41 namespace internal {
42 42
43 // ---------------------------------------------------------------------------- 43 // ----------------------------------------------------------------------------
44 // General helper functions 44 // General helper functions
45 45
46 #define IS_POWER_OF_TWO(x) (((x) & ((x) - 1)) == 0) 46 #define IS_POWER_OF_TWO(x) ((x) != 0 && (((x) & ((x) - 1)) == 0))
47 47
48 // Returns true iff x is a power of 2 (or zero). Cannot be used with the 48 // Returns true iff x is a power of 2. Cannot be used with the maximally
49 // maximally negative value of the type T (the -1 overflows). 49 // negative value of the type T (the -1 overflows).
50 template <typename T> 50 template <typename T>
51 inline bool IsPowerOf2(T x) { 51 inline bool IsPowerOf2(T x) {
52 return IS_POWER_OF_TWO(x); 52 return IS_POWER_OF_TWO(x);
53 } 53 }
54 54
55 55
56 // X must be a power of 2. Returns the number of trailing zeros. 56 // X must be a power of 2. Returns the number of trailing zeros.
57 inline int WhichPowerOf2(uint32_t x) { 57 inline int WhichPowerOf2(uint32_t x) {
58 ASSERT(IsPowerOf2(x)); 58 ASSERT(IsPowerOf2(x));
59 ASSERT(x != 0);
60 int bits = 0; 59 int bits = 0;
61 #ifdef DEBUG 60 #ifdef DEBUG
62 int original_x = x; 61 int original_x = x;
63 #endif 62 #endif
64 if (x >= 0x10000) { 63 if (x >= 0x10000) {
65 bits += 16; 64 bits += 16;
66 x >>= 16; 65 x >>= 16;
67 } 66 }
68 if (x >= 0x100) { 67 if (x >= 0x100) {
69 bits += 8; 68 bits += 8;
(...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1202 iterator end() { return container_->end(); } 1201 iterator end() { return container_->end(); }
1203 reverse_iterator rbegin() { return container_->rbegin(); } 1202 reverse_iterator rbegin() { return container_->rbegin(); }
1204 reverse_iterator rend() { return container_->rend(); } 1203 reverse_iterator rend() { return container_->rend(); }
1205 private: 1204 private:
1206 C* container_; 1205 C* container_;
1207 }; 1206 };
1208 1207
1209 } } // namespace v8::internal 1208 } } // namespace v8::internal
1210 1209
1211 #endif // V8_UTILS_H_ 1210 #endif // V8_UTILS_H_
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | src/x64/lithium-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698