Tải bản đầy đủ (.pdf) (31 trang)

kiến trúc máy tính trương văn cường ôn thi cuối kỳ sinhvienzone com

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.19 MB, 31 trang )

COMPUTER ARCHITECTURE

CuuDuongThanCong.com

/>

Nội dung
• Số floating point
• Bộ xử lý (The Processor)
• Đường dữ liệu
• Đường điều khiển

• Pipelined Datapath and Control
• Hazards
• Structural Hazards
• Data Hazards
• Control Hazards

CuuDuongThanCong.com

/>

IEEE Floating-Point Format
S
x

single: 8 bits
double: 11 bits

single: 23 bits
double: 52 bits



Exponent

Fraction

( 1)

S

(1

Fraction)

2

(Exponent

Bias)

• S: bit dấu (0 số khôn âm, 1 số âm)
• Chuẩn hóa phần lẻ (F): 1.0 ≤ |significand| < 2.0
• Phần mũ: phần mũ thực + Bias
• Chắc chắn số mũ là không dấu ( ex: 2-1 = 2126-127 , F = 126 thay vì F= -1)
• Chính xác đơn: Bias = 127; Chính xác kép: Bias = 1023

PIPELINED PROCESSOR
CuuDuongThanCong.com

/>


Single-Precision Range
• Giá trị nhỏ nhất
• Phần mũ: 00000001
phần mũ thực = 1 – 127 = –126
• Phần lẻ: 000…00 significand = 1.0
• ±1.0 × 2–126 ≈ ±1.2 × 10–38

• Giá trị lớn nhất
• Phần mũ: 11111110
phần mũ thực= 254 – 127 = +127
• Phần lẻ: 111…11 significand ≈ 2.0
• ±2.0 × 2+127 ≈ ±3.4 × 10+38

PIPELINED PROCESSOR
CuuDuongThanCong.com

/>

Floating-Point Example
• Biểu diễn số thực –0.75





–0.75 = (–1)1 × 1.12 × 2–1
S=1
Fraction = 1000…002
Exponent = –1 + Bias
• Single: –1 + 127 = 126 = 011111102

• Double: –1 + 1023 = 1022 = 011111111102

• Single: 1011111101000…00
• Double: 1011111111101000…00

PIPELINED PROCESSOR
CuuDuongThanCong.com

/>

Floating-Point Example
• Giá trị số thực của biểu diễn số sau là bao nhiêu?
11000000101000…00
• S=1
• Fraction = 01000…002
• Fxponent = 100000012 = 129

• x = (–1)1 × (1 + 012) × 2(129 – 127)
= (–1) × 1.25 × 22
= –5.0

PIPELINED PROCESSOR
CuuDuongThanCong.com

/>

MIPS Pipeline


Chia làm 5 tầng, mỗi bước 1 tầng

1. IF: Instruction fetch from memory (Nạp lệnh)
2. ID: Instruction decode & register read (Giải mã lệnh &
đọc thanh ghi)
3. EX: Execute operation or calculate address (Thực thi
phép toán hoặc tính địa chỉ)
4. MEM: Access memory operand (truy xuất toán hạng
bộ nhớ)
5. WB: Write result back to register (ghi kết quả vào
thanh ghi)

PIPELINED PROCESSOR
CuuDuongThanCong.com

/>

The Five Stages of Load Instruction
Cycle 1 Cycle 2

lw

IF

ID

Cycle 3

EX

Cycle 4


Mem

Cycle 5

WB

• IF: Nạp lệnh và cập nhật PC
• Dec: Nạp các thanh ghi và giải mã lệnh
• Exec: Tính toán địa chỉ bộ nhớ
• Mem: đọc dữ liệu từ bộ nhớ
• WB: ghi dữ liệu đọc được vào thanh ghi

PIPELINED PROCESSOR
CuuDuongThanCong.com

/>

Single Cycle Processor
• Datapath
• Control

31:26

5:0

Controller
ALU
Decoder

Main

Decoder

ALUOp[1:0]

MemWrite
MemWrite

RegWrite

RegDst

ALUSrc

Branch
PCSrc

Zero

ALUControl [2:0]

MemRead

CLK

CLK
ALUOut

Reset

ADDR


32

Instr

Datapath

WriteData

32

Data
Memory

RD

32

WD

ReadData
PC

ADDR
32

Lecture review
CuuDuongThanCong.com

Instr

RD

Instruction
Memory

MIPS Processor

/>
ReadData

32


R-type Instruction Data/Control Flow
0
Add

ALUOp
Instr[31-26]

Add

Shift
left 2

4

1
PCSrc


Branch
Control
Unit

MemtoReg
MemWrite

MemRead
ALUSrc

RegWrite
RegDst
Instr[25-21] Read Addr 1

Instruction
Memory
PC

Read
Address

ovf

Instr[31-0]

Register Read
Instr[20-16] Read Addr 2
Data 1
File
0

Write Addr
Read
1
Data 2
Instr[15
Write Data
-11]
Instr[15-0]
16

Sign
Extend

zero
ALU

0

Address
Data
Memory Read Data

1

Write Data

0

1


32

ALU
control

Instr[5-0]

CuuDuongThanCong.com

/>

Load Word Instruction Data/Control
Flow
0
Add

ALUOp
Instr[31-26]

Add

Shift
left 2

4

1
PCSrc

Branch

Control
Unit

MemtoReg
MemWrite

MemRead
ALUSrc

RegWrite
RegDst
Instr[25-21] Read Addr 1

Instruction
Memory
PC

Read
Address

ovf

Instr[31-0]

Register Read
Instr[20-16] Read Addr 2
Data 1
File
0
Write Addr

Read
1
Data 2
Instr[15
Write Data
-11]
Instr[15-0]
16

Sign
Extend

zero
ALU

0

Address
Data
Memory Read Data

1

Write Data

0

1

32


ALU
control

Instr[5-0]

CuuDuongThanCong.com

/>

Store Word Instruction Data/Control F
0
Add

ALUOp
Instr[31-26]

Add

Shift
left 2

4

1
PCSrc

Branch
Control
Unit


MemtoReg
MemWrite

MemRead
ALUSrc

RegWrite
RegDst
Instr[25-21] Read Addr 1

Instruction
Memory
PC

Read
Address

ovf

Instr[31-0]

Register Read
Instr[20-16] Read Addr 2
Data 1
File
0
Write Addr
Read
1

Data 2
Instr[15
Write Data
-11]
Instr[15-0]
16

Sign
Extend

zero
ALU

0

Address
Data
Memory Read Data

1

Write Data

0

1

32

ALU

control

Instr[5-0]

CuuDuongThanCong.com

/>

Adding the Jump Operation
Instr[25-0]

Shift
left 2

26

28

1

32

0

PC+4[31-28]

0

Add


Jump

ALUOp
Instr[31-26]

Add

Shift
left 2

4

1
PCSrc

Branch
Control
Unit

MemtoReg
MemWrite

MemRead
ALUSrc

RegWrite
RegDst
Instruction
Memory
PC


Read
Address

Instr[31-0]

ovf

Instr[25-21] Read Addr 1
Register Read
Instr[20-16] Read Addr 2
Data 1
File
0
Write Addr
Read
1
Data 2
Instr[15
Write Data
-11]
Instr[15-0]
16

Sign
Extend

zero
ALU


0

Address
Data
Memory Read Data

1

Write Data

0

1

32

ALU
control

Instr[5-0]

CuuDuongThanCong.com

/>

Pipeline Control
• IF Stage: read Instr Memory (always asserted) and
write PC (on System Clock)
• ID Stage: no optional control signals to set
EX Stage


MEM Stage

WB Stage

R

Reg
Dst
1

ALU ALU ALU Brch Mem Mem Reg Mem
Op1 Op0 Src
Read Write Write toReg
1
0
0
0
0
0
1
0

lw

0

0

0


1

0

1

0

1

1

sw

X

0

0

1

0

0

1

0


X

beq

X

0

1

0

1

0

0

0

X

PIPELINED PROCESSOR
CuuDuongThanCong.com

/>

Structure Hazards
• Xung đột do việc sự dụng nguồn tài nguyên

• MIPS pipeline với một single memory
• Load/store yêu cầu truy xuất dữ liệu
• Nạp lệnh có thể phải stall cho chu kỳ đó
• Would cause a pipeline “bubble”

• Vì vậy, pipelined datapaths bộ nhớ độc lập
instruction/data
• Hoặc instruction/data caches

Chapter 4
— The
Processo
CuuDuongThanCong.com

PIPELINED PROCESSOR
/>

A Single Memory Would Be a
Structural Hazard
Time (clock cycles)



Mem

Reg

Reg

Mem


Reg

Reg

Mem

Reg

Reg

Mem

Mem

Inst 3
Inst 4

Reg

ALU

Inst 2

Reg

ALU

Mem


Reading data from
memory

Mem

ALU

Reg

ALU

O
r
d
e
r

Inst 1

Mem

ALU

I
n
s
t
r.

lw


Mem

Reading instruction
from memory

Mem

Fix with separate instr and data memories (I$ and D$)
PIPELINED PROCESSOR
CuuDuongThanCong.com

/>
Reg


Data Hazards
• Một lệnh phụ thuộc vào việc hoàn thành truy xuất
dữ liệu bởi một lệnh trước đó.
• add
sub

$s0, $t0, $t1
$t2, $s0, $t3

PIPELINED PROCESSOR
CuuDuongThanCong.com

/>


One Way to “Fix” a Data Hazard

IM

Reg

DM

Reg

IM

Reg

ALU

O
r
d
e
r

add $1,

ALU

I
n
s
t

r.

Can fix data
hazard by
waiting – stall –
but impacts CPI

IM

Reg

stall
stall
sub $4,$1,$5

ALU

and $6,$1,$7

DM

CSE431 Chapter 4B.18

Reg

DM

Reg

Irwin, PSU, 2008

CuuDuongThanCong.com

/>

Another Way to “Fix” a Data Hazard

and $6,$1,$7

or

$8,$1,$9

Reg

IM

Reg

IM

Reg

IM

Reg

DM

Reg


DM

Reg

DM

Reg

DM

ALU

xor $4,$1,$5

IM

ALU

sub $4,$1,$5

Reg

ALU

IM

ALU

O
r

d
e
r

add $1,

ALU

I
n
s
t
r.

Fix data hazards
by forwarding
results as soon as
they are available
to where they are
needed

CSE431 Chapter 4B.20

Reg

DM

Reg

Irwin, PSU, 2008

CuuDuongThanCong.com

/>

Xung đột dữ liệu
Tóm lại, với kỹ thuật forwarding có:



ALU-ALU forwarding hay EX-EX forwarding (hình 1)
MEM-ALU forwarding hay MEM-EX forwarding (hình 2)

Hình 1.

Hình 2.

CSE431 Chapter 4B.21

Irwin, PSU, 2008
CuuDuongThanCong.com

/>

Cho chuỗi lệnh như sau :
lw $1, 40($6)
add $6, $2, $2
sw $6, 50($1)
1. Trong trường hợp pipeline 5 tầng và không dùng
kỹ thuật nhìn trước (no forwarding), sử dụng lệnh
‘nop’ để giải quyết xung đột xảy ra (nếu có) trong

chuỗi lệnh trên.
2. Trong trường hợp pipeline 5 tầng và có kỹ thuật
nhìn trước (forwarding), sử dụng lệnh ‘nop’ để giải
quyết xung đột xảy ra (nếu có) trong chuỗi lệnh trên.

CuuDuongThanCong.com

/>

Control Hazards
Xung đột điều khiển
Một số lệnh nhảy có điều kiện và không điều kiện trong MIPS
(branches, jump) tạo ra xung đột điều kiển này
Ví dụ xét đoạn chương trình sau: add $1, $5, $6
beq $1, $2, label
lw $3, 300($s0)
Nếu áp dụng pipeline thông thường, tại chu kỳ thứ ba của pipeline,
khi beq đang thực thi công đoạn ID thì lệnh lw sẽ được nạp vào.
Nhưng nếu điều kiện bằng của lệnh beq xảy ra thì lệnh thực hiệp
tiếp sau đó không phải là lw mà là lệnh được gán nhãn ‘label’, lúc
này xảy ra xung đột điều khiên.

PIPELINED PROCESSOR
CuuDuongThanCong.com

/>

Control Hazards
1


2

3

4

5

6

7

8

9
Time (cycles)

20

beq $t1, $t2, 40

24

and $t0, $s0, $s1

28

or

2C


sub $t2, $s0, $s5

30

...

IM

lw

$t1, $s4, $s0

$t1
RF $t2

IM

and

DM

-

$s0
RF $s1

IM

or


RF

DM

&

RF $s0

IM

sub

DM

|

$s0
RF $s5

CuuDuongThanCong.com

IM

slt

RF

DM


-

$s2
RF $s3

slt

slt $t3, $s2, $s3

Flush
these
instructions

$s4

...
64

RF

/>
RF

DM

$t3

RF



CuuDuongThanCong.com

/>

Datapath Branch and Jump Hardware
Jump
PCSrc
ID/EX

Shift
left 2
IF/ID

EX/MEM

Control

Add
PC+4[31-28]
4

PC

Instruction
Memory
Read
Address

Shift
left 2


Add

Read Addr 1

Data
Memory

Register Read
Read Addr 2Data 1

File
Write Addr
Write Data
16

Sign
Extend

Read
Data 2
32

MEM/WB

Branch

ALU

Address Read

Data
Write Data

ALU
cntrl

Forward
Unit

CSE431 Chapter 4B.26

Irwin, PSU, 2008
CuuDuongThanCong.com

/>

×