Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 src/Instruction_Decode/Instruction_Decode.sv
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ module Instruction_Decode
, .funct7 ( funct7 )
, .opcode ( opcode )
, .rd ( rd )
, .rs2 ( rs2 )
, .b_alu_control ( b_alu_control )
);

Expand Down
38 changes: 35 additions & 3 deletions src/ext/b/decoder.sv
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ module ext__b__decoder
, input [6:0] funct7
, input [6:0] opcode
, input [4:0] rd
, input [4:0] rs2
, output ext__b__types::b_alu_control_t b_alu_control
);

import ext__b__types::*;

localparam bit [6:0] FUNCT7_ZBA = 7'b0010000;
localparam bit [6:0] FUNCT7_ZBB = 7'b0100000;
localparam bit [6:0] FUNCT7_ZBB__LOGICAL = 7'b0100000;
localparam bit [6:0] FUNCT7_ZBB__MINMAX = 7'b0000101;
localparam bit [6:0] FUNCT7_ZBB__SEXT = 7'b0110000;
localparam bit [6:0] FUNCT7_ZBB__ZEXT = 7'b0000100;

always_comb
case (opcode)
Expand All @@ -25,19 +29,47 @@ module ext__b__decoder
default: b_alu_control = B_ALU_CTRL__NONE;
endcase

FUNCT7_ZBB:
FUNCT7_ZBB__LOGICAL:
case (funct3)
3'b111: b_alu_control = B_ALU_CTRL__ANDN;
3'b110: b_alu_control = B_ALU_CTRL__ORN;
3'b100: b_alu_control = B_ALU_CTRL__XNOR;
default: b_alu_control = B_ALU_CTRL__NONE;
endcase

FUNCT7_ZBB__MINMAX:
case (funct3)
3'b100: b_alu_control = B_ALU_CTRL__MIN;
3'b110: b_alu_control = B_ALU_CTRL__MAX;
default: b_alu_control = B_ALU_CTRL__NONE;
endcase
FUNCT7_ZBB__ZEXT:
case (funct3)
3'b100:
case (rs2)
5'b00000: b_alu_control = B_ALU_CTRL__ZEXTH;
Comment thread
TheDeepestSpace marked this conversation as resolved.
default: b_alu_control = B_ALU_CTRL__NONE;
endcase
default: b_alu_control = B_ALU_CTRL__NONE;
endcase
// TODO: Implement zbs into ALU decoder, also confirm what zbb instructions are being implemented.
default: b_alu_control = B_ALU_CTRL__NONE;

endcase
7'b0010011:
case (funct7)
FUNCT7_ZBB__SEXT:
case (funct3)
3'b001:
case (rs2)
5'b00100: b_alu_control = B_ALU_CTRL__SEXTB;
5'b00101: b_alu_control = B_ALU_CTRL__SEXTH;
default: b_alu_control = B_ALU_CTRL__NONE;
endcase
default: b_alu_control = B_ALU_CTRL__NONE;
endcase
default: b_alu_control = B_ALU_CTRL__NONE;

endcase
default: b_alu_control = B_ALU_CTRL__NONE;
endcase

Expand Down
5 changes: 5 additions & 0 deletions src/ext/b/types.svh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ package ext__b__types;
, B_ALU_CTRL__ANDN = 4'b0100
, B_ALU_CTRL__ORN = 4'b0101
, B_ALU_CTRL__XNOR = 4'b0110
, B_ALU_CTRL__MIN = 4'b0111
, B_ALU_CTRL__MAX = 4'b1000
, B_ALU_CTRL__SEXTB = 4'b1001
, B_ALU_CTRL__SEXTH = 4'b1010
, B_ALU_CTRL__ZEXTH = 4'b1011
} b_alu_control_t;

endpackage;
Expand Down
26 changes: 26 additions & 0 deletions src/ext/b/zbb.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
`include "src/ext/b/types.svh"

module zbb(
input [31:0] a
, input [31:0] b
, input ext__b__types::b_alu_control_t b_alu_control
, output reg [31:0] out
, output zeroE
);

always_comb
case (b_alu_control)
B_ALU_CTRL__ANDN: out = a & ~b; //andn
B_ALU_CTRL__ORN: out = a | ~b; //orn
B_ALU_CTRL__XNOR: out = ~(a ^ b); //xnor
B_ALU_CTRL__MIN: out = ($signed(a) < $signed(b) ? a : b); //min
B_ALU_CTRL__MAX: out = ($signed(a) < $signed(b) ? b : a); //max
B_ALU_CTRL__SEXTB: out = { {24{a[7]}}, a[7:0]}; //sext.b (sign extend byte)
B_ALU_CTRL__SEXTH: out = { {16{a[15]}}, a[15:0]}; //sext.h (sign extend halfword)
B_ALU_CTRL__ZEXTH: out = {16'b0, a[15:0]}; //zext.h (zero extend halfword)
default: out = 32'd0; //other
endcase

assign zeroE = (out == 0);

endmodule
Loading