Title: IEEE754 Rounding Modes
1(No Transcript)
2IEEE754 Rounding Modes
- Four Rounding modes
- Plus infinity
- Minus inifinity
- Truncate
- Nearest even
3Examples
4Convert_float
my_float convert_my_float(float num) struct
my_float my_num new(my_float) if (my_num)
union converter c c.f num
my_num-gtsign c.i gtgt 31 my_num-gtexponent
((c.i gtgt 23) 0xff) my_num-gtmantissa
(((c.i 0x7FFFFF) 0x800000) ltlt 3)
return my_num
5Print Binary function
void print_binary(int num) unsigned mask
0x80000000 int anded for (int i 0 i lt
32 i ) if ((i gt 0) (i 4) 0) cout
ltlt " " anded num mask if (anded)
cout ltlt "1" else cout
ltlt "0" mask mask gtgt 1
6Add function
define DBG(a) a
struct my_float my_float_add(struct my_float
first, struct my_float second,\ int
rnd_mode) int first_mantissa
first-gtmantissa int second_mantissa
second-gtmantissa int exp_diff
first-gtexponent - second-gtexponent my_float
my_result new(my_float) DBG(cout ltlt
"Starting to add" ltlt endl) if (exp_diff gt 0)
7Hazard notation
- IN our previous example the twop pairs of hazrard
condditions are - 1a. EX/Mem.RegisterRd ID/EX.RegisterRs
- 1b. EX/Mem.RegisterRd ID/EX.RegisterRt
- 2a. Mem/WB.RegisterRd ID/EX.RegisterRs
- 2b. Mem/WB.RegisterRd ID/EX.RegisterRs
- Hazard on 2 between the sub and and instructions
is - EX/Mem.RegisterRd ID/EX.RegisterRs 2
8Hazards
- Above notation will do forwarding unecessarily as
some instruction do not write registers - Soln can check WB control to check if register
writes back - What about 0
- Do not foraward as shpuld always be zero
9(No Transcript)
10No Forwarding
11Forwarding
12EX Hazard
- If (EX/Mem.RegWrite) and (EX/Mem.RegRd ! 0)
and (EM/Mem.RegRd ID/EX.RegRs) then
ForwardA 10 - If (EX/Mem.RegWrite) and (EX/Mem.RegRd ! 0)
and (EM/Mem.RegRd ID/EX.RegRt) then
ForwardB 10
13Mem Hazard
- If (Mem/WB.RegWrite) and (Mem/WB.RegRd ! 0)
and (Mem/WB.RegRd ID/EX.RegRs) then
ForwardA 01If (Mem/WB.RegWrite) and
(Mem/WB.RegRd ! 0) and (Mem/WB.RegRd
ID/EX.RegRt) then ForwardB 01
14What about
Add 1, 1, 2 Add 1, 1, 3 Add 1, 1, 4
- If (Mem/WB.RegWrite) and (Mem/WB.RegRd ! 0)
and (EX/Mem.RegRd ! ID/EX.RegRs) and
(Mem/WB.RegRd ID/EX.RegRs) then ForwardA
01If (Mem/WB.RegWrite) and (Mem/WB.RegRd !
0) and (EX/Mem.RegRd ! ID/EX.RegRt) and
(Mem/WB.RegRd ID/EX.RegRt) then ForwardB
01
15Updated datapath to resolve data hazards
16Data Hazards and Stalls
- Forwarding will not work where an instruction
tries to read a register following a load
instruction that writes the same register
17Stalls
- Hazard detection unit required at the ID stage
- If (ID/EX.MemRead) and (ID/EX.RegRt
IF/ID.RegRs) or (ID/EX.RegRt IF/ID.RegRt
then stall the pipeline
18(No Transcript)