Posts

SVUnit Upgrade

Being a relatively early adopter of svunit (for unit testing SystemVerilog code), I had a fair amount of code written to work with the early 0.X versions of svunit. The maintainers of svunit have made some good progress and are now on version 2.3 (as of writing this). My old tests don't work with the new version of the framework, but I figured out how to update them. Just in case anyone else is in the same predicament, I will share the steps I took to fix things: In the *_unit_test.sv file: remove typedef class c_<UUT>_unit_test keep the module <UUT>_unit_test declaration, but delete everything in the module except for the string name… and any interface declarations you may have added delete the c_<UUT>_unit_test class declaration add svunit_testcase svunit_ut; under the string name… Now that this is a module and not a class, tasks and functions declared in here might need to have the automatic keyword added to the declaration in order to beh...

Git Branches Are Not Branches

Git branches have confused me (someone who uses mercurial a lot and git a little) for a while, I have finally realized why. The problem is that git branch is a poorly chosen name for the thing that they really are. You see, all the changeset history in git is stored as a Directed Acyclic Graph (DAG). The code history might be simple and linear which will make the DAG have a simple path like so (o's are nodes in the graph, called changesets, -'s are references from one node to another, with time progressing from left to right): o-o-o-o-o Or the code history and corresponding DAG could be more complicated: o-o-o / o-o-o o-o-o-o-o / \ / \ o-o-o-o-o-o-o-o-o-o-----o-o Most English language speakers would agree that those parts of the DAG (code history) where a node has two children (representing two parallel lines of development) are called, branches. The above example has four branches in the history, four branche...

SystemVerilog Constraint Gotcha

I found another one (I guess I still need to order that book ). In using the UVM, I have some sequences randomizing other sub sequences. I really want it to work like this (simplified, non-UVM) example: class Foo; rand int bar; function void display (); $display ( "bar: %0d" , bar); endfunction endclass class Bar; int bar; function void body (); Foo foo = new (); bar = 3; foo. display (); assert (foo. randomize () with {bar == this .bar;}); foo. display (); endfunction endclass module top; Bar bar; initial begin bar = new (); bar. body (); end endmodule See the problem there? Here's what prints out when you run the above: bar: 0 bar: -1647275392 foo.bar is not constrained to be 3 like you might expect. That's because this.bar refers to bar that is a member of class Foo, not bar that's a member of class Bar. As far as I can tell, there is no way to refer to ba...

No More Ads, Send Tips with Bitcoin

Summary: ads are gone, send me bitcoin to say thanks instead. I have always kept notes for myself to remind myself how to do various things. I have also kept a journal since a very young age where I often include opinions and thoughts on various matters. At some point, years ago, I got the idea that I should post some of the notes and thoughts in case they would help someone else. That requires a lot more work than just typing stuff quickly into a text file, though, so I needed a little more motivation. I mean, sharing and helping others is great motivation, but when I read about Adsense from Google, and how Google could show people links to products and services related to my posts, and I could make a few bucks if people thought those links were useful and clicked on them, and how it could help out the people providing those products and services as well, it felt like this great intertwined synergy of helping people out and possibly even gaining some monetary reward as well. An...

List Foreign Keys in Your Postgresql Database

I wanted to know which tables referenced a certain other table in my database, but being a very occasional user of SQL, I didn't know where to begin to find that. Fortunately, the internet had the answer , from Tom Lane himself actually. Just run this query on your Postgresql database: select confrelid::regclass, af.attname as fcol, conrelid::regclass, a.attname as col from pg_attribute af, pg_attribute a, (select conrelid,confrelid,conkey[i] as conkey, confkey[i] as confkey from (select conrelid,confrelid,conkey,confkey, generate_series(1,array_upper(conkey,1)) as i from pg_constraint where contype = 'f') ss) ss2 where af.attnum = confkey and af.attrelid = confrelid and a.attnum = conkey and a.attrelid = conrelid; That shows all foreign key relationships in your database. If you just want to see which tables reference a particular table, do this (replace my_table and my_referenced_column with the table column you want to see t...

Free Verilog Simulators

At DVCon 2013 I asked JL Gray 's panel if we would ever have Free tools, like the software world. None of panelists seemed to think so, one of the panelists, a Mentor employee, scoffed, "you get what you pay for with free tools." Never mind that their (and Cadence's and Synopsys's) products are very likely developed with tools that contain millions of lines of Free software. So, to work towards answering my own question, I spent a little time and looked for Free/Open Source verilog simulators. Here's what I found: Icarus Verilog GPL Cver PVSim Verilog Simulator VeriWell Verilog Simulator I have personally used Icarus and Cver before, but not very extensively.  They were usable and seemed pretty complete, for Verilog.  None of the above claim any support of SystemVerilog except for Icarus.  The Icarus developer at one point expressed abhorrence at SystemVerilog but it seems support for some parts of the language have been added. PVSim and Veri...

SystemVerilog String Literal "Gotcha"

I just ran into another fun SystemVerilog Gotcha. Look this code over and see what you think should happen: module top; string foo[ byte ]; byte bar; initial begin $display ( "%0d" , "a string" == foo[ "not a byte" ]); foo[ "e" ] = "a string" ; $display ( "%0d" , "a string" == foo[ "not a byte" ]); bar = "not a byte" ; $display ( "bar: %0s" , bar); end endmodule Compile error, right? You can't index into an associative array with a string when it is declared to take a byte, can you? And you can't assign a string to a variable of type byte, right? Ha! This actually compiles and runs without any errors or warnings. String literals are packed arrays of bytes and they are automatically truncated to the width of the thing they are being assigned to. Here's the output from running the above code: 0 1 bar: e After my last...