0
\$\begingroup\$

My textbook (Harris and Harris, Digital Design and Computer Architecture) asks us to design a simplified (in that only positive numbers be considered, with NaN and infinities ignored) FP adder block. They provide the following schematic as a solution which I generally follow, except for the Shift Mantissa block:

enter image description here It is the final MUX in the Shift Mantissa block (select signal generated by the AND-OR sequence) which I don't understand.

This is certainly not an error as they give the following Verilog for that block:

module shiftmant(input  logic alessb,
                 input  logic [23:0] manta, mantb,
                 input  logic [7:0] shamt,
                 output logic [23:0] shmant);
  logic [23:0] shiftedval;
  assign shiftedval = alessb ?
    (manta >> shamt) : (mantb >> shamt);
  always_comb
    if (shamt[7] | shamt[6] | shamt[5] |
        (shamt[4] & shamt[3]))
        shmant = 24'b0;
    else
        shmant = shiftedval;
endmodule

What is the purpose of this final always_comb block (which corresponds to that final MUX I mentioned above)? Why doesn't our initial shift take care of everything, why do we need the extra logic? I've gone back over the algorithm for FP addition and don't see what this bit of hardware corresponds to.

\$\endgroup\$
1
  • \$\begingroup\$ It might be interesting to compare the compiled result with and without that block. I don't have a SV compiler handy or I'd try it. \$\endgroup\$ Commented Mar 2 at 19:01

1 Answer 1

1
\$\begingroup\$

If the shift amount is greater than the width of the mantissa (24 bits), then the mantissa of the smaller number becomes completely irrelevant and can be simply zero'd out. That what the AND-OR logic is determining.

This allows the barrel shifter to be smaller, since it only needs to handle 24 cases rather than the full 256 cases.

This would have been a lot more obvious if the Verilog had been written as

 always_comb
    if (shamt >= 24)
        shmant = 24'b0;
    else
        shmant = shiftedval;

which synthesizes to exactly the same logic as the original code.

\$\endgroup\$
4
  • \$\begingroup\$ Ah I think I see, thanks so much! Just to confirm: the barrel shifter only accepts the low 5 (out of 8) bits of \$shamt\$, whence we see that it can do shifts of up to 31 bits (which, incidentally, is more than enough than is required for a mantissa of 23 bits). We cannot use less than this for the barrel shifter since \$2^4 = 16 < 23\$ wouldn't achieve all the shifts conceivably necessary. However, by omitting the shifts associated with more significant bits in \$shamt\$ being possible, if we didn't have the AND-OR logic then we wouldn't shift in these cases. There is one thing I don't... \$\endgroup\$
    – EE18
    Commented Mar 2 at 20:09
  • \$\begingroup\$ ...follow though. Why do we AND the [4] and [3] bits. Aren't these taken care of by the barrel shifter? That is, if they're both asserted then doesn't the barrel shifter do more than enough of a shift? This seems to be a redundant gate to me. \$\endgroup\$
    – EE18
    Commented Mar 2 at 20:09
  • \$\begingroup\$ Yes, it's redundant. The barrel shifter can be (and probably is) designed to output zeros for shift amounts of 24 - 31. The AND gate is probably just there to reinforce the pedagogical point. \$\endgroup\$
    – Dave Tweed
    Commented Mar 2 at 20:30
  • \$\begingroup\$ Understood, thank you once again! \$\endgroup\$
    – EE18
    Commented Mar 2 at 20:50

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.