summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2024-04-05 22:17:43 +0000
committerElliott Hughes <enh@google.com>2024-04-05 22:17:43 +0000
commit7bb79164ba5b08c6c624320ae5bea45c8c9dd5f4 (patch)
treee42eba1966efa68a64bce372ed8880270b00069b
parentd9645b462b3242da80355218699cb9d2577314cb (diff)
parentd076d8bd089843ae105b1aeeda32dbeb667402ef (diff)
downloadzlib-7bb79164ba5b08c6c624320ae5bea45c8c9dd5f4.tar.gz
Upgrade zlib to d076d8bd089843ae105b1aeeda32dbeb667402ef
This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update external/zlib For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md Test: TreeHugger Change-Id: If13e974ed2ff48552ede5d8f23a5dc7da47d3bec
-rw-r--r--CMakeLists.txt18
-rw-r--r--METADATA6
-rw-r--r--contrib/optimizations/chunkcopy.h75
-rw-r--r--google/compression_utils.cc1
-rw-r--r--google/zip_reader_unittest.cc8
5 files changed, 100 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c3f4247..5db4a6e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -79,9 +79,16 @@ if (ENABLE_SIMD_OPTIMIZATIONS)
add_definitions(-DRISCV_RVV)
add_definitions(-DDEFLATE_SLIDE_HASH_RVV)
add_definitions(-DADLER32_SIMD_RVV)
- #TODO(cavalcantii): add remaining flags as we port optimizations to RVV.
- # Required by CPU features detection code.
- SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --target=riscv64-unknown-linux-gnu -march=rv64gcv")
+
+ # TODO(cavalcantii): add remaining flags as we port optimizations to RVV.
+ # chunk_copy is required for READ64 and unconditional decode of literals.
+ add_definitions(-DINFLATE_CHUNK_GENERIC)
+ add_definitions(-DINFLATE_CHUNK_READ_64LE)
+
+ # Tested with clang-17, unaligned loads are required by read64 & chunk_copy.
+ # TODO(cavalcantii): replace internal clang flags for -munaligned-access
+ # when we have a newer compiler available.
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --target=riscv64-unknown-linux-gnu -march=rv64gcv -Xclang -target-feature -Xclang +unaligned-scalar-mem")
endif()
endif()
@@ -192,9 +199,14 @@ set(ZLIB_SRCS
if (ENABLE_SIMD_OPTIMIZATIONS)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
message("RISCVV: Add optimizations.")
+ list(REMOVE_ITEM ZLIB_SRCS inflate.c)
list(APPEND ZLIB_PRIVATE_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/adler32_simd.h)
+ list(APPEND ZLIB_PRIVATE_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/contrib/optimizations/chunkcopy.h)
list(APPEND ZLIB_PRIVATE_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/cpu_features.h)
+
list(APPEND ZLIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/adler32_simd.c)
+ list(APPEND ZLIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/contrib/optimizations/inffast_chunk.c)
+ list(APPEND ZLIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/contrib/optimizations/inflate.c)
list(APPEND ZLIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/cpu_features.c)
else()
list(REMOVE_ITEM ZLIB_SRCS inflate.c)
diff --git a/METADATA b/METADATA
index 370833b..7196acc 100644
--- a/METADATA
+++ b/METADATA
@@ -8,12 +8,12 @@ third_party {
license_type: NOTICE
last_upgrade_date {
year: 2024
- month: 3
- day: 26
+ month: 4
+ day: 5
}
identifier {
type: "Git"
value: "https://chromium.googlesource.com/chromium/src/third_party/zlib/"
- version: "30bf3a72e77abb71568fa1e6258a0a731fef9ba3"
+ version: "d076d8bd089843ae105b1aeeda32dbeb667402ef"
}
}
diff --git a/contrib/optimizations/chunkcopy.h b/contrib/optimizations/chunkcopy.h
index f40546d..97efff3 100644
--- a/contrib/optimizations/chunkcopy.h
+++ b/contrib/optimizations/chunkcopy.h
@@ -21,8 +21,10 @@
#if defined(__clang__) || defined(__GNUC__) || defined(__llvm__)
#define Z_BUILTIN_MEMCPY __builtin_memcpy
+#define Z_BUILTIN_MEMSET __builtin_memset
#else
#define Z_BUILTIN_MEMCPY zmemcpy
+#define Z_BUILTIN_MEMSET zmemset
#endif
#if defined(INFLATE_CHUNK_SIMD_NEON)
@@ -31,6 +33,8 @@ typedef uint8x16_t z_vec128i_t;
#elif defined(INFLATE_CHUNK_SIMD_SSE2)
#include <emmintrin.h>
typedef __m128i z_vec128i_t;
+#elif defined(INFLATE_CHUNK_GENERIC)
+typedef struct { uint8_t x[16]; } z_vec128i_t;
#else
#error chunkcopy.h inflate chunk SIMD is not defined for your build target
#endif
@@ -265,6 +269,77 @@ static inline z_vec128i_t v_load8_dup(const void* src) {
static inline void v_store_128(void* out, const z_vec128i_t vec) {
_mm_storeu_si128((__m128i*)out, vec);
}
+#elif defined(INFLATE_CHUNK_GENERIC)
+/*
+ * Default implementations for chunk-copy functions rely on memcpy() being
+ * inlined by the compiler for best performance. This is most likely to work
+ * as expected when the length argument is constant (as is the case here) and
+ * the target supports unaligned loads and stores. Since that's not always a
+ * safe assumption, this may need extra compiler arguments such as
+ * `-mno-strict-align` or `-munaligned-access`, or the availability of
+ * extensions like SIMD.
+ */
+
+/*
+ * v_load64_dup(): load *src as an unaligned 64-bit int and duplicate it in
+ * every 64-bit component of the 128-bit result (64-bit int splat).
+ */
+static inline z_vec128i_t v_load64_dup(const void* src) {
+ int64_t in;
+ Z_BUILTIN_MEMCPY(&in, src, sizeof(in));
+ z_vec128i_t out;
+ for (int i = 0; i < sizeof(out); i += sizeof(in)) {
+ Z_BUILTIN_MEMCPY((uint8_t*)&out + i, &in, sizeof(in));
+ }
+ return out;
+}
+
+/*
+ * v_load32_dup(): load *src as an unaligned 32-bit int and duplicate it in
+ * every 32-bit component of the 128-bit result (32-bit int splat).
+ */
+static inline z_vec128i_t v_load32_dup(const void* src) {
+ int32_t in;
+ Z_BUILTIN_MEMCPY(&in, src, sizeof(in));
+ z_vec128i_t out;
+ for (int i = 0; i < sizeof(out); i += sizeof(in)) {
+ Z_BUILTIN_MEMCPY((uint8_t*)&out + i, &in, sizeof(in));
+ }
+ return out;
+}
+
+/*
+ * v_load16_dup(): load *src as an unaligned 16-bit int and duplicate it in
+ * every 16-bit component of the 128-bit result (16-bit int splat).
+ */
+static inline z_vec128i_t v_load16_dup(const void* src) {
+ int16_t in;
+ Z_BUILTIN_MEMCPY(&in, src, sizeof(in));
+ z_vec128i_t out;
+ for (int i = 0; i < sizeof(out); i += sizeof(in)) {
+ Z_BUILTIN_MEMCPY((uint8_t*)&out + i, &in, sizeof(in));
+ }
+ return out;
+}
+
+/*
+ * v_load8_dup(): load the 8-bit int *src and duplicate it in every 8-bit
+ * component of the 128-bit result (8-bit int splat).
+ */
+static inline z_vec128i_t v_load8_dup(const void* src) {
+ int8_t in = *(const uint8_t*)src;
+ z_vec128i_t out;
+ Z_BUILTIN_MEMSET(&out, in, sizeof(out));
+ return out;
+}
+
+/*
+ * v_store_128(): store the 128-bit vec in a memory destination (that might
+ * not be 16-byte aligned) void* out.
+ */
+static inline void v_store_128(void* out, const z_vec128i_t vec) {
+ Z_BUILTIN_MEMCPY(out, &vec, sizeof(vec));
+}
#endif
/*
diff --git a/google/compression_utils.cc b/google/compression_utils.cc
index c2b17e4..0ba3110 100644
--- a/google/compression_utils.cc
+++ b/google/compression_utils.cc
@@ -6,7 +6,6 @@
#include "base/check_op.h"
#include "base/process/memory.h"
-#include "base/sys_byteorder.h"
#include "third_party/zlib/google/compression_utils_portable.h"
diff --git a/google/zip_reader_unittest.cc b/google/zip_reader_unittest.cc
index e6f89d7..9eb7d7d 100644
--- a/google/zip_reader_unittest.cc
+++ b/google/zip_reader_unittest.cc
@@ -72,7 +72,7 @@ class FileWrapper {
// A mock that provides methods that can be used as callbacks in asynchronous
// unzip functions. Tracks the number of calls and number of bytes reported.
// Assumes that progress callbacks will be executed in-order.
-class MockUnzipListener : public base::SupportsWeakPtr<MockUnzipListener> {
+class MockUnzipListener final {
public:
MockUnzipListener()
: success_calls_(0),
@@ -98,12 +98,18 @@ class MockUnzipListener : public base::SupportsWeakPtr<MockUnzipListener> {
int progress_calls() { return progress_calls_; }
int current_progress() { return current_progress_; }
+ base::WeakPtr<MockUnzipListener> AsWeakPtr() {
+ return weak_ptr_factory_.GetWeakPtr();
+ }
+
private:
int success_calls_;
int failure_calls_;
int progress_calls_;
int64_t current_progress_;
+
+ base::WeakPtrFactory<MockUnzipListener> weak_ptr_factory_{this};
};
class MockWriterDelegate : public zip::WriterDelegate {