[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 39/49] target/i386: use compiler builtin to compute PF
From: |
Paolo Bonzini |
Subject: |
[PULL 39/49] target/i386: use compiler builtin to compute PF |
Date: |
Thu, 31 Oct 2024 18:52:03 +0100 |
This removes the 256 byte parity table from the executable.
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
include/qemu/host-utils.h | 9 ++++++
target/i386/tcg/helper-tcg.h | 6 +++-
target/i386/tcg/cc_helper_template.h.inc | 20 +++++++-------
target/i386/tcg/cc_helper.c | 35 ------------------------
target/i386/tcg/int_helper.c | 4 +--
5 files changed, 26 insertions(+), 48 deletions(-)
diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
index ead97d354d6..4d28fa22cfa 100644
--- a/include/qemu/host-utils.h
+++ b/include/qemu/host-utils.h
@@ -313,6 +313,15 @@ static inline int ctpop8(uint8_t val)
return __builtin_popcount(val);
}
+/*
+ * 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);
+}
+
/**
* ctpop16 - count the population of one bits in a 16-bit value.
* @val: The value to search
diff --git a/target/i386/tcg/helper-tcg.h b/target/i386/tcg/helper-tcg.h
index 15d6c6f8b4f..696d6ef016f 100644
--- a/target/i386/tcg/helper-tcg.h
+++ b/target/i386/tcg/helper-tcg.h
@@ -21,6 +21,7 @@
#define I386_HELPER_TCG_H
#include "exec/exec-all.h"
+#include "qemu/host-utils.h"
/* Maximum instruction code size */
#define TARGET_MAX_INSN_SIZE 16
@@ -87,7 +88,10 @@ G_NORETURN void x86_cpu_do_unaligned_access(CPUState *cs,
vaddr vaddr,
#endif
/* cc_helper.c */
-extern const uint8_t parity_table[256];
+static inline unsigned int compute_pf(uint8_t x)
+{
+ return !parity8(x) * CC_P;
+}
/* misc_helper.c */
void cpu_load_eflags(CPUX86State *env, int eflags, int update_mask);
diff --git a/target/i386/tcg/cc_helper_template.h.inc
b/target/i386/tcg/cc_helper_template.h.inc
index 4cbbc73c3cd..8af8b8539f9 100644
--- a/target/i386/tcg/cc_helper_template.h.inc
+++ b/target/i386/tcg/cc_helper_template.h.inc
@@ -45,7 +45,7 @@ static uint32_t glue(compute_all_add, SUFFIX)(DATA_TYPE dst,
DATA_TYPE src1)
DATA_TYPE src2 = dst - src1;
cf = dst < src1;
- pf = parity_table[(uint8_t)dst];
+ pf = compute_pf(dst);
af = (dst ^ src1 ^ src2) & CC_A;
zf = (dst == 0) * CC_Z;
sf = lshift(dst, 8 - DATA_BITS) & CC_S;
@@ -65,7 +65,7 @@ static uint32_t glue(compute_all_adc, SUFFIX)(DATA_TYPE dst,
DATA_TYPE src1,
DATA_TYPE src2 = dst - src1 - src3;
cf = (src3 ? dst <= src1 : dst < src1);
- pf = parity_table[(uint8_t)dst];
+ pf = compute_pf(dst);
af = (dst ^ src1 ^ src2) & 0x10;
zf = (dst == 0) << 6;
sf = lshift(dst, 8 - DATA_BITS) & 0x80;
@@ -85,7 +85,7 @@ static uint32_t glue(compute_all_sub, SUFFIX)(DATA_TYPE dst,
DATA_TYPE src2)
DATA_TYPE src1 = dst + src2;
cf = src1 < src2;
- pf = parity_table[(uint8_t)dst];
+ pf = compute_pf(dst);
af = (dst ^ src1 ^ src2) & CC_A;
zf = (dst == 0) * CC_Z;
sf = lshift(dst, 8 - DATA_BITS) & CC_S;
@@ -107,7 +107,7 @@ static uint32_t glue(compute_all_sbb, SUFFIX)(DATA_TYPE
dst, DATA_TYPE src2,
DATA_TYPE src1 = dst + src2 + src3;
cf = (src3 ? src1 <= src2 : src1 < src2);
- pf = parity_table[(uint8_t)dst];
+ pf = compute_pf(dst);
af = (dst ^ src1 ^ src2) & 0x10;
zf = (dst == 0) << 6;
sf = lshift(dst, 8 - DATA_BITS) & 0x80;
@@ -128,7 +128,7 @@ static uint32_t glue(compute_all_logic, SUFFIX)(DATA_TYPE
dst, DATA_TYPE src1)
uint32_t cf, pf, af, zf, sf, of;
cf = 0;
- pf = parity_table[(uint8_t)dst];
+ pf = compute_pf(dst);
af = 0;
zf = (dst == 0) * CC_Z;
sf = lshift(dst, 8 - DATA_BITS) & CC_S;
@@ -144,7 +144,7 @@ static uint32_t glue(compute_all_inc, SUFFIX)(DATA_TYPE
dst, DATA_TYPE src1)
cf = src1;
src1 = dst - 1;
src2 = 1;
- pf = parity_table[(uint8_t)dst];
+ pf = compute_pf(dst);
af = (dst ^ src1 ^ src2) & CC_A;
zf = (dst == 0) * CC_Z;
sf = lshift(dst, 8 - DATA_BITS) & CC_S;
@@ -160,7 +160,7 @@ static uint32_t glue(compute_all_dec, SUFFIX)(DATA_TYPE
dst, DATA_TYPE src1)
cf = src1;
src1 = dst + 1;
src2 = 1;
- pf = parity_table[(uint8_t)dst];
+ pf = compute_pf(dst);
af = (dst ^ src1 ^ src2) & CC_A;
zf = (dst == 0) * CC_Z;
sf = lshift(dst, 8 - DATA_BITS) & CC_S;
@@ -173,7 +173,7 @@ static uint32_t glue(compute_all_shl, SUFFIX)(DATA_TYPE
dst, DATA_TYPE src1)
uint32_t cf, pf, af, zf, sf, of;
cf = (src1 >> (DATA_BITS - 1)) & CC_C;
- pf = parity_table[(uint8_t)dst];
+ pf = compute_pf(dst);
af = 0; /* undefined */
zf = (dst == 0) * CC_Z;
sf = lshift(dst, 8 - DATA_BITS) & CC_S;
@@ -192,7 +192,7 @@ static uint32_t glue(compute_all_sar, SUFFIX)(DATA_TYPE
dst, DATA_TYPE src1)
uint32_t cf, pf, af, zf, sf, of;
cf = src1 & 1;
- pf = parity_table[(uint8_t)dst];
+ pf = compute_pf(dst);
af = 0; /* undefined */
zf = (dst == 0) * CC_Z;
sf = lshift(dst, 8 - DATA_BITS) & CC_S;
@@ -209,7 +209,7 @@ static uint32_t glue(compute_all_mul, SUFFIX)(DATA_TYPE
dst, target_long src1)
uint32_t cf, pf, af, zf, sf, of;
cf = (src1 != 0);
- pf = parity_table[(uint8_t)dst];
+ pf = compute_pf(dst);
af = 0; /* undefined */
zf = (dst == 0) * CC_Z;
sf = lshift(dst, 8 - DATA_BITS) & CC_S;
diff --git a/target/i386/tcg/cc_helper.c b/target/i386/tcg/cc_helper.c
index 1b83775a914..f1940b40927 100644
--- a/target/i386/tcg/cc_helper.c
+++ b/target/i386/tcg/cc_helper.c
@@ -22,41 +22,6 @@
#include "exec/helper-proto.h"
#include "helper-tcg.h"
-const uint8_t parity_table[256] = {
- CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
- 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
- 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
- CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
- 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
- CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
- CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
- 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
- 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
- CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
- CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
- 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
- CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
- 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
- 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
- CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
- 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
- CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
- CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
- 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
- CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
- 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
- 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
- CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
- CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
- 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
- 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
- CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
- 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
- CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
- CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
- 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
-};
-
#define SHIFT 0
#include "cc_helper_template.h.inc"
#undef SHIFT
diff --git a/target/i386/tcg/int_helper.c b/target/i386/tcg/int_helper.c
index e1f92405282..1a02e9d8434 100644
--- a/target/i386/tcg/int_helper.c
+++ b/target/i386/tcg/int_helper.c
@@ -237,7 +237,7 @@ void helper_daa(CPUX86State *env)
env->regs[R_EAX] = (env->regs[R_EAX] & ~0xff) | al;
/* well, speed is not an issue here, so we compute the flags by hand */
eflags |= (al == 0) << 6; /* zf */
- eflags |= parity_table[al]; /* pf */
+ eflags |= compute_pf(al);
eflags |= (al & 0x80); /* sf */
CC_SRC = eflags;
CC_OP = CC_OP_EFLAGS;
@@ -269,7 +269,7 @@ void helper_das(CPUX86State *env)
env->regs[R_EAX] = (env->regs[R_EAX] & ~0xff) | al;
/* well, speed is not an issue here, so we compute the flags by hand */
eflags |= (al == 0) << 6; /* zf */
- eflags |= parity_table[al]; /* pf */
+ eflags |= compute_pf(al);
eflags |= (al & 0x80); /* sf */
CC_SRC = eflags;
CC_OP = CC_OP_EFLAGS;
--
2.47.0
- [PULL 20/49] target/i386/hvf: fix handling of XSAVE-related CPUID bits, (continued)
- [PULL 20/49] target/i386/hvf: fix handling of XSAVE-related CPUID bits, Paolo Bonzini, 2024/10/31
- [PULL 19/49] target/i386: Expose new feature bits in CPUID 8000_0021_EAX/EBX, Paolo Bonzini, 2024/10/31
- [PULL 21/49] tests/lcitool: Update libvirt-ci and add libcbor dependency, Paolo Bonzini, 2024/10/31
- [PULL 23/49] hw/core: Add Enclave Image Format (EIF) related helpers, Paolo Bonzini, 2024/10/31
- [PULL 22/49] device/virtio-nsm: Support for Nitro Secure Module device, Paolo Bonzini, 2024/10/31
- [PULL 24/49] core/machine: Make create_default_memdev machine a virtual method, Paolo Bonzini, 2024/10/31
- [PULL 25/49] machine/nitro-enclave: New machine type for AWS Nitro Enclaves, Paolo Bonzini, 2024/10/31
- [PULL 31/49] target/i386: Rearrange CCOp, Paolo Bonzini, 2024/10/31
- [PULL 34/49] target/i386: optimize computation of ZF from CC_OP_DYNAMIC, Paolo Bonzini, 2024/10/31
- [PULL 35/49] target/i386: optimize TEST+Jxx sequences, Paolo Bonzini, 2024/10/31
- [PULL 39/49] target/i386: use compiler builtin to compute PF,
Paolo Bonzini <=
- [PULL 49/49] target/i386: Introduce GraniteRapids-v2 model, Paolo Bonzini, 2024/10/31
- [PULL 30/49] target/i386: remove CC_OP_CLR, Paolo Bonzini, 2024/10/31
- [PULL 28/49] target/i386: use tcg_gen_ext_tl when applicable, Paolo Bonzini, 2024/10/31
- [PULL 36/49] target/i386: add a few more trivial CCPrepare cases, Paolo Bonzini, 2024/10/31
- [PULL 42/49] target/i386: cpu: set correct supported XCR0 features for TCG, Paolo Bonzini, 2024/10/31
- [PULL 45/49] target/i386: add AVX10 feature and AVX10 version property, Paolo Bonzini, 2024/10/31
- [PULL 47/49] target/i386: Add feature dependencies for AVX10, Paolo Bonzini, 2024/10/31
- [PULL 27/49] ci: always invoke meson through pyvenv, Paolo Bonzini, 2024/10/31
- [PULL 26/49] docs/nitro-enclave: Documentation for nitro-enclave machine type, Paolo Bonzini, 2024/10/31
- [PULL 38/49] target/i386: make flag variables unsigned, Paolo Bonzini, 2024/10/31