From f36dbd2b333137f2ed88edbc3f1cc1080568de3f Mon Sep 17 00:00:00 2001 From: Margen67 Date: Fri, 25 Jul 2025 17:28:25 -0700 Subject: [PATCH] [3PP] Switch to zlib-ng --- .gitmodules | 7 ++-- premake5.lua | 2 +- src/xenia/kernel/premake5.lua | 17 ++++++++- src/xenia/kernel/util/xlast.cc | 12 +++---- third_party/zlib | 1 - third_party/zlib-ng | 1 + third_party/zlib-ng.lua | 63 ++++++++++++++++++++++++++++++++++ third_party/zlib.lua | 16 --------- 8 files changed, 91 insertions(+), 28 deletions(-) delete mode 160000 third_party/zlib create mode 160000 third_party/zlib-ng create mode 100644 third_party/zlib-ng.lua delete mode 100644 third_party/zlib.lua diff --git a/.gitmodules b/.gitmodules index 0790831e2..2502770d6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -98,9 +98,10 @@ [submodule "third_party/rapidcsv"] path = third_party/rapidcsv url = https://github.com/d99kris/rapidcsv.git -[submodule "third_party/zlib"] - path = third_party/zlib - url = https://github.com/madler/zlib.git +[submodule "third_party/zlib-ng"] + path = third_party/zlib-ng + url = https://github.com/zlib-ng/zlib-ng.git + ignore = dirty [submodule "third_party/pugixml"] path = third_party/pugixml url = https://github.com/zeux/pugixml.git diff --git a/premake5.lua b/premake5.lua index 548140fb9..6a4c9c986 100644 --- a/premake5.lua +++ b/premake5.lua @@ -300,7 +300,7 @@ workspace("xenia") include("third_party/xxhash.lua") include("third_party/zarchive.lua") include("third_party/zstd.lua") - include("third_party/zlib.lua") + include("third_party/zlib-ng.lua") include("third_party/pugixml.lua") if os.istarget("windows") then diff --git a/src/xenia/kernel/premake5.lua b/src/xenia/kernel/premake5.lua index bd00330bc..f478c9f22 100644 --- a/src/xenia/kernel/premake5.lua +++ b/src/xenia/kernel/premake5.lua @@ -9,7 +9,7 @@ project("xenia-kernel") links({ "aes_128", "fmt", - "zlib", + "zlib-ng", "pugixml", "xenia-apu", "xenia-base", @@ -18,7 +18,22 @@ project("xenia-kernel") "xenia-vfs", }) defines({ + "X86_FEATURES", + "X86_HAVE_XSAVE_INTRIN", + "X86_SSSE3", + "X86_SSE42", + "WITH_GZFILEOP", }) + if os.istarget("windows") then + defines({ + "X86_SSE2", + "X86_AVX2", + "X86_AVX512", + "X86_AVX512VNNI", + "X86_PCLMULQDQ_CRC", + "X86_VPCLMULQDQ_CRC", + }) + end recursive_platform_files() files({ "debug_visualizers.natvis", diff --git a/src/xenia/kernel/util/xlast.cc b/src/xenia/kernel/util/xlast.cc index ab5e68afa..20b7c878d 100644 --- a/src/xenia/kernel/util/xlast.cc +++ b/src/xenia/kernel/util/xlast.cc @@ -8,7 +8,7 @@ */ #include "xenia/kernel/util/xlast.h" -#include "third_party/zlib/zlib.h" +#include "third_party/zlib-ng/zlib-ng.h" #include "xenia/base/filesystem.h" #include "xenia/base/logging.h" #include "xenia/base/string_util.h" @@ -50,14 +50,14 @@ XLast::XLast(const uint8_t* compressed_xml_data, parsed_xlast_ = std::make_unique(); xlast_decompressed_xml_.resize(decompressed_data_size); - z_stream stream; + zng_stream stream; stream.zalloc = Z_NULL; stream.zfree = Z_NULL; stream.opaque = Z_NULL; stream.avail_in = 0; stream.next_in = Z_NULL; - int ret = inflateInit2( + int ret = zng_inflateInit2( &stream, 16 + MAX_WBITS); // 16 + MAX_WBITS enables gzip decoding if (ret != Z_OK) { XELOGE("XLast: Error during Zlib stream init"); @@ -70,13 +70,13 @@ XLast::XLast(const uint8_t* compressed_xml_data, stream.avail_out = decompressed_data_size; stream.next_out = reinterpret_cast(xlast_decompressed_xml_.data()); - ret = inflate(&stream, Z_NO_FLUSH); + ret = zng_inflate(&stream, Z_NO_FLUSH); if (ret == Z_STREAM_ERROR) { XELOGE("XLast: Error during XLast decompression"); - inflateEnd(&stream); + zng_inflateEnd(&stream); return; } - inflateEnd(&stream); + zng_inflateEnd(&stream); parse_result_ = parsed_xlast_->load_buffer(xlast_decompressed_xml_.data(), xlast_decompressed_xml_.size()); diff --git a/third_party/zlib b/third_party/zlib deleted file mode 160000 index 51b7f2abd..000000000 --- a/third_party/zlib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf diff --git a/third_party/zlib-ng b/third_party/zlib-ng new file mode 160000 index 000000000..860e4cff7 --- /dev/null +++ b/third_party/zlib-ng @@ -0,0 +1 @@ +Subproject commit 860e4cff7917d93f54f5d7f0bc1d0e8b1a3cb988 diff --git a/third_party/zlib-ng.lua b/third_party/zlib-ng.lua new file mode 100644 index 000000000..9884307c2 --- /dev/null +++ b/third_party/zlib-ng.lua @@ -0,0 +1,63 @@ +group("third_party") +project("zlib-ng") + uuid("13d4073d-f1c9-47e3-a057-79b133596fc2") + kind("StaticLib") + language("C") + + defines({ + "X86_FEATURES", + "X86_HAVE_XSAVE_INTRIN", + "X86_SSSE3", + "X86_SSE42", + "WITH_GZFILEOP", + }) + if os.istarget("windows") then + defines({ + "X86_SSE2", + "X86_AVX2", + "X86_AVX512", + "X86_AVX512VNNI", + "X86_PCLMULQDQ_CRC", + "X86_VPCLMULQDQ_CRC", + }) + end + + files({ + "zlib-ng/*.c", + "zlib-ng/arch/x86/*.c", + "zlib-ng/arch/generic/*.c", + }) + if not os.istarget("windows") then + removefiles({ + "zlib-ng/arch/x86/adler32_avx2.c", + "zlib-ng/arch/x86/adler32_avx512.c", + "zlib-ng/arch/x86/adler32_avx512_vnni.c", + "zlib-ng/arch/x86/chunkset_avx2.c", + "zlib-ng/arch/x86/compare256_avx2.c", + "zlib-ng/arch/x86/crc32_pclmulqdq.c", + "zlib-ng/arch/x86/crc32_vpclmulqdq.c", + "zlib-ng/arch/x86/slide_hash_avx2.c", + }) + end + + includedirs({ + "zlib-ng", + }) + + local zlibng_dir = path.getabsolute("zlib-ng") + local zlibng_h_src_files = { + path.join(zlibng_build_dir, "zlib-ng.h"), + path.join(zlibng_build_dir, "zconf-ng.h"), + path.join(zlibng_build_dir, "zlib_name_mangling-ng.h"), + path.join(zlibng_build_dir, "gzread.c"), + } + for i = 1,#zlibng_h_src_files,1 + do + if not os.isfile(path.join(zlibng_dir, zlibng_h_src_files[i])) then + zlibng_build = true + break + end + end + if zlibng_build then + os.execute("cmake -DZLIB_ENABLE_TESTS=OFF -DWITH_GTEST=OFF "..zlibng_dir.." -B"..zlibng_dir) + end diff --git a/third_party/zlib.lua b/third_party/zlib.lua deleted file mode 100644 index 8471ad8cb..000000000 --- a/third_party/zlib.lua +++ /dev/null @@ -1,16 +0,0 @@ -group("third_party") -project("zlib") - uuid("13d4073d-f1c9-47e3-a057-79b133596fc2") - kind("StaticLib") - language("C") - cdialect("C90") - filter({"toolset:gcc or clang"}) - buildoptions({ - "-Wno-implicit-function-declaration" - }) - filter {} - - files({ - "zlib/*.c", - "zlib/*.h", - }) \ No newline at end of file