Signed Integers: 2's Complement: Arithmetic Circuits & Multipliers
Signed Integers: 2's Complement: Arithmetic Circuits & Multipliers
Signed Integers: 2's Complement: Arithmetic Circuits & Multipliers
N bits
-2N-1 2N-2
… … … 23 22 21 20
42 = 0000000000101010
________00101010 we can quickly build a circuit to add two 4-bit numbers…
“Ripple-
-5 = ________11111011
1111111111111011 carry
adder”
Extend the MSB (aka the “sign bit”)
into the higher-order bit positions
S ABC
But what
about the
CO ABC ABC ABC ABC “+1”?
Using a fixed word size can lead to overflow, e.g., when the operation
produces a result that’s too large to fit in the word size. One can
Worst-case path: carry propagation from LSB to MSB, (N) is read
“order N” :
e.g., when adding 11…111 to 00…001.
•Avoid overflow: choose a sufficiently large word size means that the
•Detect overflow: have the hardware remember if an operation latency of our
tPD = (N-1)*(tPD,OR + tPD,AND) + tPD,XOR (N) adder grows at
produced an overflow – trap or check status at end worst in
•Embrace overflow: sometimes this is exactly what you want, e.g., proportion to
when doing index arithmetic for circular buffers of size 2N. CI to CO CIN-1 to SN-1 the number of
•“Correct” overflow: replace result with most positive or most bits in the
operands.
negative number as appropriate, aka saturating arithmetic. Good for
digital signal processing.
6.111 Fall 2017 Lecture 8 9 6.111 Fall 2017 Lecture 8 10
How about the tPD of this circuit? Alternate Adder Logic Formulation
Cin Full Co
Adder
S
Generate (G) = AB
Is the tPD of this circuit = 2 * tPD,N-BIT RIPPLE ? Propagate (P) = A B
BP= P0P1P2P3
Y[64] P,G P,G
A[63:60]
P,G P,G
CLB15 Y[63:60] P0 G0 P1 G1 P2 G2 P3 G3
B[63:60]
Ci,0
C/S Co,0
C/S Co,1
C/S Co,2
C/S 0 Co,3
A[7:4]
B[7:4] CLB1 Y[7:4]
1
A[3:0]
CLB0 Y[3:0]
B[3:0] Key Idea: if (P0 P1 P2 P3) then Co,3 = Ci,0
CLBs must be in same column
6.111 Fall 2017 Lecture 8 15 6.111 Fall 2017 Lecture 8 16
16-bit Carry Bypass Adder Critical Path Analysis
BP= P0P1P2P3 BP= P4P5P6P7 BP= P0P1P2P3 BP2= P4P5P6P7 BP3= P8P9P10P11
BP= P8P9P10P11 BP= P12P13P14P15 BP4= P12P13P14P15
P,G P,G P,G P,G P,G P,G P,G P,G P,G P,G P,G P,G P,G P,G P,G P,G
P,G P,G P,G P,G P,G P,G P,G P,G P,G P,G P,G P,G P,G P,G P,G P,G
Ci,0 Ci,0 Co,3
Co,3 Co,11 Co,7 Co,11
C/S C/S C/S C/S 0 C/S C/S C/S C/S 0
Co,7
C/S C/S C/S C/S 0 C/S C/S C/S C/S 0
C/S C/S C/S C/S 0 C/S C/S C/S C/S 0 C/S C/S C/S C/S 0 C/S C/S C/S C/S 0
Co,0 Co,1 Co,2 Co,4 Co,5 Co,6 Co,0 Co,1 Co,2 Co,4 Co,5 Co,6
1 1 Co,8 Co,9 Co,10 Co,12 Co,13 Co,14 1 1 Co,8 Co,9 Co,10 Co,12 Co,13 Co,14
1 1 1 1
Co,15 Co,15
What is the worst case propagation delay For the second stage, is the critical path:
for the 16-bit adder?
BP2 = 0 or BP2 = 1 ?
Assume the following for delay each gate:
P, G from A, B: 1 delay unit Message: Timing analysis is very tricky –
P, G, Ci to Co or Sum for a C/S: 1 delay unit Must carefully consider data dependencies for false paths
2:1 mux delay: 1 delay unit
P/G generation
1st level of
lookahead
Log2(N)
tPD = Θ(log(N))
FA FA FA HA
Multiplying N-bit number by M-bit number gives (N+M)-bit result x3 x2 x1 x0
y3
z2
Easy part: forming partial products
(just an AND gate since BI is either 0 or 1) FA FA FA HA
FA FA FA FA FA FA HA Step 2: don’t want all those extra additions, so Step 4: finish computing the constants…
x3 x2 x1 x0
y2 add a carefully chosen constant, remembering
z1 to subtract it at the end. Convert subtraction
into add of (complement + 1).
X3Y0 X2Y0 X1Y0 X0Y0
FA FA FA FA FA HA X3Y0 X3Y0 X3Y0 X3Y0 X3Y0 X2Y0 X1Y0 X0Y0 + X3Y1 X2Y1 X1Y1 X0Y1
+ 1 + X2Y2 X1Y2 X0Y2 X0Y2
x3 x2 x1 y3 + X3Y3 X2Y3 X1Y3 X0Y3
x0 + X3Y1 X3Y1 X3Y1 X3Y1 X2Y1 X1Y1 X0Y1
z2 + 1 + 1 1
+ X3Y2 X3Y2 X3Y2 X2Y2 X1Y2 X0Y2
FA FA FA FA FA 1 NB: There are tricks we + 1
can use to eliminate the + X3Y3 X3Y3 X2Y3 X1Y3 X0Y3 –B = ~B + 1 Result: multiplying 2’s complement operands
takes just about same amount of hardware as
+ 1
extra circuitry we + 1
z7 z6 z5 multiplying unsigned operands!
added…
z4 z3 - 1 1 1 1
6.111 Fall 2017 Lecture 8 29 6.111 Fall 2017 Lecture 8 30
FA FA FA
The product then becomes: HA
2 2 2 2 y3
XY = x3y326 + Σ xiy32i+3 + 23 - 26 + Σ x3yj2j+3 + 23 – 26 + Σ Σ xiyj2i+j x3 x2 x1 x0
i=0 j=0 i=0 j=0 1 z2
2 2 2 2
= x3y326 + Σ xiy32i+3 + Σ x3yj2j+3 + Σ Σ xiyj2i+j + 24 – 27
i=0 j=0 i=0 j=0 FA
HA FA FA HA
Assume the multiplicand (A) has N bits and the Init: P = 0; Load A,B
multiplier (B) has M bits. If we only want to invest in a
single N-bit adder, we can build a sequential circuit
Repeat M times {
P A Repeat N times {
that processes a single partial product at a time and B shift A,P:
then cycle the circuit M times: Amsb = Alsb
Pmsb = Plsb + Alsb*Blsb + C/0
0 }
shift P,B: Pmsb = C, Bmsb = Plsb
Init: P0, load A and B
SN SN-1…S0 LSB C FA }
HA FA FA HA
FA FA FA HA
x3 x2 x1 y3
x0
z2
FA FA FA HA
• Design Specs • Implement a warp speed debug mode for the one hz clock.
– Operating voltage 8-18VDC This will allow for viewing signals on the logic analyzer or
– Operating temp: -10C +65C Modelsim without waiting for 27/25 million clock cycles.
– Attitude: sea level Avoids recomplilations.
Fuel pump
Cloaking – Shock/Vibration
device relay
• Notes assign warp_speed = sw[6];
– Protected against 24V power always @ (posedge clk) begin
surges
if (count == (warp_speed ? 3 : 26_999_999)) count <= 0;
– CMOS implementation
else count <= count +1;
– CMOS inputs protected against
end
200V noise spikes
– On state DC current <10ma
assign one_hz = (count == (warp_speed ? 3 : 26_999_999)) ;
– Include T_PASSENGER_DELAY
and Fuel Pump Disable
– System disabled (cloaked) when
being serviced.
Student Comments
• “All very reasonable except for lab 4, Car Alarm. Total pain in the
ass. “