self checking test bench for square root algorithm

1.4k views Asked by At

I have written verilog code for a non-restoring square root algorithm which is synthesisable. My senior says that it now requires a self checking testbench. I know that there is an operator $sqrt in verilog, which is applicable to real numbers. I am dealing with binary bits.

So what can I do to create a self checking testbench for this maths function?

2

There are 2 answers

0
mcleod_ideafix On BEST ANSWER

If your algortihm gets both the square root and the remainder, you can do a TB that performs the inverse operation, that is:

Given N, your algorithm gets q (integer square root of N) and r (integer remainder)

So for correctness, your TB must check that q*q+r equals N for every N within the range defined by the number of bits N has

2
AudioBubble On

Instead of trying to precompute the desired answer, just pick random binary integers in the correct range and square them. Feed the squared value to your square root algorithm and then verify that the original randomly chosen binary value pops out.

A self-checking test bench doesn't necessarily need to use random inputs or be exhaustive, it just needs to verify the results and tell you whether the design under test has passed or failed. You shouldn't need to check any values manually or look at any traces in the simulator.