Docsity

exam for phys 2212 an, Exams of Physics

Toggle sidebar
bg1
ECE 2035
Programming HW/SW Systems
Spring 2024
4 problems
Final Exam (RISC-V)
29 April 2024
1
(1 point) Provide your name, ID, signature:
Your Name (please print clearly) ________________________________________________
Your Student ID (9 digit)______________________________
This exam will be conducted according to the Georgia Tech Honor Code. I pledge to neither give
nor receive unauthorized assistance on this exam and to abide by all provisions of the Honor
Code.
Signed __________________________________________________________________
Instructions: This is a closed book, closed note exam. Calculators are not permitted.
Please work the exam in dark pencil or pen and do not separate the pages of the exam. Note that
this exam is double sided. If a line or box is provided for your answer, please write only the
answer there. Additional explanations can be placed outside the specified area. If you run out of
room, please mark on the problem that you will continue on the pages at the end of the exam.
Also please identify the problem that is being continued, and draw a box around it.
Read each question over before you start to work.
If you have a question, raise your hand and I will come to you; do not leave your seat.
For maximum credit, show your work.
Good Luck!
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download exam for phys 2212 an and more Exams Physics in PDF only on Docsity!

4 problems Final Exam (RISC-V) 29 April 2024

(1 point) Provide your name, ID, signature:

Your Name (please print clearly) ________________________________________________

Your Student ID (9 digit)______________________________

This exam will be conducted according to the Georgia Tech Honor Code. I pledge to neither give

nor receive unauthorized assistance on this exam and to abide by all provisions of the Honor

Code.

Signed __________________________________________________________________

Instructions: This is a closed book, closed note exam. Calculators are not permitted.

Please work the exam in dark pencil or pen and do not separate the pages of the exam. Note that

this exam is double sided. If a line or box is provided for your answer, please write only the

answer there. Additional explanations can be placed outside the specified area. If you run out of

room, please mark on the problem that you will continue on the pages at the end of the exam.

Also please identify the problem that is being continued, and draw a box around it.

Read each question over before you start to work.

I f you have a question, raise your hand and I will come to you; do not leave your seat.

For maximum credit, show your work.

Good Luck!

4 problems Final Exam (RISC-V) 29 April 2024

Problem 1 ( 2 parts, 24 points) Compiler Optimization

Consider the following C code fragment. Assume that any functions called by slowpoke perform arith-

metic expressions and printing that do not change the values of any global variables, including the global

array A. Also assume that these functions are called by other functions besides slowpoke.

int A[ 100 ] = {1, 9 , - 7, …}; int reportStatus(int m) {...}; int slowpoke(int a, int b){ int top = 99; int c = 0; int k = - 8; for (int i=top; i>(b-a); --i){ A[i] = k * A[i-1]; c += a*b; if (k){ continue; } reportStatus(A[i]); } return(c); }

Part A ( 8 points) Loop invariant removal:

A.1 List all instructions or subexpressions that can be moved before the loop in slowpoke.

A.2 Fill in the table below to explain how performing this optimization (loop invariant removal without

any other optimizations) affects each of the given factors in slowpoke’s implementation. Be specific

about which items of storage and which instructions are added or removed if your answer is Increases or

Decreases.

Factor Circle one (increase/decrease/same): Explain why

Stack, heap, or

global data storage

Increases Decreases Stays Same

Runtime (dynamic

RISC-V instruc-

tion count)

Increases Decreases Stays Same

4 problems Final Exam (RISC-V) 29 April 2024

Part C ( 8 points) Now assume constant propagation and dead code elimination optimizations are ap-

plied to the code below.

C.1 Show the constant propagation and cross out any dead code that can be eliminated from slowpoke.

int A[ 100 ] = {1, 9 , - 7, …}; int reportStatus(int m) {...}; int slowpoke(int a, int b){ int top = 99; int c = 0; int k = - 8; for (int i=top; i>(b-a); --i){ A[i] = k * A[i-1]; c += a*b; if (k){ continue; } reportStatus(A[i]); } return(c); }

C.2 Fill in the table below to explain how the dead code elimination optimization affects each of the

given factors in slowpoke’s implementation. Be specific about which items of storage and which instruc-

tions are added or removed if your answer is Increases or Decreases.

Factor Circle one (increase/decrease/same): Explain why

Stack, heap, or

global data storage Increases Decreases Stays Same

Runtime (dynamic

RISC-V instruc-

tion count)

Increases Decreases Stays Same

Static RISC-V

code size Increases Decreases Stays Same

4 problems Final Exam (RISC-V) 29 April 2024

Problem 2 ( 4 parts, 2 4 points) Dynamic Allocation on Heap; Garbage Collection

Below is a snapshot of heap storage. Values that are pointers are denoted with a “$”. The heap pointer is

$ 7180. The heap has been allocated contiguously beginning at $70 00 , with no gaps between blocks.

addr value addr value addr value addr value addr value addr value 7000 8 7032 17 7064 12 7096 8 7128 12 7160 $ 7004 7032 7036 $71 32 7068 7084 7100 3 7132 34 7164 12 7008 128 7040 330 7072 0 7104 $7016 7136 $7068 7168 9 7012 12 7044 16 7076 $ 7148 7108 4 7140 $7 084 7172 0 7016 $71 48 7048 12 7080 12 7112 $7084 7144 16 7176 0 7020 $7068 7052 13 7084 7004 7116 8 7148 125 7180 4 7024 $71 12 7056 24 7088 4 7120 55 7152 50 7184 12 7028 12 7060 0 7092 $ 7084 7124 0 7156 45 7188 46

Suppose the stack holds a local variable whose value is the memory address $7 016 and $ 5 holds the

memory address $71 12. No other registers, global variables, or stack locations currently hold heap

memory addresses.

Part A (6 points) In the box on the right, list the addresses of all blocks in the heap that are not garbage.

Show work to the left or on the extra scratch pages at the end of the exam. List of addresses:

Part B (6 points) If a reference counting garbage collection strategy is being used, what would be the ref-

erence counts of the objects at the following addresses?

Address Reference Count Address Reference Count Address Reference Count

Part C ( 5 points) Suppose the freelist is initially empty. If mark-and-sweep is used to sweep up all gar-

bage blocks and put them on the freelist, what is the size of the largest freed block that can be reused?

Size of largest freed block: bytes

Part D ( 7 points) If the local variable whose value is the address $ 7016 is popped from the stack (but $ 5

is still holding $71 12 ), which addresses from Part A will be reclaimed by each of the following strategies?

Reference Counting:

Mark and Sweep:

4 problems Final Exam (RISC-V) 29 April 2024

Problem 4 ( 4 parts, 16 points) Structs, Pointers, Arrays

Assuming a 64-bit system with 64 - bit memory interface and 64 - bit addresses, answer the following

addressing questions. Assume all alignment restrictions imposed by hardware are obeyed, and the compiler

does not add additional alignment restrictions. Note: int and float are 4 bytes, and double is 8 bytes.

For each part below, fill in the value of each expression given that the expression in the comment is true.

Assume variables are allocated in global memory in the order they are declared. Please only write

numbers or chars in each answer box.

typedef struct{ double Mass; int V[ 5 ]; } Moon; int D; // &D == 4000; Moon *NeptuneMoonIDs[ 14 ]; char Fave[] = “HIPPOCAMP”; char *P = &Fave[7]; double B[ 16 ][ 8 ][ 4 ]; &NeptuneMoonIDs[ 5 ] sizeof(Moon) *P-- &B[4][5][ 2 ] - B

4 problems Final Exam (RISC-V) 29 April 2024

Problem 5 (2 parts, 15 points) Compound Predicates, Memory Access

Part 5 A (9 points) Consider the following compound predicate if-then-else statement.

int z = 0;

if (!game_over && ((x>y) || (x<10)))

z = 77 ;

else

z = 3 ;

Which of the following nested if-the-else statements are equivalent to the compound predicate statement

above? Select all that are equivalent.

int z = 0;

if (game_over)

z = 3 ;

else if (x>y)

z = 77 ;

else if (x<10)

z = 77 ;

else

z = 3 ;

int z = 0;

if (!game_over)

if (x>y)

z = 77 ;

else if (x<10)

z = 77 ;

else

z = 3 ;

int z = 0;

if (game_over)

z = 3 ;

else if (x<=y)

if (x>=10)

z = 3 ;

else

z = 77 ;

Equivalent? YES NO Equivalent? YES NO Equivalent? YES NO