This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Pseudocode for saturation (Oh no, not again)

In some instruction descriptions there are calls to SignedSatQ (directly or indirectly).

The pseudocode for SignedSatQ:

(bits(N), boolean) SignedSatQ(integer i, integer N)

if i > 2^(N-1) - 1 then

result = 2^(N-1) - 1; saturated = TRUE;

elsif i < -(2^(N-1)) then

result = -(2^(N-1)); saturated = TRUE;

else

result = i; saturated = FALSE;

return (result<N-1:0>, saturated);

What's the idea with 'result<N-1:0>' in the return (shifting the result one bit left)?

  • In pseudocode integers and bitstrings are different things. Integers are arbitrary precision and bitstrings are, well, strings of bits...

    In this function, "result" is an integer. To convert an integer to a bitstring, you can apply the bit splice operation. Hence "result<N-1:0>" is just converting the integer to an N-bit string (i.e. extracting bits N-1 to 0). It's not shifting the result.

  • Thanks. Only now I notice the difference - funny.

    I was confusing this: "(-, shift_n) = DecodeImmShift(‘10’, imm3:imm2);"

    and this (in angle brackets): "result<N-1:0>"

    Range versus catenation.