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

Side by Side Diff: src/base/bits.h

Issue 2013393002: Fix wrong endianness of wasm header in WasmModuleWriter on big-endian platforms (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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_BASE_BITS_H_ 5 #ifndef V8_BASE_BITS_H_
6 #define V8_BASE_BITS_H_ 6 #define V8_BASE_BITS_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include "src/base/macros.h" 9 #include "src/base/macros.h"
10 #if V8_CC_MSVC 10 #if V8_CC_MSVC
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 return static_cast<unsigned>(result); 124 return static_cast<unsigned>(result);
125 #else 125 #else
126 if (value == 0) return 32; 126 if (value == 0) return 32;
127 unsigned count = 0; 127 unsigned count = 0;
128 for (value ^= value - 1; value >>= 1; ++count) { 128 for (value ^= value - 1; value >>= 1; ++count) {
129 } 129 }
130 return count; 130 return count;
131 #endif 131 #endif
132 } 132 }
133 133
134 inline int16_t ChangeEndianness(int16_t value) {
135 #if V8_HAS_BUILTIN_BSWAP16
136 return __builtin_bswap16(value);
137 #else
138 return (value << 8) | ((value >> 8) & 0xFF);
139 #endif
140 }
141
142 inline uint16_t ChangeEndianness(uint16_t value) {
143 #if V8_HAS_BUILTIN_BSWAP16
144 return __builtin_bswap16(value);
145 #else
146 return (value << 8) | (value >> 8);
147 #endif
148 }
149
150 inline int32_t ChangeEndianness(int32_t value) {
151 #if V8_HAS_BUILTIN_BSWAP32
152 return __builtin_bswap32(value);
153 #else
154 int32_t tmp;
155 tmp = ((value << 8) & 0xFF00FF00) | ((value >> 8) & 0xFF00FF);
156 return (tmp << 16) | ((tmp >> 16) & 0xFFFF);
157 #endif
158 }
159
160 inline uint32_t ChangeEndianness(uint32_t value) {
161 #if V8_HAS_BUILTIN_BSWAP32
162 return __builtin_bswap32(value);
163 #else
164 int32_t tmp;
165 tmp = ((value << 8) & 0xFF00FF00) | ((value >> 8) & 0xFF00FF);
166 return (tmp << 16) | (tmp >> 16);
167 #endif
168 }
169
170 inline int64_t ChangeEndianness(int64_t value) {
171 #if V8_HAS_BUILTIN_BSWAP64
172 return __builtin_bswap64(value);
173 #else
174 int64_t tmp;
175 tmp = ((value << 8) & 0xFF00FF00FF00FF00ULL) |
176 ((value >> 8) & 0x00FF00FF00FF00FFULL);
177 tmp = ((tmp << 16) & 0xFFFF0000FFFF0000ULL) |
178 ((tmp >> 16) & 0x0000FFFF0000FFFFULL);
179 return (tmp << 32) | ((tmp >> 32) & 0xFFFFFFFFULL);
180 #endif
181 }
182
183 inline int64_t ChangeEndianness(uint64_t value) {
184 #if V8_HAS_BUILTIN_BSWAP64
185 return __builtin_bswap64(value);
186 #else
187 int64_t tmp;
188 tmp = ((value << 8) & 0xFF00FF00FF00FF00ULL) |
189 ((value >> 8) & 0x00FF00FF00FF00FFULL);
190 tmp = ((tmp << 16) & 0xFFFF0000FFFF0000ULL) |
191 ((tmp >> 16) & 0x0000FFFF0000FFFFULL);
192 return (tmp << 32) | (tmp >> 32);
193 #endif
194 }
134 195
135 // CountTrailingZeros64(value) returns the number of zero bits preceding the 196 // CountTrailingZeros64(value) returns the number of zero bits preceding the
136 // least significant 1 bit in |value| if |value| is non-zero, otherwise it 197 // least significant 1 bit in |value| if |value| is non-zero, otherwise it
137 // returns 64. 198 // returns 64.
138 inline unsigned CountTrailingZeros64(uint64_t value) { 199 inline unsigned CountTrailingZeros64(uint64_t value) {
139 #if V8_HAS_BUILTIN_CTZ 200 #if V8_HAS_BUILTIN_CTZ
140 return value ? __builtin_ctzll(value) : 64; 201 return value ? __builtin_ctzll(value) : 64;
141 #else 202 #else
142 if (value == 0) return 64; 203 if (value == 0) return 64;
143 unsigned count = 0; 204 unsigned count = 0;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // SignedSaturatedSub64(lhs, rhs) substracts |lhs| by |rhs|, 376 // SignedSaturatedSub64(lhs, rhs) substracts |lhs| by |rhs|,
316 // checks and returns the result. 377 // checks and returns the result.
317 int64_t SignedSaturatedSub64(int64_t lhs, int64_t rhs); 378 int64_t SignedSaturatedSub64(int64_t lhs, int64_t rhs);
318 379
319 380
320 } // namespace bits 381 } // namespace bits
321 } // namespace base 382 } // namespace base
322 } // namespace v8 383 } // namespace v8
323 384
324 #endif // V8_BASE_BITS_H_ 385 #endif // V8_BASE_BITS_H_
OLDNEW
« no previous file with comments | « include/v8config.h ('k') | src/wasm/encoder.cc » ('j') | src/wasm/encoder.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698