Skip to contentSkip to conversation

target/xtensa: clean up unaligned access

PATCH In review Max Filippov 3 participants 3 messages May 19, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 target/xtensa: clean up unaligned access

Xtensa cores may or may not have hardware support for unaligned memory access. Remove TARGET_ALIGNED_ONLY=y from all xtensa configurations and pass MO_ALIGN in memory access flags for all operations that would raise an exception.
Simplify use of gen_load_store_alignment by passing access size and alignment requirements in single parameter.
Drop condition from xtensa_cpu_do_unaligned_access and replace it with assertion.
Add a test.

---
Changes v3->v4:
- do additional cleanup in gen_load_store_alignment parameters as suggested by Richard.

Changes v2->v3:
- drop assertion for !XTENSA_OPTION_HW_ALIGNMENT from xtensa_cpu_do_unaligned_access to correctly handle acquire/release intsructions;
- add tests for acquire/release instructions.

Changes v1->v2:
- correctly handle case of !XCHAL_UNALIGNED_*_EXCEPTION in the test

 default-configs/targets/xtensa-linux-user.mak |   1 -
 default-configs/targets/xtensa-softmmu.mak    |   1 -
 .../targets/xtensaeb-linux-user.mak           |   1 -
 default-configs/targets/xtensaeb-softmmu.mak  |   1 -
 target/xtensa/helper.c                        |  13 +-
 target/xtensa/translate.c                     | 120 +++++-----
 tests/tcg/xtensa/test_load_store.S            | 221 ++++++++++++++++++
 7 files changed, 288 insertions(+), 70 deletions(-)
 create mode 100644 tests/tcg/xtensa/test_load_store.S
default-configs/targets/xtensa-linux-user.mak +0 -1
index fc95cc60f585..420b30a68d94 100644
@@ -1,5 +1,4 @@
 TARGET_ARCH=xtensa
 TARGET_SYSTBL_ABI=common
 TARGET_SYSTBL=syscall.tbl
-TARGET_ALIGNED_ONLY=y
 TARGET_HAS_BFLT=y
default-configs/targets/xtensa-softmmu.mak +0 -1
index 26c0285655cd..f075557bfa9d 100644
@@ -1,3 +1,2 @@
 TARGET_ARCH=xtensa
-TARGET_ALIGNED_ONLY=y
 TARGET_SUPPORTS_MTTCG=y
default-configs/targets/xtensaeb-linux-user.mak +0 -1
index cfc3518118c9..1ea0f1ba9156 100644
@@ -1,6 +1,5 @@
 TARGET_ARCH=xtensa
 TARGET_SYSTBL_ABI=common
 TARGET_SYSTBL=syscall.tbl
-TARGET_ALIGNED_ONLY=y
 TARGET_WORDS_BIGENDIAN=y
 TARGET_HAS_BFLT=y
default-configs/targets/xtensaeb-softmmu.mak +0 -1
index 14cb9289a620..405cf5acbb4a 100644
@@ -1,4 +1,3 @@
 TARGET_ARCH=xtensa
-TARGET_ALIGNED_ONLY=y
 TARGET_WORDS_BIGENDIAN=y
 TARGET_SUPPORTS_MTTCG=y
target/xtensa/helper.c +6 -7
index eeffee297d15..f18ab383fd89 100644
@@ -270,13 +270,12 @@ void xtensa_cpu_do_unaligned_access(CPUState *cs,
     XtensaCPU *cpu = XTENSA_CPU(cs);
     CPUXtensaState *env = &cpu->env;
 
-    if (xtensa_option_enabled(env->config, XTENSA_OPTION_UNALIGNED_EXCEPTION) &&
-        !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {
-        cpu_restore_state(CPU(cpu), retaddr, true);
-        HELPER(exception_cause_vaddr)(env,
-                                      env->pc, LOAD_STORE_ALIGNMENT_CAUSE,
-                                      addr);
-    }
+    assert(xtensa_option_enabled(env->config,
+                                 XTENSA_OPTION_UNALIGNED_EXCEPTION));
+    cpu_restore_state(CPU(cpu), retaddr, true);
+    HELPER(exception_cause_vaddr)(env,
+                                  env->pc, LOAD_STORE_ALIGNMENT_CAUSE,
+                                  addr);
 }
 
 bool xtensa_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
target/xtensa/translate.c +61 -59

297 lines not on this page · raw message

tests/tcg/xtensa/test_load_store.S new file +221 -0

221 lines not on this page · raw message

Signature · 1 line
2.20.1
Reviewed-by on v4 1/1
#1 lore raw
Quoted 10 lines · Max Filippov

Xtensa cores may or may not have hardware support for unaligned memory access. Remove TARGET_ALIGNED_ONLY=y from all xtensa configurations and pass MO_ALIGN in memory access flags for all operations that would raise an exception.
Simplify use of gen_load_store_alignment by passing access size and alignment requirements in single parameter.
Drop condition from xtensa_cpu_do_unaligned_access and replace it with assertion.
Add a test.

Quoted 4 lines

---

r~

Reviewed-by on v4 1/1
#2 lore raw
In reply to Max Filippov
Quoted 10 lines · Max Filippov

Xtensa cores may or may not have hardware support for unaligned memory access. Remove TARGET_ALIGNED_ONLY=y from all xtensa configurations and pass MO_ALIGN in memory access flags for all operations that would raise an exception.
Simplify use of gen_load_store_alignment by passing access size and alignment requirements in single parameter.
Drop condition from xtensa_cpu_do_unaligned_access and replace it with assertion.
Add a test.

Quoted 4 lines

---

Based-on: <[email protected]>

Quoted 1 line
 create mode 100644 tests/tcg/xtensa/test_load_store.S

Except this asm file,

Thanks!