Skip to content

Commit 9a38fad

Browse files
Implement register codes
1 parent 3edf40f commit 9a38fad

5 files changed

Lines changed: 94 additions & 8 deletions

File tree

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ A single thread contains a program counter, ALU, LSU, and registers. Thread take
2929
2. a, b, and c register
3030
### Instruction Set
3131
The instruction set is 24 bits wide. 8 for opcode and 16 additional bits for immediate. The first 5 opcode bits specify instruction. The next 3 specify target or source / destination registers if an instruction uses it.
32+
#### Opcodes
3233
- move
3334
`00001` + target --> moves immediate into register
3435
`00010` + src/dst --> moves value in register to register
@@ -68,7 +69,14 @@ The instruction set is 24 bits wide. 8 for opcode and 16 additional bits for imm
6869
`10101` --> signals that the thread has finished execution
6970
- store
7071
`10110` + src/dst --> takes address from src register and stores the value in dst register into memory
71-
72+
#### Register Codes
73+
`000` --> A --> B
74+
`001` --> A --> C
75+
`010` --> B --> A
76+
`011` --> B --> C
77+
`100` --> C --> A
78+
`101` --> C --> B
79+
7280
Potentially we may need more instructions but I can't think of any more that we need right now?
7381
# How To Run
7482
`sbt run test`

src/main/scala/main/Core.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Core extends Module {
3434

3535
val read_ready_delayed = RegNext(dispatcher.io.read_requested, false.B);
3636
dispatcher.io.read_ready := read_ready_delayed;
37-
dispatcher.io.read_opcode := Operation.safe(memory.io.readPorts(0).data(6, 3))._1;
37+
dispatcher.io.read_opcode := memory.io.readPorts(0).data(7, 0);
3838
dispatcher.io.read_immediate_l := memory.io.readPorts(1).data(7, 0);
3939
dispatcher.io.read_immediate_u := memory.io.readPorts(2).data(7, 0);
4040

@@ -57,6 +57,8 @@ class Core extends Module {
5757
thread.io.dispatcher_opcode_loaded := dispatcher.io.opcode_loaded;
5858
thread.io.dispatcher_program_pointer := dispatcher.io.program_pointer;
5959
thread.io.operation := dispatcher.io.opcode;
60+
thread.io.src_register := dispatcher.io.src_register;
61+
thread.io.dst_register := dispatcher.io.dst_register;
6062
thread.io.immediate_a := 2.U(8.W);
6163
thread.io.immediate_b := 3.U(8.W);
6264

src/main/scala/main/Dispatcher.scala

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ class Dispatcher extends Module {
1111
val read_requested = Output(UInt(8.W));
1212
val read_program_pointer = Output(UInt(8.W));
1313
val read_ready = Input(Bool());
14-
val read_opcode = Input(Operation());
14+
val read_opcode = Input(UInt(8.W));
1515
val read_immediate_l = Input(UInt(8.W));
1616
val read_immediate_u = Input(UInt(8.W));
1717

1818
val opcode_loaded = Output(Bool());
1919
val opcode = Output(Operation());
20+
val src_register = Output(Register());
21+
val dst_register = Output(Register());
2022
val program_pointer = Output(UInt(8.W));
2123
});
2224

@@ -29,12 +31,17 @@ class Dispatcher extends Module {
2931
io.opcode_loaded := opcode_loaded;
3032
val opcode = RegInit(Operation.NoOp);
3133
io.opcode := opcode;
34+
val src_register = RegInit(Register.A);
35+
io.src_register := src_register;
36+
val dst_register = RegInit(Register.B);
37+
io.dst_register := dst_register;
3238
val program_pointer = RegInit(0.U(8.W));
3339
io.program_pointer := program_pointer;
3440

3541
when(io.thread_requesting_opcode) {
3642
printf(p"\t[Dispatcher]=====");
3743
printf(p"\n\t\tMarked read requested!\n\n");
44+
3845
read_program_pointer := io.thread_program_pointer;
3946
read_requested := true.B;
4047
}
@@ -43,10 +50,46 @@ class Dispatcher extends Module {
4350
printf(p"\t[Dispatcher]=====");
4451
printf(p"\n\t\tRead Complete ${io.read_opcode}");
4552
printf(p"\n\t\tImmediate Lower ${io.read_immediate_l}");
46-
printf(p"\n\t\tImmediate Upper ${io.read_immediate_u}\n\n");
47-
opcode := io.read_opcode;
53+
printf(p"\n\t\tImmediate Upper ${io.read_immediate_u}");
54+
55+
opcode := Operation.safe(io.read_opcode(6, 3))._1;
56+
57+
val registers_code = io.read_opcode(2, 0);
58+
59+
when(registers_code === 0.U) {
60+
src_register := Register.A;
61+
dst_register := Register.B;
62+
}
63+
64+
when(registers_code === 1.U) {
65+
src_register := Register.A;
66+
dst_register := Register.C;
67+
}
68+
69+
when(registers_code === 2.U) {
70+
src_register := Register.B;
71+
dst_register := Register.A;
72+
}
73+
74+
when(registers_code === 3.U) {
75+
src_register := Register.B;
76+
dst_register := Register.C;
77+
}
78+
79+
when(registers_code === 4.U) {
80+
src_register := Register.C;
81+
dst_register := Register.A;
82+
}
83+
84+
when(registers_code === 5.U) {
85+
src_register := Register.C;
86+
dst_register := Register.B;
87+
}
88+
4889
opcode_loaded := true.B;
90+
4991
program_pointer := io.read_program_pointer;
92+
5093
read_requested := false.B;
5194
}
5295
}

src/main/scala/main/Register.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import chisel3._
2+
import chisel3.util._
3+
import _root_.circt.stage.ChiselStage
4+
5+
object Register extends ChiselEnum {
6+
val A, B, C = Value
7+
}

src/main/scala/main/Thread.scala

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class Thread extends Module {
88
val dispatcher_program_pointer = Input(UInt(8.W));
99

1010
val operation = Input(Operation());
11+
val src_register = Input(Register());
12+
val dst_register = Input(Register());
1113
val immediate_a = Input(UInt(8.W));
1214
val immediate_b = Input(UInt(8.W));
1315

@@ -52,9 +54,33 @@ class Thread extends Module {
5254
when(io.operation === Operation.Add || io.operation === Operation.Sub || io.operation === Operation.Mul || io.operation === Operation.Div) {
5355
alu.io.execute := true.B;
5456
alu.io.operation := io.operation;
55-
alu.io.rs := register_a;
56-
alu.io.rt := register_b;
57-
register_a := alu.io.output
57+
58+
when(io.src_register === Register.A) {
59+
alu.io.rs := register_a;
60+
}
61+
62+
when(io.src_register === Register.B) {
63+
alu.io.rs := register_b;
64+
}
65+
66+
when(io.src_register === Register.C) {
67+
alu.io.rs := register_c;
68+
}
69+
70+
when(io.dst_register === Register.A) {
71+
alu.io.rt := register_a;
72+
register_a := alu.io.output
73+
}
74+
75+
when(io.dst_register === Register.B) {
76+
alu.io.rt := register_b;
77+
register_b := alu.io.output
78+
}
79+
80+
when(io.dst_register === Register.C) {
81+
alu.io.rt := register_c;
82+
register_c := alu.io.output
83+
}
5884

5985
program_counter.io.update := true.B;
6086
program_counter.io.branch := false.B;

0 commit comments

Comments
 (0)