aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/lzma/liblzma/simple
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2023-01-05 21:33:07 +0300
committershadchin <shadchin@yandex-team.com>2023-01-05 21:33:07 +0300
commit97c1b4fc326f4a9435bc743e56681bb148b17c37 (patch)
treec7d8dd514d722f747f5c6584343aeeddd5d2f8be /contrib/libs/lzma/liblzma/simple
parentd7b4c95518652104d51c915f0fd20fd3e954135c (diff)
downloadydb-97c1b4fc326f4a9435bc743e56681bb148b17c37.tar.gz
Update contrib/libs/lzma to 5.4.0
Diffstat (limited to 'contrib/libs/lzma/liblzma/simple')
-rw-r--r--contrib/libs/lzma/liblzma/simple/arm.c4
-rw-r--r--contrib/libs/lzma/liblzma/simple/arm64.c136
-rw-r--r--contrib/libs/lzma/liblzma/simple/armthumb.c4
-rw-r--r--contrib/libs/lzma/liblzma/simple/ia64.c4
-rw-r--r--contrib/libs/lzma/liblzma/simple/powerpc.c4
-rw-r--r--contrib/libs/lzma/liblzma/simple/simple_coder.h9
-rw-r--r--contrib/libs/lzma/liblzma/simple/sparc.c4
-rw-r--r--contrib/libs/lzma/liblzma/simple/x86.c4
8 files changed, 169 insertions, 0 deletions
diff --git a/contrib/libs/lzma/liblzma/simple/arm.c b/contrib/libs/lzma/liblzma/simple/arm.c
index ff5073ae58..6e53970d2f 100644
--- a/contrib/libs/lzma/liblzma/simple/arm.c
+++ b/contrib/libs/lzma/liblzma/simple/arm.c
@@ -53,6 +53,7 @@ arm_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
}
+#ifdef HAVE_ENCODER_ARM
extern lzma_ret
lzma_simple_arm_encoder_init(lzma_next_coder *next,
const lzma_allocator *allocator,
@@ -60,8 +61,10 @@ lzma_simple_arm_encoder_init(lzma_next_coder *next,
{
return arm_coder_init(next, allocator, filters, true);
}
+#endif
+#ifdef HAVE_DECODER_ARM
extern lzma_ret
lzma_simple_arm_decoder_init(lzma_next_coder *next,
const lzma_allocator *allocator,
@@ -69,3 +72,4 @@ lzma_simple_arm_decoder_init(lzma_next_coder *next,
{
return arm_coder_init(next, allocator, filters, false);
}
+#endif
diff --git a/contrib/libs/lzma/liblzma/simple/arm64.c b/contrib/libs/lzma/liblzma/simple/arm64.c
new file mode 100644
index 0000000000..5e7f26562d
--- /dev/null
+++ b/contrib/libs/lzma/liblzma/simple/arm64.c
@@ -0,0 +1,136 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file arm64.c
+/// \brief Filter for ARM64 binaries
+///
+/// This converts ARM64 relative addresses in the BL and ADRP immediates
+/// to absolute values to increase redundancy of ARM64 code.
+///
+/// Converting B or ADR instructions was also tested but it's not useful.
+/// A majority of the jumps for the B instruction are very small (+/- 0xFF).
+/// These are typical for loops and if-statements. Encoding them to their
+/// absolute address reduces redundancy since many of the small relative
+/// jump values are repeated, but very few of the absolute addresses are.
+//
+// Authors: Lasse Collin
+// Jia Tan
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "simple_private.h"
+
+
+static size_t
+arm64_code(void *simple lzma_attribute((__unused__)),
+ uint32_t now_pos, bool is_encoder,
+ uint8_t *buffer, size_t size)
+{
+ size_t i;
+
+ // Clang 14.0.6 on x86-64 makes this four times bigger and 40 % slower
+ // with auto-vectorization that is enabled by default with -O2.
+ // Such vectorization bloat happens with -O2 when targeting ARM64 too
+ // but performance hasn't been tested.
+#ifdef __clang__
+# pragma clang loop vectorize(disable)
+#endif
+ for (i = 0; i + 4 <= size; i += 4) {
+ uint32_t pc = (uint32_t)(now_pos + i);
+ uint32_t instr = read32le(buffer + i);
+
+ if ((instr >> 26) == 0x25) {
+ // BL instruction:
+ // The full 26-bit immediate is converted.
+ // The range is +/-128 MiB.
+ //
+ // Using the full range is helps quite a lot with
+ // big executables. Smaller range would reduce false
+ // positives in non-code sections of the input though
+ // so this is a compromise that slightly favors big
+ // files. With the full range only six bits of the 32
+ // need to match to trigger a conversion.
+ const uint32_t src = instr;
+ instr = 0x94000000;
+
+ pc >>= 2;
+ if (!is_encoder)
+ pc = 0U - pc;
+
+ instr |= (src + pc) & 0x03FFFFFF;
+ write32le(buffer + i, instr);
+
+ } else if ((instr & 0x9F000000) == 0x90000000) {
+ // ADRP instruction:
+ // Only values in the range +/-512 MiB are converted.
+ //
+ // Using less than the full +/-4 GiB range reduces
+ // false positives on non-code sections of the input
+ // while being excellent for executables up to 512 MiB.
+ // The positive effect of ADRP conversion is smaller
+ // than that of BL but it also doesn't hurt so much in
+ // non-code sections of input because, with +/-512 MiB
+ // range, nine bits of 32 need to match to trigger a
+ // conversion (two 10-bit match choices = 9 bits).
+ const uint32_t src = ((instr >> 29) & 3)
+ | ((instr >> 3) & 0x001FFFFC);
+
+ // With the addition only one branch is needed to
+ // check the +/- range. This is usually false when
+ // processing ARM64 code so branch prediction will
+ // handle it well in terms of performance.
+ //
+ //if ((src & 0x001E0000) != 0
+ // && (src & 0x001E0000) != 0x001E0000)
+ if ((src + 0x00020000) & 0x001C0000)
+ continue;
+
+ instr &= 0x9000001F;
+
+ pc >>= 12;
+ if (!is_encoder)
+ pc = 0U - pc;
+
+ const uint32_t dest = src + pc;
+ instr |= (dest & 3) << 29;
+ instr |= (dest & 0x0003FFFC) << 3;
+ instr |= (0U - (dest & 0x00020000)) & 0x00E00000;
+ write32le(buffer + i, instr);
+ }
+ }
+
+ return i;
+}
+
+
+static lzma_ret
+arm64_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
+ const lzma_filter_info *filters, bool is_encoder)
+{
+ return lzma_simple_coder_init(next, allocator, filters,
+ &arm64_code, 0, 4, 4, is_encoder);
+}
+
+
+#ifdef HAVE_ENCODER_ARM64
+extern lzma_ret
+lzma_simple_arm64_encoder_init(lzma_next_coder *next,
+ const lzma_allocator *allocator,
+ const lzma_filter_info *filters)
+{
+ return arm64_coder_init(next, allocator, filters, true);
+}
+#endif
+
+
+#ifdef HAVE_DECODER_ARM64
+extern lzma_ret
+lzma_simple_arm64_decoder_init(lzma_next_coder *next,
+ const lzma_allocator *allocator,
+ const lzma_filter_info *filters)
+{
+ return arm64_coder_init(next, allocator, filters, false);
+}
+#endif
diff --git a/contrib/libs/lzma/liblzma/simple/armthumb.c b/contrib/libs/lzma/liblzma/simple/armthumb.c
index a8da334a04..25d8dbd4f3 100644
--- a/contrib/libs/lzma/liblzma/simple/armthumb.c
+++ b/contrib/libs/lzma/liblzma/simple/armthumb.c
@@ -58,6 +58,7 @@ armthumb_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
}
+#ifdef HAVE_ENCODER_ARMTHUMB
extern lzma_ret
lzma_simple_armthumb_encoder_init(lzma_next_coder *next,
const lzma_allocator *allocator,
@@ -65,8 +66,10 @@ lzma_simple_armthumb_encoder_init(lzma_next_coder *next,
{
return armthumb_coder_init(next, allocator, filters, true);
}
+#endif
+#ifdef HAVE_DECODER_ARMTHUMB
extern lzma_ret
lzma_simple_armthumb_decoder_init(lzma_next_coder *next,
const lzma_allocator *allocator,
@@ -74,3 +77,4 @@ lzma_simple_armthumb_decoder_init(lzma_next_coder *next,
{
return armthumb_coder_init(next, allocator, filters, false);
}
+#endif
diff --git a/contrib/libs/lzma/liblzma/simple/ia64.c b/contrib/libs/lzma/liblzma/simple/ia64.c
index 6492d0a384..692b0a295e 100644
--- a/contrib/libs/lzma/liblzma/simple/ia64.c
+++ b/contrib/libs/lzma/liblzma/simple/ia64.c
@@ -94,6 +94,7 @@ ia64_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
}
+#ifdef HAVE_ENCODER_IA64
extern lzma_ret
lzma_simple_ia64_encoder_init(lzma_next_coder *next,
const lzma_allocator *allocator,
@@ -101,8 +102,10 @@ lzma_simple_ia64_encoder_init(lzma_next_coder *next,
{
return ia64_coder_init(next, allocator, filters, true);
}
+#endif
+#ifdef HAVE_DECODER_IA64
extern lzma_ret
lzma_simple_ia64_decoder_init(lzma_next_coder *next,
const lzma_allocator *allocator,
@@ -110,3 +113,4 @@ lzma_simple_ia64_decoder_init(lzma_next_coder *next,
{
return ia64_coder_init(next, allocator, filters, false);
}
+#endif
diff --git a/contrib/libs/lzma/liblzma/simple/powerpc.c b/contrib/libs/lzma/liblzma/simple/powerpc.c
index 0b60e9b3fe..3a340fd171 100644
--- a/contrib/libs/lzma/liblzma/simple/powerpc.c
+++ b/contrib/libs/lzma/liblzma/simple/powerpc.c
@@ -58,6 +58,7 @@ powerpc_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
}
+#ifdef HAVE_ENCODER_POWERPC
extern lzma_ret
lzma_simple_powerpc_encoder_init(lzma_next_coder *next,
const lzma_allocator *allocator,
@@ -65,8 +66,10 @@ lzma_simple_powerpc_encoder_init(lzma_next_coder *next,
{
return powerpc_coder_init(next, allocator, filters, true);
}
+#endif
+#ifdef HAVE_DECODER_POWERPC
extern lzma_ret
lzma_simple_powerpc_decoder_init(lzma_next_coder *next,
const lzma_allocator *allocator,
@@ -74,3 +77,4 @@ lzma_simple_powerpc_decoder_init(lzma_next_coder *next,
{
return powerpc_coder_init(next, allocator, filters, false);
}
+#endif
diff --git a/contrib/libs/lzma/liblzma/simple/simple_coder.h b/contrib/libs/lzma/liblzma/simple/simple_coder.h
index 19c2ee03af..668a5092ad 100644
--- a/contrib/libs/lzma/liblzma/simple/simple_coder.h
+++ b/contrib/libs/lzma/liblzma/simple/simple_coder.h
@@ -61,6 +61,15 @@ extern lzma_ret lzma_simple_armthumb_decoder_init(lzma_next_coder *next,
const lzma_filter_info *filters);
+extern lzma_ret lzma_simple_arm64_encoder_init(lzma_next_coder *next,
+ const lzma_allocator *allocator,
+ const lzma_filter_info *filters);
+
+extern lzma_ret lzma_simple_arm64_decoder_init(lzma_next_coder *next,
+ const lzma_allocator *allocator,
+ const lzma_filter_info *filters);
+
+
extern lzma_ret lzma_simple_sparc_encoder_init(lzma_next_coder *next,
const lzma_allocator *allocator,
const lzma_filter_info *filters);
diff --git a/contrib/libs/lzma/liblzma/simple/sparc.c b/contrib/libs/lzma/liblzma/simple/sparc.c
index 74b2655f36..bad8492ebc 100644
--- a/contrib/libs/lzma/liblzma/simple/sparc.c
+++ b/contrib/libs/lzma/liblzma/simple/sparc.c
@@ -65,6 +65,7 @@ sparc_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
}
+#ifdef HAVE_ENCODER_SPARC
extern lzma_ret
lzma_simple_sparc_encoder_init(lzma_next_coder *next,
const lzma_allocator *allocator,
@@ -72,8 +73,10 @@ lzma_simple_sparc_encoder_init(lzma_next_coder *next,
{
return sparc_coder_init(next, allocator, filters, true);
}
+#endif
+#ifdef HAVE_DECODER_SPARC
extern lzma_ret
lzma_simple_sparc_decoder_init(lzma_next_coder *next,
const lzma_allocator *allocator,
@@ -81,3 +84,4 @@ lzma_simple_sparc_decoder_init(lzma_next_coder *next,
{
return sparc_coder_init(next, allocator, filters, false);
}
+#endif
diff --git a/contrib/libs/lzma/liblzma/simple/x86.c b/contrib/libs/lzma/liblzma/simple/x86.c
index 0e78909ccc..232b29542e 100644
--- a/contrib/libs/lzma/liblzma/simple/x86.c
+++ b/contrib/libs/lzma/liblzma/simple/x86.c
@@ -141,6 +141,7 @@ x86_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
}
+#ifdef HAVE_ENCODER_X86
extern lzma_ret
lzma_simple_x86_encoder_init(lzma_next_coder *next,
const lzma_allocator *allocator,
@@ -148,8 +149,10 @@ lzma_simple_x86_encoder_init(lzma_next_coder *next,
{
return x86_coder_init(next, allocator, filters, true);
}
+#endif
+#ifdef HAVE_DECODER_X86
extern lzma_ret
lzma_simple_x86_decoder_init(lzma_next_coder *next,
const lzma_allocator *allocator,
@@ -157,3 +160,4 @@ lzma_simple_x86_decoder_init(lzma_next_coder *next,
{
return x86_coder_init(next, allocator, filters, false);
}
+#endif