蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

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

PYTHONWindows x64、CPython 3.12.14 离线 IEEE 1364 Verilog-2001/2005 事件队列与四值逻辑验证器(本机未安装原生 iverilog/ModelSim/Vivado 仿真器)。explore-intro.py
explore-intro.py145 行
"""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()
本例需在 Windows x64、CPython 3.12.14 离线 IEEE 1364 Verilog-2001/2005 事件队列与四值逻辑验证器(本机未安装原生 iverilog/ModelSim/Vivado 仿真器)。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Windows x64、CPython 3.12.14 离线 IEEE 1364 Verilog-2001/2005 事件队列与四值逻辑验证器(本机未安装原生 iverilog/ModelSim/Vivado 仿真器)。

入口文件:projects/verilog-intro-lab/explore-intro.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 explore-intro.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows x64、CPython 3.12.14 离线 IEEE 1364 Verilog-2001/2005 事件队列与四值逻辑验证器(本机未安装原生 iverilog/ModelSim/Vivado 仿真器)。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:Verilog

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

下载课程关联工程包:Verilog

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

搜索教程、工具与资讯

热门搜索

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

欢迎登录蓝色天空网

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