idea icon Tip of the Month


We can update you automatically when our Tip of the Month changes.
To receive regular notification of updates to our Tip of the Month section, click here.


Synthesizing "+" : Part One

This month we’re going to look at the synthesis of arithmetic circuitry. Suppose that the following circuit is to be realised using VHDL.

You might decide to write the VHDL code like this...

architecture synth of arithmetic is
  use IEEE.numeric_std.all;  -- this package allows std_logic_vector + natural

  signal  a, b : std_logic_vector (7 downto 0);
  signal  c : std_logic;

begin

  compare_add: process (a, b, c)
    variable s : std_logic_vector (7 downto 0);
  begin
    if (a > b) then
      s := s + 1;
    end if;
    if (c = '1') then
      s := s + 1;
    end if;
    ...
  end process;
  
end synth;

Functionally this code is correct. Unfortunately, some synthesis tools will not give you the hardware architecture you are looking for. For example, one of the golden rules of RTL synthesis is:

So the architecture created by the synthesis tool is as follows:

 

... and there’s no way to optimize the multiplexers away, or to merge the adders into the multiplexers as random logic with good results. Hmmm...

How do we write the code to create the multiplexer-less architecture we desire? The simple solution is to write the VHDL code without using if statements, as follows:

compare_add: process (a, b, c)
  use work.std_boolean.all; -- ">" overloaded to return std_logic
  variable compare : std_logic;
  variable c2 : std_logic_vector (1 downto 0);
  variable s : std_logic_vector (7 downto 0);
begin
  compare := a > b;
  c2 := ('0' & c) + ('0' & compare);
  s := s + c2;
  ...
end process;

Note that this has required the use of a std_logic_vector comparison operator which is overloaded to return a std_logic type rather than the conventional boolean type. In this case, it is the ">" operator which is overloaded.

So to create the desired architecture, code up the VHDL without using IF statements. That’s a tip!

Now, at the start of this month’s Tip, I said “some” synthesis tools follow the rules of RTL synthesis to the letter to give a multiplexer-oriented structure — what about those that don’t? Hmmm, sounds like next month’s Tip to me...


Previous Tips of the Month can be downloaded from here...


wand iconComprehensive VHDL for FPGA / ASIC
chip iconAdvanced VHDL for Synthesis


river sceneDoulos Home Page

Copyright 1995-1997 Doulos
This page was last updated 24th January 1997.

mail iconWe welcome your e-mail comments. Please contact us at: webmaste@doulos.co.uk