# openasic-org/xk264 architecture

> Architecture diagram of the GitHub repository openasic-org/xk264, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openasic-org/xk264
- Repository: https://github.com/openasic-org/xk264

## Overview

This repository is an H.264/AVC encoder IP core. Its documented capabilities cover YUV 4:2:0 input, inter- and intra-prediction, quarter-pixel interpolation, transform/quantization, CAVLC, and deblocking, with I/P GOP support. The graph sketches those domain stages around the top-level RTL and encoded-bitstream output. No source excerpts were provided, and the README lists features rather than wiring, so the stage-to-stage links are dashed and unverified; paths identify existing RTL modules from the tree.

Main entry points: [`rtl/top/top.v`](https://github.com/openasic-org/xk264/blob/main/rtl/top/top.v) (Encoder top), [`rtl/top/bs_buf.v`](https://github.com/openasic-org/xk264/blob/main/rtl/top/bs_buf.v) (Bitstream buffer), [`rtl/top/top_ctrl.v`](https://github.com/openasic-org/xk264/blob/main/rtl/top/top_ctrl.v) (Top control), [`rtl/fetch/fetch.v`](https://github.com/openasic-org/xk264/blob/main/rtl/fetch/fetch.v) (Macroblock fetch)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Encoder control"]
  node_encoder["Encoder top<br/>[top.v]"]
  node_control_logic["Top control<br/>[top_ctrl.v]"]
  node_fetch["Macroblock fetch<br/>[fetch.v]"]
end

subgraph group_prediction["Prediction"]
  node_ime["Integer motion search<br/>[ime_top.v]"]
  node_fme["Fractional motion search<br/>[fme_top.v]"]
  node_motion_comp["Motion compensation<br/>[mc_top.v]"]
  node_intra["Intra prediction<br/>[intra_top.v]"]
end

subgraph group_transform["Transform coding"]
  node_transform_quant["Transform and quantize<br/>[tq_top.v]"]
  node_cavlc["CAVLC coding<br/>[cavlc_top.v]"]
end

subgraph group_output["Filtering and output"]
  node_deblock["Deblocking filter<br/>[db_top.v]"]
  node_bitstream["Bitstream buffer<br/>[bs_buf.v]"]
end

node_input(("YUV input"))
node_encoded_output(("Encoded bitstream"))

node_input -.->|"supplies frames"| node_encoder
node_encoder -.->|"coordinates"| node_control_logic
node_encoder -.->|"fetches data"| node_fetch
node_encoder -.->|"searches motion"| node_ime
node_encoder -.->|"refines motion"| node_fme
node_encoder -.->|"predicts inter"| node_motion_comp
node_encoder -.->|"predicts intra"| node_intra
node_encoder -.->|"transforms residual"| node_transform_quant
node_encoder -.->|"codes coefficients"| node_cavlc
node_encoder -.->|"filters pictures"| node_deblock
node_encoder -.->|"packs output"| node_bitstream
node_bitstream -.->|"emits stream"| node_encoded_output

click node_encoder "https://github.com/openasic-org/xk264/blob/main/rtl/top/top.v"
click node_control_logic "https://github.com/openasic-org/xk264/blob/main/rtl/top/top_ctrl.v"
click node_fetch "https://github.com/openasic-org/xk264/blob/main/rtl/fetch/fetch.v"
click node_ime "https://github.com/openasic-org/xk264/blob/main/rtl/ime/ime_top.v"
click node_fme "https://github.com/openasic-org/xk264/blob/main/rtl/fme/fme_top.v"
click node_motion_comp "https://github.com/openasic-org/xk264/blob/main/rtl/mc/mc_top.v"
click node_intra "https://github.com/openasic-org/xk264/blob/main/rtl/intra/intra_top.v"
click node_transform_quant "https://github.com/openasic-org/xk264/blob/main/rtl/tq/tq_top.v"
click node_cavlc "https://github.com/openasic-org/xk264/blob/main/rtl/cavlc/cavlc_top.v"
click node_deblock "https://github.com/openasic-org/xk264/blob/main/rtl/db/db_top.v"
click node_bitstream "https://github.com/openasic-org/xk264/blob/main/rtl/top/bs_buf.v"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_encoder,node_control_logic,node_fetch toneBlue
class node_ime,node_fme,node_motion_comp,node_intra toneAmber
class node_transform_quant,node_cavlc toneMint
class node_deblock,node_bitstream toneRose
class node_input,node_encoded_output toneIndigo
```

## Components

### Encoder control

- [Encoder top](https://github.com/openasic-org/xk264/blob/main/rtl/top/top.v): `rtl/top/top.v`
- [Top control](https://github.com/openasic-org/xk264/blob/main/rtl/top/top_ctrl.v): `rtl/top/top_ctrl.v`
- [Macroblock fetch](https://github.com/openasic-org/xk264/blob/main/rtl/fetch/fetch.v): `rtl/fetch/fetch.v`

### Prediction

- [Integer motion search](https://github.com/openasic-org/xk264/blob/main/rtl/ime/ime_top.v): `rtl/ime/ime_top.v`
- [Fractional motion search](https://github.com/openasic-org/xk264/blob/main/rtl/fme/fme_top.v): `rtl/fme/fme_top.v`
- [Motion compensation](https://github.com/openasic-org/xk264/blob/main/rtl/mc/mc_top.v): `rtl/mc/mc_top.v`
- [Intra prediction](https://github.com/openasic-org/xk264/blob/main/rtl/intra/intra_top.v): `rtl/intra/intra_top.v`

### Transform coding

- [Transform and quantize](https://github.com/openasic-org/xk264/blob/main/rtl/tq/tq_top.v): `rtl/tq/tq_top.v`
- [CAVLC coding](https://github.com/openasic-org/xk264/blob/main/rtl/cavlc/cavlc_top.v): `rtl/cavlc/cavlc_top.v`

### Filtering and output

- [Deblocking filter](https://github.com/openasic-org/xk264/blob/main/rtl/db/db_top.v): `rtl/db/db_top.v`
- [Bitstream buffer](https://github.com/openasic-org/xk264/blob/main/rtl/top/bs_buf.v): `rtl/top/bs_buf.v`

### Other components

- **YUV input**
- **Encoded bitstream**

## Connections

- YUV input → Encoder top: supplies frames
- Encoder top → Top control: coordinates
- Encoder top → Macroblock fetch: fetches data
- Encoder top → Integer motion search: searches motion
- Encoder top → Fractional motion search: refines motion
- Encoder top → Motion compensation: predicts inter
- Encoder top → Intra prediction: predicts intra
- Encoder top → Transform and quantize: transforms residual
- Encoder top → CAVLC coding: codes coefficients
- Encoder top → Deblocking filter: filters pictures
- Encoder top → Bitstream buffer: packs output
- Bitstream buffer → Encoded bitstream: emits stream
