Skip to content

Commit

Permalink
If bundled instructions both write to the same register, throwsan error
Browse files Browse the repository at this point in the history
  • Loading branch information
Emoun committed Feb 6, 2024
1 parent d62a305 commit 3ee79a4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ add_subdirectory(tests)

# Save the target triple in a variable
execute_process( COMMAND gcc -dumpmachine OUTPUT_VARIABLE DUMP_MACHINE OUTPUT_STRIP_TRAILING_WHITESPACE )
message(WARNING "Machine Triple: ${DUMP_MACHINE}")
message(STATUS "Machine Triple: ${DUMP_MACHINE}")
if (${DUMP_MACHINE} MATCHES "x86_64-linux-gnu")
set( TARGET_TRIPLE "x86_64-linux-gnu")
elseif(${DUMP_MACHINE} MATCHES "x86_64-apple-darwin.*")
Expand Down
36 changes: 21 additions & 15 deletions src/simulation-core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,26 @@ namespace patmos
debug_out << pst << " : ";
}

// Check permissive instructions
if( Use_permissive_dual_issue && f == &instruction_data_t::DR) {
assert(NUM_SLOTS = 2);
auto &pipe_instr0 = Pipeline[pst][0];
auto &pipe_instr1 = Pipeline[pst][1];
auto pred0 = PRR.get(pipe_instr0.Pred).get();
auto pred1 = PRR.get(pipe_instr1.Pred).get();
auto &pipe_instr0 = Pipeline[pst][0];
auto &pipe_instr1 = Pipeline[pst][1];
auto pred0 = PRR.get(pipe_instr0.Pred).get();
auto pred1 = PRR.get(pipe_instr1.Pred).get();

if(pred0 && pred1) {
boost::optional<const char*> err;

if(pipe_instr0.I->get_dst_reg(Pipeline[pst][0]) != patmos::GPR_e::r0 &&
pipe_instr0.I->get_dst_reg(Pipeline[pst][0]) == pipe_instr1.I->get_dst_reg(Pipeline[pst][1])
){
err = "register write";
} else if( Use_permissive_dual_issue && f == &instruction_data_t::DR) {
assert(NUM_SLOTS = 2);

#define is_combi(pred1, pred2) (\
(pipe_instr0.I->pred1() && pipe_instr1.I->pred2()) || \
(pipe_instr0.I->pred2() && pipe_instr1.I->pred1()) )

if(pred0 && pred1) {
boost::optional<const char*> err;
// Check permissive instructions
if( is_combi(is_load, is_load) ||
is_combi(is_store, is_store) ||
is_combi(is_store, is_load)
Expand All @@ -155,13 +161,13 @@ namespace patmos
} else if(is_combi(is_multiply, is_multiply)) {
err = "multiply";
}
}

if(err) {
auto msg = std::string("Two simultaneously enabled ");
msg.append(*err);
msg.append(" operations");
patmos::simulation_exception_t::illegal(msg, Pipeline[pst][0]);
}
if(err) {
auto msg = std::string("Two simultaneously enabled ");
msg.append(*err);
msg.append(" operations");
patmos::simulation_exception_t::illegal(msg, Pipeline[pst][0]);
}
}

Expand Down
8 changes: 6 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Errors : 0")
test_asm(18 "Emitted: 28 bytes
Errors : 0")

test_asm(19 "Emitted: 28 bytes
test_asm(19 "Emitted: 32 bytes
Errors : 0")

test_asm(21 "Emitted: 92 bytes
Expand Down Expand Up @@ -201,6 +201,8 @@ test_asm(75 "Errors : 0")

test_asm(76 "Errors : 0")

test_asm(77 "Errors : 0")

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# SIMULATOR TESTS
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Expand All @@ -213,7 +215,7 @@ endmacro (test_sim)
macro (test_sim_arg num args expr)
ADD_TEST(sim-test-arg-${num} ${CMAKE_BINARY_DIR}/src/pasim -V --maxc 40000 -o - ${CMAKE_CURRENT_BINARY_DIR}/test${num}.bin ${args})
SET_TESTS_PROPERTIES(sim-test-arg-${num} PROPERTIES PASS_REGULAR_EXPRESSION ${expr} DEPENDS asm-test-${num})
endmacro (test_sim)
endmacro (test_sim_arg)

macro (test_dsim num expr)
ADD_TEST(simd-test-${num} ${CMAKE_BINARY_DIR}/src/pasim -V -G 10 --maxc 40000 ${CMAKE_CURRENT_BINARY_DIR}/test${num}.bin)
Expand Down Expand Up @@ -440,3 +442,5 @@ test_sim(74 "r1 : 00000539")
test_sim(75 "\\\\\\[Error\\\\\\] Illegal instruction:.*00000008:.*invalid")

test_sim(76 "r1 : 00000539")

test_sim(77 "\\\\\\[Error\\\\\\] Illegal instruction: Two simultaneously enabled register write operations")
3 changes: 2 additions & 1 deletion tests/test19.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#

.word 28;
(p0) addi r1 = r0 , 5 || (p0) addi r1 = r0 , 7;
pand p1 = p0, !p0
(p1) addi r1 = r0 , 5 || (p0) addi r1 = r0 , 7;
halt;
nop;
nop;
Expand Down
11 changes: 11 additions & 0 deletions tests/test77.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Tests two enabled instructions cannot be bundled if they write to the same register
#

.word 100;
addi r1 = r0, 1 || addi r1 = r0, 2;
halt;
nop;
nop;
nop;

0 comments on commit 3ee79a4

Please sign in to comment.