Al Williams

Dr. Dobb's Bloggers

Primitive Verilog

October 07, 2013

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.

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:

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.

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.

Video

This month's Dr. Dobb's Journal

This month,
Dr. Dobb's Journal is devoted to mobile programming. We introduce you to Apple's new Swift programming language, discuss the perils of being the third-most-popular mobile platform, revisit SQLite on Android
, and much more!