Skip to content

Commit 146cd19

Browse files
Changqing-JINGatc-github
authored andcommitted
[Tricore]: Fixed i32.load16_s and i32.load16_u producing incorrect results with unaligned addresses due to shared load cache between signed and unsigned variants (#748)
1 parent 01ed7ed commit 146cd19

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

RELEASENOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Wasm Compiler Release Notes
22

3+
## 3.0.10
4+
- TriCore backend: Fixed i32.load16_s and i32.load16_u producing incorrect results with unaligned addresses due to shared load cache between signed and unsigned variants
5+
36
## 3.0.9
47
- x86_64 backend: fix wrong register selection of f32/f64 max/min.
58

@@ -76,6 +79,7 @@
7679
- Stop supporting of tc1.6 and only support tc1.8
7780

7881
## Release v2 known issues
82+
- [Bug fixed by 3.0.10](#3010)
7983
- [Bug fixed by 3.0.9](#309)
8084
- [Bug fixed by 3.0.4](#304)
8185

src/core/compiler/backend/tricore/tricore_backend.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,9 +2113,10 @@ StackElement Backend::executeLinearMemoryLoad(OPCode const opcode, uint32_t cons
21132113
RelPatchObj const end{as_.INSTR(J_disp24sx2).prepJmp()};
21142114
unaligned.linkToHere();
21152115
{ // Unaligned
2116-
if (unalignedAccessCodePositions_.load2 == UINT32_MAX) {
2116+
uint32_t &load2PosRef{signExtend ? unalignedAccessCodePositions_.load2s : unalignedAccessCodePositions_.load2u};
2117+
if (load2PosRef == UINT32_MAX) {
21172118
RelPatchObj const skip{as_.INSTR(J_disp24sx2).prepJmp()};
2118-
unalignedAccessCodePositions_.load2 = output_.size();
2119+
load2PosRef = output_.size();
21192120
// Push register to the stack
21202121
constexpr REG helperReg{REG::D15};
21212122
as_.INSTR(STW_deref_Ab_off10sx_Da_preinc).setAb(REG::SP).setOff10sx(SafeInt<10>::fromConst<-4>()).setDa(helperReg)();
@@ -2136,7 +2137,7 @@ StackElement Backend::executeLinearMemoryLoad(OPCode const opcode, uint32_t cons
21362137
skip.linkToHere();
21372138
}
21382139

2139-
as_.INSTR(FCALL_disp24sx2).prepJmp().linkToBinaryPos(unalignedAccessCodePositions_.load2);
2140+
as_.INSTR(FCALL_disp24sx2).prepJmp().linkToBinaryPos(load2PosRef);
21402141
as_.INSTR(MOVD_Da_Ab).setDa(targetRegElem.reg).setAb(WasmABI::REGS::memLdStReg)();
21412142
}
21422143
end.linkToHere();

src/core/compiler/backend/tricore/tricore_backend.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,10 @@ class Tricore_Backend final {
733733
/// @brief Positions of where the logic for unaligned memory load/store is, can be reused by later code to save space
734734
class UnalignedAccessCodePositions final {
735735
public:
736-
uint32_t load2 = UINT32_MAX; ///< Position of unaligned load 2 bytes memory access
737-
uint32_t load4 = UINT32_MAX; ///< Position of unaligned load 4 bytes memory access
738-
uint32_t load8 = UINT32_MAX; ///< Position of unaligned load 8 bytes memory access
736+
uint32_t load2s = UINT32_MAX; ///< Position of unaligned load 2 signed bytes memory access
737+
uint32_t load2u = UINT32_MAX; ///< Position of unaligned load 2 unsigned bytes memory access
738+
uint32_t load4 = UINT32_MAX; ///< Position of unaligned load 4 bytes memory access
739+
uint32_t load8 = UINT32_MAX; ///< Position of unaligned load 8 bytes memory access
739740

740741
uint32_t store2 = UINT32_MAX; ///< Position of unaligned store 2 bytes memory access
741742
uint32_t store4 = UINT32_MAX; ///< Position of unaligned store 4 bytes memory access
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(module
2+
(memory 1)
3+
4+
(data (i32.const 100) "\ff\7f\80\00\ff\ff\00\80\00\00\00\00\ff\ff\ff\7f")
5+
6+
(func (export "i32_load16_s_misaligned") (result i32)
7+
i32.const 0
8+
i32.load16_s offset=101
9+
)
10+
11+
(func (export "i32_load16_u_misaligned") (result i32)
12+
i32.const 101
13+
i32.load16_u
14+
)
15+
)
16+
17+
(assert_return (invoke "i32_load16_u_misaligned") (i32.const 32895))
18+
19+

0 commit comments

Comments
 (0)