April 21st, 2012
A small nugget of information that might be useful to someone:
The standard timestamps in struct stat have type time_t which only gives a resolution of seconds which is less than required in many situations. Luckily most operating systems provide a higher resolution timestamp within struct stat but the field name differs among Linux, BSD, etc. On Linux you can get at this with st_mtim.tv_nsec and on BSD it is st_mtimespec.tv_nsec (this also works for OS X).
With autoconf you can use something like:
And then later you can pull the nanoseconds out of the timestamp with:
#if defined HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
ns = st.st_mtimespec.tv_nsec;
#elif defined HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
ns = st.st_mtim.tv_nsec;
ns = 0;
This works the same way for atime and ctime as well as mtime. Make sure to handle the #else case as some systems (Cygwin?) don’t have this at all.
April 15th, 2012
A while ago I posted about a VHDL compiler I’d started writing. Well I’ve been working on it a bit during the evenings and weekends and it’s acquired several new features. Probably the most significant is that it can now compile the standard IEEE
numeric_std packages as well the Synopsys
std_logic_unsigned packages. If you clone the latest version from GitHub these will be built and installed for you automatically. Note that the original IEEE sources cannot be redistributed due to copyright restrictions so you’ll have to faff about downloading them from the IEEE standards website first – see
lib/ieee/README for details.
NVC also now supports a wider range of concurrent statements, including selected and conditional assignments.
This means we can rewrite the counter example from before in a more normal way:
entity counter is
generic ( WIDTH : integer );
clk : in std_logic;
reset : in std_logic;
count : out unsigned(WIDTH - 1 downto 0) );
architecture rtl of counter is
signal count_r : unsigned(WIDTH - 1 downto 0);
count <= count_r;
process (clk) is
if rising_edge(clk) then
if reset = '1' then
count_r <= (others => '0');
count_r <= count_r + 1;
And similarly for the top-level test bench:
entity counter_tb is end entity;
architecture test of counter_tb is
constant WIDTH : integer := 16;
signal clk : std_logic := '0';
signal reset : std_logic := '1';
signal count : unsigned(WIDTH - 1 downto 0);
clk <= not clk after 5 ns;
reset <= '0' after 10 ns;
uut: entity work.counter
generic map ( WIDTH )
port map ( clk, reset, count );
Next we have to analyse and elaborate the design:
$ nvc -a counter.vhd
$ nvc -e counter_tb
/usr/lib/llvm-3.0/bin/llvm-ld -r -b /home/nick/nvc/build/work/_WORK.COUNTER_TB.final.bc /home/nick/nvc/build/work/_WORK.COUNTER_TB.elab.bc /home/nick/share/nvc/ieee/_IEEE.NUMERIC_STD-body.bc /home/nick/share/nvc/ieee/_IEEE.STD_LOGIC_1164-body.bc
llvm-ld line at the end is a new stage that links together the LLVM bitcode for the elaborated design with the bitcode for any referenced packages – the IEEE standard libraries in this case. This allows LLVM’s link time optimisation to optimise across package boundaries. For example, inlining trivial functions like rising_edge directly into the process.
$ nvc -r --stop-time=1ms --stats counter_tb
** Note: setup:28ms run:104ms maxrss:17872kB
LLVM JIT compilation accounts for most of the memory usage and 28ms setup time. However this overhead should be insignificant for any long-running simulation.
Just running the above simulation is fairly boring so I’ve also started adding a basic VCD dumper. This only works for a small set of data types but includes std_logic and std_logic_vector so should hopefully be quite useful in practice.
$ nvc -r --stop-time=100ns --vcd=out.vcd counter_tb
The output can then be opened in a VCD viewer such as GTKWave.
Note that writing out a VCD will slow the simulation considerably. In the future I’d like to be able to selectively dump signals and support other formats such as GHW or LXT2.
April 14th, 2012
I went to Munich for a few days last week with my friend Kelly. Mostly it rained so thankfully there were plenty of indoor museums to do. But on the one sunny day we went to this awesome castle at Neuschwanstein in the Alps.
Unfortunately one whole side of the castle was covered in scaffolding but thankfully not the side with the “classic” view:
There’s a few more photos here.
April 2nd, 2012
Yesterday while I was out exploring I discovered this beautiful pink tree. Is it a cherry blossom? Maybe a tree scientist would know. Anyway, the tree was full of bees! Which is a bit of rarity these days I think. Tried to take some photos of them but unfortunately they don’t much like posing. Also some pigs for good measure.