Skip to content

Commit c6c65f4

Browse files
miladfarcatargos
authored andcommitted
deps: V8: cherry-pick 8ca4ae9a0c39
Original commit message: Move ByteReverse helpers under src/base This patch is needed to fix compilation errors on BE platforms after this change: http://crrev.com/c/7203818 Bug: 448409803 Change-Id: Ife2e582f641c465c070ab397ca3c64f619715976 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7209841 Reviewed-by: Michael Lippautz <[email protected]> Commit-Queue: Milad Farazmand <[email protected]> Cr-Commit-Position: refs/heads/main@{#104029} Refs: v8/v8@8ca4ae9
1 parent 24f92ec commit c6c65f4

File tree

4 files changed

+43
-40
lines changed

4 files changed

+43
-40
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.10',
41+
'v8_embedder_string': '-node.11',
4242

4343
##### V8 defaults for Node.js #####
4444

deps/v8/src/base/bits.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,39 @@ inline int32_t WraparoundNeg32(int32_t x) {
483483
return static_cast<int32_t>(-static_cast<uint32_t>(x));
484484
}
485485

486+
inline constexpr uint16_t ByteReverse16(uint16_t value) {
487+
#if V8_HAS_BUILTIN_BSWAP16
488+
return __builtin_bswap16(value);
489+
#else
490+
return value << 8 | (value >> 8 & 0x00FF);
491+
#endif
492+
}
493+
494+
inline constexpr uint32_t ByteReverse32(uint32_t value) {
495+
#if V8_HAS_BUILTIN_BSWAP32
496+
return __builtin_bswap32(value);
497+
#else
498+
return value << 24 | ((value << 8) & 0x00FF0000) |
499+
((value >> 8) & 0x0000FF00) | ((value >> 24) & 0x00000FF);
500+
#endif
501+
}
502+
503+
inline constexpr uint64_t ByteReverse64(uint64_t value) {
504+
#if V8_HAS_BUILTIN_BSWAP64
505+
return __builtin_bswap64(value);
506+
#else
507+
size_t bits_of_v = sizeof(value) * kBitsPerByte;
508+
return value << (bits_of_v - 8) |
509+
((value << (bits_of_v - 24)) & 0x00FF000000000000) |
510+
((value << (bits_of_v - 40)) & 0x0000FF0000000000) |
511+
((value << (bits_of_v - 56)) & 0x000000FF00000000) |
512+
((value >> (bits_of_v - 56)) & 0x00000000FF000000) |
513+
((value >> (bits_of_v - 40)) & 0x0000000000FF0000) |
514+
((value >> (bits_of_v - 24)) & 0x000000000000FF00) |
515+
((value >> (bits_of_v - 8)) & 0x00000000000000FF);
516+
#endif
517+
}
518+
486519
// SignedSaturatedAdd64(lhs, rhs) adds |lhs| and |rhs|,
487520
// checks and returns the result.
488521
V8_BASE_EXPORT int64_t SignedSaturatedAdd64(int64_t lhs, int64_t rhs);

deps/v8/src/base/memcopy.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,11 @@ inline void MemCopyAndSwitchEndianness(void* dst, void* src,
202202
MemCopy(dst, src, num_elements);
203203
return;
204204
case 2:
205-
COPY_LOOP(uint16_t, ByteReverse16);
205+
COPY_LOOP(uint16_t, bits::ByteReverse16);
206206
case 4:
207-
COPY_LOOP(uint32_t, ByteReverse32);
207+
COPY_LOOP(uint32_t, bits::ByteReverse32);
208208
case 8:
209-
COPY_LOOP(uint64_t, ByteReverse64);
209+
COPY_LOOP(uint64_t, bits::ByteReverse64);
210210
default:
211211
UNREACHABLE();
212212
}

deps/v8/src/utils/utils.h

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -765,51 +765,21 @@ bool StringToIndex(Stream* stream, index_t* index);
765765
// return an address significantly above the actual current stack position.
766766
V8_EXPORT_PRIVATE V8_NOINLINE uintptr_t GetCurrentStackPosition();
767767

768-
static inline uint16_t ByteReverse16(uint16_t value) {
769-
#if V8_HAS_BUILTIN_BSWAP16
770-
return __builtin_bswap16(value);
771-
#else
772-
return value << 8 | (value >> 8 & 0x00FF);
773-
#endif
774-
}
775-
776-
static inline uint32_t ByteReverse32(uint32_t value) {
777-
#if V8_HAS_BUILTIN_BSWAP32
778-
return __builtin_bswap32(value);
779-
#else
780-
return value << 24 | ((value << 8) & 0x00FF0000) |
781-
((value >> 8) & 0x0000FF00) | ((value >> 24) & 0x00000FF);
782-
#endif
783-
}
784-
785-
static inline uint64_t ByteReverse64(uint64_t value) {
786-
#if V8_HAS_BUILTIN_BSWAP64
787-
return __builtin_bswap64(value);
788-
#else
789-
size_t bits_of_v = sizeof(value) * kBitsPerByte;
790-
return value << (bits_of_v - 8) |
791-
((value << (bits_of_v - 24)) & 0x00FF000000000000) |
792-
((value << (bits_of_v - 40)) & 0x0000FF0000000000) |
793-
((value << (bits_of_v - 56)) & 0x000000FF00000000) |
794-
((value >> (bits_of_v - 56)) & 0x00000000FF000000) |
795-
((value >> (bits_of_v - 40)) & 0x0000000000FF0000) |
796-
((value >> (bits_of_v - 24)) & 0x000000000000FF00) |
797-
((value >> (bits_of_v - 8)) & 0x00000000000000FF);
798-
#endif
799-
}
800-
801768
template <typename V>
802769
static inline V ByteReverse(V value) {
803770
size_t size_of_v = sizeof(value);
804771
switch (size_of_v) {
805772
case 1:
806773
return value;
807774
case 2:
808-
return static_cast<V>(ByteReverse16(static_cast<uint16_t>(value)));
775+
return static_cast<V>(
776+
base::bits::ByteReverse16(static_cast<uint16_t>(value)));
809777
case 4:
810-
return static_cast<V>(ByteReverse32(static_cast<uint32_t>(value)));
778+
return static_cast<V>(
779+
base::bits::ByteReverse32(static_cast<uint32_t>(value)));
811780
case 8:
812-
return static_cast<V>(ByteReverse64(static_cast<uint64_t>(value)));
781+
return static_cast<V>(
782+
base::bits::ByteReverse64(static_cast<uint64_t>(value)));
813783
default:
814784
UNREACHABLE();
815785
}

0 commit comments

Comments
 (0)