v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
string-hasher.cc
Go to the documentation of this file.
1
2// Copyright 2024 the V8 project authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5
7
9
10namespace v8::internal {
11
13 static constexpr unsigned kCompressionFactor = 2;
14 static constexpr unsigned kExpansionFactor = 1;
15
16 V8_INLINE static uint64_t Read64(const uint8_t* ptr) {
17 const uint16_t* p = reinterpret_cast<const uint16_t*>(ptr);
18 DCHECK_LE(p[0], 0xff);
19 DCHECK_LE(p[1], 0xff);
20 DCHECK_LE(p[2], 0xff);
21 DCHECK_LE(p[3], 0xff);
22 DCHECK_LE(p[4], 0xff);
23 DCHECK_LE(p[5], 0xff);
24 DCHECK_LE(p[6], 0xff);
25 DCHECK_LE(p[7], 0xff);
26#ifdef __SSE2__
27 __m128i x = _mm_loadu_si128(reinterpret_cast<const __m128i*>(p));
28 return _mm_cvtsi128_si64(_mm_packus_epi16(x, x));
29#elif defined(__ARM_NEON__)
30 int16x8_t x;
31 memcpy(&x, p, sizeof(x));
32 return vget_lane_u64(vreinterpret_u64_u8(vmovn_u16(x)), 0);
33#else
34 return (uint64_t{p[0]}) | (uint64_t{p[1]} << 8) | (uint64_t{p[2]} << 16) |
35 (uint64_t{p[3]} << 24) | (uint64_t{p[4]} << 32) |
36 (uint64_t{p[5]} << 40) | (uint64_t{p[6]} << 48) |
37 (uint64_t{p[7]} << 56);
38#endif
39 }
40
41 V8_INLINE static uint64_t Read32(const uint8_t* ptr) {
42 const uint16_t* p = reinterpret_cast<const uint16_t*>(ptr);
43 DCHECK_LE(p[0], 0xff);
44 DCHECK_LE(p[1], 0xff);
45 DCHECK_LE(p[2], 0xff);
46 DCHECK_LE(p[3], 0xff);
47#ifdef __SSE2__
48 __m128i x = _mm_loadu_si64(reinterpret_cast<const __m128i*>(p));
49 return _mm_cvtsi128_si64(_mm_packus_epi16(x, x));
50#elif defined(__ARM_NEON__)
51 int8x8_t x;
52 memcpy(&x, p, sizeof(x));
53 int16x8_t x_wide = vcombine_u64(x, x);
54 return vget_lane_u32(vreinterpret_u32_u8(vmovn_u16(x_wide)), 0);
55#else
56 return (uint64_t{p[0]}) | (uint64_t{p[1]} << 8) | (uint64_t{p[2]} << 16) |
57 (uint64_t{p[3]} << 24);
58#endif
59 }
60
61 V8_INLINE static uint64_t ReadSmall(const uint8_t* ptr, size_t k) {
62 const uint16_t* p = reinterpret_cast<const uint16_t*>(ptr);
63 DCHECK_LE(p[0], 0xff);
64 DCHECK_LE(p[k >> 1], 0xff);
65 DCHECK_LE(p[k - 1], 0xff);
66 return (uint64_t{p[0]} << 56) | (uint64_t{p[k >> 1]} << 32) | p[k - 1];
67 }
68};
69
70namespace detail {
71uint64_t HashConvertingTo8Bit(const uint16_t* chars, uint32_t length,
72 uint64_t seed) {
73 return rapidhash<ConvertTo8BitHashReader>(
74 reinterpret_cast<const uint8_t*>(chars), length, seed);
75}
76} // namespace detail
77
78} // namespace v8::internal
int x
V8_EXPORT_PRIVATE uint64_t HashConvertingTo8Bit(const uint16_t *chars, uint32_t length, uint64_t seed)
#define DCHECK_LE(v1, v2)
Definition logging.h:490
static constexpr unsigned kExpansionFactor
static V8_INLINE uint64_t Read64(const uint8_t *ptr)
static V8_INLINE uint64_t Read32(const uint8_t *ptr)
static constexpr unsigned kCompressionFactor
static V8_INLINE uint64_t ReadSmall(const uint8_t *ptr, size_t k)
#define V8_INLINE
Definition v8config.h:500