1
votes

I have a module which is basically a LUT whose input is 64 bits. The LUT always block consists of a case statement which compares the input to over 200 different integers. The default case in the case statement checks if the input is > 100 or not before assigning the output a default value.

My problem is that when I synthesize, it leads to a 65 bit comparator, and I was wondering if there are better ways of doing it so that a large comparator isn't synthesized.

Here's my code snippet:

    always @(in)
    begin
    case (in) 
        -100: out <= 495050;
        -99: out <= 500000;
        ...
         99: out <= 99500000;
        100: out <= 99504950;

        default: 
        begin
            if (in > 100)
                out <= 99504950;
            else
                out <= 495050;
        end
    endcase
end

Thanks,

Faisal

2

2 Answers

3
votes

Assuming that in is a 64 bit number, what you can do is to chop it off such that you only have to 'compare' the lowest few bits, and then you can do quick checks to see if the number is outside of the range needed.

For example, let's just chop off in at 8 bits, and assign it to an 8 bit signed register. This should allow you to represent between -128 and 127.

You can test if the full number is larger than 127 by: !in[63] && (|in[62:8]) (check if any upper bit is 1, and the MSB is not set).

You can test if the full number is less than -128 by: in[63] && !(&in[62:8]) (check if any upper bit is 0, and the MSB is set).

Now you know three things:

  1. if the number is larger than 127
  2. if the number is between 127 and -128
  3. and if the number is less than -128.

You should be able to use a small 8-bit LUT for the inbetween case, or use your default values if it's in either of the upper ranges.

Note I might expect a good synthesizer to do this automatically for you, but if you look at the generated netlist and it's too large you can try this to see if it gives you a better result.

2
votes

It seems like You have calculated table with some function values of input x = [-100;100]. If so, it would be better to store them in memory one after another starting from some base address. So to read them, You can write base + X + 100 value on the address bus, and obtain value you need.

In case you need a gigantic multiplexer, you may want to try using a "parallel" case directive.

As for comparator in "default" - I have the same problem, so I am waiting for an answer.

I wanted to write this as a comment but I have no such privilege