-1

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?

0

2 Answers 2

2

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

0
0

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.

2
  • It sounds like you are suggesting only checking inputs 1, 4, 9, 16, etc. If inputs 2, 3, 5, 6 are valid inputs, then at least some of those must be checked; that's where the likely bugs reside.
    – toolic
    Dec 7, 2013 at 14:21
  • @toolic Good point. My original thought was that the input values and their square roots should just be precomputed and read from a file, perhaps that's the best approach in the long run.
    – user1619508
    Dec 7, 2013 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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