Commit 94a1cb96 authored by phlo's avatar phlo

updated FENCE to mark next instruction as barrier

parent b8314541
......@@ -21,7 +21,9 @@
// constructors
//------------------------------------------------------------------------------
Program::Program(std::istream & f, const std::string & p) : path(p)
Program::Program(std::istream & f, const std::string & p) :
path(p),
set_memory_barrier(false)
{
std::string token;
......@@ -206,30 +208,24 @@ Program::Program(std::istream & f, const std::string & p) : path(p)
void Program::push_back (Instruction && op)
{
// assign checkpoint
// collect checkpoint id
if (&op.symbol() == &Instruction::Check::symbol)
{
// collect checkpoint id
checkpoints[op.arg()].push_back(size());
// set the following instruction's type
set_type = set_type.value_or(0) | op.type();
checkpoints[op.arg()].push_back(size());
// return;
}
// assign memory barrier
// define the following instruction as memory barrier
if (&op.symbol() == &Instruction::Fence::symbol)
{
// set the following instruction's type
set_type = set_type.value_or(0) | op.type() | Instruction::Type::barrier;
set_memory_barrier = true;
// return;
return;
}
// define instruction as checkpoint or memory barrier
if (set_type)
if (set_memory_barrier)
{
op.type(op.type() | Instruction::Type::barrier);
set_memory_barrier = false;
}
// append instruction
......
......@@ -67,9 +67,9 @@ struct Program : public std::vector<Instruction>
//
std::unordered_set<std::string> labels;
// next instruction's type
// define next instruction as memory barrier
//
std::optional<uint8_t> set_type;
bool set_memory_barrier;
//----------------------------------------------------------------------------
// constructors
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -52,8 +52,11 @@ TEST_F(Encoder, constructor_flush_pcs)
reset_encoder();
for (const auto & p : *encoder->programs)
ASSERT_EQ(2, p.size());
for (const auto & pcs : encoder->flush_pcs)
ASSERT_EQ(std::vector<word_t>({0, 1, 2}), pcs.second);
ASSERT_EQ(std::vector<word_t>({0, 1}), pcs.second);
}
TEST_F(Encoder, constructor_check_pcs)
......
......@@ -1405,15 +1405,15 @@ TEST_F(smtlib_Encoder, define_store_buffer_constraints)
"\n"
"(assert "
"(ite sb-full_1_0 "
"(=> (or stmt_1_0_0 stmt_1_0_1 stmt_1_0_2) (not thread_1_0)) "
"(=> (or stmt_1_0_0 stmt_1_0_1) (not thread_1_0)) "
"(not flush_1_0)))\n"
"(assert "
"(ite sb-full_1_1 "
"(=> (or stmt_1_1_0 stmt_1_1_1 stmt_1_1_2) (not thread_1_1)) "
"(=> (or stmt_1_1_0 stmt_1_1_1) (not thread_1_1)) "
"(not flush_1_1)))\n"
"(assert "
"(ite sb-full_1_2 "
"(=> (or stmt_1_2_0 stmt_1_2_1 stmt_1_2_2) (not thread_1_2)) "
"(=> (or stmt_1_2_0 stmt_1_2_1) (not thread_1_2)) "
"(not flush_1_2)))\n"
"\n",
encoder->str());
......@@ -1428,15 +1428,15 @@ TEST_F(smtlib_Encoder, define_store_buffer_constraints)
ASSERT_EQ(
"(assert "
"(ite sb-full_1_0 "
"(=> (or stmt_1_0_0 stmt_1_0_1 stmt_1_0_2) (not thread_1_0)) "
"(=> (or stmt_1_0_0 stmt_1_0_1) (not thread_1_0)) "
"(not flush_1_0)))\n"
"(assert "
"(ite sb-full_1_1 "
"(=> (or stmt_1_1_0 stmt_1_1_1 stmt_1_1_2) (not thread_1_1)) "
"(=> (or stmt_1_1_0 stmt_1_1_1) (not thread_1_1)) "
"(not flush_1_1)))\n"
"(assert "
"(ite sb-full_1_2 "
"(=> (or stmt_1_2_0 stmt_1_2_1 stmt_1_2_2) (not thread_1_2)) "
"(=> (or stmt_1_2_0 stmt_1_2_1) (not thread_1_2)) "
"(not flush_1_2)))\n"
"\n",
encoder->str());
......
......@@ -90,21 +90,20 @@ TEST_F(Program, parse)
{
program = create_from_file<::Program>("data/increment.cas.asm");
ASSERT_EQ(7, program.size());
ASSERT_EQ(6, program.size());
ASSERT_EQ(1, program.checkpoints.size());
ASSERT_EQ(1, program.labels.size());
ASSERT_EQ(1, program.pc_to_label.size());
ASSERT_EQ("LOOP", *program.pc_to_label[3]);
ASSERT_EQ("LOOP", *program.pc_to_label[2]);
ASSERT_EQ(1, program.label_to_pc.size());
ASSERT_EQ(3, program.label_to_pc[program.pc_to_label[3]]);
ASSERT_EQ(2, program.label_to_pc[program.pc_to_label[2]]);
ASSERT_EQ("0\tSTORE\t0", program.print(true, 0));
ASSERT_EQ("1\tFENCE\t", program.print(true, 1));
ASSERT_EQ("2\tCHECK\t0", program.print(true, 2));
ASSERT_EQ("LOOP\tMEM\t0", program.print(true, 3));
ASSERT_EQ("4\tADDI\t1", program.print(true, 4));
ASSERT_EQ("5\tCAS\t0", program.print(true, 5));
ASSERT_EQ("6\tJMP\tLOOP", program.print(true, 6));
ASSERT_EQ("1\tCHECK\t0", program.print(true, 1));
ASSERT_EQ("LOOP\tMEM\t0", program.print(true, 2));
ASSERT_EQ("3\tADDI\t1", program.print(true, 3));
ASSERT_EQ("4\tCAS\t0", program.print(true, 4));
ASSERT_EQ("5\tJMP\tLOOP", program.print(true, 5));
// indirect addressing
program = create_from_file<::Program>("data/indirect.addressing.asm");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment