Skip to content

Commit

Permalink
'callnd' no longer executes the following instruction before transfer…
Browse files Browse the repository at this point in the history
…ing control
  • Loading branch information
Emoun committed Jan 25, 2023
1 parent abf8ed4 commit b9e2e51
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 10 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/simulator-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ jobs:
- platform: macos-12
cc: clang
cxx: clang++
- platform: macos-11
cc: clang
cxx: clang++
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/build-package
Expand All @@ -52,7 +49,7 @@ jobs:
- platform: ubuntu-20.04
cc: gcc
cxx: g++
- platform: macos-11
- platform: macos-12
cc: clang
cxx: clang++
# Run after the test jobs finish
Expand All @@ -65,8 +62,3 @@ jobs:
- uses: softprops/action-gh-release@v1
with:
files: build/patmos-simulator-*.tar.gz





9 changes: 8 additions & 1 deletion include/instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2075,9 +2075,16 @@ namespace patmos
push_dbgstack(s, ops, ops.DR_Pred, s.BASE, ret_pc, ops.EX_Address);

fetch_and_dispatch(s, ops, ops.DR_Pred, ops.EX_Address, ops.EX_Address);
if (!ops.OPS.CFLi.D && ops.DR_Pred && !s.is_stalling(SMW))
if (!ops.OPS.CFLi.D && ops.DR_Pred)
{
s.pipeline_flush(SMW);

if (!ops.OPS.CFLi.D){
// The above flush resets the execution stage's.
// We reassign it here in case we are stalling, such that the repeated
// calls to this function will get the right "ret_pc" every time.
s.Pipeline[SEX][0].Address = ret_pc;
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Errors : 0")

test_asm(52 "Emitted: 40 bytes
Errors : 0")

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# SIMULATOR TESTS
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Expand Down Expand Up @@ -198,6 +199,12 @@ macro (test_elf_io_sim num expr)
SET_TESTS_PROPERTIES(sim-test-stdin-input-${num} PROPERTIES PASS_REGULAR_EXPRESSION ${expr})
endmacro (test_elf_io_sim)

macro (test_elf_exit_sim num expr)
# Test elf programs exit code
ADD_TEST(sim-exit-test-${num} ${CMAKE_BINARY_DIR}/src/pasim -V --maxc 40000 -o - ${PROJECT_SOURCE_DIR}/tests/test${num}.elf)
SET_TESTS_PROPERTIES(sim-exit-test-${num} PROPERTIES PASS_REGULAR_EXPRESSION ${expr})
endmacro (test_elf_exit_sim)

macro (test_sim_lp num expr)
ADD_TEST(sim-test-${num} ${CMAKE_BINARY_DIR}/src/pasim -V -S lblock --maxc 40000 ${CMAKE_CURRENT_BINARY_DIR}/test${num}.bin)
SET_TESTS_PROPERTIES(sim-test-${num} PROPERTIES PASS_REGULAR_EXPRESSION ${expr})
Expand Down Expand Up @@ -320,3 +327,8 @@ test_sim_scba(50 "Align .*spill.*: 2 2
test_sim(51 "r1 : 00400000 r2 : 003ffffb r3 : 00000005")

test_sim(52 "\\\\\\[Error\\\\\\] Illegal instruction: Use of load result without delay slot!(.)*(0)*14:( )*addil r8 = r3, 1")

test_elf_exit_sim(53 "r1 : 00000000")

test_elf_exit_sim(54 "r1 : 0000007b r2 : 000001c8")

Binary file added tests/test53.elf
Binary file not shown.
36 changes: 36 additions & 0 deletions tests/test53.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
;
; Tests 'callnd' doesn't execute the following instructions before the call.
;
; We test this as an .elf because this error didn't show up in binary mode.
;
; Compile with:
;
; patmos-llc test53.ll -filetype=obj -o test53.elf && patmos-ld.lld --nostdlib --static -o test53.elf test53.elf
;

define i32 @_start() #0 {
entry:
%0 = tail call i32 asm sideeffect "
li $0 = 123
pmov $$p7 = !$$p0
callnd test_fn
pmov $$p7 = $$p0
pmov $$p7 = $$p0
pmov $$p7 = $$p0
nop
nop
nop
li $$r0 = 24
test_fn:
li (!$$p7) $0 = 0 # Set to 0 only if p7 is false
li ( $$p7) $0 = 1 # Set to 1 only if p7 is true
brcf 0 # halt
nop
nop
nop
", "=r"()
ret i32 %0
}

attributes #0 = { naked noinline }
Binary file added tests/test54.elf
Binary file not shown.
34 changes: 34 additions & 0 deletions tests/test54.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
;
; Tests 'callnd' and 'retnd' work correctly together (returns to the right address).
;
; We test this as an .elf because this error didn't show up in binary mode.
;
; Compile with:
;
; patmos-llc test54.ll -filetype=obj -o test54.elf && patmos-ld.lld --nostdlib --static -o test54.elf test54.elf
;

define i32 @_start() #0 {
entry:
%0 = tail call i32 asm sideeffect "
li $$r1 = 0
li $$r2 = 0
callnd test_fn
li $$r2 = 456 # Checkpoint
brcf 0 # halt
nop
nop
nop
li $$r0 = 24
test_fn:
li $$r1 = 123 # Checkpoint
retnd
nop
nop
nop
", "=r"()
ret i32 %0
}

attributes #0 = { naked noinline }

0 comments on commit b9e2e51

Please sign in to comment.