Shifting and Logic Units

Shifting and Logic Units

Shifting and Boolean Units 01011 +00101● Shifts of shifts ● Boolean logic 10000 ● An ALU 10/16/2017 Comp 411 - Fall 2017 1 Shifting Logic X7 0 R 1 7 Shifting is a common operation that is applied to X6 groups of bits. Shifting is used for alignment, 0 R 1 6 selecting parts of a word, as well as for X5 arithmetic operations. 0 R 1 5 X << 1 is approx the same as 2*X X4 X >> 1 can be the same as X/2 0 R 1 4 X3 For example: 0 R 1 3 X = 20 = 00010100 10 2 X2 0 R Left Shift: 1 2 (X << 1) = 001010002 = 4010 X1 0 R 1 1 Right Shift: X (X >> 1) = 00001010 = 10 0 2 10 0 R “0” 1 0 Signed or “Arithmetic” Right Shift: LFT1 (-X >> 1) = (111011002 >> 1) = 111101102 = -1010 10/16/2017 Comp 411 - Fall 2017 2 More Shifting X7 X 0 7 X R7 0 S 7 0 1 1 7 S 1 7 X Using the same 6 X 0 6 0 basic idea we can X R6 S 6 0 1 1 6 S build left shifters 1 6 X 5 X 0 5 0 of arbitrary shift X R5 S 5 0 1 1 5 S amounts using 1 5 X 4 X muxes. 0 4 0 X R4 S 4 0 1 1 4 S 1 4 X Each shift amount 3 X 0 R 3 0 X3 1 3 S requires its own 0 1 3 S set of muxes. 1 3 X 2 0 X2 X R 0 2 1 2 S2 Hum, maybe 0 S 1 1 2 X we could do 1 X something 0 R 1 0 X1 1 1 S more clever. 0 1 1 S 1 1 X 0 0 X R 0 0 X0 1 0 S 0 “0” 1 0 S “0” “0” 1 0 LFT1 LFT2 10/16/2017 Comp 411 - Fall 2017 LFT3 3 Barrel Shifting X7 R 0 7 S 0 7 1 0 1 T If we connect our 1 7 X6 R 0 6 S “shift-left-two” shifter to 0 6 1 0 1 T the output of our 1 6 X5 R 0 5 S “shift-left-one” we can 0 5 1 0 1 T shift by 0, 1, 2, or 3 bits. 1 5 X4 R 0 4 S 0 4 And, if we add one more 1 0 1 T 1 4 “shift-left-4” shifter we X3 R 0 3 S 0 3 can do any shift up to 7 1 0 1 T 1 3 bits! X2 R 0 2 S 0 2 So, let’s put a box around it 1 0 1 T 1 2 and call it a new functional X1 R 0 1 S 0 1 block. A 1 0 1 T N-bits X 1 1 0 R log (N) 0 0 S 2 Left 0 0 bits “0” 1 0 S Barrel “0” 1 T “0” 1 0 Shifter LFT1 LFT2 N-bits LFT4 10/16/2017 Comp 411 - Fall 2017 Y 4 Adding a Twist It would be straightforward to construct a “right barrel shifter” unit. However, a simple trick that enables a “left barrel shifter” to do both. A A A A A A A A A A A A A A A A 0 7 1 6 2 5 3 4 4 3 5 2 6 1 7 0 1 0 1 0 1 0 1A 0 1 0 1 0 1 0 1 0 RGT 7- 0 SHFT Left Barrel Shifter Y0 Y7 Y1 Y6 Y2 Y5 Y3 Y4 Y4 Y3 Y5 Y2 Y6 Y1 Y7 Y 0 Y 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 RGT Z7 Z6 Z5 Z4 Z3 Z2 Z1 Z0 10/16/2017 Comp 411 - Fall 2017 5 Rotate AND Arithmetic shifts X7 0 S 1 7 The basics are the same for logical X6 0 S and arithmetic shifts except instead 1 6 X5 of shifting in zeros for the vacated 0 S 1 5 bits on arithmetic shifts, you shift in X4 0 S 1 4 copies of X0. For rotates, you shift X3 in the bits from the other end. 0 S 1 3 X2 This adds two control lines, ASR, 0 S ASR 1 2 X and ROT, which are shared “0” 1 0 0 0 S X0 1 1 1 amongst all of the LFTx units. X 1 7 X0 “0” 0 0 0 S X0 1 1 0 1 X6 ROT LFT2 10/16/2017 Comp 411 - Fall 2017 6 Bitwise Logical Operations We need to perform logical operations, or Booleans, on groups of bits. Which ones? ANDing is used for “masking” off groups of bits. ex. 10101110 & 00001111 = 00001110 (mask selects last 4 bits) ORing is used for “setting” groups of bits. ex. 10101110 | 00001111 = 10101111 (1’s set last 4 bits) EORing is used for “complementing” groups of bits. ex. 10101110 ^ 00001111 = 10100001 (1’s complement last 4 bits) BICing is used to “clear” groups of bits (BIC = bit clear). ex. 10101110 & ~(00001111) = 01010000 (1’s clear) 10/16/2017 Comp 411 - Fall 2017 7 Boolean Unit (The obvious way) It is simple to build up a Boolean unit using primitive gates and a mux to select the function. B Ai i This logic Since there is no interconnection block is between bits, this unit can be simply repeated for each bit (i.e. replicated at each position. The cost 32 times) is about 7 gates per bit. One for 00 01 10 11 each primitive function, and Bool approx 3 for the 4-input mux. This is a straightforward, but not elegant design. Qi 10/16/2017 Comp 411 - Fall 2017 8 Cooler Bools We can better leverage a MUX’s capabilities in our Boolean unit design, by connecting the bits to the select lines. MVN I should pay MOV OR MOV more attention to OR EOR AND Why is this better? those muxes MVN EOR BIC OR While it might take a little 00 01 10 11 logic to decode the truth Ai, Bi table inputs, you only have to do it once, independent Qi of the number of bits. A B Which ever way BTW, it also handles the makes the most Opcode sense to you. Let’s Boolean MOV and MVN cases. get a box around it! Q 10/16/2017 Comp 411 - Fall 2017 9 Decoding the Booleans and others It may seem a little tedious, but all the controls that we need can be derived from the ARM OpCode encodings. The ‘X’s in the truth table are “don’t cares” they provide flexibility in the implementation. 10/16/2017 Comp 411 - Fall 2017 10 An ALU, at last That’s a lot of We give the “Math Center” of a computer a special name-- stuff the Arithmetic Logic Unit (ALU). For us, it just a big box! A B Shft 5 Bidirectional Rot/Asr 2 Barrel Shifter Sub/Rsb 2 ADD 4 b00,b01,b10,b11 SUB Boolean RSB Math 1 0 … C,V Z N R 11 10/16/2017 Comp 411 - Fall 2017 .

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    11 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us