Pārlūkot izejas kodu

Fix nonexhaustive match causing funct3 to not be applied to imm shifts

master
peteraa pirms 6 gadiem
vecāks
revīzija
6fa8d3537a
3 mainītis faili ar 21 papildinājumiem un 23 dzēšanām
  1. +4
    -4
      src/test/scala/RISCV/Ops.scala
  2. +16
    -18
      src/test/scala/RISCV/assembler.scala
  3. +1
    -1
      src/test/scala/RISCV/printUtils.scala

+ 4
- 4
src/test/scala/RISCV/Ops.scala Parādīt failu

@@ -98,11 +98,11 @@ object Ops {
def nop = add(0, 0, 0)
}

case class ArithImmShift(imm11: Imm, rd: Reg, rs1: Reg, shamt: Imm, op: ArithOp) extends Op with IType
case class ArithImmShift(rd: Reg, rs1: Reg, shamt: Imm, op: ArithOp) extends Op with IType
object ArithImmShift {
def sll( rd: Int, rs1: Int, imm: Int) = ArithImmShift(Imm(0), Reg(rd), Reg(rs1), Imm(imm), SLL)
def srl( rd: Int, rs1: Int, imm: Int) = ArithImmShift(Imm(0), Reg(rd), Reg(rs1), Imm(imm), SRL)
def sra( rd: Int, rs1: Int, imm: Int) = ArithImmShift(Imm(32), Reg(rd), Reg(rs1), Imm(imm), SRA)
def sll( rd: Int, rs1: Int, imm: Int) = ArithImmShift(Reg(rd), Reg(rs1), Imm(imm), SLL)
def srl( rd: Int, rs1: Int, imm: Int) = ArithImmShift(Reg(rd), Reg(rs1), Imm(imm), SRL)
def sra( rd: Int, rs1: Int, imm: Int) = ArithImmShift(Reg(rd), Reg(rs1), Imm(imm), SRA)
}

case class LUI(rd: Reg, imm: Imm) extends Op with UType


+ 16
- 18
src/test/scala/RISCV/assembler.scala Parādīt failu

@@ -127,15 +127,9 @@ object assembler {
/**
* Used by SRI, SRAI, SLLI
*/
def setShiftTypeImmediate(funct7: Int, shamt: Int, addr: Addr): Int => InstructionFragment = {
val shamtPoints = List((24, 5))
val funct7Points = List((31, 6))

base => {
val withF7 = applyImmediateU(funct7, funct7Points, addr)(base)
val withShamt = withF7.flatMap(base2 => applyImmediateU(shamt, shamtPoints, addr)(base2))
withShamt
}
def setShiftTypeImmediate(shamt: Int, addr: Addr): Int => InstructionFragment = {
val points = List((24, 5))
applyImmediateU(shamt, points, addr)
}

def setOpCode(opcode: Int): Int => Int = setField(0, 7, opcode)
@@ -222,7 +216,7 @@ object assembler {
case DONE => instruction => Right(instruction)
case op: Arith => instruction => Right(instruction)
case op: ArithImm => setItypeImmediate(op.imm.value, addr)
case op: ArithImmShift => setShiftTypeImmediate(op.imm11.value, op.shamt.value, addr)
case op: ArithImmShift => setShiftTypeImmediate(op.shamt.value, addr)
case op: Branch => setBranchDestination(labelMap, op, addr)
case op: JALR => instruction => labelMap.lift(op.dst).toRight(s"label ${op.dst} not found", addr).flatMap(addr => setItypeImmediate(addr.value, addr)(instruction))
case op: AUIPC => setUtypeImmediate(op.imm.value, addr)
@@ -252,14 +246,18 @@ object assembler {
val opcode = setOpCode(op)

val extras: Int => Int = (instruction: Int) => op match {
case op: Branch => setComparisonFunct(op.comp)(instruction)
case op: ArithImm => setArithFunct(op.op)(instruction)
case op: Arith => setArithFunct(op.op)(instruction)
case op: JALR => setFunct3("000".binary)(instruction)
case op: LW => setFunct3("010".binary)(instruction)
case op: SW => setFunct3("010".binary)(instruction)
case DONE => (setFunct3("000".binary) andThen setFunct7("0000000".binary))(instruction)
case _ => instruction
case op: Branch => setComparisonFunct(op.comp)(instruction)
case op: ArithImm => setArithFunct(op.op)(instruction)
case op: ArithImmShift => setArithFunct(op.op)(instruction)
case op: Arith => setArithFunct(op.op)(instruction)
case op: JALR => setFunct3("000".binary)(instruction)
case op: LW => setFunct3("010".binary)(instruction)
case op: SW => setFunct3("010".binary)(instruction)
case DONE => (setFunct3("000".binary) andThen setFunct7("0000000".binary))(instruction)

case op: AUIPC => instruction
case op: JAL => instruction
case op: LUI => instruction
}

val withOp = opcode(0)


+ 1
- 1
src/test/scala/RISCV/printUtils.scala Parādīt failu

@@ -119,7 +119,7 @@ object PrintUtils {


def printBinary(bin: Map[Addr, Int]): String = {
bin.toList.sortBy(_._1.value).map{ case(addr, op) => s"$addr: ${op.hs}" }.mkString("\n","\n","\n")
bin.toList.sortBy(_._1.value).map{ case(addr, op) => s"$addr: ${op.hs}\t--\t${op.binary}" }.mkString("\n","\n","\n")
}




Notiek ielāde…
Atcelt
Saglabāt