Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] checking saturation logic

Status
Not open for further replies.

rakeshk.r

Member level 2
Joined
Nov 12, 2013
Messages
47
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
421
Hi, Lets say, I have a 6 bit rounded result (4 Int,2 Frac) from a signed multiplication. But i need a 4 bit output (2 int and 2 frac). So now I will have to check if the result overflows when i remove some integer bits. From this point could you check if i am doing the following logic correctly.

Assume 'x' is the 6 bit rounded result. and 'res' is the 4 bit output needed.

Code:
if x(5 downto 4) /= (x(3)&x(3)) then 

    if x(5) = '1' then
         res <= (3=>'0', others=>'1');
    else
        res <= (3=>'1', others=>'0');
    end if;

else
    res <= x (3 downto 0);     
end if;
 

why not simply write this:

Code:
if x > POS_SAT_VALUE then
  res <= MAX;
elsif x < NEG_SAT_VALUE then
  res <= MIN;
else
  res <= x(res'range);
end if;

It is much clearer.
 
considering my example above, POS_SAT_VALUE = "0111" and NEG_SAT_VALUE = "1000". MAX ="0111" and MIN = "1000" right ?
 

Yes.

If you tried out the fixed point packages, it would easy to do something like:

Code:
if x > to_sfixed(1.75, 4, -2) then
  res <= to_sfixed(1.75, 1, -2);
elsif x < to_sfixed(-2.0, 4, -2) then
  res <= to_sfixed(-2.0, 1, -2);
else
  res <= x(1 downto -2);
end if;
 

I think I made a mistake in the code mentioned in the question.
Code:
if x(5) = '1' then
         res <= (3=>'1', others=>'0'); -- max neg
    else
        res <= (3=>'0', others=>'1'); -- max pos 
    end if;
Isn't it ?

- - - Updated - - -

why not simply write this:

Code:
if x > POS_SAT_VALUE then
  res <= MAX;
elsif x < NEG_SAT_VALUE then
  res <= MIN;
else
  res <= x(res'range);
end if;

It is much clearer.

Does this logic work for the case where guard bits are used ?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top