How saheelfaisal/function-unit-verilog works
Project type and purpose
• This is a hardware-design project written in Verilog, implementing a “function unit” that combines an ALU (arithmetic/logic unit) and a shifter.
• The purpose is educational: to build and simulate a component of a basic CPU datapath for a microprocessor architecture class.
File structure
• Top-level files:
• function_unit.v (the top-level module)
• function_unit_tb.v (its testbench)
• Subdirectories:
• ALU/alu.v and ALU/alu_tb.v – implements and tests the 15-operation ALU
• Shifter/shifter.v and Shifter/shifter_tb.v – implements and tests left/right shifts and pass-through
• sim_results holds output logs from simulation runs, confirming correctness of each module.
README for additional insights
• Confirms two main sub-modules (ALU and Shifter) and the overall function unit wrapper.
• No external dependencies or non-Verilog code—all simulation and synthesis is local.
a. Main components
• Input bus A (e.g., 32 bits)
• Input bus B (e.g., 32 bits)
• ALU sub-module (implements arithmetic/logic ops)
• Shifter sub-module (implements shift ops)
• Operation‐select logic (control signals to choose ALU vs. Shifter and specific function within each)
• Multiplexer at the output to select either ALU result or Shifter result
• Output bus (result)
b. Relationships and data flow
1. A and B feed both ALU and Shifter in parallel.
2. A separate control bus “op_code” steers:
• Which ALU function (add, sub, and, or, etc.)
• Which Shifter function (left, right, pass-through)
3. ALU produces alu_result; Shifter produces shift_result.
4. A 2-to-1 multiplexer uses a top-level control bit to hand off either alu_result or shift_result to the function_unit output.
c. Architectural patterns and design principles
• Hierarchical module design: a single top-level unit delegates to two specialized sub-units.
• Clear separation of concerns: ALU handles all arithmetic/logic; Shifter handles bit shifts.
• Testbench structure mirrors hierarchy: each module has its own testbench, plus the top-level has a combined testbench.
d. Relevant technologies/frameworks
• Verilog HDL for implementation
• Simulation tools (e.g., Icarus Verilog, ModelSim) for generating the sim_results logs
• Standard digital‐design conventions for bus widths and control‐signal encoding
Essential elements to capture
• Hierarchical dependencies (top-level invokes submodules).
• Data paths for A and B.
• Control paths for op_code.
• Result selection via multiplexer.
• Testbench files and simulation results as side annotations.