> configure(npc)
ysyx_22040000 李心杨 Linux calcite 6.6.19 #1-NixOS SMP PREEMPT_DYNAMIC Fri Mar 1 12:35:11 UTC 2024 x86_64 GNU/Linux 11:40:05 up 1:16, 2 users, load average: 0.90, 0.86, 0.79
This commit is contained in:
parent
2a27cd71c7
commit
110d8d5288
3 changed files with 278 additions and 16 deletions
|
@ -8,33 +8,39 @@ class ALUControlInterface extends Bundle {
|
||||||
object OpSelect extends ChiselEnum {
|
object OpSelect extends ChiselEnum {
|
||||||
val aOpAdd, aOpSub, aOpNot, aOpAnd, aOpOr, aOpXor, aOpSlt, aOpEq, aOpNop = Value
|
val aOpAdd, aOpSub, aOpNot, aOpAnd, aOpOr, aOpXor, aOpSlt, aOpEq, aOpNop = Value
|
||||||
}
|
}
|
||||||
|
object SrcSelect extends ChiselEnum {
|
||||||
|
val aSrcRs2, aSrcImm = Value
|
||||||
|
}
|
||||||
val op = Input(OpSelect())
|
val op = Input(OpSelect())
|
||||||
|
val src = Input(SrcSelect())
|
||||||
|
|
||||||
type CtrlTypes = OpSelect.Type :: HNil
|
type CtrlTypes = OpSelect.Type :: SrcSelect.Type :: HNil
|
||||||
def ctrlBindPorts: CtrlTypes = {
|
def ctrlBindPorts: CtrlTypes = {
|
||||||
op :: HNil
|
op :: src :: HNil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ALU[T <: UInt](tpe: T) extends Module {
|
class ALU[T <: UInt](tpe: T) extends Module {
|
||||||
val control = IO(new ALUControlInterface)
|
val control = IO(new ALUControlInterface)
|
||||||
val in = IO(new Bundle {
|
val in = IO(new Bundle {
|
||||||
val a = Input(tpe)
|
val a = Input(Vec(control.SrcSelect.getWidth, tpe))
|
||||||
val b = Input(tpe)
|
val b = Input(tpe)
|
||||||
})
|
})
|
||||||
val out = IO(new Bundle {
|
val out = IO(new Bundle {
|
||||||
val result = Output(tpe)
|
val result = Output(tpe)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
val a = in.a(control.src.asUInt)
|
||||||
|
|
||||||
// val adder_b = (Fill(tpe.getWidth, io.op(0)) ^ io.b) + io.op(0) // take (-b) if sub
|
// val adder_b = (Fill(tpe.getWidth, io.op(0)) ^ io.b) + io.op(0) // take (-b) if sub
|
||||||
val add = in.a + in.b
|
val add = a + in.b
|
||||||
val sub = in.a - in.b
|
val sub = a - in.b
|
||||||
val and = in.a & in.b
|
val and = a & in.b
|
||||||
val not = ~in.a
|
val not = ~a
|
||||||
val or = in.a | in.b
|
val or = a | in.b
|
||||||
val xor = in.a ^ in.b
|
val xor = a ^ in.b
|
||||||
val slt = in.a < in.b
|
val slt = a < in.b
|
||||||
val eq = in.a === in.b
|
val eq = a === in.b
|
||||||
|
|
||||||
import control.OpSelect._
|
import control.OpSelect._
|
||||||
|
|
||||||
|
|
|
@ -38,23 +38,25 @@ class Control(width: Int) extends Module {
|
||||||
|
|
||||||
// TODO: Add .ctrlTypes together instead of writing them by hand.
|
// TODO: Add .ctrlTypes together instead of writing them by hand.
|
||||||
type T =
|
type T =
|
||||||
Bool :: reg.WriteSelect.Type :: pc.SrcSelect.Type :: alu.OpSelect.Type :: HNil
|
Bool :: reg.WriteSelect.Type :: pc.SrcSelect.Type :: alu.OpSelect.Type :: alu.SrcSelect.Type :: HNil
|
||||||
val dst: T = reg.ctrlBindPorts ++ pc.ctrlBindPorts ++ alu.ctrlBindPorts
|
val dst: T = reg.ctrlBindPorts ++ pc.ctrlBindPorts ++ alu.ctrlBindPorts
|
||||||
import reg.WriteSelect._
|
import reg.WriteSelect._
|
||||||
import pc.SrcSelect._
|
import pc.SrcSelect._
|
||||||
import alu.OpSelect._
|
import alu.OpSelect._
|
||||||
|
import alu.SrcSelect._
|
||||||
import RV32Inst._
|
import RV32Inst._
|
||||||
val ControlMapping: Array[(BitPat, T)] = Array(
|
val ControlMapping: Array[(BitPat, T)] = Array(
|
||||||
// Regs :: PC :: Exe
|
// Regs :: PC :: Exe
|
||||||
// writeEnable :: writeSelect :: srcSelect ::
|
// writeEnable :: writeSelect :: srcSelect ::
|
||||||
(addi, false.B :: rAluOut :: pStaticNpc :: aOpAdd :: HNil),
|
(addi, true.B :: rAluOut :: pStaticNpc :: aOpAdd :: aSrcImm :: HNil),
|
||||||
)
|
)
|
||||||
|
println(ControlMapping)
|
||||||
def toBits(t: T): BitPat = {
|
def toBits(t: T): BitPat = {
|
||||||
val list: List[Data] = t.toList
|
val list: List[Data] = t.toList
|
||||||
list.map(x => BitPat(x.litValue.toInt.U(x.getWidth.W))).reduceLeft(_ ## _)
|
list.map(x => BitPat(x.litValue.toInt.U(x.getWidth.W))).reduceLeft(_ ## _)
|
||||||
}
|
}
|
||||||
|
|
||||||
val default = BitPat("b???????")
|
val default = BitPat("b????????")
|
||||||
|
|
||||||
reg.writeEnable := false.B
|
reg.writeEnable := false.B
|
||||||
reg.writeSelect := reg.WriteSelect(0.U)
|
reg.writeSelect := reg.WriteSelect(0.U)
|
||||||
|
@ -126,6 +128,5 @@ class Flow extends Module {
|
||||||
|
|
||||||
alu.in.a := reg.out.src(0)
|
alu.in.a := reg.out.src(0)
|
||||||
alu.in.b := reg.out.src(1)
|
alu.in.b := reg.out.src(1)
|
||||||
printf("Yes\n")
|
|
||||||
dontTouch(control.out)
|
dontTouch(control.out)
|
||||||
}
|
}
|
||||||
|
|
257
npc/waveform.vcd
257
npc/waveform.vcd
|
@ -125,108 +125,363 @@ b00000000000000000000000000000000 I
|
||||||
b00000000000000000000000000000000 J
|
b00000000000000000000000000000000 J
|
||||||
b00000000000000000000000000000000 K
|
b00000000000000000000000000000000 K
|
||||||
b00000000000000000000000000000000 L
|
b00000000000000000000000000000000 L
|
||||||
0M
|
1M
|
||||||
0N
|
0N
|
||||||
b0000 O
|
b0000 O
|
||||||
0P
|
0P
|
||||||
b0000000 Q
|
b0000000 Q
|
||||||
1R
|
1R
|
||||||
#1
|
#1
|
||||||
|
b00000000000000000000000000001000 &
|
||||||
|
b00000000000000000000000000000100 '
|
||||||
|
b0000000100 (
|
||||||
|
b00000000000010000100000100010011 )
|
||||||
|
b00010 *
|
||||||
|
b10000 +
|
||||||
|
0M
|
||||||
#2
|
#2
|
||||||
|
1M
|
||||||
#3
|
#3
|
||||||
|
b00000000000000000000000000001100 &
|
||||||
|
b00000000000000000000000000001000 '
|
||||||
|
b0000001000 (
|
||||||
|
0M
|
||||||
#4
|
#4
|
||||||
|
1M
|
||||||
#5
|
#5
|
||||||
|
b00000000000000000000000000010000 &
|
||||||
|
b00000000000000000000000000001100 '
|
||||||
|
b0000001100 (
|
||||||
|
0M
|
||||||
#6
|
#6
|
||||||
|
1M
|
||||||
#7
|
#7
|
||||||
|
b00000000000000000000000000010100 &
|
||||||
|
b00000000000000000000000000010000 '
|
||||||
|
b0000010000 (
|
||||||
|
b00000000000000000000000000000000 )
|
||||||
|
b00000 *
|
||||||
|
b00000 +
|
||||||
|
0M
|
||||||
#8
|
#8
|
||||||
|
1M
|
||||||
#9
|
#9
|
||||||
|
b00000000000000000000000000011000 &
|
||||||
|
b00000000000000000000000000010100 '
|
||||||
|
b0000010100 (
|
||||||
|
0M
|
||||||
#10
|
#10
|
||||||
|
1M
|
||||||
#11
|
#11
|
||||||
|
b00000000000000000000000000011100 &
|
||||||
|
b00000000000000000000000000011000 '
|
||||||
|
b0000011000 (
|
||||||
|
0M
|
||||||
#12
|
#12
|
||||||
|
1M
|
||||||
#13
|
#13
|
||||||
|
b00000000000000000000000000100000 &
|
||||||
|
b00000000000000000000000000011100 '
|
||||||
|
b0000011100 (
|
||||||
|
0M
|
||||||
#14
|
#14
|
||||||
|
1M
|
||||||
#15
|
#15
|
||||||
|
b00000000000000000000000000100100 &
|
||||||
|
b00000000000000000000000000100000 '
|
||||||
|
b0000100000 (
|
||||||
|
0M
|
||||||
#16
|
#16
|
||||||
|
1M
|
||||||
#17
|
#17
|
||||||
|
b00000000000000000000000000101000 &
|
||||||
|
b00000000000000000000000000100100 '
|
||||||
|
b0000100100 (
|
||||||
|
0M
|
||||||
#18
|
#18
|
||||||
|
1M
|
||||||
#19
|
#19
|
||||||
|
b00000000000000000000000000101100 &
|
||||||
|
b00000000000000000000000000101000 '
|
||||||
|
b0000101000 (
|
||||||
|
0M
|
||||||
#20
|
#20
|
||||||
|
1M
|
||||||
#21
|
#21
|
||||||
|
b00000000000000000000000000110000 &
|
||||||
|
b00000000000000000000000000101100 '
|
||||||
|
b0000101100 (
|
||||||
|
0M
|
||||||
#22
|
#22
|
||||||
|
1M
|
||||||
#23
|
#23
|
||||||
|
b00000000000000000000000000110100 &
|
||||||
|
b00000000000000000000000000110000 '
|
||||||
|
b0000110000 (
|
||||||
|
0M
|
||||||
#24
|
#24
|
||||||
|
1M
|
||||||
#25
|
#25
|
||||||
|
b00000000000000000000000000111000 &
|
||||||
|
b00000000000000000000000000110100 '
|
||||||
|
b0000110100 (
|
||||||
|
0M
|
||||||
#26
|
#26
|
||||||
|
1M
|
||||||
#27
|
#27
|
||||||
|
b00000000000000000000000000111100 &
|
||||||
|
b00000000000000000000000000111000 '
|
||||||
|
b0000111000 (
|
||||||
|
0M
|
||||||
#28
|
#28
|
||||||
|
1M
|
||||||
#29
|
#29
|
||||||
|
b00000000000000000000000001000000 &
|
||||||
|
b00000000000000000000000000111100 '
|
||||||
|
b0000111100 (
|
||||||
|
0M
|
||||||
#30
|
#30
|
||||||
|
1M
|
||||||
#31
|
#31
|
||||||
|
b00000000000000000000000001000100 &
|
||||||
|
b00000000000000000000000001000000 '
|
||||||
|
b0001000000 (
|
||||||
|
0M
|
||||||
#32
|
#32
|
||||||
|
1M
|
||||||
#33
|
#33
|
||||||
|
b00000000000000000000000001001000 &
|
||||||
|
b00000000000000000000000001000100 '
|
||||||
|
b0001000100 (
|
||||||
|
0M
|
||||||
#34
|
#34
|
||||||
|
1M
|
||||||
#35
|
#35
|
||||||
|
b00000000000000000000000001001100 &
|
||||||
|
b00000000000000000000000001001000 '
|
||||||
|
b0001001000 (
|
||||||
|
0M
|
||||||
#36
|
#36
|
||||||
|
1M
|
||||||
#37
|
#37
|
||||||
|
b00000000000000000000000001010000 &
|
||||||
|
b00000000000000000000000001001100 '
|
||||||
|
b0001001100 (
|
||||||
|
0M
|
||||||
#38
|
#38
|
||||||
|
1M
|
||||||
#39
|
#39
|
||||||
|
b00000000000000000000000001010100 &
|
||||||
|
b00000000000000000000000001010000 '
|
||||||
|
b0001010000 (
|
||||||
|
0M
|
||||||
#40
|
#40
|
||||||
|
1M
|
||||||
#41
|
#41
|
||||||
|
b00000000000000000000000001011000 &
|
||||||
|
b00000000000000000000000001010100 '
|
||||||
|
b0001010100 (
|
||||||
|
0M
|
||||||
#42
|
#42
|
||||||
|
1M
|
||||||
#43
|
#43
|
||||||
|
b00000000000000000000000001011100 &
|
||||||
|
b00000000000000000000000001011000 '
|
||||||
|
b0001011000 (
|
||||||
|
0M
|
||||||
#44
|
#44
|
||||||
|
1M
|
||||||
#45
|
#45
|
||||||
|
b00000000000000000000000001100000 &
|
||||||
|
b00000000000000000000000001011100 '
|
||||||
|
b0001011100 (
|
||||||
|
0M
|
||||||
#46
|
#46
|
||||||
|
1M
|
||||||
#47
|
#47
|
||||||
|
b00000000000000000000000001100100 &
|
||||||
|
b00000000000000000000000001100000 '
|
||||||
|
b0001100000 (
|
||||||
|
0M
|
||||||
#48
|
#48
|
||||||
|
1M
|
||||||
#49
|
#49
|
||||||
|
b00000000000000000000000001101000 &
|
||||||
|
b00000000000000000000000001100100 '
|
||||||
|
b0001100100 (
|
||||||
|
0M
|
||||||
#50
|
#50
|
||||||
|
1M
|
||||||
#51
|
#51
|
||||||
|
b00000000000000000000000001101100 &
|
||||||
|
b00000000000000000000000001101000 '
|
||||||
|
b0001101000 (
|
||||||
|
0M
|
||||||
#52
|
#52
|
||||||
|
1M
|
||||||
#53
|
#53
|
||||||
|
b00000000000000000000000001110000 &
|
||||||
|
b00000000000000000000000001101100 '
|
||||||
|
b0001101100 (
|
||||||
|
0M
|
||||||
#54
|
#54
|
||||||
|
1M
|
||||||
#55
|
#55
|
||||||
|
b00000000000000000000000001110100 &
|
||||||
|
b00000000000000000000000001110000 '
|
||||||
|
b0001110000 (
|
||||||
|
0M
|
||||||
#56
|
#56
|
||||||
|
1M
|
||||||
#57
|
#57
|
||||||
|
b00000000000000000000000001111000 &
|
||||||
|
b00000000000000000000000001110100 '
|
||||||
|
b0001110100 (
|
||||||
|
0M
|
||||||
#58
|
#58
|
||||||
|
1M
|
||||||
#59
|
#59
|
||||||
|
b00000000000000000000000001111100 &
|
||||||
|
b00000000000000000000000001111000 '
|
||||||
|
b0001111000 (
|
||||||
|
0M
|
||||||
#60
|
#60
|
||||||
|
1M
|
||||||
#61
|
#61
|
||||||
|
b00000000000000000000000010000000 &
|
||||||
|
b00000000000000000000000001111100 '
|
||||||
|
b0001111100 (
|
||||||
|
0M
|
||||||
#62
|
#62
|
||||||
|
1M
|
||||||
#63
|
#63
|
||||||
|
b00000000000000000000000010000100 &
|
||||||
|
b00000000000000000000000010000000 '
|
||||||
|
b0010000000 (
|
||||||
|
0M
|
||||||
#64
|
#64
|
||||||
|
1M
|
||||||
#65
|
#65
|
||||||
|
b00000000000000000000000010001000 &
|
||||||
|
b00000000000000000000000010000100 '
|
||||||
|
b0010000100 (
|
||||||
|
0M
|
||||||
#66
|
#66
|
||||||
|
1M
|
||||||
#67
|
#67
|
||||||
|
b00000000000000000000000010001100 &
|
||||||
|
b00000000000000000000000010001000 '
|
||||||
|
b0010001000 (
|
||||||
|
0M
|
||||||
#68
|
#68
|
||||||
|
1M
|
||||||
#69
|
#69
|
||||||
|
b00000000000000000000000010010000 &
|
||||||
|
b00000000000000000000000010001100 '
|
||||||
|
b0010001100 (
|
||||||
|
0M
|
||||||
#70
|
#70
|
||||||
|
1M
|
||||||
#71
|
#71
|
||||||
|
b00000000000000000000000010010100 &
|
||||||
|
b00000000000000000000000010010000 '
|
||||||
|
b0010010000 (
|
||||||
|
0M
|
||||||
#72
|
#72
|
||||||
|
1M
|
||||||
#73
|
#73
|
||||||
|
b00000000000000000000000010011000 &
|
||||||
|
b00000000000000000000000010010100 '
|
||||||
|
b0010010100 (
|
||||||
|
0M
|
||||||
#74
|
#74
|
||||||
|
1M
|
||||||
#75
|
#75
|
||||||
|
b00000000000000000000000010011100 &
|
||||||
|
b00000000000000000000000010011000 '
|
||||||
|
b0010011000 (
|
||||||
|
0M
|
||||||
#76
|
#76
|
||||||
|
1M
|
||||||
#77
|
#77
|
||||||
|
b00000000000000000000000010100000 &
|
||||||
|
b00000000000000000000000010011100 '
|
||||||
|
b0010011100 (
|
||||||
|
0M
|
||||||
#78
|
#78
|
||||||
|
1M
|
||||||
#79
|
#79
|
||||||
|
b00000000000000000000000010100100 &
|
||||||
|
b00000000000000000000000010100000 '
|
||||||
|
b0010100000 (
|
||||||
|
0M
|
||||||
#80
|
#80
|
||||||
|
1M
|
||||||
#81
|
#81
|
||||||
|
b00000000000000000000000010101000 &
|
||||||
|
b00000000000000000000000010100100 '
|
||||||
|
b0010100100 (
|
||||||
|
0M
|
||||||
#82
|
#82
|
||||||
|
1M
|
||||||
#83
|
#83
|
||||||
|
b00000000000000000000000010101100 &
|
||||||
|
b00000000000000000000000010101000 '
|
||||||
|
b0010101000 (
|
||||||
|
0M
|
||||||
#84
|
#84
|
||||||
|
1M
|
||||||
#85
|
#85
|
||||||
|
b00000000000000000000000010110000 &
|
||||||
|
b00000000000000000000000010101100 '
|
||||||
|
b0010101100 (
|
||||||
|
0M
|
||||||
#86
|
#86
|
||||||
|
1M
|
||||||
#87
|
#87
|
||||||
|
b00000000000000000000000010110100 &
|
||||||
|
b00000000000000000000000010110000 '
|
||||||
|
b0010110000 (
|
||||||
|
0M
|
||||||
#88
|
#88
|
||||||
|
1M
|
||||||
#89
|
#89
|
||||||
|
b00000000000000000000000010111000 &
|
||||||
|
b00000000000000000000000010110100 '
|
||||||
|
b0010110100 (
|
||||||
|
0M
|
||||||
#90
|
#90
|
||||||
|
1M
|
||||||
#91
|
#91
|
||||||
|
b00000000000000000000000010111100 &
|
||||||
|
b00000000000000000000000010111000 '
|
||||||
|
b0010111000 (
|
||||||
|
0M
|
||||||
#92
|
#92
|
||||||
|
1M
|
||||||
#93
|
#93
|
||||||
|
b00000000000000000000000011000000 &
|
||||||
|
b00000000000000000000000010111100 '
|
||||||
|
b0010111100 (
|
||||||
|
0M
|
||||||
#94
|
#94
|
||||||
|
1M
|
||||||
#95
|
#95
|
||||||
|
b00000000000000000000000011000100 &
|
||||||
|
b00000000000000000000000011000000 '
|
||||||
|
b0011000000 (
|
||||||
|
0M
|
||||||
#96
|
#96
|
||||||
|
1M
|
||||||
#97
|
#97
|
||||||
|
b00000000000000000000000011001000 &
|
||||||
|
b00000000000000000000000011000100 '
|
||||||
|
b0011000100 (
|
||||||
|
0M
|
||||||
#98
|
#98
|
||||||
|
1M
|
||||||
#99
|
#99
|
||||||
|
b00000000000000000000000011001100 &
|
||||||
|
b00000000000000000000000011001000 '
|
||||||
|
b0011001000 (
|
||||||
|
0M
|
||||||
|
|
Loading…
Reference in a new issue