Docsity

CS61C Spring 2008 Exam - UC Berkeley EECS Department, Exams of Structural Analysis

Toggle sidebar
bg1
University of California, Berkeley – College of Engineering
Department of Electrical Engineering and Computer Sciences
Spring 2008 Instructor: Dr. Dan Garcia 2008-05-19
 CS61C Final 
After the exam, indicate on the line above where you fall in the emotion spectrum between ā€œsad ā€ & ā€œsmileyā€...
Last Name
First Name
Student ID Number
Login
cs61c-
Login First Letter (please circle)
a b c d e f g h i j k l m
Login Second Letter (please circle)
a b c d e f g h i j k l m
n o p q r s t u v w x y z
The name of your SECTION TA (please circle)
Ben Brian Casey Dave Keaton Matt Omar
Name of the person to your Left
Name of the person to your Right
All the work is my own. I had no prior knowledge of the exam
contents nor will I share the contents with others in CS61C
who have not taken it yet. (please sign)
Instructions (Read Me!)
• This booklet contains 9 numbered pages including the cover page.
Put all answers on these pages; don’t hand in any stray pieces of paper.
• Please turn off all pagers, cell phones & beepers. Remove all hats & headphones. Place your backpacks,
laptops and jackets at the front. Sit in every other seat. Nothing may be placed in the ā€œno fly zoneā€ spare
seat/desk between students.
• You have 180 minutes to complete this exam. The exam is closed book, no computers, PDAs or calculators.
You may use two pages (US Letter, front and back) of notes and the green sheet.
• There may be partial credit for incomplete answers; write as much of the solution as you can. We will deduct
points if your solution is far more complicated than necessary. When we provide a blank, please fit your answer
within the space provided. ā€œIEC formatā€ refers to the mebi, tebi, etc prefixes.
• You must complete ALL THE QUESTIONS, regardless of your score on the midterm. Clobbering only
works from the Final to the Midterm, not vice versa. You have 3 hours... relax.
Question
M1
M2
M3
Ms
F1
F2
F3
F4
Fs
Total
Minutes
20
20
20
60
24
30
24
42
120
180
Points
10
10
10
30
18
24
18
30
90
120
Score
Confessional:
pf3
pf4
pf5
pf8

Partial preview of the text

Download CS61C Spring 2008 Exam - UC Berkeley EECS Department and more Exams Structural Analysis in PDF only on Docsity!

University of California, Berkeley – College of Engineering

Department of Electrical Engineering and Computer Sciences

Spring 2008 Instructor: Dr. Dan Garcia 2008 - 05 - 19

 CS61C Final 

After the exam, indicate on the line above where you fall in the emotion spectrum between ā€œsadā€ & ā€œsmileyā€...

Last Name

First Name

Student ID Number

Login cs61c-

Login First Letter (please circle) a^ b^ c^ d^ e^ f^ g^ h^ i^ j^ k^ l^ m

Login Second Letter (please circle) a^ b^ c^ d^ e^ f^ g^ h^ i^ j^ k^ l^ m

n o p q r s t u v w x y z

The name of your SECTION TA (please circle) Ben Brian Casey Dave Keaton Matt Omar

Name of the person to your Left

Name of the person to your Right

All the work is my own. I had no prior knowledge of the exam contents nor will I share the contents with others in CS61C

who have not taken it yet. (please sign)

Instructions (Read Me!)

  • This booklet contains 9 numbered pages including the cover page. Put all answers on these pages; don’t hand in any stray pieces of paper.
  • Please turn off all pagers, cell phones & beepers. Remove all hats & headphones. Place your backpacks, laptops and jackets at the front. Sit in every other seat. Nothing may be placed in the ā€œno fly zoneā€ spare seat/desk between students.
  • You have 180 minutes to complete this exam. The exam is closed book, no computers, PDAs or calculators. You may use two pages (US Letter, front and back) of notes and the green sheet.
  • There may be partial credit for incomplete answers; write as much of the solution as you can. We will deduct points if your solution is far more complicated than necessary. When we provide a blank, please fit your answer within the space provided. ā€œIEC formatā€ refers to the mebi, tebi, etc prefixes.
  • You must complete ALL THE QUESTIONS, regardless of your score on the midterm. Clobbering only works from the Final to the Midterm, not vice versa. You have 3 hours... relax. Question M1 M2 M3 Ms F1 F2 F3 F4 Fs Total Minutes 20 20 20 60 24 30 24 42 120 180 Points 10 10 10 30 18 24 18 30 90 120 Score

Confessional:

M1) Hey buddy, can you run these instructions for me? Thanks! (10 pts, 20 min)

Consider the following non-delayed branch MIPS function foo:

a) What does the following function call (in C) return? ________

foo(-1, 0x308 8 0001, 0x 0048 1020, 0x 000 42042); foo: li $v0, la $t9,loop sw $a1,0($t9) sw $a2,4($t9) sw $a3,8($t9) loop: nop nop nop bne $a0,$0,loop jr $ra

b) You can probably see how foo could pose a security threat if misused. For the good of humanity, we must

seal its functionality forever, and render it harmless. That is, you’re going to call it once with a special set of

arguments for $a0-$a3 (list these below in human-readable form … not as numbers!) so that every future call

to foo always just returns $a0 regardless of the value of $a1-$a3. Oh, and the call to foo with the

arguments below should cause it (this time only) to return 0 to signal success that it has been ā€œneutralizedā€.

$a0: __________________________ $a1: __________________________ $a2: __________________________ $a3: __________________________

M3) Memories, like the smile we left behind… (10 pts, 20 mins)

a) Here is code and output for a small program, called memtest,

run on an unknown machine with an unknown architecture.

What are two possible reasons the program didn’t print out 1?

main() { char *p = (char *) malloc ( 1 ); char *q = (char *) malloc ( 1 ); printf("%u\n", (unsigned int) q - (unsigned int) p); } unix% ./memtest 16

b) Consider the heap pictured below. The first 8 bytes are reserved for the buddy system. The heap is filled

left to right when more than one slot can satisfy a request. Any free buddy pairs are consolidated immediately

when possible. For the series of memory requests below, fill in the heap snapshot after every 2 nd^ line.

Be sure to label your allocated space and the block boundaries, as is shown in the initial heap.

For the following two questions, we are counting the number of different instructions (add, sub, …), not including

the arguments they could accept. E.g., add $t0,$t0,$t0 and add $s 1 ,$s 2 ,$s 3 are only counted as one, add.

c) How many unique TAL MIPS instructions could ( not do) we have? _____________________________

d) How many unique MAL MIPS instructions could ( not do) we have? _____________________________

1 C = malloc(1); 2 free(B); 3 D = malloc(2); 4 free(A); 5 E = malloc(3); 6 F = malloc(2); 7 free(D); 8 G = malloc(3);

e) Fill the table with ALL the choices that

fit. Some may be blank, and the letters may be used more than once.

Consumes

(input/uses)

Creates/Causes

(output/side-effects)

1. Slab Allocator

2. Assembler

3. Linker

4. Compiler

5. Reference Counting

6. Copying

7. Mark and Sweep

A. Executable

B. .o files

C. Root Set

D. Relocation Table

E. C Source Code

F. Internal Fragmentation

G. Allocation Requests

H. Symbol Table

I. MAL

J. Half the Heap

K. Library Files

L. External Fragmentation

M. Memory Leak

F1) How many CS majors to change a lightbulb? None, that’s HW! ( 18 pts, 24 mins)

Questions (a), (b), (c) and (d) are independent.

a) You are an intern at a massive hardware firm. Your first task is to design an ā€œodd counterā€ circuit that receives

a single bit input every cycle and outputs a single bit every cycle. It outputs a 1 if and only if it has seen an

odd number of ones AND an odd number of zeros. It starts in a state where it has seen an even number of

ones and an even number of zeros (remember, zero is an even number). As an example,

the input: I: 1 1 0 1 1 1 0 0 0 1 0 1 1 0 0

will produce the output: O: 0 0 0 1 0 1 0 1 0 0 0 1 0 0 0

Complete the FSM diagram below. The names of the states are arbitrary, but use S

is the start state. Fill in the truth table on the right. The previous state is encoded in

(P1,P0), the next state is encoded in (N1,N0), and the output is encoded as O. Make

sure to indicate the value of the output on your state.

b) Rebuild this circuit with the fewest gates in the box to the

right, using ONLY AND, OR and NOT gates.

c) Finally, your boss wants you to choose an XOR gate

for the circuit to the right: The clock speed is 2Ghz,

the setup, hold, and clock-to-q times of the register

are 40, 70, and 60 picoseconds (10-^12 s) respectively.

What range of XOR gate delays is acceptable?

E.g., ā€œat least W psā€, ā€œat most X psā€, or ā€œY to Z psā€.

d) You’re asked to create all the unique 3-to- 2 circuits (i.e., 3 inputs: I2,I1,I 0

and 2 outputs), with one minor catch. Your circuit must ignore the value of I 1

if the value of I 2 is 1. How many different circuits will you have to make? Use

IEC terminology, like 128 mebicircuits, 512 tebicircuits, etc.

P1 P0 I O N1 N
S00 S
S01 S

F 3 ) You have a case of the soiflz? Go to Datapathology! (18 pts, 24 mins)

On the right is the single-cycle MIPS datapath you all know and love. Ignore pipelining for the question. Your

job is to modify the diagram to support a

new MIPS instruction to perform the

following C code in one MAL instruction

(ptr is an array of ints):

if(ptr[IMMEDIATE] == 0) { ptr[IMMEDIATE] = 1; }

We’ll call our new instruction soiflz,

for store one if load zero.

If the word (that is stored IMMEDIATE

integers past the base pointer in rs) is 0,

then set that word to be 1.

a) Make up the syntax for the MAL

MIPS instruction that does it (show an example where ptr lives in $t0, and IMMEDIATE is 8 ). On the right,

show the register transfer language (RTL) description of soiflz.

Syntax RTL

b) Change as little as possible in the datapath above (draw your changes right in the figure) to enable

soiflz and list all changes below. Your modification may use adders, shifters, muxes, wires, and new control

signals. If necessary, you may replace existing labels. You may not need all boxes.

(i)

(ii)

(iii)

(iv)

c) We now want to set all the control lines appropriately. List what each signal should be: an intuitive name or

{0, 1, x – don’t care}. Include any new control signals you added.

RegDst RegWr nPC_sel ExtOp ALUSrc ALUctr MemWr MemtoReg

d) Your smart friend argues that because of this very instruction , you should have a fourth instruction format

(in addition to R, I and J). There’s a clear downside: it would cause more complexity with control & datapath.

That said, what would be the upside?

F 4 ) Please Pass Professor’s Pretty Pipeline-pourri Problem… ( 30 pts, 42 min)

Given a standard five (5) stage pipelined processor with:

  • No Forwarding
  • Stalls on ALL data and control hazards; no out-of-order execution ; non-delayed branches
  • Branch comparison occurs during the second stage; instructions are not fetched until branch comparison is done
  • Memory CAN be read & written on the same clock cycle
  • The same register CAN be read and written on the same clock cycle

a) Fill in the corresponding pipeline stages (F,D,E,M,W) at the appropriate times in the table below for the following six

MIPS instructions assuming the above properties of your CPU. You don’t need to fill anything in for instruction (7).

d) What recent breakthrough allows improved bit density on disk drives? __________________________

e) What’s the speedup (over a 1-core machine) for a 20%-serial program on a 16-core machine? __________

f) Two threads run cal and bears below.

What can go wrong and how do we fix it? ________________________________________________

g) A processor run on a particular benchmark

has the instruction mix and CPI shown in the table

at the bottom right. How many times faster would

the benchmark run if we quadruple

the CPI of the ALU from 2 to 8? _________

h) Which is the best way to communicate with a remote

sensor measuring lunar eclipses, via polling or interrupts? ___________

i) What protocol guarantees delivery on a network? ________________

j) What is one reason MapReduce is better than MPI? ___________________________________________

Cycle Instruction 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 (1) add $s0 $s1 $t (2) addi $t0 $t0 4 (3) sw $s0 0($t1) (4) and $t1 $t1 $t (5) lw $t2 4($t1) (6) bne $t2 $t1 - 6 #goto 1 (7) sub $s0 $s0 $t

b) Assuming we’ve been in this loop for 1000 iterations, how many cycles does it take to evaluate each loop?

c) You (as the one who wrote the code in part (a)) are pretty unhappy with all the hazards you discovered

when filling out the table. Suddenly, Sir Mips-a-lot – a representative of the MIPS fabrication plant – runs in and shouts: ā€œDon’t sulk!! We just implemented delayed branches !ā€. You decide to move instruction (2) into the delayed branch slot after (6). Again, assuming we’ve been in the loop for 1000 iterations, NOW how many cycles to evaluate each loop? cal() { lock(&lockA); lock(&lockB); sharedVar++; unlock(&lockB); unlock(&lockA); } bears() { lock(&lockB); lock(&lockA); sharedVar++; unlock(&lockA); unlock(&lockB); } Frequency CPI Memory 30% 4 Branch 20% 4 ALU 50% 2  8