Professional Documents
Culture Documents
Report
April 9, 2020
Practical Session 4 : Coding
Answer:
Output: z = 4.905000
2. Second method is based on C promotion , so while multiplying type is
converted to appropriate one , in order to get expected output we simply
change position of 1/2 and put it after g(which is float) so it will be
converted to float while computation.
Answer:
Output: “Normal”
Output: p1 = 2500000000000000
p2 = -1794967296000000
Answer:
same type , hence types are converted by processor to the most precise one in
calculation . In our example p2 gives us a strangely large and negative number ,
because the processor firstly multiplies x which is an integer of big value
(50000) by x, here we get integer overflow. Integer overflow - trying to put in
place into computer memory an integer which is too large , it gives big negative
random numbers.
1. Solution is to multiply integer “x” by long long “a” and after that by
integer “x” , because they will be promoted to the “long long” and as
result overflowing was avoided. So all we need to do is add parentheses ,
see code:
Output: p1 = 2500000000000000
p2 = 2500000000000000
Now it works properly.
Output: p1 = 2500000000000000
p2 = 2500000000000000
2. Data Locality
3.1 Organization
Now dividing cache memory by size of block , and taking power we get number
of blocks:
Answer:
if 32 → 2 15 ÷ 2 5 = 2 10 , so 10 blocks
if 64 → 2 15 ÷ 2 6 = 2 9 , so 9 blocks
if 128 → 2 15 ÷ 2 7 = 2 8 , so 8 blocks
a)Fully-associative
- Firstly we find offset which can be calculated by formula -
log2(block-size):
tag = 24 − 6 = 18 bit
set = 2 15 ÷ 2 6 = 2 9 = 9 bit
tag = 24 − 6 − 9 = 9 bit
- Here each set contains 4 blocks , so we should divide set index by 22 :
set = 2 15 ÷ 2 6 ÷ 2 2 = 2 7 = 7 bit
tag = 24 − 7 − 6 = 11 bit