Creative Uses of Addition

I’ve never been a fan of VHDL’s numeric_std.  It makes a distinction between unsigned, signed, and std_logic_vector for the addition operation.  The operation is (or should be) the same in all cases.  My main issue is that over half of the time, I don’t personally consider the vector to represent a number.  This article is to show a few cases where the additions clearly don’t have numeric arguments.

The addition operation is actually very interesting — there is a propagation of logic in many cases.  This makes it strangely useful outside of mathematical applications.  When this happens, it appears to be interesting and creative.

The first example is the “find first set lsb” operation.  The basic code for this is:

p_lsb : process (clk) is
begin
  if rising_edge(clk) then
    dout <= -din and din;
  end if;
end process;

This line of code might make for an interview question.  The operation can be shown in this simple example:

  • din = 01011100
  • -din = 1010100
  • -din and din = 00000100

Which is exactly the first lsb that is set to a ‘1’.  Without much more work, you could do the bit-reverse and get the first set msb.

The operation is also useful with xnor:

  • din = 01011100
  • -din = 10100100
  • -din xnor din = 00000111

One example of this might be a least-recently used list, where the “hit” item is moved to the “front”, or lsb in this case.  The items in the non-matching cases are conditionally shifted.  The operation also has some use with “or” and “xor”.

I should note that I don’t really suggest this method in general.  In some cases it can work well, but keep in mind that it is very obscured.  Further, the fast adder chains are very localized features for the operation.  This means the inputs shouldn’t have a high fan-in, nor should the output have a high fanout.  If the sources/loads aren’t local, there could be a high routing penalty, making the structure a detriment.

In any case, the specialized operation above clearly isn’t making use of the addition operation for its numeric properties.  The input really is best described as a std_logic_vector.

This entry was posted in Fundamentals. Bookmark the permalink.

Comments are closed.