[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 42/57] tcg: Introduce atom_and_align_for_opc
From: |
Richard Henderson |
Subject: |
[PATCH v3 42/57] tcg: Introduce atom_and_align_for_opc |
Date: |
Tue, 25 Apr 2023 20:31:31 +0100 |
Examine MemOp for atomicity and alignment, adjusting alignment
as required to implement atomicity on the host.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tcg/tcg.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
diff --git a/tcg/tcg.c b/tcg/tcg.c
index c5a0cfd846..d7ff96fd1d 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -220,6 +220,11 @@ static void * const qemu_st_helpers[MO_SIZE + 1]
__attribute__((unused)) = {
#endif
};
+static MemOp atom_and_align_for_opc(TCGContext *s, MemOp *p_atom_a,
+ MemOp *p_atom_u, MemOp opc,
+ MemOp host_atom, bool allow_two_ops)
+ __attribute__((unused));
+
TCGContext tcg_init_ctx;
__thread TCGContext *tcg_ctx;
@@ -5123,6 +5128,70 @@ static void tcg_reg_alloc_call(TCGContext *s, TCGOp *op)
}
}
+/*
+ * Return the alignment and atomicity to use for the inline fast path
+ * for the given memory operation. The alignment may be larger than
+ * that specified in @opc, and the correct alignment will be diagnosed
+ * by the slow path helper.
+ */
+static MemOp atom_and_align_for_opc(TCGContext *s, MemOp *p_atom_a,
+ MemOp *p_atom_u, MemOp opc,
+ MemOp host_atom, bool allow_two_ops)
+{
+ MemOp align = get_alignment_bits(opc);
+ MemOp atom, atmax, atmin, size = opc & MO_SIZE;
+
+ /* When serialized, no further atomicity required. */
+ if (s->gen_tb->cflags & CF_PARALLEL) {
+ atom = opc & MO_ATOM_MASK;
+ } else {
+ atom = MO_ATOM_NONE;
+ }
+
+ atmax = opc & MO_ATMAX_MASK;
+ if (atmax == MO_ATMAX_SIZE) {
+ atmax = size;
+ } else {
+ atmax = atmax >> MO_ATMAX_SHIFT;
+ }
+
+ switch (atom) {
+ case MO_ATOM_NONE:
+ /* The operation requires no specific atomicity. */
+ atmax = atmin = MO_8;
+ break;
+ case MO_ATOM_IFALIGN:
+ /* If unaligned, the subobjects are bytes. */
+ atmin = MO_8;
+ break;
+ case MO_ATOM_WITHIN16:
+ /* If unaligned, there are subobjects if atmax < size. */
+ atmin = (atmax < size ? atmax : MO_8);
+ atmax = size;
+ break;
+ case MO_ATOM_SUBALIGN:
+ /* If unaligned but not odd, there are subobjects up to atmax - 1. */
+ atmin = (atmax == MO_8 ? MO_8 : atmax - 1);
+ break;
+ default:
+ g_assert_not_reached();
+ }
+
+ /*
+ * If there are subobjects, and the host model does not match, then we
+ * need to raise the initial alignment check. If the backend is prepared
+ * to double-check alignment and issue two half size ops, we need not
+ * raise initial alignment beyond half.
+ */
+ if (atmin > MO_8 && host_atom != atom) {
+ align = MAX(align, size - allow_two_ops);
+ }
+
+ *p_atom_a = atmax;
+ *p_atom_u = atmin;
+ return align;
+}
+
/*
* Similarly for qemu_ld/st slow path helpers.
* We must re-implement tcg_gen_callN and tcg_reg_alloc_call simultaneously,
--
2.34.1
- [PATCH v3 33/57] tcg/sparc64: Split out tcg_out_movi_s32, (continued)
- [PATCH v3 33/57] tcg/sparc64: Split out tcg_out_movi_s32, Richard Henderson, 2023/04/25
- [PATCH v3 31/57] tcg/sparc64: Rename tcg_out_movi_imm13 to tcg_out_movi_s13, Richard Henderson, 2023/04/25
- [PATCH v3 28/57] tcg/mips: Use full load/store helpers in user-only mode, Richard Henderson, 2023/04/25
- [PATCH v3 35/57] accel/tcg: Remove helper_unaligned_{ld,st}, Richard Henderson, 2023/04/25
- [PATCH v3 37/57] tcg/loongarch64: Support softmmu unaligned accesses, Richard Henderson, 2023/04/25
- [PATCH v3 36/57] tcg/loongarch64: Assert the host supports unaligned accesses, Richard Henderson, 2023/04/25
- [PATCH v3 38/57] tcg/riscv: Support softmmu unaligned accesses, Richard Henderson, 2023/04/25
- [PATCH v3 39/57] tcg: Introduce tcg_target_has_memory_bswap, Richard Henderson, 2023/04/25
- [PATCH v3 40/57] tcg: Add INDEX_op_qemu_{ld,st}_i128, Richard Henderson, 2023/04/25
- [PATCH v3 41/57] tcg: Support TCG_TYPE_I128 in tcg_out_{ld, st}_helper_{args, ret}, Richard Henderson, 2023/04/25
- [PATCH v3 42/57] tcg: Introduce atom_and_align_for_opc,
Richard Henderson <=
- [PATCH v3 43/57] tcg/i386: Use atom_and_align_for_opc, Richard Henderson, 2023/04/25
- [PATCH v3 44/57] tcg/aarch64: Use atom_and_align_for_opc, Richard Henderson, 2023/04/25
- [PATCH v3 45/57] tcg/arm: Use atom_and_align_for_opc, Richard Henderson, 2023/04/25
- [PATCH v3 46/57] tcg/loongarch64: Use atom_and_align_for_opc, Richard Henderson, 2023/04/25
- [PATCH v3 47/57] tcg/mips: Use atom_and_align_for_opc, Richard Henderson, 2023/04/25
- [PATCH v3 48/57] tcg/ppc: Use atom_and_align_for_opc, Richard Henderson, 2023/04/25
- [PATCH v3 49/57] tcg/riscv: Use atom_and_align_for_opc, Richard Henderson, 2023/04/25
- [PATCH v3 50/57] tcg/s390x: Use atom_and_align_for_opc, Richard Henderson, 2023/04/25
- [PATCH v3 51/57] tcg/sparc64: Use atom_and_align_for_opc, Richard Henderson, 2023/04/25
- [PATCH v3 52/57] tcg/i386: Honor 64-bit atomicity in 32-bit mode, Richard Henderson, 2023/04/25