蓝色天空.知识 · 实践 · 创造
我的收藏
Verilog 教程目录 36章
Verilog / LEARN BY DOING

1.2 Verilog 简介

系统梳理 Verilog HDL 的多层次数字电路建模定位、从 GDA 到 IEEE 1364-2001 的标准化演进、核心语言特性以及 FPGA/ASIC 芯片实现途径。

学完这一章,你能够

  • 系统梳理 Verilog HDL 的多层次数字电路建模定位、从 GDA 到 IEEE 1364-2001 的标准化演进、核心语言特性以及 FPGA/ASIC 芯片实现途径。

Verilog 的定位与发展历史

Verilog HDL 是一门具备多层次电路描述与建模能力的硬件描述语言(Hardware Description Language),能够从行为级、数据流级到门级与开关级刻画数字系统。借助其层次化与结构化表达,工程师可以显著简化复杂数字硬件的设计流程,提升模块复用度、代码可读性与工程可靠性。

Verilog 的演进跨越了从厂商私有仿真语言到国际标准的完整历程:1983 年,Gateway Design Automation(GDA)公司的 Phil Moorby 设计了 Verilog,最初用作内部逻辑仿真语言;1989 年 Cadence 收购 GDA 后,Verilog 一度成为 Cadence 的私有资产;1990 年 Cadence 发起成立 OVI(Open Verilog International)组织将其开放给业界;1992 年 OVI 正式推动其向 IEEE 国际标准演进;1995 年 IEEE 发布首个国际标准 IEEE Std 1364-1995(Verilog 1.0);2001 年发布广泛采用的 IEEE Std 1364-2001(Verilog 2.0 / Verilog-2001),凭借简洁语法与深厚的 EDA 生态奠定了主流集成电路设计语言的地位。

核心语言特性与三种建模方式

Verilog 的语言特性围绕数字电路的并发本质与层次封装展开:首先,它支持三种互补的建模抽象——以过程块(`initial`/`always`)描述算法的行为级建模、以连续赋值(`assign`)刻画组合信号流向的数据流建模,以及通过门原语与子模块例化互连的结构级建模;其次,核心数据类型分为代表物理连线的线网(`wire`)与代表抽象存储单元的寄存器(`reg`);同时可通过任意深度的模块实例化构建清晰的层次化系统。

在扩展与验证能力方面,Verilog 支持用户自定义原语(UDP)来灵活描述组合或时序底层逻辑;提供显式时序结构以标注端口到端口时延、路径时延及建立/保持时间检查;允许通过编程语言接口(PLI)调用外部 C/C++ 函数访问模块内部节点以丰富测试手段;并且同一门语言既能编写可综合的硬件设计,也能编写仿真激励与测试约束,使设计者在功能设计阶段无需过早陷入工艺、温度等底层物理细节。

主要应用与芯片实现途径

Verilog 的核心工程落点在于设计和实现各类专用数字集成电路(ASIC)与可编程硬件系统,主流实现途径分为三类。第一类是可编程逻辑器件,典型代表为 FPGA(现场可编程门阵列)与 CPLD(复杂可编程逻辑器件),它们直接面向开发者,具备可反复编程、原型验证快捷、前期研发成本低等优势。

第二类是半定制或全定制 ASIC,即利用 Verilog 完成特定用途专用芯片的逻辑设计并流片制造,按基本单元工艺可分为门阵列 ASIC、标准单元 ASIC 与全定制 ASIC;第三类是混合 ASIC(常见于片上可编程系统 SoC/FPGA),在提供可编程逻辑资源的同时,集成 CPU 硬核、片上 RAM、锁相环(PLL)与专用乘法器等硬核标准单元,兼顾灵活性与高性能。

离线验证 Verilog 发展时间线、三种建模方式等价性与芯片实现分类

含完整源码 · 145 行
展开查看收起
python
"""Offline Verilog semantic verification lab for Chapter 01 (intro)."""
import json
import shutil

VERSION = "CPython 3.12.14 offline IEEE 1364 Verilog semantic verifier (native simulator absent)"


def case_verilog_toolchain_absence_probe():
    tools = ("iverilog", "vvp", "verilator", "vsim", "vivado", "quartus_sh")
    found = {t: shutil.which(t) is not None for t in tools}
    expected = {
        "any_native_tool_found": False,
        "offline_mode": True,
        "probed_tools": list(tools),
    }
    actual = {
        "any_native_tool_found": any(found.values()),
        "offline_mode": not any(found.values()),
        "probed_tools": list(tools),
    }
    return {
        "name": "verilog_toolchain_absence_probe",
        "summary": "如实探测本机 iverilog/vvp/verilator/vsim/vivado/quartus_sh 工具链,确认离线语义校验模式",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_ieee1364_history_timeline():
    milestones = [
        (1983, "GDA", "Phil Moorby created Verilog for internal logic simulation"),
        (1989, "Cadence", "Acquired GDA; Verilog became proprietary"),
        (1990, "OVI", "Open Verilog International founded to open the language"),
        (1992, "OVI->IEEE", "Initiated IEEE standardization"),
        (1995, "IEEE 1364-1995", "Verilog 1.0 first international standard"),
        (2001, "IEEE 1364-2001", "Verilog 2.0 (Verilog-2001) standard"),
    ]
    years = [y for y, _, _ in milestones]
    strictly_increasing = all(years[i] < years[i + 1] for i in range(len(years) - 1))
    expected = {
        "count": 6,
        "strictly_increasing": True,
        "first_year": 1983,
        "first_ieee_standard": "IEEE 1364-1995",
        "verilog_2001_standard": "IEEE 1364-2001",
    }
    actual = {
        "count": len(milestones),
        "strictly_increasing": strictly_increasing,
        "first_year": milestones[0][0],
        "first_ieee_standard": milestones[4][1],
        "verilog_2001_standard": milestones[5][1],
    }
    return {
        "name": "ieee1364_history_timeline",
        "summary": "校验 Verilog 从 1983 年 GDA 诞生到 IEEE 1364-1995 与 IEEE 1364-2001 标准化演进时间线",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_three_modeling_styles_equivalence():
    # Compare 1-bit 2:1 MUX across structural (gate primitives), dataflow (assign), and behavioral (always @*)
    def mux_structural(sel, d0, d1):
        not_sel = 1 - sel
        w0 = d0 & not_sel
        w1 = d1 & sel
        return w0 | w1

    def mux_dataflow(sel, d0, d1):
        return d1 if sel else d0

    def mux_behavioral(sel, d0, d1):
        out_reg = 0
        if sel == 1:
            out_reg = d1
        else:
            out_reg = d0
        return out_reg

    vectors = [(s, a, b) for s in (0, 1) for a in (0, 1) for b in (0, 1)]
    res_struct = [mux_structural(*v) for v in vectors]
    res_flow = [mux_dataflow(*v) for v in vectors]
    res_behav = [mux_behavioral(*v) for v in vectors]
    expected = {
        "vector_count": 8,
        "all_styles_match": True,
        "truth_outputs": [0, 0, 1, 1, 0, 1, 0, 1],
    }
    actual = {
        "vector_count": len(vectors),
        "all_styles_match": res_struct == res_flow == res_behav,
        "truth_outputs": res_struct,
    }
    return {
        "name": "three_modeling_styles_equivalence",
        "summary": "验证结构级(门例化)、数据流级(assign)与行为级(always)三种建模方式的逻辑等价性",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def case_asic_fpga_target_classification():
    targets = {
        "pld": {"devices": ["FPGA", "CPLD"], "reconfigurable": True},
        "custom_asic": {"types": ["gate_array", "standard_cell", "full_custom"], "reconfigurable": False},
        "hybrid_asic": {"hard_ips": ["CPU", "RAM", "PLL", "Multiplier"], "reconfigurable": True},
    }
    expected = {
        "path_count": 3,
        "pld_devices": ["FPGA", "CPLD"],
        "custom_asic_subtypes": 3,
        "hybrid_hard_ip_count": 4,
    }
    actual = {
        "path_count": len(targets),
        "pld_devices": targets["pld"]["devices"],
        "custom_asic_subtypes": len(targets["custom_asic"]["types"]),
        "hybrid_hard_ip_count": len(targets["hybrid_asic"]["hard_ips"]),
    }
    return {
        "name": "asic_fpga_target_classification",
        "summary": "核对可编程逻辑器件(FPGA/CPLD)、半/全定制 ASIC 与混合 ASIC 三类实现途径特征",
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def main():
    cases = [
        case_verilog_toolchain_absence_probe(),
        case_ieee1364_history_timeline(),
        case_three_modeling_styles_equivalence(),
        case_asic_fpga_target_classification(),
    ]
    print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
在 CPython 3.12.14 离线脚本中确认本地未安装原生 Verilog 仿真器,并验证 IEEE 1364 时间线、结构/数据流/行为三种 2 选 1 多路器真值等价以及 PLD/ASIC/混合 ASIC 分类全部通过。

查看独立实例 ↗ 在独立页面查看源码、运行环境与工程包

本地运行

解压后按 README 说明在对应本地环境运行脚本。

下载本章实验包 (mbskycom202612a2580.zip) ↓ 查看运行说明 ↗

本章附件与实例包

下载课程关联工程包:Verilog

课程关联工程包(登记关联36章) · 含当前章节或实例 · mbskycom202612a2580.zip

下载课程关联工程包:Verilog

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2600.zip

常见错误与边界检查

  • 实际端口、文档资源与应用配置都应和测试条件一致。

技术规范与官方资料

练习与参考解答

查看参考解答

行为级以 `always`/`initial` 过程块描述算法行为,抽象层次最高;数据流级通过 `assign` 连续赋值刻画信号运算与传递关系;结构级则显式例化逻辑门原语或下层子模块并连接线网,最贴近物理电路网表。

SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习