RISC-V Step 4: Branch Comparator
advanced · riscv · 200 XP
Sign in to write your solution, run it in the simulator and submit it for grading.
Sign in or create a free account →Problem
RISC-V Step 4: Branch Comparator
Conditional branches compare two registers and jump if the condition holds. This unit decides **whether a branch is taken**.
**Interface:** `input [31:0] a, b` (the values of `rs1` and `rs2`), `input [2:0] funct3`, `output take`.
| `funct3` | Instruction | `take` when |
|----------|-------------|-------------|
| 000 | BEQ | `a == b` |
| 001 | BNE | `a != b` |
| 100 | BLT | `a < b`, signed |
| 101 | BGE | `a >= b`, signed |
| 110 | BLTU | `a < b`, unsigned |
| 111 | BGEU | `a >= b`, unsigned |
`funct3` values 010 and 011 are not branches and are never tested. Note **BGE means greater than or equal**: equal values take the branch.
Constraints
- Purely combinational.
- BLT/BGE compare as signed; BLTU/BGEU as unsigned.
Examples
Input: BLT, a=0xFFFFFFFF (-1), b=1
Output: take=1
-1 < 1 signed
Input: BLTU, a=0xFFFFFFFF, b=1
Output: take=0
Huge unsigned value
Input: BGE, a=5, b=5
Output: take=1
Equal counts as >=
Common questions
- What does the RISC-V Step 4: Branch Comparator problem ask you to build?
- RISC-V Step 4: Branch Comparator Conditional branches compare two registers and jump if the condition holds. This unit decides **whether a branch is taken**. **Interface:** `input [31:0] a, b` (the values of `rs1` and `rs2`), `input [2:0] funct3`, `output take`.
- What constraints does RISC-V Step 4: Branch Comparator have?
- Purely combinational.; BLT/BGE compare as signed; BLTU/BGEU as unsigned.
- What is an example input and output for RISC-V Step 4: Branch Comparator?
- Input BLT, a=0xFFFFFFFF (-1), b=1 gives output take=1. -1 < 1 signed
- Which Verilog concepts does RISC-V Step 4: Branch Comparator practise?
- riscv, risc-v, branch, comparator, cpu.