diff mbox series

[v2,05/21] include/exec/memop: Introduce memop_atomicity_bits

Message ID 20241005200600.493604-6-richard.henderson@linaro.org (mailing list archive)
State New, archived
Headers show
Series accel/tcg: Introduce tlb_fill_align hook | expand

Commit Message

Richard Henderson Oct. 5, 2024, 8:05 p.m. UTC
Split out of mmu_lookup.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/exec/memop.h | 24 ++++++++++++++++++++++++
 accel/tcg/cputlb.c   | 16 ++--------------
 2 files changed, 26 insertions(+), 14 deletions(-)

Comments

Helge Deller Oct. 7, 2024, 9:04 p.m. UTC | #1
On 10/5/24 22:05, Richard Henderson wrote:
> Split out of mmu_lookup.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>


Reviewed-by: Helge Deller <deller@gmx.de>


> ---
>   include/exec/memop.h | 24 ++++++++++++++++++++++++
>   accel/tcg/cputlb.c   | 16 ++--------------
>   2 files changed, 26 insertions(+), 14 deletions(-)
>
> diff --git a/include/exec/memop.h b/include/exec/memop.h
> index f53bf618c6..b699bf7688 100644
> --- a/include/exec/memop.h
> +++ b/include/exec/memop.h
> @@ -193,4 +193,28 @@ static inline unsigned memop_alignment_bits(MemOp memop)
>       return a;
>   }
>
> +/*
> + * memop_atomicity_bits:
> + * @memop: MemOp value
> + *
> + * Extract the atomicity size from the memop.
> + */
> +static inline unsigned memop_atomicity_bits(MemOp memop)
> +{
> +    unsigned size = memop & MO_SIZE;
> +
> +    switch (memop & MO_ATOM_MASK) {
> +    case MO_ATOM_NONE:
> +        size = MO_8;
> +        break;
> +    case MO_ATOM_IFALIGN_PAIR:
> +    case MO_ATOM_WITHIN16_PAIR:
> +        size = size ? size - 1 : 0;
> +        break;
> +    default:
> +        break;
> +    }
> +    return size;
> +}
> +
>   #endif
> diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c
> index b5bff220a3..f5fca5a118 100644
> --- a/accel/tcg/cputlb.c
> +++ b/accel/tcg/cputlb.c
> @@ -1751,20 +1751,8 @@ static bool mmu_lookup(CPUState *cpu, vaddr addr, MemOpIdx oi,
>        * Device memory type require alignment.
>        */
>       if (unlikely(flags & TLB_CHECK_ALIGNED)) {
> -        MemOp size = l->memop & MO_SIZE;
> -
> -        switch (l->memop & MO_ATOM_MASK) {
> -        case MO_ATOM_NONE:
> -            size = MO_8;
> -            break;
> -        case MO_ATOM_IFALIGN_PAIR:
> -        case MO_ATOM_WITHIN16_PAIR:
> -            size = size ? size - 1 : 0;
> -            break;
> -        default:
> -            break;
> -        }
> -        if (addr & ((1 << size) - 1)) {
> +        a_bits = memop_atomicity_bits(l->memop);
> +        if (addr & ((1 << a_bits) - 1)) {
>               cpu_unaligned_access(cpu, addr, type, l->mmu_idx, ra);
>           }
>       }
Peter Maydell Oct. 8, 2024, 2:05 p.m. UTC | #2
On Sat, 5 Oct 2024 at 21:06, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Split out of mmu_lookup.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
diff mbox series

Patch

diff --git a/include/exec/memop.h b/include/exec/memop.h
index f53bf618c6..b699bf7688 100644
--- a/include/exec/memop.h
+++ b/include/exec/memop.h
@@ -193,4 +193,28 @@  static inline unsigned memop_alignment_bits(MemOp memop)
     return a;
 }
 
+/*
+ * memop_atomicity_bits:
+ * @memop: MemOp value
+ *
+ * Extract the atomicity size from the memop.
+ */
+static inline unsigned memop_atomicity_bits(MemOp memop)
+{
+    unsigned size = memop & MO_SIZE;
+
+    switch (memop & MO_ATOM_MASK) {
+    case MO_ATOM_NONE:
+        size = MO_8;
+        break;
+    case MO_ATOM_IFALIGN_PAIR:
+    case MO_ATOM_WITHIN16_PAIR:
+        size = size ? size - 1 : 0;
+        break;
+    default:
+        break;
+    }
+    return size;
+}
+
 #endif
diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c
index b5bff220a3..f5fca5a118 100644
--- a/accel/tcg/cputlb.c
+++ b/accel/tcg/cputlb.c
@@ -1751,20 +1751,8 @@  static bool mmu_lookup(CPUState *cpu, vaddr addr, MemOpIdx oi,
      * Device memory type require alignment.
      */
     if (unlikely(flags & TLB_CHECK_ALIGNED)) {
-        MemOp size = l->memop & MO_SIZE;
-
-        switch (l->memop & MO_ATOM_MASK) {
-        case MO_ATOM_NONE:
-            size = MO_8;
-            break;
-        case MO_ATOM_IFALIGN_PAIR:
-        case MO_ATOM_WITHIN16_PAIR:
-            size = size ? size - 1 : 0;
-            break;
-        default:
-            break;
-        }
-        if (addr & ((1 << size) - 1)) {
+        a_bits = memop_atomicity_bits(l->memop);
+        if (addr & ((1 << a_bits) - 1)) {
             cpu_unaligned_access(cpu, addr, type, l->mmu_idx, ra);
         }
     }