Commit 3e2940e5 authored by Benoit Perrot's avatar Benoit Perrot
Browse files

Augment supported instruction set and syntaxes

parent b33ae777
2003-07-05 Benot Perrot <benoit@lrde.epita.fr>
* dev/mipsy.xml,
* src/inst/program_builder.cc, src/inst/program_solver.hh,
* src/vm/virtual_machine.hh, src/vm/virtual_machine.cc:
Support more comparison instructions.
Implement shift (logical and arithmetical) and rotate.
Add some syntaxes to branch instructions.
2003-06-29 Benot Perrot <benoit@lrde.epita.fr>
* dev/mipsy.xml, src/inst/program_builder.cc:
......
......@@ -115,20 +115,44 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</syntax>
</instruction>
<instruction opcode="neg" level="pseudo">
<syntax alias="sub">
<register />
<hidden value="* new Register(Register::zero)" />
<register default="@0" />
</syntax>
</instruction>
<instruction opcode="negu" level="pseudo">
<syntax alias="subu">
<register />
<hidden value="* new Register(Register::zero)" />
<register default="@0" />
</syntax>
</instruction>
<instruction opcode="sll" level="native">
<instruction opcode="abs" level="complex">
<syntax>
<register />
<register default="@0" />
</syntax>
</instruction>
<instruction opcode="mul" level="native">
<format>
<register name="dest" />
<register name="src" />
<immediate name="imm" />
<register name="src1" />
<register name="src2" />
</format>
<syntax>
<register />
<register />
<immediate />
<register />
</syntax>
</instruction>
<instruction opcode="slv" level="native">
<instruction opcode="div" level="native">
<format>
<register name="dest" />
<register name="src1" />
......@@ -140,31 +164,53 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<register />
</syntax>
</instruction>
<instruction opcode="neg" level="pseudo">
<syntax alias="sub">
<instruction opcode="divu" level="native">
<format>
<register name="dest" />
<register name="src1" />
<register name="src2" />
</format>
<syntax>
<register />
<register />
<register />
<hidden value="* new Register(Register::zero)" />
<register default="@0" />
</syntax>
</instruction>
<instruction opcode="negu" level="pseudo">
<syntax alias="subu">
<instruction opcode="remu" level="native">
<format>
<register name="dest" />
<register name="src1" />
<register name="src2" />
</format>
<syntax>
<register />
<register />
<register />
<hidden value="* new Register(Register::zero)" />
<register default="@0" />
</syntax>
</instruction>
<instruction opcode="abs" level="complex">
<!-- Binary instructions -->
<instruction opcode="sll" level="native">
<format>
<register name="dest" />
<register name="src" />
<immediate name="imm" />
</format>
<syntax>
<register />
<register default="@0" />
<register />
<immediate />
</syntax>
<syntax alias="sllv">
<register />
<register />
<register />
</syntax>
</instruction>
<instruction opcode="mul" level="native">
<instruction opcode="sllv" level="native">
<format>
<register name="dest" />
<register name="src1" />
......@@ -177,20 +223,24 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</syntax>
</instruction>
<instruction opcode="div" level="native">
<instruction opcode="sra" level="native">
<format>
<register name="dest" />
<register name="src1" />
<register name="src2" />
<register name="src" />
<immediate name="imm" />
</format>
<syntax>
<register />
<register />
<immediate />
</syntax>
<syntax alias="srav">
<register />
<register />
<register />
</syntax>
</instruction>
<instruction opcode="divu" level="native">
<instruction opcode="srav" level="native">
<format>
<register name="dest" />
<register name="src1" />
......@@ -203,7 +253,24 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</syntax>
</instruction>
<instruction opcode="remu" level="native">
<instruction opcode="srl" level="native">
<format>
<register name="dest" />
<register name="src" />
<immediate name="imm" />
</format>
<syntax>
<register />
<register />
<immediate />
</syntax>
<syntax alias="srlv">
<register />
<register />
<register />
</syntax>
</instruction>
<instruction opcode="srlv" level="native">
<format>
<register name="dest" />
<register name="src1" />
......@@ -216,8 +283,32 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</syntax>
</instruction>
<instruction opcode="rol" level="complex">
<syntax>
<register />
<register />
<register />
</syntax>
<syntax>
<register />
<register />
<immediate />
</syntax>
</instruction>
<instruction opcode="ror" level="complex">
<syntax>
<register />
<register />
<register />
</syntax>
<syntax>
<register />
<register />
<immediate />
</syntax>
</instruction>
<!-- Binary instructions -->
<instruction opcode="and" level="native">
<format>
<register name="dest" />
......@@ -289,6 +380,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<register default="@0" />
<register />
</syntax>
<syntax level="complex">
<register />
<register default="@0" />
<immediate />
</syntax>
</instruction>
<instruction opcode="xor" level="native">
......@@ -322,41 +418,117 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</instruction>
<instruction opcode="not" level="pseudo">
<syntax alias="xori">
<syntax alias="nor">
<register />
<register default="@0"/>
<hidden value="* new IntExp(~0)" />
<hidden value="* new Register(Register::zero)" />
</syntax>
</instruction>
<!-- Test instructions -->
<instruction opcode="slt" level="native">
<format>
<register name="dest" />
<register name="src1" />
<register name="src2" />
</format>
<instruction opcode="seq" level="complex">
<syntax>
<register />
<register />
<register />
</syntax>
<syntax>
<register />
<register />
<immediate />
</syntax>
</instruction>
<instruction opcode="slti" level="native">
<format>
<register name="dest" />
<register name="src" />
<immediate name="imm" />
</format>
<instruction opcode="sne" level="complex">
<syntax>
<register />
<register />
<register />
</syntax>
<syntax>
<register />
<register />
<immediate />
</syntax>
</instruction>
<instruction opcode="sltu" level="native">
<instruction opcode="sge" level="complex">
<syntax>
<register />
<register />
<register />
</syntax>
<syntax>
<register />
<register />
<immediate />
</syntax>
</instruction>
<instruction opcode="sgeu" level="complex">
<syntax>
<register />
<register />
<register />
</syntax>
<syntax>
<register />
<register />
<immediate />
</syntax>
</instruction>
<instruction opcode="sgt" level="complex">
<syntax alias="slt">
<register />
<register value="@2"/>
<register value="@1"/>
</syntax>
<syntax>
<register />
<register />
<immediate />
</syntax>
</instruction>
<instruction opcode="sgtu" level="complex">
<syntax alias="sltu">
<register />
<register value="@2"/>
<register value="@1"/>
</syntax>
<syntax>
<register />
<register />
<immediate />
</syntax>
</instruction>
<instruction opcode="sle" level="complex">
<syntax>
<register />
<register />
<register />
</syntax>
<syntax>
<register />
<register />
<immediate />
</syntax>
</instruction>
<instruction opcode="sleu" level="complex">
<syntax>
<register />
<register />
<register />
</syntax>
<syntax>
<register />
<register />
<immediate />
</syntax>
</instruction>
<instruction opcode="slt" level="native">
<format>
<register name="dest" />
<register name="src1" />
......@@ -367,8 +539,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<register />
<register />
</syntax>
<syntax alias="slti">
<register />
<register />
<immediate />
</syntax>
</instruction>
<instruction opcode="sltiu" level="native">
<instruction opcode="slti" level="native">
<format>
<register name="dest" />
<register name="src" />
......@@ -380,25 +557,29 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<immediate />
</syntax>
</instruction>
<instruction opcode="seq" level="complex">
<instruction opcode="sltu" level="native">
<format>
<register name="dest" />
<register name="src1" />
<register name="src2" />
</format>
<syntax>
<register />
<register />
<register />
</syntax>
<syntax>
<syntax alias="sltiu">
<register />
<register />
<immediate />
</syntax>
</instruction>
<instruction opcode="sne" level="complex">
<syntax>
<register />
<register />
<register />
</syntax>
<instruction opcode="sltiu" level="native">
<format>
<register name="dest" />
<register name="src" />
<immediate name="imm" />
</format>
<syntax>
<register />
<register />
......@@ -408,6 +589,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<!-- Branch instructions -->
<instruction opcode="beq" level="native">
<format>
<register name="src1"/>
......@@ -419,14 +601,20 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<register />
<label />
</syntax>
<syntax level="complex">
<register />
<immediate />
<label />
</syntax>
</instruction>
<instruction opcode="beqz" level="pseudo">
<syntax alias="beq">
<hidden value="* new Register(Register::zero)"/>
<register />
<hidden value="* new Register(Register::zero)"/>
<label />
</syntax>
</instruction>
<instruction opcode="bne" level="native">
<format>
<register name="src1"/>
......@@ -438,8 +626,21 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<register />
<label />
</syntax>
<syntax level="complex">
<register />
<immediate />
<label />
</syntax>
</instruction>
<instruction opcode="bnez" level="pseudo">
<syntax alias="bne">
<register />
<hidden value="* new Register(Register::zero)"/>
<label />
</syntax>
</instruction>
<instruction opcode="bge" level="complex">
<syntax>
<register />
......@@ -638,6 +839,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</syntax>
</instruction>
<!-- Load instructions -->
<instruction opcode="lw" level="native">
<format>
......@@ -702,6 +904,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</instruction>
<!-- Store instructions -->
<instruction opcode="sw" level="native">
<format>
......@@ -730,6 +933,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</instruction>
<!-- Data movement instructions -->
<instruction opcode="move" level="pseudo">
<syntax alias="add">
<register />
......@@ -738,6 +943,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</syntax>
</instruction>
<!-- Exception and trap instructions -->
<instruction opcode="syscall" level="native">
<format>
......
<
......@@ -36,8 +36,60 @@ namespace inst
add_inst(* new Sub(dest, * new Register(Register::zero), src));
}
// Bitwise instructions -------------------------------------
void
ProgramBuilder::add_rol(Register& dest, Register& src1, Register& src2)
{
Register& at = * new Register(Register::at);
_program->text_section ().
add_inst(* new Subu(at, * new Register(Register::zero), src2));
_program->text_section ().add_inst(* new Srlv(at, src1, at));
_program->text_section ().add_inst(* new Sllv(dest, src1, src2));
_program->text_section ().add_inst(* new Or(dest, dest, at));
}
void
ProgramBuilder::add_rol(Register& dest, Register& src1, Exp& src2)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Sll(at, src1, src2));
_program->text_section ().
add_inst(* new Srl(dest, src1,
* new OpExp(*new IntExp(32), OpExp::sub, src2)));
_program->text_section ().add_inst(* new Or(dest, dest, at));
}
void
ProgramBuilder::add_ror(Register& dest, Register& src1, Register& src2)
{
Register& at = * new Register(Register::at);
_program->text_section ().
add_inst(* new Subu(at, * new Register(Register::zero), src2));
_program->text_section ().add_inst(* new Sllv(at, src1, at));
_program->text_section ().add_inst(* new Srlv(dest, src1, src2));
_program->text_section ().add_inst(* new Or(dest, dest, at));
}
void
ProgramBuilder::add_ror(Register& dest, Register& src1, Exp& src2)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Srl(at, src1, src2));
_program->text_section ().
add_inst(* new Sll(dest, src1,
* new OpExp(*new IntExp(32), OpExp::sub, src2)));
_program->text_section ().add_inst(* new Or(dest, dest, at));
}
void
ProgramBuilder::add_nor(Register& dest, Register& src1, Exp& src2)
{
_program->text_section ().add_inst(* new Ori(dest, src1, src2));
_program->text_section ().
add_inst(* new Nor(dest, dest, * new Register(Register::zero)));
}
// Test instructions -------------------------------------
// Equal
void
ProgramBuilder::add_seq(Register& dest, Register& src1, Register& src2)
{
......@@ -68,9 +120,98 @@ namespace inst
add_inst(* new Sltu(dest, *new Register(Register::zero), dest));
}
// Greater
void
ProgramBuilder::add_sge(Register& dest, Register& src1, Register& src2)
{
_program->text_section ().add_inst(* new Slt(dest, src1, src2));
_program->text_section ().add_inst(* new Xori(dest, dest, *new IntExp(1)));
}
void
ProgramBuilder::add_sge(Register& dest, Register& src1, Exp& src2)
{
_program->text_section ().add_inst(* new Slti(dest, src1, src2));
_program->text_section ().add_inst(* new Xori(dest, dest, *new IntExp(1)));
}
void
ProgramBuilder::add_sgeu(Register& dest, Register& src1, Register& src2)
{
_program->text_section ().add_inst(* new Sltu(dest, src1, src2));
_program->text_section ().add_inst(* new Xori(dest, dest, *new IntExp(1)));
}
void
ProgramBuilder::add_sgeu(Register& dest, Register& src1, Exp& src2)
{
_program->text_section ().add_inst(* new Sltiu(dest, src1, src2));
_program->text_section ().add_inst(* new Xori(dest, dest, *new IntExp(1)));
}
void
ProgramBuilder::add_sgt(Register& dest, Register& src1, Exp& src2)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Li(at, src2));
_program->text_section ().add_inst(* new Slt(dest, at, src1));
}
void
ProgramBuilder::add_sgtu(Register& dest, Register& src1, Exp& src2)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Li(at, src2));
_program->text_section ().add_inst(* new Sltu(dest, at, src1));
}
// Lower
void
ProgramBuilder::add_sle(Register& dest, Register& src1, Register& src2)
{
_program->text_section ().add_inst(* new Slt(dest, src2, src1));
_program->text_section ().add_inst(* new Xori(dest, dest, *new IntExp(1)));
}
void
ProgramBuilder::add_sle(Register& dest, Register& src1, Exp& src2)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Li(at, src2));
_program->text_section ().add_inst(* new Slt(dest, at, src1));
_program->text_section ().add_inst(* new Xori(dest, dest, *new IntExp(1)));
}
void
ProgramBuilder::add_sleu(Register& dest, Register& src1, Register& src2)
{
_program->text_section ().add_inst(* new Sltu(dest, src2, src1));
_program->text_section ().add_inst(* new Xori(dest, dest, *new IntExp(1)));
}
void
ProgramBuilder::add_sleu(Register& dest, Register& src1, Exp& src2)
{
Register& at = * new Register(Register::at);
_program->text_section ().add_inst(* new Li(at, src2));
_program->text_section ().add_inst(* new Sltu(dest, at, src1));
_program->text_section ().add_inst(* new Xori(dest, dest, *new IntExp(1)));
}