Provide a default implementation of QuicPrefetch().
The new implementation is based on the one used in Chrome; it's the same as the one used in google3, but with MSVC support.
PiperOrigin-RevId: 373573478
diff --git a/quic/platform/api/quic_prefetch.h b/common/platform/api/quiche_prefetch.h
similarity index 75%
rename from quic/platform/api/quic_prefetch.h
rename to common/platform/api/quiche_prefetch.h
index 49dbe48..706a709 100644
--- a/quic/platform/api/quic_prefetch.h
+++ b/common/platform/api/quiche_prefetch.h
@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef QUICHE_QUIC_PLATFORM_API_QUIC_PREFETCH_H_
-#define QUICHE_QUIC_PLATFORM_API_QUIC_PREFETCH_H_
+#ifndef QUICHE_COMMON_PLATFORM_API_QUICHE_PREFETCH_H_
+#define QUICHE_COMMON_PLATFORM_API_QUICHE_PREFETCH_H_
-#include "net/quic/platform/impl/quic_prefetch_impl.h"
+#include "quiche_platform_impl/quiche_prefetch_impl.h"
-namespace quic {
+namespace quiche {
// Move data into the cache before it is read, or "prefetch" it.
//
@@ -30,10 +30,10 @@
// performance, so use them only when representative benchmarks show
// an improvement.
-inline void QuicPrefetchT0(const void* addr) {
- return QuicPrefetchT0Impl(addr);
+inline void QuichePrefetchT0(const void* addr) {
+ return QuichePrefetchT0Impl(addr);
}
-} // namespace quic
+} // namespace quiche
-#endif // QUICHE_QUIC_PLATFORM_API_QUIC_PREFETCH_H_
+#endif // QUICHE_COMMON_PLATFORM_API_QUICHE_PREFETCH_H_
diff --git a/common/platform/default/quiche_platform_impl/quiche_prefetch_impl.h b/common/platform/default/quiche_platform_impl/quiche_prefetch_impl.h
new file mode 100644
index 0000000..8945481
--- /dev/null
+++ b/common/platform/default/quiche_platform_impl/quiche_prefetch_impl.h
@@ -0,0 +1,28 @@
+// Copyright 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef QUICHE_COMMON_PLATFORM_DEFAULT_QUICHE_PLATFORM_IMPL_QUICHE_PREFETCH_IMPL_H_
+#define QUICHE_COMMON_PLATFORM_DEFAULT_QUICHE_PLATFORM_IMPL_QUICHE_PREFETCH_IMPL_H_
+
+#if defined(_MSC_VER)
+#include <intrin.h>
+#endif
+
+namespace quiche {
+
+inline void QuichePrefetchT0Impl(const void* addr) {
+#if !defined(DISABLE_BUILTIN_PREFETCH)
+#if defined(__GNUC__) || (defined(_M_ARM64) && defined(__clang__))
+ __builtin_prefetch(addr, 0, 3);
+#elif defined(_MSC_VER)
+ _mm_prefetch(reinterpret_cast<const char*>(addr), _MM_HINT_T0);
+#else
+ (void*)addr;
+#endif
+#endif // !defined(DISABLE_BUILTIN_PREFETCH)
+}
+
+} // namespace quiche
+
+#endif // QUICHE_COMMON_PLATFORM_DEFAULT_QUICHE_PLATFORM_IMPL_QUICHE_PREFETCH_IMPL_H_
diff --git a/quic/core/quic_utils.cc b/quic/core/quic_utils.cc
index 1a79dca..1f0137a 100644
--- a/quic/core/quic_utils.cc
+++ b/quic/core/quic_utils.cc
@@ -21,8 +21,8 @@
#include "quic/platform/api/quic_bug_tracker.h"
#include "quic/platform/api/quic_flag_utils.h"
#include "quic/platform/api/quic_flags.h"
-#include "quic/platform/api/quic_prefetch.h"
#include "common/platform/api/quiche_logging.h"
+#include "common/platform/api/quiche_prefetch.h"
#include "common/quiche_endian.h"
namespace quic {
@@ -266,9 +266,9 @@
char* next_base = static_cast<char*>(iov[iovnum + 1].iov_base);
// Prefetch 2 cachelines worth of data to get the prefetcher started; leave
// it to the hardware prefetcher after that.
- QuicPrefetchT0(next_base);
+ quiche::QuichePrefetchT0(next_base);
if (iov[iovnum + 1].iov_len >= 64) {
- QuicPrefetchT0(next_base + ABSL_CACHELINE_SIZE);
+ quiche::QuichePrefetchT0(next_base + ABSL_CACHELINE_SIZE);
}
}