Skip to content

Commit 77dee16

Browse files
Add ALU
1 parent b75279b commit 77dee16

File tree

8 files changed

+60
-26
lines changed

8 files changed

+60
-26
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,7 @@ dist/*
319319
target/
320320
lib_managed/
321321
src_managed/
322-
project/boot/
323-
project/plugins/project/
322+
project/
324323

325324
# Scala-IDE specific
326325
.scala_dependencies

generated/ALU.sv

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Generated by CIRCT firtool-1.128.0
2+
module ALU(
3+
input clock,
4+
reset,
5+
io_add,
6+
io_compare,
7+
input [31:0] io_a,
8+
io_b,
9+
output [31:0] io_output
10+
);
11+
12+
assign io_output =
13+
io_compare
14+
? {29'h0, io_a > io_b, io_a == io_b, io_a < io_b}
15+
: io_add ? io_a + io_b : io_a * io_b;
16+
endmodule
17+

generated/filelist.f

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALU.sv

project/build.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

project/plugins.sbt

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/main/scala/RISCV/ALU.scala

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
11
package RISCV
22

3+
import chisel3._
4+
import chisel3.util._
5+
import _root_.circt.stage.ChiselStage
36

7+
class ALU(val width: Int = 32) extends Module {
8+
val io = IO(new Bundle {
9+
val add = Input(Bool());
10+
val compare = Input(Bool());
11+
12+
val a = Input(UInt(width.W));
13+
val b = Input(UInt(width.W));
14+
15+
val output = Output(UInt(width.W));
16+
})
17+
18+
when(io.compare) {
19+
val gt = io.a > io.b;
20+
val eq = io.a === io.b;
21+
val lt = io.a < io.b;
22+
23+
io.output := Cat(0.U((width - 3).W), gt, eq, lt);
24+
}.otherwise {
25+
when(io.add) {
26+
io.output := io.a + io.b;
27+
}.otherwise {
28+
io.output := io.a * io.b;
29+
}
30+
}
31+
}
32+
33+
object ALU extends App {
34+
ChiselStage.emitSystemVerilogFile(
35+
new ALU(32),
36+
firtoolOpts = Array(
37+
"-disable-all-randomization",
38+
"-strip-debug-info",
39+
"-default-layer-specialization=enable"
40+
),
41+
args = Array("--target-dir", "generated")
42+
)
43+
}

src/main/scala/RISCV/EmitVerilog.scala

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/main/scala/RISCV/Hart.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ class Hart(val width: Int = 32) extends Module {
1515

1616
val program_pointer = RegInit(0.U(width.W))
1717

18-
val registers = Module(new Registers(width, 32));
18+
val registers = Module(new Registers());
1919
}

0 commit comments

Comments
 (0)