Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ out/**
!out/.gitkeep
build/**
!build/.gitkeep
.DS_Store
50 changes: 50 additions & 0 deletions src/ext/b/zbs.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Zbs: Single-Bit Operations (RV32)
//
// Implements:
// - bclr / bclri
// - bset / bseti
// - binv / binvi
// - bext / bexti
//
// Design note:
// - Purely combinational ALU block
// - reg2[4:0] used as bit index
// - R/I distinction handled in decoder

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the documentation here I would just specify the section of the specification that corresponds to Zbs extension

module zbs (
input logic [31:0] reg1 // rs1 operand
, input logic [31:0] reg2 // rs2 or immediate (bit index source)
Comment thread
TheDeepestSpace marked this conversation as resolved.
Outdated
, input logic [1:0] inst // operation selector
, output logic [31:0] out //result
);

logic [4:0] index;
logic [31:0] mask;

always_comb
index = reg2[4:0];

always_comb
mask = 32'h1 << index;

always_comb
case (inst)

// 00 : bclr / bclri → clear selected bit
2'b00: out = reg1 & ~mask;

// 01 : bset / bseti → set selected bit
2'b01: out = reg1 | mask;

// 10 : binv / binvi → invert selected bit
2'b10: out = reg1 ^ mask;

// 11 : bext / bexti → extract selected bit (to bit[0])
2'b11: out = (reg1 >> index) & 32'h1;

// others → safe default
default: out = 32'd0;

endcase

endmodule
Loading