On 10/20/24 08:53, Paolo Bonzini wrote:
This removes the 256 byte parity table from the executable on
x86, s390 and RISC-V/zbb hosts.
Signed-off-by: Paolo Bonzini <pbonz...@redhat.com>
---
include/qemu/host-utils.h | 16 ++++++++++++++++
target/i386/tcg/helper-tcg.h | 12 ++++++++++++
target/i386/tcg/cc_helper_template.h.inc | 20 ++++++++++----------
target/i386/tcg/cc_helper.c | 2 ++
target/i386/tcg/int_helper.c | 4 ++--
5 files changed, 42 insertions(+), 12 deletions(-)
diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
index ead97d354d6..bd4c684e5b5 100644
--- a/include/qemu/host-utils.h
+++ b/include/qemu/host-utils.h
@@ -126,6 +126,13 @@ static inline uint64_t muldiv64_round_up(uint64_t a,
uint32_t b, uint32_t c)
}
#endif
+#if defined __POPCNT__ || defined __s390x__|| defined __riscv_zbb
+#define HAVE_FAST_CTPOP 1
+#endif
+#if defined __i386__ || defined __x86_64__ || defined HAVE_FAST_CTPOP
+#define HAVE_FAST_PARITY8 1
+#endif
This misses out on a few, and is rather pointless; see below.
+/*
+ * parity8 - return the parity (1 = odd) of an 8-bit value.
+ * @val: The value to search
+ */
+static inline int parity8(uint8_t val)
+{
+ return __builtin_parity(val);
+}
This should be pretty darn close to ideal for all hosts.
+#ifdef HAVE_FAST_PARITY8
+static inline unsigned int compute_pf(uint8_t x)
+{
+ return !parity8(x) * CC_P;
+}
+#else
extern const uint8_t parity_table[256];
+static inline unsigned int compute_pf(uint8_t x)
+{
+ return parity_table[x];
+}
+#endif
All common hosts have either parity or popcount. I think there's no point keeping the
other path for some hosts (non-zbb riscv, older sparc64, ?). They are just as well served
by pulling in libgcc's implementations.
r~