0
\$\begingroup\$

Looking for a clever solution (writing in Verilog)

Let’s say I have two 8 bit values, and each value has an 8 bit score, for a total of four inputs, and I want to combine the two values into one 8 bit value based on the scores. Hypothetically, the simplest way would be

((score1*value1)+(score2*value2))/(score1+score2)

However, it seems to me this is not “easily synthesizable” because of the division by values that are not powers of two.

Anyone have clever ideas to write a code that would serve this function that is synthesizable? I don’t have specific definition for this fusion in mind, but it has to be synthesizable. I am also ok with less possibilities to fuse the values, meaning that I am ok with say, only 128 ways of fusing the values

\$\endgroup\$
  • \$\begingroup\$ What you are describing is called weighted arithmetic mean link \$\endgroup\$ – Rokta May 22 '18 at 13:43
2
\$\begingroup\$

The most direct solution would probably be to use a lookup table for \$\frac{1}{score1+score2}\$.

That would mean that you only need two adds and three multiplies.

If you need a result every clock, you'd have a three-stage pipeline:

  • In the first stage, compute

    • temp1 = score1 × value1
    • temp2 = score2 × value2
    • temp3 = score1 + score2
  • In the second stage, compute

    • temp4 = temp1 + temp2
    • temp5 = 1/temp3 (table lookup)
  • In the third stage, compute

    • result = temp4 × temp5
\$\endgroup\$
  • \$\begingroup\$ But the value for 1/(score1+score2)is less than one, and I am working in binary, so how would the LUT look? \$\endgroup\$ – David May 28 '18 at 14:15
  • \$\begingroup\$ Fixed-point binary numbers are not limited to representing integers only. In this case, the output of the LUT would represent fractions in the range \$\frac{0}{256}\$ through \$\frac{255}{256}\$. When you multiply this with temp4, the high half of the product is your result. (i.e., discard the 8 LSBs) \$\endgroup\$ – Dave Tweed May 28 '18 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.