<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>my tech blog &#187; Verilog</title>
	<atom:link href="http://billauer.se/blog/tag/verilog/feed/" rel="self" type="application/rss+xml" />
	<link>https://billauer.se/blog</link>
	<description>Anything I found worthy to write down.</description>
	<lastBuildDate>Thu, 12 Mar 2026 11:36:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Verilog: Declaring each port (or argument) once</title>
		<link>https://billauer.se/blog/2009/07/verilog-standard-short-port-declaration-output-reg-autoarg/</link>
		<comments>https://billauer.se/blog/2009/07/verilog-standard-short-port-declaration-output-reg-autoarg/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 16:25:16 +0000</pubDate>
		<dc:creator>eli</dc:creator>
				<category><![CDATA[FPGA]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[1364-2001]]></category>
		<category><![CDATA[output reg]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[standard]]></category>
		<category><![CDATA[Verilog]]></category>

		<guid isPermaLink="false">https://billauer.se/blog/?p=324</guid>
		<description><![CDATA[(&#8230;or why the Verilog-emacs AUTOARG is redundant) In Verilog, I never understood why port declarations appear both in the module declaration, and then immediately afterwards, along with the wires and registers. I mean, if the ports in the module declaration are always deducible from what follows immediately, why is the language forcing me to write [...]]]></description>
			<content:encoded><![CDATA[<p>(&#8230;or why the Verilog-emacs AUTOARG is redundant)</p>
<p>In Verilog, I never understood why port declarations appear both in the module declaration, and then immediately afterwards, along with the wires and registers. I mean, if the ports in the module declaration are always deducible from what follows immediately, why is the language forcing me to write it twice?</p>
<p>The short answer is: It doesn&#8217;t.</p>
<p>Let&#8217;s have a look on this simple module:</p>
<pre>module example(clk, outdata, inbit, outbit);
   parameter width = 16;

   input clk;
   input inbit;
   output outbit;
   output [(width-1):0] outdata;

   reg [(width-1):0]		outdata;

   assign 	outbit = !inbit;

   always @(posedge clk)
     outdata &lt;= outdata + 1;

endmodule</pre>
<p>There is nothing new here, even for the Verilog beginner: It demonstrates a simple combinatoric input-output relation. We also have an output, which happens to be a register as well (I didn&#8217;t even bother to reset it).</p>
<p>And as usual, every port is mentioned twice. Yuck.</p>
<p>Instead, we can go:</p>
<pre>module example #(parameter width = 16)
  (
   input clk,
   input inbit,
   output outbit,
   output reg [(width-1):0] outdata
   );	       

   assign 	outbit = !inbit;

   always @(posedge clk)
     outdata &lt;= outdata + 1;

endmodule</pre>
<p>At this point, I&#8217;d like to point out, that this is no dirty trick; This type of module declaration is explicitly defined in the Verilog 2001 standard (or by its official name, IEEE Std 1364-2001). This goes both for defining the ports and the parameters  (thanks to <a href="http://outputlogic.com/" target="_blank">Evgeni </a>for pointing out the possibility to set parameters as shown above).</p>
<p>According to the BNF definition in Annex A (A.1.3, to be precise), a module definition must take one of the two formats shown above, but mixing them is not allowed.</p>
<p>So here are few things to note when using the latter format:</p>
<ul>
<li>Each port declaration ends with a comma, not a semicolon. Same goes for parameter declarations.</li>
<li>It&#8217;s not allowed to declare anything about the port again in the module&#8217;s body. Repeating the port&#8217;s name as a wire or reg is not allowed.</li>
<li>Use &#8220;output reg&#8221; (which is legal in either format)  instead of declaring the register in the module&#8217;s body (which is not allowed in this setting)</li>
<li>Syntax highlighters and indenters may not work well</li>
</ul>
<p>The question is now: How could I not know about this?</p>
]]></content:encoded>
			<wfw:commentRss>https://billauer.se/blog/2009/07/verilog-standard-short-port-declaration-output-reg-autoarg/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Xilinx&#8217; XST synthesizer bug: ROM generation using case</title>
		<link>https://billauer.se/blog/2009/03/xst-rom-case-synthesizer-bug/</link>
		<comments>https://billauer.se/blog/2009/03/xst-rom-case-synthesizer-bug/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 16:46:49 +0000</pubDate>
		<dc:creator>eli</dc:creator>
				<category><![CDATA[FPGA]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[case]]></category>
		<category><![CDATA[default]]></category>
		<category><![CDATA[ROM]]></category>
		<category><![CDATA[synthesizer]]></category>
		<category><![CDATA[Verilog]]></category>
		<category><![CDATA[Xilinx]]></category>
		<category><![CDATA[XST]]></category>

		<guid isPermaLink="false">https://billauer.se/blog/?p=27</guid>
		<description><![CDATA[Take a close look on the Verilog code below. This is a plainly-written synchronous ROM. Do you see anything wrong with it? (Spoiler: There is nothing wrong with it. Not that I know of) module coeffs   (    clk, en,    addr, data    );    input clk, en;    input [9:0] addr;    [...]]]></description>
			<content:encoded><![CDATA[<p>Take a close look on the Verilog code below. This is a plainly-written synchronous ROM. Do you see anything wrong with it? (Spoiler: There is nothing wrong with it. Not that I know of)</p>
<pre>module coeffs
  (
   clk, en,
   addr, data
   );

   input clk, en;
   input [9:0] addr;
   output [15:0] data;

   reg [15:0]      data;

   always @(posedge clk)
     if (en)
       case (addr)
     0: data &lt;= 16'h101a;
     1: data &lt;= 16'h115b;
     2: data &lt;= 16'h0f1c;
     3: data &lt;= 16'h0f6d;
     4: data &lt;= 16'hffa4;

... and counting up ...

     249: data &lt;= 16'h0031;
     250: data &lt;= 16'hfffa;
     251: data &lt;= 16'hffee;
     default: data &lt;= 0;
   endcase
endmodule</pre>
<p>But it so happens, that Xilinx&#8217; XST synthesizer failed to get this one right. XST J.39, release 9.2.03i, if you insist.</p>
<p>And when I say it didn&#8217;t get it right, I mean that what I got on the hardware didn&#8217;t implement what the Verilog says it should.</p>
<p>First, what it should have done: Since the address space consists of 10 bits, and there are a lot of, but less than 1024 data elements, the synthesizer should have matched this with a 1k x 18 block RAM, set the values as INIT parameters, and not allow any writes. And so it did. Almost.</p>
<p>The problem, it seems, lies in the fact that only 252 data slots are assigned, leaving 3/4 of the ROM with zeroes. This is where the synthesizer tried to be smarter, for no practical reason. Based upon what I saw with the FPGA Editor, the synthesizer detected, that if any of addr[9] or addr[8] are nonzero, then the output is zero anyhow. Since the block RAM has a synchronous reset input, which affects only the output, the synthesizer decided to feed this reset with (addr[9] || addr[8]). This doesn&#8217;t change anything: If any of these lines is high, the output should be zero. It would be anyhow, since the block RAM itself contains zeros on the relevant addresses, but this reset logic doesn&#8217;t hurt. As long as you get it right, that is. Which wasn&#8217;t the case this time.</p>
<p>What really happened, was that the synthesizer mistakenly reversed the polarity of the logic of the reset line, so it got (!addr[8] &amp;&amp; !addr[9]) instead. That made the memory array produce zeros for any address. And the design didn&#8217;t work.</p>
<p>It looks like the idea was to reverse the polarity at the block RAM&#8217;s reset input as well (which costs nothing in terms of logic resources) but somehow this didn&#8217;t come about.</p>
<p>Workaround: It looks like the &#8220;default&#8221; statement triggered this bug. Since the Verilog file was generated by a computer program anyhow, I let it go on running all the way to 1023, explicitly assigning zeros to each address. This is completely equivalent, of course, but made the design work in real life.</p>
<p>One of these bugs you wouldn&#8217;t expect.</p>
]]></content:encoded>
			<wfw:commentRss>https://billauer.se/blog/2009/03/xst-rom-case-synthesizer-bug/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
