intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Bài giảng Kiến trúc máy tính: Thiết kế bộ xử lý theo kiến trúc MIPS - Nguyễn Kim Khánh

Chia sẻ: Codon_04 Codon_04 | Ngày: | Loại File: PDF | Số trang:74

201
lượt xem
30
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Cùng tìm hiểu việc thực hiện bộ xử lý MIPS cơ bản; thiết kế khối datapath; thiết kế control unit; kỹ thuật đường ống lệnh được trình bày cụ thể trong "Bài giảng Kiến trúc máy tính: Thiết kế bộ xử lý theo kiến trúc MIPS" do Nguyễn Kim Khánh biên soạn.

Chủ đề:
Lưu

Nội dung Text: Bài giảng Kiến trúc máy tính: Thiết kế bộ xử lý theo kiến trúc MIPS - Nguyễn Kim Khánh

  1. NKK-HUST Kiến trúc máy tính Thiết kế bộ xử lý theo kiến trúc MIPS Nguyễn Kim Khánh Trường Đại học Bách khoa Hà Nội Jan2015 Computer Architecture - MIPS 1
  2. NKK-HUST Nội dung 1. Thực hiện bộ xử lý MIPS cơ bản 2. Thiết kế khối datapath 3. Thiết kế control unit 4. Kỹ thuật đường ống lệnh Jan2015 Computer Architecture - MIPS 2
  3. NKK-HUST 1. Thực hiện bộ xử lý MIPS cơ bản n  Xem xét hai cách thực hiện bộ xử lý theo kiến trúc MIPS: n  Phiên bản đơn giản n  Phiên bản được đường ống hóa (gần với thực tế) n  Chỉ thực hiện với một số lệnh cơ bản của MIPS, nhưng chỉ ra hầu hết các khía cạnh: n  Các lệnh tham chiếu bộ nhớ: lw, sw n  Các lệnh số học/logic: add, sub, and, or, slt n  Các lệnh chuyển điều khiển: beq, j Jan2015 Computer Architecture - MIPS 3
  4. NKK-HUST Tổng quan quá trình thực hiện các lệnh n  Hai bước đầu tiên với mỗi lệnh: n  Đưa địa chỉ từ bộ đếm chương trình PC đến bộ nhớ lệnh, tìm và nhận lệnh từ bộ nhớ này n  Sử dụng các số hiệu thanh ghi trong lệnh để chọn và đọc một hoặc hai thanh ghi: n  Lệnh lw: đọc 1 thanh ghi n  Các lệnh khác (không kể lệnh jump): đọc 2 thanh ghi Jan2015 Computer Architecture - MIPS 4
  5. NKK-HUST Tổng quan quá trình thực hiện các lệnh (tiếp) n  Các bước tiếp theo tùy thuộc vào loại lệnh: n  Sử dụng ALU hoặc bộ cộng Add để: n  Tính kết quả phép toán với các lệnh số học/logic n  So sánh các toán hạng với lệnh branch n  Tính địa chỉ đích với các lệnh branch n  Tính địa chỉ ngăn nhớ dữ liệu với lệnh load/store n  Truy cập bộ nhớ dữ liệu với lệnh load/store n  Lệnh lw: đọc dữ liệu từ bộ nhớ n  Lệnh sw: ghi dữ liệu ra bộ nhớ n  Ghi dữ liệu đến thanh ghi đích: n  Các lệnh số học/logic: kết quả phép toán n  Lệnh lw: dữ liệu được đọc từ bộ nhớ dữ liệu Jan2015 Computer Architecture - MIPS 5
  6. NKK-HUST Tổng quan quá trình thực hiện các lệnh (tiếp) n  Thay đổi nội dung bộ đếm chương trình PC: n  Với các lệnh rẽ nhánh (branch), tùy thuộc vào kết quả so sánh: n  Điều kiện thỏa mãn: PC ß địa chỉ đích (địa chỉ của lệnh cần rẽ tới) n  Điều kiện không thỏa mãn: PC ß PC + 4 (địa chỉ của lệnh kế tiếp) n  Với các lệnh còn lại (không kể các lệnh jump) n  PC ß PC + 4 (địa chỉ của lệnh kế tiếp) Jan2015 Computer Architecture - MIPS 6
  7. NKK-HUST Sơ đồ khái quát của bộ xử lý MIPS Jan2015 Computer Architecture - MIPS 7
  8. NKK-HUST Sử dụng bộ chọn kênh (MUX) n  Không thể nối trực tiếp tại các vị trí được đánh dấu n  Sử dụng MUX Jan2015 Computer Architecture - MIPS 8
  9. NKK-HUST Bộ xử lý với các đường điều khiển chính Jan2015 Computer Architecture - MIPS 9
  10. NKK-HUST 2. Thiết kế khối Datapath n  Datapath: gồm các thành phần để xử lý dữ liệu và địa chỉ n  Tập thanh ghi, ALUs, MUX’s, bộ nhớ, … n  Sẽ xây dựng tăng dần khối datapath cho MIPS Jan2015 Computer Architecture - MIPS 10
  11. NKK-HUST Processor 252 Các 252 thành phần để thực hiện nhận lệnh Chapter 4 The Processor Chapter 4 The Processor n Instruction Instruction address address Instruction PC Instruction Add SumInstruction PCAdd Sum Add Sum PC on Instruction Instruction y memory memory a. Instruction memory b. Program counter c. Adder mory n  Bộ đếm chươngFIGURE trình b. Program PC: a. Instruction countermemoryc. Adder b. Program counter 4.5 Two state elements are needed to store and access instructions, and an c. Adder FIGURE 4.5 Two state elements are needed to store and access instructions, and an o state elements are needed to store and access adder is needed to compute instructions, and an the next instruction address. The state elements are the instruction n  to compute the next instruction Thanh ghi 32-bit chứa địa chỉ của lệnh hiện tại adder is needed to compute address. Th e state memory and the program counter. memory elements the next andare thetheinstruction program The instruction address. counter. instruction memory need The state elements The instruction memory needare the instruction only provide read access because the datapath does not write instructions. Sinceonly provide read the instruction accessonly memory because reads, the we treat it as combinational rogram counter. The instruction datapath memorydoes neednotonly writeprovide readSince access because thememory only reads, we treat it as combinational Địa chỉ khởi động = 0xBFC0 0000 n  instruction rite instructions. Since the memory logic: the output only instructions. at anyreads, weects timecontrol refl treat signal the theitcontents as instruction logic: the output at any time reflects the contents of the location specified by the address input, and no read combinational is needed. of the (Welocation will needspecifi ed by to write thethe address input, instruction memory andwhen no read we load the program; this is any time reflects the contents of the location control signalspecifi ed by(We is needed. the address will need input, to write and the no read instruction memory when we load the program; not hard to add, and we ignore it for simplicity.) The program counter is a 32-bit register this is that is written at the ded. (We will need to n  writeBộ nhớ lệnh (Instruction memory): the instruction not hard to end of every we ignore it for simplicity.) The program memory add, and we clockiscycle counter when ignorewe end andadd a 32-bit it thus load for of itsdoes register the not twothat program; simplicity.) every clock need 32-bit Th cycle eandthis program a write is inputs written and is thus counter does atcontrol not the thesignal. place is need sum on a 32-bit Thits a register write e adder controlthat is written signal. Th e at adder is an ALU wired to always output. the is an ALU wired to always add its two 32-bit inputs and place the sum on its output. n  puts and place the sum on its output. Chứa các lệnh của chương trình ycle and thus does not need a write control signal. The adder is an ALU wired to always n  Khiwhich có were which từ địaintroduced chỉ lệnh werePC introduced đưa inđến Chapter 2. Recall thì lệnh that a typicalđọc được instance ra of such an in Chapter instruction is add2. Recall that a typical $t1,$t2,$t3, instance which of such reads $t2 an and writes $t1. and $t3 instruction is add $t1,$t2,$t3, The processor’s which reads $t2 and registers 32 general-purpose $t3 andare writes $t1. stored in a structure called a roduced in Chapter n  Bộ2.register cộng Recall Th (Add): that a typical fiele processor’s A state được instance 32register sử of suchdụng file. A register general-purpose an registers file isare tăng nội dung stored inofa registers a collection structureincalled which PCaany register can be ddregister $t1,$t2,$t3, which element reads register $t2 that consists and $t3 file. A register read and writes fileoriswritten $t1. by specifying a collection the number of registers in whichofany the register in thebefile. The register file can or’selement 32 general-purpose thêm file A state that consists of a 4 registers set of để are registers trỏ stored that tới read or written by specifying in alệnh structure containsthe kế thenumber tiếp called register of a state theofregister the computer. In Th in the file. addition, wefiwill e register le need an ALU to register file of a set of registers Jan2015 that can is a collection be read and of registers written in which any Computerregister canread Architecturebe - MIPS 11 contains the register operate state of on thethe values computer. In from the registers. addition, we will need an ALU to by supplying a register bycan be read andthe specifying written numberoperate of the on register in the the values file. read fromThethe R-format register filehave three register operands, so we will need to read two instructions registers.
  12. NKK-HUST Thực hiện phần nhận lệnh Increment by 4 for next instruction 32-bit register Jan2015 Computer Architecture - MIPS 12
  13. NKK-HUST Thực hiện lệnh số học/logic kiểu R op rs rt rd shamt funct 31:26 25:21 20:16 15:11 10:6 5:0 n  bits 31:26: mã thao tác (opcode) n  000000 với các lệnh kiểu R n  bits 25:21: số hiệu thanh ghi nguồn thứ nhất rs n  bits 20:16: số hiệu thanh ghi nguồn thứ hai rt n  bits 15:11: số hiệu thanh ghi đích rd n  bits 10:6: số bit được dịch với các lệnh dịch bit n  00000 với các lệnh khác n  bits 5:0: mã hàm để xác định phép toán (function code) Jan2015 Computer Architecture - MIPS 13
  14. NKK-HUST 310 Chapter 4 The Processor Các thành phần thực hiện lệnh kiểu R 5 Read ALU operation 4 register 1 Read Register 5 Read data 1 numbers register 2 Zero Registers Data ALU ALU 5 Write result register Read Write data 2 Data Data RegWrite a. Registers n  Tập thanh ghi (Registers): có 32 thanhb. ALU ghi 32-bit, mỗi thanh ghi được xác định bởi số hiệu 5-bit FIGURE 4.7 The two elements needed to implement R-format ALU operations are the register file and the ALU. The register file contains all the registers and has two read ports and one write n  Read register 1, ofRead register 2: tocác đầu port. The design of multiported register files is discussed in Section C.8 of always outputs the contents the registers corresponding the Read vào đểonchọn các Appendix C. The register file register inputs the outputs; no thanh ghi cần other đọc control inputs are needed. In contrast, a register write must be explicitly indicated by asserting the write control signal. Remember that writes are edge-triggered, so that all the write inputs (i.e., the value to n  Write register: be written, đầuandvào the register number, đểcontrol the write chọn thanh signal) ghiatcần must be valid ghi the clock edge. Since writes to the register file are edge-triggered, our design can legally read and write the same register within a clock cycle: n  Read data the read will get the1, Read value written indata an earlier2: hai clock cycle,đầu ravalue while the dữwritten liệuwillđọc từ tothanh be available a read in ghi (32-bit) a subsequent clock cycle. The inputs carrying the register number to the register file are all 5 bits wide, whereas n  Write the lines Data: carrying data đầu valuesvào dữwide. are 32 bits liệu ghi vào The operation to bethanh performed ghi by the (32-bit) ALU is controlled with the ALU operation signal, which will be 4 bits wide, using the ALU designed in Appendix C. We will n  RegWrite: tín output use the Zero detection hiệuof điều the ALU khiển ghi dữbranches. shortly to implement liệu vào thanh The overflow outputghi will not be needed until Section 4.9, when we discuss exceptions; we omit it until then. n  ALU để thực hiện các phép toán số học/logic Jan2015 Computer Architecture - MIPS 14
  15. NKK-HUST Mô tả thực hiện lệnh số học/logic kiểu R n  Hai số hiệu thanh ghi rs và rt đưa đến hai đầu vào Read register 1, Read register 2 để chọn hai thanh ghi nguồn n  Số hiệu thanh ghi rd đưa đến đầu vào Write register để chọn thanh ghi đích n  Hai dữ liệu từ hai thanh ghi nguồn được đọc ra 2 đầu ra Read data 1 và Read data 2 , rồi đưa đến đầu vào của ALU n  ALU operation (4-bit): tín hiệu điều khiển chọn phép toán ở ALU n  ALU thực hiện phép toán tương ứng, kết quả phép toán ở đầu ra ALU result được đưa về đầu vào Write Data của tập thanh ghi để ghi vào thanh ghi đích n  RegWrite: tín hiệu điều khiển ghi dữ liệu vào thanh ghi đích Jan2015 Computer Architecture - MIPS 15
  16. NKK-HUST Thực hiện các lệnh lw/sw op rs rt imm 31:26 25:21 20:16 15:0 n  bits 31:26 là mã thao tác n  100011 (35) với lệnh lw n  101011 (43) với lệnh sw n  bits 25:21: số hiệu thanh ghi cơ sở rs n  bits 20:16: số hiệu thanh ghi rt n  thanh ghi đích với lệnh lw n  thanh ghi nguồn với lệnh sw n  bits 15:0: hằng số imm có giá trị trong dải [-215 , +215 – 1] n  Địa chỉ từ nhớ dữ liệu = nội dung thanh ghi rs + imm n  lw rt, imm(rs) # (rt) = mem[(rs)+SignExtImm] n  sw rt, imm(rs) # mem[(rs)+SignExtImm] = (rt) Jan2015 Computer Architecture - MIPS 16
  17. NKK-HUST Các thành phần thực hiện các lệnh lw/sw Chapter 4 The Processor Tập thanh ghi Bộ số học/logic 5 Read ALU operation 4 register 1 Read Register 5 Read data 1 numbers register 2 Zero Registers Data ALU ALU 5 Write result register Read Write data 2 Data Data 4.3 Building a Datapath RegWrite a. Registers Bộ nhớ dữ liệu b. ALU Bộ mở rộng số có dấu FIGURE 4.7 MemWrite The two elements needed to implement R-format ALU operations are the từ 16-bit à 32-bit register file and the ALU. The register file contains all the registers and has two read ports and one write port. The design of multiported register files is discussed in Section C.8 of Appendix C. The register file always outputs the contents of the registers corresponding to the Read register inputs Read on the outputs; no Address other control inputs are needed. In contrast, a register write must be explicitly indicated data by asserting the write control signal. Remember that writes are edge-triggered, so that all the write inputs (i.e., the value to 16 32 be written, the register number, and the write control signal) must be valid at the clock edge. Since writes to Sign- Data the register file are edge-triggered, our design can legally read and write the same register within a clock cycle: extend the read will get the value written in an earlier clock cycle, while the value written will be available to a read in a subsequent clock cycle. The inputs carrying the register number to Write memory the register file are all 5 bits wide, whereas data the lines carrying data values are 32 bits wide. The operation to be performed by the ALU is controlled with the ALU operation signal, which will be 4 bits wide, using the ALU designed in Appendix C. We will use the Zero detection output of the ALU shortly to implement branches. The overflow output will not be needed until Section 4.9, when we discuss exceptions; we omit it until then. MemRead Jan2015 Computer Architecture - MIPS 17 a. Data memory unit b. Sign extension unit In addition, we will need a unit to sign-extend the 16-bit offset field in the
  18. NKK-HUST Thực hiện lệnh lw n  Số hiệu thanh ghi rs đưa đến đầu vào Read register 1 để chọn thanh ghi cơ sở rs, nội dung rs được đưa ra đầu ra Read Data 1, rồi chuyển đến ALU n  Hằng số imm 16-bit đưa đến bộ Sign-extend để mở rộng thành 32-bit, rồi chuyển đến ALU n  ALU cộng hai giá trị trên đưa ra ALU result chính là địa chỉ của dữ liệu cần đọc từ bộ nhớ dữ liệu; địa chỉ này được đưa đến đầu vào Address của bộ nhớ dữ liệu n  Số hiệu thanh ghi rt đưa đến đầu vào Write Register để chọn thanh ghi đích n  Dữ liệu 32-bit ở bộ nhớ dữ liệu, tại vị trí địa chỉ đã được tính, được đọc ra ở đầu ra Read data của bộ nhớ dữ liệu nhờ tín hiệu điều khiển MemRead, rồi đưa về đầu vào Write Data của tập thanh ghi để ghi vào thanh ghi đích rt Jan2015 Computer Architecture - MIPS 18
  19. NKK-HUST Thực hiện lệnh sw n  Số hiệu thanh ghi rs đưa đến đầu vào Read register 1 để chọn thanh ghi cơ sở rs, nội dung rs được đưa ra đầu ra Read Data 1, rồi chuyển đến ALU n  Hằng số imm 16-bit đưa đến bộ Sign-extend để mở rộng thành 32-bit, rồi chuyển đến ALU n  ALU cộng hai giá trị trên đưa ra ALU result chính là địa chỉ của vị trí ở bộ nhớ dữ liệu; địa chỉ này được đưa đến đầu vào Address của bộ nhớ dữ liệu n  Số hiệu thanh ghi rt đưa đến đầu vào Read register 2 để chọn thanh ghi dữ liệu nguồn rt, nội dung rt được đưa ra đầu ra Read data 2 n  Dữ liệu 32-bit này sẽ được đưa đến đầu vào Write data của bộ nhớ dữ liệu và được ghi vào vị trí nhớ có địa chỉ đã được tính, nhờ tín hiệu điều khiển MemWrite Jan2015 Computer Architecture - MIPS 19
  20. NKK-HUST Thực hiện lệnh Branch (beq, bne) 4 or 5 rs rt imm 31:26 25:21 20:16 15:0 n  bits 31:26 mã thao tác n  000100 (4) với lệnh beq n  000101 (5) với lệnh bne n  bits 25:21 số hiệu thanh ghi nguồn rs n  bits 20:16 số hiệu thanh ghi nguồn rt n  bits 15:0 hằng số imm có giá trị trong dải [-215 , +215 – 1] n  So sánh nội dung hai thanh ghi rs và rt: n  Nếu điều kiện đúng: rẽ nhánh đến nhãn đích n  PC ß (PC +4) + hằng số x 4 n  Nếu điều kiện sai: chuyển sang thực hiện lệnh kế tiếp n  PC ß PC + 4 Jan2015 Computer Architecture - MIPS 20
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2