Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼

Al Williams

Dr. Dobb's Bloggers

Primitive Verilog

October 07, 2013

Call me Al. Some years ago — never mind how long precisely — having little or no money in my purse, and nothing particular to interest me, I learned how to program computers using assembly and FORTRAN. (I apparently also read Moby Dick somewhere along the way.) After a few years I learned to program in PL/I (that last character is a Roman numeral one, so that's pronounced PL-one not PL-eye). What struck me about PL/I was that almost no one used all of it. IBM had developed the language to replace FORTRAN and Cobol and so it had features that were aimed at both types of developers. As a FORTRAN guy, I almost never used some features and I'm sure the Cobol guys didn't use some of mine.

I find the same thing happens with Verilog, but for a different reason. Verilog is decidedly schizophrenic. There is part of the Verilog language that synthesizers can commonly convert into FPGA logic and then there is an entire part of the language that doesn't synthesize. I do use a small amount of code that doesn't synthesize when writing test benches, but mostly I just figure out how to write test code using the synthesizable subset of Verilog.

Of course, different synthesizers, in theory, could handle different constructs, so your mileage may vary. The other day, I was reading someone else's test bench and ran into Verilog user-defined primitives (UDPs). I dimly remembered that these existed, and wondered why I didn't use them myself. I checked, and sure enough my usual synthesizer doesn't handle them.

There are two types of UDPs: combinatorial and sequential. As you might expect, the combinatorial is just logic and the sequential has a clock-based flip flop component. Here's a UDP that implements an XOR gate with an active low enable pin:

primitive ngated_xor(z,a,b,en_n);
output z;
input a,b,en_n;
// a    b   en_n    z
    0    0       0     : 0;
    0    1       0     : 1;
    1    0       0     : 1;
    1    1       0     : 0;
    ?    ?       1     : 0;

You can probably guess that the ? entries mean any value (0, 1, or x). You can create these just like you'd create a normal primitive like an and gate:

ngated_xor gxor1(result, inA, inB, oe_n);

At this point, you have to wonder why this is interesting. You could get the same result (and synthesize it) with, say, a case statement or using a collection of gates. However, next time I'll talk about primitives that have state and can respond to signal edges as well as levels.

Perhaps like PL/I, I don't really need to use all the Verilog features. But it is still interesting to learn all that you can about your tools. I'll talk about sequential primitives next time. Meanwhile, if you want to wax nostalgic about PL/I, you might find the Iron Spring compiler for Linux interesting.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.