Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -891,13 +891,13 @@ REPOSITORY_LOCATIONS_SPEC = dict(
project_desc = "Google’s open source high-performance JavaScript and WebAssembly engine, written in C++",
project_url = "https://v8.dev",
# NOTE: Update together with com_googlesource_chromium_base_trace_event_common and com_googlesource_chromium_zlib.
version = "10.0.139.6",
version = "10.4.132.18",
# Static snapshot created using https://storage.googleapis.com/envoyproxy-wee8/wee8-fetch-deps.sh.
sha256 = "3585ebc8db95e61b65260b3d141ed5392b843bd066744fa62ce92dab3708e2f8",
sha256 = "154223731091f531a3cb1a95ab9c14225983891240220a9e232c729358badd2c",
urls = ["https://storage.googleapis.com/envoyproxy-wee8/v8-{version}.tar.gz"],
use_category = ["dataplane_ext"],
extensions = ["envoy.wasm.runtime.v8"],
release_date = "2022-03-07",
release_date = "2022-07-11",
cpe = "cpe:2.3:a:google:v8:*",
),
com_googlesource_chromium_base_trace_event_common = dict(
Expand All @@ -921,13 +921,13 @@ REPOSITORY_LOCATIONS_SPEC = dict(
project_url = "https://chromium.googlesource.com/chromium/src/third_party/zlib/",
# NOTE: Update together with v8 and com_googlesource_chromium_base_trace_event_common.
# Use version and sha256 from https://storage.googleapis.com/envoyproxy-wee8/v8-<v8_version>-deps.sha256.
version = "9538f4194f6e5eff1bd59f2396ed9d05b1a8d801",
version = "64bbf988543996eb8df9a86877b32917187eba8f",
# Static snapshot created using https://storage.googleapis.com/envoyproxy-wee8/wee8-fetch-deps.sh.
sha256 = "7045c6808267f3e803e3196fa06346647c2a060cfd1a2f96ef6325fba6eaa956",
sha256 = "6e70bbb25ad1c567e3b44f4ad76f50fcc8fb7d34c6e2e8858e033ffd579ac1af",
urls = ["https://storage.googleapis.com/envoyproxy-wee8/chromium-zlib-{version}.tar.gz"],
use_category = ["dataplane_ext"],
extensions = ["envoy.wasm.runtime.v8"],
release_date = "2022-02-15",
release_date = "2022-05-31",
cpe = "N/A",
),
com_github_google_quiche = dict(
Expand Down Expand Up @@ -1119,8 +1119,8 @@ REPOSITORY_LOCATIONS_SPEC = dict(
project_name = "WebAssembly for Proxies (C++ host implementation)",
project_desc = "WebAssembly for Proxies (C++ host implementation)",
project_url = "https://github.com/proxy-wasm/proxy-wasm-cpp-host",
version = "0746300de0c645f6a87a5fc51954c6fdb86bb7e6",
sha256 = "6a2d1bd5a378c16e1d2b739a7fc1565d492f3280866f72919ca86ab7bd9a7948",
version = "bcd1c4a698ca2cee79959e150ba3b02ffa790eea",
sha256 = "b1124d3667c24d1ad3ddb8f12c3646fe9bf31a1316dd4ce50efc9f1a2f82f68a",
strip_prefix = "proxy-wasm-cpp-host-{version}",
urls = ["https://github.com/proxy-wasm/proxy-wasm-cpp-host/archive/{version}.tar.gz"],
use_category = ["dataplane_ext"],
Expand Down
307 changes: 295 additions & 12 deletions bazel/v8.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# 1. Use already imported python dependencies.
# 2. Fix the include path for //external:zlib.
# 3. Add support for --define=no_debug_info=1.
# 4. Disable pointer compression (https://crbug.com/v8/12592).
# 5. Add M1 CPU support https://chromium-review.googlesource.com/c/v8/v8/+/3502848
# 4. Disable pointer compression (limits the maximum number of WasmVMs).
# 5. Don't expose Wasm C API (only Wasm C++ API).
# 6. Fix cross-compilation (https://crrev.com/c/3735165).
# 7. Fix build errors in SIMD IndexOf/includes (https://crrev.com/c/3749192).
# 8. Fix build on arm64.

diff --git a/BUILD.bazel b/BUILD.bazel
index 13f2a5bebf..2197568c48 100644
Expand All @@ -27,10 +30,18 @@ index 13f2a5bebf..2197568c48 100644

# Default setting for v8_enable_pointer_compression.
diff --git a/bazel/defs.bzl b/bazel/defs.bzl
index dee5e69cc4..d0b5a3c49a 100644
index e957c0fad3..eee285ab60 100644
--- a/bazel/defs.bzl
+++ b/bazel/defs.bzl
@@ -151,6 +151,11 @@ def _default_args():
@@ -116,6 +116,7 @@ def _default_args():
}) + select({
"@v8//bazel/config:is_clang": [
"-Wno-invalid-offsetof",
+ "-Wno-unneeded-internal-declaration",
"-std=c++17",
],
"@v8//bazel/config:is_gcc": [
@@ -151,6 +152,11 @@ def _default_args():
"-fno-integrated-as",
],
"//conditions:default": [],
Expand All @@ -42,14 +53,6 @@ index dee5e69cc4..d0b5a3c49a 100644
}),
includes = ["include"],
linkopts = select({
@@ -383,6 +388,7 @@ def _v8_target_cpu_transition_impl(settings, attr):
"k8": "x64",
"x86_64": "x64",
"darwin": "x64",
+ "darwin_arm64": "arm64",
"darwin_x86_64": "x64",
"x64_windows": "x64",
"x86": "ia32",
diff --git a/src/snapshot/snapshot-utils.cc b/src/snapshot/snapshot-utils.cc
index 6db6698d7e..b56d31085f 100644
--- a/src/snapshot/snapshot-utils.cc
Expand All @@ -63,3 +66,283 @@ index 6db6698d7e..b56d31085f 100644

namespace v8 {
namespace internal {
diff --git a/src/wasm/c-api.cc b/src/wasm/c-api.cc
index ce3f569fd5..dc8a4c4f6a 100644
--- a/src/wasm/c-api.cc
+++ b/src/wasm/c-api.cc
@@ -2238,6 +2238,8 @@ auto Instance::exports() const -> ownvec<Extern> {

} // namespace wasm

+#if 0
+
// BEGIN FILE wasm-c.cc

extern "C" {
@@ -3257,3 +3259,5 @@ wasm_instance_t* wasm_frame_instance(const wasm_frame_t* frame) {
#undef WASM_DEFINE_SHARABLE_REF

} // extern "C"
+
+#endif
diff --git a/src/execution/clobber-registers.cc b/src/execution/clobber-registers.cc
index 8f7fba765f..a7f5bf80cf 100644
--- a/src/execution/clobber-registers.cc
+++ b/src/execution/clobber-registers.cc
@@ -5,19 +5,22 @@

#include "src/base/build_config.h"

-#if V8_HOST_ARCH_ARM
+// Check both {HOST_ARCH} and {TARGET_ARCH} to disable the functionality of this
+// file for cross-compilation. The reason is that the inline assembly code below
+// does not work for cross-compilation.
+#if V8_HOST_ARCH_ARM && V8_TARGET_ARCH_ARM
#include "src/codegen/arm/register-arm.h"
-#elif V8_HOST_ARCH_ARM64
+#elif V8_HOST_ARCH_ARM64 && V8_TARGET_ARCH_ARM64
#include "src/codegen/arm64/register-arm64.h"
-#elif V8_HOST_ARCH_IA32
+#elif V8_HOST_ARCH_IA32 && V8_TARGET_ARCH_IA32
#include "src/codegen/ia32/register-ia32.h"
-#elif V8_HOST_ARCH_X64
+#elif V8_HOST_ARCH_X64 && V8_TARGET_ARCH_X64
#include "src/codegen/x64/register-x64.h"
-#elif V8_HOST_ARCH_LOONG64
+#elif V8_HOST_ARCH_LOONG64 && V8_TARGET_ARCH_LOONG64
#include "src/codegen/loong64/register-loong64.h"
-#elif V8_HOST_ARCH_MIPS
+#elif V8_HOST_ARCH_MIPS && V8_TARGET_ARCH_MIPS
#include "src/codegen/mips/register-mips.h"
-#elif V8_HOST_ARCH_MIPS64
+#elif V8_HOST_ARCH_MIPS64 && V8_TARGET_ARCH_MIPS64
#include "src/codegen/mips64/register-mips64.h"
#endif

@@ -26,14 +29,15 @@ namespace internal {

#if V8_CC_MSVC
// msvc only support inline assembly on x86
-#if V8_HOST_ARCH_IA32
+#if V8_HOST_ARCH_IA32 && V8_TARGET_ARCH_IA32
#define CLOBBER_REGISTER(R) __asm xorps R, R

#endif

#else // !V8_CC_MSVC

-#if V8_HOST_ARCH_X64 || V8_HOST_ARCH_IA32
+#if (V8_HOST_ARCH_X64 && V8_TARGET_ARCH_X64) || \
+ (V8_HOST_ARCH_IA32 && V8_TARGET_ARCH_IA32)
#define CLOBBER_REGISTER(R) \
__asm__ volatile( \
"xorps " \
@@ -42,20 +46,19 @@ namespace internal {
"%%" #R :: \
:);

-#elif V8_HOST_ARCH_ARM64
+#elif V8_HOST_ARCH_ARM64 && V8_TARGET_ARCH_ARM64
#define CLOBBER_REGISTER(R) __asm__ volatile("fmov " #R ",xzr" :::);

-#elif V8_HOST_ARCH_LOONG64
+#elif V8_HOST_ARCH_LOONG64 && V8_TARGET_ARCH_LOONG64
#define CLOBBER_REGISTER(R) __asm__ volatile("movgr2fr.d $" #R ",$zero" :::);

-#elif V8_HOST_ARCH_MIPS
+#elif V8_HOST_ARCH_MIPS && V8_TARGET_ARCH_MIPS
#define CLOBBER_USE_REGISTER(R) __asm__ volatile("mtc1 $zero,$" #R :::);

-#elif V8_HOST_ARCH_MIPS64
+#elif V8_HOST_ARCH_MIPS64 && V8_TARGET_ARCH_MIPS64
#define CLOBBER_USE_REGISTER(R) __asm__ volatile("dmtc1 $zero,$" #R :::);

-#endif // V8_HOST_ARCH_X64 || V8_HOST_ARCH_IA32 || V8_HOST_ARCH_ARM64 ||
- // V8_HOST_ARCH_LOONG64 || V8_HOST_ARCH_MIPS || V8_HOST_ARCH_MIPS64
+#endif // V8_HOST_ARCH_XXX && V8_TARGET_ARCH_XXX

#endif // V8_CC_MSVC

diff --git a/src/objects/simd.cc b/src/objects/simd.cc
index 0a73b9c686..be6b72d157 100644
--- a/src/objects/simd.cc
+++ b/src/objects/simd.cc
@@ -354,8 +354,13 @@ Address ArrayIndexOfIncludes(Address array_start, uintptr_t array_len,
if (reinterpret_cast<uintptr_t>(array) % sizeof(double) != 0) {
// Slow scalar search for unaligned double array.
for (; from_index < array_len; from_index++) {
- if (fixed_array.get_representation(static_cast<int>(from_index)) ==
- *reinterpret_cast<uint64_t*>(&search_num)) {
+ if (fixed_array.is_the_hole(static_cast<int>(from_index))) {
+ // |search_num| cannot be NaN, so there is no need to check against
+ // holes.
+ continue;
+ }
+ if (fixed_array.get_scalar(static_cast<int>(from_index)) ==
+ search_num) {
return from_index;
}
}
diff --git a/src/objects/simd.cc b/src/objects/simd.cc
index d3cedfe330..0a73b9c686 100644
--- a/src/objects/simd.cc
+++ b/src/objects/simd.cc
@@ -95,24 +95,21 @@ inline int extract_first_nonzero_index(T v) {
}

template <>
-inline int extract_first_nonzero_index(int32x4_t v) {
- int32x4_t mask = {4, 3, 2, 1};
+inline int extract_first_nonzero_index(uint32x4_t v) {
+ uint32x4_t mask = {4, 3, 2, 1};
mask = vandq_u32(mask, v);
return 4 - vmaxvq_u32(mask);
}

template <>
-inline int extract_first_nonzero_index(int64x2_t v) {
- int32x4_t mask = {2, 0, 1, 0}; // Could also be {2,2,1,1} or {0,2,0,1}
- mask = vandq_u32(mask, vreinterpretq_s32_s64(v));
+inline int extract_first_nonzero_index(uint64x2_t v) {
+ uint32x4_t mask = {2, 0, 1, 0}; // Could also be {2,2,1,1} or {0,2,0,1}
+ mask = vandq_u32(mask, vreinterpretq_u32_u64(v));
return 2 - vmaxvq_u32(mask);
}

-template <>
-inline int extract_first_nonzero_index(float64x2_t v) {
- int32x4_t mask = {2, 0, 1, 0}; // Could also be {2,2,1,1} or {0,2,0,1}
- mask = vandq_u32(mask, vreinterpretq_s32_f64(v));
- return 2 - vmaxvq_u32(mask);
+inline int32_t reinterpret_vmaxvq_u64(uint64x2_t v) {
+ return vmaxvq_u32(vreinterpretq_u32_u64(v));
}
#endif

@@ -204,14 +201,14 @@ inline uintptr_t fast_search_noavx(T* array, uintptr_t array_len,
}
#elif defined(NEON64)
if constexpr (std::is_same<T, uint32_t>::value) {
- VECTORIZED_LOOP_Neon(int32x4_t, int32x4_t, vdupq_n_u32, vceqq_u32,
+ VECTORIZED_LOOP_Neon(uint32x4_t, uint32x4_t, vdupq_n_u32, vceqq_u32,
vmaxvq_u32)
} else if constexpr (std::is_same<T, uint64_t>::value) {
- VECTORIZED_LOOP_Neon(int64x2_t, int64x2_t, vdupq_n_u64, vceqq_u64,
- vmaxvq_u32)
+ VECTORIZED_LOOP_Neon(uint64x2_t, uint64x2_t, vdupq_n_u64, vceqq_u64,
+ reinterpret_vmaxvq_u64)
} else if constexpr (std::is_same<T, double>::value) {
- VECTORIZED_LOOP_Neon(float64x2_t, float64x2_t, vdupq_n_f64, vceqq_f64,
- vmaxvq_f64)
+ VECTORIZED_LOOP_Neon(float64x2_t, uint64x2_t, vdupq_n_f64, vceqq_f64,
+ reinterpret_vmaxvq_u64)
}
#else
UNREACHABLE();
diff --git a/src/objects/simd.cc b/src/objects/simd.cc
index be6b72d157..a71968fd10 100644
--- a/src/objects/simd.cc
+++ b/src/objects/simd.cc
@@ -148,9 +148,14 @@ inline int32_t reinterpret_vmaxvq_u64(uint64x2_t v) {
template <typename T>
inline uintptr_t fast_search_noavx(T* array, uintptr_t array_len,
uintptr_t index, T search_element) {
- static_assert(std::is_same<T, uint32_t>::value ||
- std::is_same<T, uint64_t>::value ||
- std::is_same<T, double>::value);
+ static constexpr bool is_uint32 =
+ sizeof(T) == sizeof(uint32_t) && std::is_integral<T>::value;
+ static constexpr bool is_uint64 =
+ sizeof(T) == sizeof(uint64_t) && std::is_integral<T>::value;
+ static constexpr bool is_double =
+ sizeof(T) == sizeof(double) && std::is_floating_point<T>::value;
+
+ static_assert(is_uint32 || is_uint64 || is_double);

#if !(defined(__SSE3__) || defined(NEON64))
// No SIMD available.
@@ -178,14 +183,14 @@ inline uintptr_t fast_search_noavx(T* array, uintptr_t array_len,

// Inserting one of the vectorized loop
#ifdef __SSE3__
- if constexpr (std::is_same<T, uint32_t>::value) {
+ if constexpr (is_uint32) {
#define MOVEMASK(x) _mm_movemask_ps(_mm_castsi128_ps(x))
#define EXTRACT(x) base::bits::CountTrailingZeros32(x)
VECTORIZED_LOOP_x86(__m128i, __m128i, _mm_set1_epi32, _mm_cmpeq_epi32,
MOVEMASK, EXTRACT)
#undef MOVEMASK
#undef EXTRACT
- } else if constexpr (std::is_same<T, uint64_t>::value) {
+ } else if constexpr (is_uint64) {
#define SET1(x) _mm_castsi128_ps(_mm_set1_epi64x(x))
#define CMP(a, b) _mm_cmpeq_pd(_mm_castps_pd(a), _mm_castps_pd(b))
#define EXTRACT(x) base::bits::CountTrailingZeros32(x)
@@ -193,20 +198,20 @@ inline uintptr_t fast_search_noavx(T* array, uintptr_t array_len,
#undef SET1
#undef CMP
#undef EXTRACT
- } else if constexpr (std::is_same<T, double>::value) {
+ } else if constexpr (is_double) {
#define EXTRACT(x) base::bits::CountTrailingZeros32(x)
VECTORIZED_LOOP_x86(__m128d, __m128d, _mm_set1_pd, _mm_cmpeq_pd,
_mm_movemask_pd, EXTRACT)
#undef EXTRACT
}
#elif defined(NEON64)
- if constexpr (std::is_same<T, uint32_t>::value) {
+ if constexpr (is_uint32) {
VECTORIZED_LOOP_Neon(uint32x4_t, uint32x4_t, vdupq_n_u32, vceqq_u32,
vmaxvq_u32)
- } else if constexpr (std::is_same<T, uint64_t>::value) {
+ } else if constexpr (is_uint64) {
VECTORIZED_LOOP_Neon(uint64x2_t, uint64x2_t, vdupq_n_u64, vceqq_u64,
reinterpret_vmaxvq_u64)
- } else if constexpr (std::is_same<T, double>::value) {
+ } else if constexpr (is_double) {
VECTORIZED_LOOP_Neon(float64x2_t, uint64x2_t, vdupq_n_f64, vceqq_f64,
reinterpret_vmaxvq_u64)
}
@@ -240,9 +245,14 @@ template <typename T>
TARGET_AVX2 inline uintptr_t fast_search_avx(T* array, uintptr_t array_len,
uintptr_t index,
T search_element) {
- static_assert(std::is_same<T, uint32_t>::value ||
- std::is_same<T, uint64_t>::value ||
- std::is_same<T, double>::value);
+ static constexpr bool is_uint32 =
+ sizeof(T) == sizeof(uint32_t) && std::is_integral<T>::value;
+ static constexpr bool is_uint64 =
+ sizeof(T) == sizeof(uint64_t) && std::is_integral<T>::value;
+ static constexpr bool is_double =
+ sizeof(T) == sizeof(double) && std::is_floating_point<T>::value;
+
+ static_assert(is_uint32 || is_uint64 || is_double);

const int target_align = 32;
// Scalar loop to reach desired alignment
@@ -256,21 +266,21 @@ TARGET_AVX2 inline uintptr_t fast_search_avx(T* array, uintptr_t array_len,
}

// Generating vectorized loop
- if constexpr (std::is_same<T, uint32_t>::value) {
+ if constexpr (is_uint32) {
#define MOVEMASK(x) _mm256_movemask_ps(_mm256_castsi256_ps(x))
#define EXTRACT(x) base::bits::CountTrailingZeros32(x)
VECTORIZED_LOOP_x86(__m256i, __m256i, _mm256_set1_epi32, _mm256_cmpeq_epi32,
MOVEMASK, EXTRACT)
#undef MOVEMASK
#undef EXTRACT
- } else if constexpr (std::is_same<T, uint64_t>::value) {
+ } else if constexpr (is_uint64) {
#define MOVEMASK(x) _mm256_movemask_pd(_mm256_castsi256_pd(x))
#define EXTRACT(x) base::bits::CountTrailingZeros32(x)
VECTORIZED_LOOP_x86(__m256i, __m256i, _mm256_set1_epi64x,
_mm256_cmpeq_epi64, MOVEMASK, EXTRACT)
#undef MOVEMASK
#undef EXTRACT
- } else if constexpr (std::is_same<T, double>::value) {
+ } else if constexpr (is_double) {
#define CMP(a, b) _mm256_cmp_pd(a, b, _CMP_EQ_OQ)
#define EXTRACT(x) base::bits::CountTrailingZeros32(x)
VECTORIZED_LOOP_x86(__m256d, __m256d, _mm256_set1_pd, CMP,
1 change: 1 addition & 0 deletions test/tools/wee8_compile/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ envoy_cc_library(
name = "wee8_compile_lib",
srcs = ["wee8_compile.cc"],
copts = [
"-Wno-comments",
"-Wno-non-virtual-dtor",
"-Wno-unused-parameter",
],
Expand Down
Loading