riple

Stay Hungry, Stay Foolish.

学习SystemVerilog(一)——不学习它的理由

0
阅读(31797)

想要学习SystemVerilog已经很久了。曾经尝试通过Accellera网站上给出的LRM学习,怎奈内容众多,找不出入手点和重点,只能 望而却步。虽然手头有三本SystemVerilog方面的书:《SVA应用指南》,《SystemVerilog验证方法学》和《高级验证方法学》,但 是难成系统。第一本只给出了SystemVerilog在断言方面的应用,详细实用但是不全面;第二本给出了SystemVerilog在验证领域的应 用,详细全面但是过于高级而不实用,很难作为入门教材;第三本也给出了验证领域的应用,详细但是不够全面,也有高级而不实用的问题。

    十一放假前,从图书馆借来了两本书:SystemVerilog for Design 和SystemVerilog for Verification。利用放假的“娱余时间”通读了两本书的前言部分和前一本书的各个章节。通过读这两本书的前言部分,我对 SystemVerilog有了一些整体的认识;通过读第一本书的各个章节,我对SystemVerilog的细节有了一些初步和不成熟的认识。

    随着这些认识而来的是两种相反但是不矛盾的想法:不应该学SystemVerilog和应该学SystemVerilog。

 

    现在来说说为什么不该学SystemVerilog。

    从Verilog到SystemVerilog的发展过程来看,两种语言都有其产生的必要性。Verilog在上世纪80年代中期产生,解决了当时一万门 以上设计面临的种种问题,Verilog的产生带来了门级设计到RTL级设计的变革,接下来的近20年,随着设计规模的扩大,Verilog也在不断的演 变和扩展,但是抽象层次始终徘徊在RTL级别;进入90年代以后,Verilog较弱的验证能力逐渐显露出来,而Verilog的几次标准化过程都没能解 决这一问题,在验证领域各种新的语言不断出现以代替Verilog;90年代后期,一个叫Co-Design的公司尝试扩展Verilog,增强其更高抽 象级别的描述能力和用于的验证能力,这一工作产生了我们现在看到的SystemVerilog——HDL & HVL。

    从我们当前的设计需要看,我们的设计规模是否达到了RTL抽象级别不能描述的程度?对于我这样的FPGA设计者来说(我相信看我博客的人大多是FPGA设 计者),工作中使用的芯片资源不超过6000个LE,以一个LE等价于12个门电路来计算(谁说的来哉?),设计规模不过72000门。Verilog的 设计描述能力足以应对我的日常工作。即使我的下一个项目规模是当前项目的10倍,我所做的工作不过是规划10个当前项目大小的模块,然后用近似10倍的工 作量完成10个模块的编码,每个模块的设计仍然可以用Verilog完成。

    虽然SystemVerilog提供了更高级别的抽象层次描述能力,但是目前的综合工具仍然不能支持其简单和直接的实现,还是需要人工逐级细化到RTL级 别才能交给综合工具。只有ESL工具的进一步演化才能解决高层次抽象级别描述的可综合问题,而不是SystemVerilog。 SystemVerilog是这一过程中可选的一种描述语言

    第一个认识是在阅读这两本书前言的过程中思考上述问题得到的:我们现在的设计规模虽然很大,但是我们能够人工实现的设计量与Verilog最初产生时的设 计能力相比,仍然没有超出Verilog的设计能力,仍然是RTL级别。(这当然不是原书作者的观点,而且我得到的认识也不只这一点,其他的认识与这一点 正好相反,放在下一篇。)

 

    通读完了SystemVerilog for Design的各个章节,我最深刻的感受是自己对Verilog语言掌握得还很不够。毕竟,Verilog是SystemVerilog的基础,而我的基 础又是很差的,只够应付当前工作的需要。

    这本书中提到的对Verilog的扩展和改进的大多数内容虽然很吸引人,虽然很有道理,在实际应用中也确实方便和准确了些,但是只不过是方便和准确了“一 些”而已。从语言设计者的角度来说,在SystemVerilog中改进Verilog的不足是必要的,但是从语言使用者的角度来说,这些改进不是根本性 的,也不是采用SystemVerilog的决定性因素。从这些内容来看,不学SystemVerilog也可以设计好数字电路。(尽管如此,这本书的另 外一些内容却给出了学习SystemVerilog的必要性,这些内容我放在下一篇里。)

    第二个认识:对于刚刚进入逻辑设计领域的设计者来说,从工作出发,学好Verilog是必要的,学习SystemVerilog是要以学好Verilog 为基础的,在Verilog的掌握和使用尚不成熟时,就强学强记SystemVerilog的高级功能是不切实际的,甚至可以说是好高骛远。

 

    下面是从SystemVerilog LRM中摘抄的一段,给出了SystemVerilog对Verilog的所有扩展和增强。内容显然太丰富了些,更适合对SystemVerilog有了 全面而深入认识的人士(比如语言的设计者),从归纳和总结的角度阅读,对于我这样基础薄弱的初学者来说,太具震慑力了些。

SystemVerilog adds extended and new constructs to Verilog-2001, including:
— Extensions to data types for better encapsulation and compactness of code and for tighter specification
    — C data types: int, typedef, struct, union, enum
    — other data types: bounded queues, logic (0, 1, X, Z) and bit (0, 1), tagged unions for safety
    — dynamic data types: string, classes, dynamic queues, dynamic arrays, associative arrays including automatic memory management freeing users from de-allocation issues
    — dynamic casting and bit-stream casting
    — Automatic/static specification on a per variable instance basis
— Extended operators for concise description
    — Wild equality and inequality
    — built-in methods to extend the language
    — operator overloading
    — streaming operators
    — set membership
— Extended procedural statements
    — pattern matching on selection statements for use with tagged unions
    — enhanced loop statements plus the foreach statement
    — C like jump statements: return, break, continue
    — final blocks that executes at the end of simulation (inverse of initial)
    — extended event control and sequence events
— Enhanced process control
    — Extensions to always blocks to include synthesis consistent simulation semantics
    — Extensions to fork…join to model pipelines and for enhanced process control
    — Fine-grain process control
— Enhanced tasks and functions
    — C like void functions
    — pass by reference
    — default arguments
    — pass by name
    — optional arguments
    — import/export functions for DPI (Direct Programming Interface)
— Classes: Object-Oriented mechanism that provides abstraction, encapsulation, and safe pointer capabilities
— Automated testbench support with random constraints
— Interprocess communication synchronization
    — semaphores
    — mailboxes
    — event extensions, event variables, and event sequencing
— Clarification and extension of the scheduling semantics
— Cycle-Based Functionality: Clocking blocks and cycle-based attributes that help reduce development, ease maintainability, and promote reusability:
    — cycle-based signal drives and samples
    — synchronous samples
    — race-free program context
— Assertion mechanism for verifying design intent and functional coverage intent.
    — property and sequence declarations
    — assertions and Coverage statements with action blocks
— Extended hierarchy support
    — packages for declaration encapsulation with import for controlled access
    — compilation-unit scope nested modules and extern modules for separate compilation support
    — extension of port declarations to support interfaces, events, and variables.
    — $root to provide unambiguous access using hierarchical references
— Interfaces to encapsulate communication and facilitate “Communication Oriented” design
— Functional coverage
— Direct Programming Interface (DPI) for clean, efficient interoperation with other languages (C provided)
— Assertion API
— Coverage API
— Data Read API
— VPI extensions for SystemVerilog constructs
— Concurrent assertion formal semantics

 

相关链接:

http://www.eda.org/sv/SystemVerilog_3.1a.pdf

http://www.accellera.org/home