Commit b33ae777 authored by Benoit Perrot's avatar Benoit Perrot
Browse files

Use gcc's expansion of complex and pseudo instructions.

parent 41930bab
2003-06-29 Benot Perrot <benoit@lrde.epita.fr>
* dev/mipsy.xml, src/inst/program_builder.cc:
Use gcc's expansion of complex and pseudo instructions.
* src/vm/virtual_machine.cc:
Check overflow in Sub.
2003-06-29 Benot Perrot <benoit@lrde.epita.fr>
* dev/mipsy-parser-gen.py:
......
......@@ -142,21 +142,27 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</instruction>
<instruction opcode="neg" level="complex">
<syntax>
<instruction opcode="neg" level="pseudo">
<syntax alias="sub">
<register />
<register default="@0"/>
<hidden value="* new Register(Register::zero)" />
<register default="@0" />
</syntax>
</instruction>
<instruction opcode="negu" level="pseudo">
<syntax alias="sub">
<syntax alias="subu">
<register />
<hidden value="* new Register(Register::zero)" />
<register default="@0"/>
<register default="@0" />
</syntax>
</instruction>
<instruction opcode="abs" level="complex">
<syntax>
<register />
<register default="@0" />
</syntax>
</instruction>
<instruction opcode="mul" level="native">
<format>
......
......@@ -26,53 +26,46 @@ namespace inst
// Arithmetics instructions ------------------------------
void
ProgramBuilder::add_neg(Register& dest, Register& src)
ProgramBuilder::add_abs(Register& dest, Register& src)
{
_program->text_section ().add_inst(* new Xori(dest, src, *new IntExp(~0)));
_program->text_section ().add_inst(* new Addi(dest, dest, *new IntExp(1)));
// FIXME: this move should be in the delay slot
_program->text_section ().
add_inst(* new Add(dest, src, *new Register(Register::zero)));
_program->text_section ().add_inst(* new Bgez(src, *new IntExp(4)));
_program->text_section ().
add_inst(* new Sub(dest, * new Register(Register::zero), src));
}
// Test instructions -------------------------------------
void
ProgramBuilder::add_seq(Register& dest, Register& src1, Register& src2)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Slt(dest, src1, src2));
_program->text_section ().add_inst(* new Slt(at, src2, src1));
_program->text_section ().add_inst(* new Or(dest, dest, at));
_program->text_section ().add_inst(* new Xori(dest, dest, *new IntExp(1)));
_program->text_section ().add_inst(* new Xor(dest, src1, src2));
_program->text_section ().add_inst(* new Sltiu(dest, dest,
* new IntExp(1)));
}
void
ProgramBuilder::add_seq(Register& dest, Register& src, Exp& exp)
{
Register& at = * new Register(Register::at);
_program->text_section ().
add_inst(* new Addi(* new Register(Register::zero), at, exp));
_program->text_section ().add_inst(* new Slti(dest, src, exp));
_program->text_section ().add_inst(* new Slt(at, at, src));
_program->text_section ().add_inst(* new Or(dest, dest, at));
_program->text_section ().add_inst(* new Xori(dest, dest, *new IntExp(1)));
_program->text_section ().add_inst(* new Xori(dest, src, exp));
_program->text_section ().add_inst(* new Sltiu(dest, dest,
* new IntExp(1)));
}
void
ProgramBuilder::add_sne(Register& dest, Register& src1, Register& src2)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Slt(dest, src1, src2));
_program->text_section ().add_inst(* new Slt(at, src2, src1));
_program->text_section ().add_inst(* new Or(dest, dest, at));
_program->text_section ().add_inst(* new Xor(dest, src1, src2));
_program->text_section ().
add_inst(* new Sltu(dest, *new Register(Register::zero), dest));
}
void
ProgramBuilder::add_sne(Register& dest, Register& src, Exp& exp)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Xori(dest, src, exp));
_program->text_section ().
add_inst(* new Addi(* new Register(Register::zero), at, exp));
_program->text_section ().add_inst(* new Slti(dest, src, exp));
_program->text_section ().add_inst(* new Slt(at, at, src));
_program->text_section ().add_inst(* new Or(dest, dest, at));
add_inst(* new Sltu(dest, *new Register(Register::zero), dest));
}
......@@ -83,66 +76,78 @@ namespace inst
ProgramBuilder::add_bge(Register& src1, Register& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Sub(at, src1, src2));
_program->text_section ().add_inst(* new Bgez(at, dest));
_program->text_section ().add_inst(* new Slt(at, src1, src2));
_program->text_section ().
add_inst(* new Beq(at, * new Register(Register::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bge(Register& src1, Exp& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Slti(at, src1, src2));
_program->text_section ().
add_inst(* new Addi(at, src1,
*new OpExp(*new IntExp(0), OpExp::sub, src2)));
_program->text_section ().add_inst(* new Bgez(at, dest));
add_inst(* new Beq(at, * new Register(Register::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bgeu(Register& src1, Register& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Subu(at, src1, src2));
_program->text_section ().add_inst(* new Bgez(at, dest));
_program->text_section ().add_inst(* new Sltu(at, src1, src2));
_program->text_section ().
add_inst(* new Beq(at, * new Register(Register::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bgeu(Register& src1, Exp& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Sltiu(at, src1, src2));
_program->text_section ().
add_inst(* new Addiu(at, src1,
*new OpExp(*new IntExp(0), OpExp::sub, src2)));
_program->text_section ().add_inst(* new Bgez(at, dest));
add_inst(* new Beq(at, * new Register(Register::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bgt(Register& src1, Register& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Sub(at, src1, src2));
_program->text_section ().add_inst(* new Bgtz(at, dest));
_program->text_section ().add_inst(* new Slt(at, src2, src1));
_program->text_section ().
add_inst(* new Bne(at, * new Register(Register::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bgt(Register& src1, Exp& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().
add_inst(* new Addi(at, src1,
*new OpExp(*new IntExp(0), OpExp::sub, src2)));
_program->text_section ().add_inst(* new Bgtz(at, dest));
add_inst(* new Slti(at, src1,
* new OpExp(src2, OpExp::add, *new IntExp(1))));
_program->text_section ().
add_inst(* new Beq(at, * new Register(Register::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bgtu(Register& src1, Register& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Subu(at, src1, src2));
_program->text_section ().add_inst(* new Bgtz(at, dest));
_program->text_section ().add_inst(* new Sltu(at, src2, src1));
_program->text_section ().
add_inst(* new Bne(at, * new Register(Register::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bgtu(Register& src1, Exp& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().
add_inst(* new Addiu(at, src1,
*new OpExp(*new IntExp(0), OpExp::sub, src2)));
_program->text_section ().add_inst(* new Bgtz(at, dest));
add_inst(* new Sltiu(at, src1,
* new OpExp(src2, OpExp::add, *new IntExp(1))));
_program->text_section ().
add_inst(* new Beq(at, * new Register(Register::zero), dest));
// FIXME: nop in delay slot
}
// Lower
......@@ -150,73 +155,85 @@ namespace inst
ProgramBuilder::add_ble(Register& src1, Register& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Sub(at, src1, src2));
_program->text_section ().add_inst(* new Blez(at, dest));
_program->text_section ().add_inst(* new Slt(at, src2, src1));
_program->text_section ().
add_inst(* new Beq(at, * new Register(Register::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_ble(Register& src1, Exp& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().
add_inst(* new Addi(at, src1,
*new OpExp(*new IntExp(0), OpExp::sub, src2)));
_program->text_section ().add_inst(* new Blez(at, dest));
add_inst(* new Slti(at, src1,
* new OpExp(src2, OpExp::add, *new IntExp(1))));
_program->text_section ().
add_inst(* new Bne(at, * new Register(Register::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bleu(Register& src1, Register& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Subu(at, src1, src2));
_program->text_section ().add_inst(* new Blez(at, dest));
_program->text_section ().add_inst(* new Sltu(at, src2, src1));
_program->text_section ().
add_inst(* new Beq(at, * new Register(Register::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bleu(Register& src1, Exp& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().
add_inst(* new Addiu(at, src1,
*new OpExp(*new IntExp(0), OpExp::sub, src2)));
_program->text_section ().add_inst(* new Blez(at, dest));
add_inst(* new Sltiu(at, src1,
* new OpExp(src2, OpExp::add, *new IntExp(1))));
_program->text_section ().
add_inst(* new Bne(at, * new Register(Register::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_blt(Register& src1, Register& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Sub(at, src1, src2));
_program->text_section ().add_inst(* new Bltz(at, dest));
_program->text_section ().add_inst(* new Slt(at, src1, src2));
_program->text_section ().
add_inst(* new Bne(at, * new Register(Register::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_blt(Register& src1, Exp& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Slti(at, src1, src2));
_program->text_section ().
add_inst(* new Addi(at, src1,
*new OpExp(*new IntExp(0), OpExp::sub, src2)));
_program->text_section ().add_inst(* new Bltz(at, dest));
add_inst(* new Bne(at, * new Register(Register::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bltu(Register& src1, Register& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Subu(at, src1, src2));
_program->text_section ().add_inst(* new Bltz(at, dest));
_program->text_section ().add_inst(* new Sltu(at, src1, src2));
_program->text_section ().
add_inst(* new Bne(at, * new Register(Register::zero), dest));
// FIXME: nop in delay slot
}
void
ProgramBuilder::add_bltu(Register& src1, Exp& src2, Exp& dest)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Sltiu(at, src1, src2));
_program->text_section ().
add_inst(* new Addiu(at, src1,
*new OpExp(*new IntExp(0), OpExp::sub, src2)));
_program->text_section ().add_inst(* new Bltz(at, dest));
add_inst(* new Bne(at, * new Register(Register::zero), dest));
// FIXME: nop in delay slot
}
// Load address ------------------------------------------
void
ProgramBuilder::add_la (Register& dest, Exp& exp, Register& base)
{
_program->text_section ().add_inst(* new Addi(dest, base, exp));
_program->text_section ().add_inst(* new Addiu(dest, base, exp));
}
void
ProgramBuilder::add_la (Register& reg, Exp& exp)
......
......@@ -78,7 +78,8 @@ namespace vm
register_t c = a - b;
cpu.set_register(sub.get_dest (), c);
// FIXME: Check overflow !
if ((a < b && c > 0) || (a > b && c < 0))
std::cerr << "Runtime Exception: Overflow" << std::endl;
}
void
VirtualMachine::visit(const inst::Subu& subu)
......
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