( ESNUG 336 Item 6 ) -------------------------------------------- [11/11/99]
Subject: ( ESNUG 329 #7 330 #5 ) Getting *Signed* Comparitors w/ DC 99.05
>> An old collegue in the Netherlands, Rob van der Valk, gave me a hint on
>> how to do the signed comparisons after he saw my letter in ESNUG. The
>> trick is to invert the MSB's of the operands and do an unsigned
>> comparison on that. So instead of:
>>
>> op_a[n:0] > op_b[n:0]
>> do:
>> {~op_a[n],op_a[n-1:0]} > {~op_b[n],op_b[n-1:0]}
>>
>> That's easier and smaller in logic than the functions I wrote.
>>
>> - Menno Spijker
>> Mitel Semiconductor Kanata, Canada
>
>
> From: Charutosh Dixit <charu@lsil.com>
>
> John,
>
> The solution given for above for signed comparators looks flawed to me.
> The correct solution is: If we have two signed numbers to be compared, we
> swap the MSBs of the two numbers and then perform the regular magnitude
> comparison. The scheme works as follows:
>
> a. When the two numbers have the same sign, MSB swapping does not have
> any effect and the regular magnitude comparison is done
>
> b. When the two numbers have opposite sign, like for example A=0011 and
> B=1001, then the positive number (A) is the bigger number. By
> swapping the MSB we get A=1011 and B=0001, and thus the positive
> number is made bigger in magnitude (1011 > 0001), for the magnitude
> comparison that follows this process.
>
> Hope this helps your ESNUG readers.
>
> - Charu Dixit
> LSI Logic Milpitas, CA
From: Gil Herbeck <gilherbeck@home.com>
John,
There is nothing flawed about the first approach. The flaw is in the tools
that would force a designer to have to use this workaround. In any case,
both approaches are arithmetically correct. This would be an interesting
test for formal verification. Can you have your EDA buddies try their
formal tools on these two RTL designs and let us know how they do? I
suspect that they will work since the vast majority of the circuits should
be the same. But still, it would be interesting to see for sure.
- Gil Herbeck
Radix20 Design Services Livermore, CA
---- ---- ---- ---- ---- ---- ----
From: Dave Knierim <davekn@pogo.WV.TEK.COM>
John,
Both solutions work fine. Charutosh's "proof" for his version works on
Menno's version as well:
a. When the two numbers have the same sign, MSB INVERSION does not have
any effect on the regular magnitude comparison. For the example of
A=0011 and B=0001, A is larger than B. Inverting the MSB's results
in A=1011 and B=1001. A is still larger than B.
b. When the two numbers have opposite sign, like for example A=0011 and
B=1001, then the positive number (A) is the bigger number. By INVERTING
the MSB's we get A=1011 and B=0001, and thus the positive number is made
bigger in magnitude (1011 > 0001), for the magnitude comparison that
follows this process.
- David Knierim
Tektronix
---- ---- ---- ---- ---- ---- ----
From: Surendra Rajupalem <srajupal@lsil.com>
Hi John,
In signed magnitude comparision, the basic trick is make the positive
numbers bigger in magnitude and negative numbers smaller in magnitude.
Assuming sign bit for positive numbers is 0 and vice versa for negative
numbers that is 1. Both the above implementations works, but the latter
will save two inverters because of the swap.
If the sign bit is 1 for positive numbers and 0 for negative numbers just
compare the numbers including sign bit like unsigned magnitude numbers
without any MSB manipulation.
- Surendra Rajupalem
LSI Logic Advanced DSP Development Dallas, TX
---- ---- ---- ---- ---- ---- ----
From: Peter Johnson <pete@sei.com>
John,
You might want to let Charu Dixit know that his swap the MSBs is the same as
Menno Spijker's solution for case b). Swapping two bits which are different
is the same as inverting the bits. Although I must admit that swapping the
MSBs does result in a solution in zero gates (rather than two inverters).
- Pete Johnson
Silicon Engineering, Inc. Scotts Valley, CA
---- ---- ---- ---- ---- ---- ----
From: Howard Landman <HowardL@SiTera.com>
John,
I'm not sure I understand what Charutosh's objection is. Rob/Menno's
solution appears to work fine. The reason:
a. When the two numbers have the same sign, inverting the MSB inverts
both MSBs and the result of the magnitude comparison is unchanged.
b. When the two numbers have opposite sign, like for example A=0011 and
B=1001, then the positive number (A) is the bigger number. By
inverting MSBs we get A=1011 and B=0001, and thus the positive
number is made bigger in magnitude (1011 > 0001).
Of course, Charutosh's variant also works fine. They're almost equivalent
in cost and performance; the only difference is Rob's solution requires
inverters on the MSB (which might slow the circuit down -- but usually MSB
delay is *not* the biggest problem), while Charutosh's involves swapping
some routing, which may or may not be a problem depending on the layout
(but probably not - the two MSBs get used together). Either one is far
better than some of the kludges discussed previously.
- Howard Landman
SiTera Longmont, Colorado
|
|