# saheelfaisal/function-unit-verilog architecture

> Architecture diagram of the GitHub repository saheelfaisal/function-unit-verilog, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/saheelfaisal/function-unit-verilog
- Repository: https://github.com/saheelfaisal/function-unit-verilog

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Top-level Function Unit
    subgraph "Function Unit (function_unit.v)"
        direction TB
        ABus["Input Bus A (32-bit)"]:::comp
        BBus["Input Bus B (32-bit)"]:::comp
        OpCode["Control Bus op_code"]:::control
        ABus --> ALU
        BBus --> ALU
        OpCode --> ALU
        ABus --> Shifter
        BBus --> Shifter
        OpCode --> Shifter
        ALU --> MUX
        Shifter --> MUX
        OpCodeMux["Mux Select Bit"]:::control
        OpCodeMux --> MUX
        MUX{"2-to-1 MUX"}:::control
        MUX --> OutputBus
        OutputBus["Output Bus (Result)"]:::comp
    end

    %% Testbenches and Simulation Results
    subgraph "Verification" 
        direction TB
        FunctionUnitTB["Function Unit TB"]:::tb
        ALUTB["ALU TB"]:::tb
        ShifterTB["Shifter TB"]:::tb
        SimResults["Simulation Results"]:::tb
        ALULog["ALU Log"]:::tb
        FuncLog["Function Unit Log"]:::tb
        FunctionUnitTB --> SimResults
        ALUTB --> ALULog
        ShifterTB --> SimResults
        SimResults --> FuncLog
    end

    %% Documentation and Config
    subgraph "Project Docs & Config"
        direction TB
        Readme["README.md"]:::tb
        GitIgnore[".gitignore"]:::tb
    end

    %% Click Events
    click FunctionUnit "https://github.com/saheelfaisal/function-unit-verilog/blob/main/function_unit.v"
    click FunctionUnitTB "https://github.com/saheelfaisal/function-unit-verilog/blob/main/function_unit_tb.v"
    click ALU "https://github.com/saheelfaisal/function-unit-verilog/blob/main/ALU/alu.v"
    click ALUTB "https://github.com/saheelfaisal/function-unit-verilog/blob/main/ALU/alu_tb.v"
    click Shifter "https://github.com/saheelfaisal/function-unit-verilog/blob/main/Shifter/shifter.v"
    click ShifterTB "https://github.com/saheelfaisal/function-unit-verilog/blob/main/Shifter/shifter_tb.v"
    click SimResults "https://github.com/saheelfaisal/function-unit-verilog/tree/main/sim_results/"
    click ALULog "https://github.com/saheelfaisal/function-unit-verilog/blob/main/sim_results/alu.txt"
    click FuncLog "https://github.com/saheelfaisal/function-unit-verilog/blob/main/sim_results/function_unit.txt"
    click Readme "https://github.com/saheelfaisal/function-unit-verilog/blob/main/README.md"
    click GitIgnore "https://github.com/saheelfaisal/function-unit-verilog/blob/main/.gitignore"

    %% Styles
    classDef comp fill:#cce5ff,stroke:#3399ff;
    classDef control fill:#d4edda,stroke:#28a745;
    classDef tb fill:#ffe5cc,stroke:#ff9933;
```
