Homework 6 (In-class assignment)
Due by midnight on Monday, Mar. 2, 2015
10 points

Name: _______________________________

Partner name: __________________________________

Find a partner and work together on this portion of the homework assignment!

Be sure to list your name, and your partner's name. Everyone must submit their own copy of the worksheet to the eCompanion dropbox by the end of class.

1. (2 points) Convert the following logic statements to assembly and store the result in a register. You may use pseudo-instructions.

a) x > y && y > z

b) x >= y || y < z

c) What branch instructions would you need to use the logic instructions from part a as the condition in a while loop? Hint: See the example code on the class website.

d) What branch instructions would you need to use the logic instructions from part b as the condition in a while loop? Hint: See the example code on the class website.

2. (1 point) What is a thread? What is a process? Hint: see the notes for today on the class website:

3. (2 points) Write an if-then-else statement in MIPS using the logic instructions from question 1 b).

4. (1 point) The "move" instruction allows you to move data from one register to another. This can be helpful when reading in integer data.

a) Write a statement to move the contents of register $s1 to register $t3

b) Move is a pseudo instruction. This means it is made from other instructions. You can use the "or" instruction to accomplish a move since "or" operates bitwise. For example 0110b "or" 0000b is 0110b. Write an "or" statement in MIPS to move the contents of register $v0 to register $t2. You may use $zero in your answer.

5. (4 points) Flynn's Taxonomy is provided in the notes for today's assignment. Read the slides about Flynn's taxonomy.

SISD - means we run one instruction on one set of data (ex: a = b + c)
SIMD - means we run one (the same) instruction on many pieces of data (ex: a[0 to 3] = b[0 to 3] + c[0 to 3])
MISD - means we have multiple instructions operating on the same data
at the same time. This is very unusual.
MIMD - means many instructions work on many pieces of data at the same time.
This means that we may have many programs running at the same time.

a. Open the program at this link. Copy the program into nano on LittleFe2. Save the
program as fourDSum.c. Compile the program using the following command:

gcc fourDSum.c -std=c99 -o fourDSum.exe

Run the program to see what happens. What is the result?

b. Next, create assembly code from this program using the following command:

gcc -std=c99 -S -c fourDSum.c

The assembly code will be stored in a file named fourDSum.s

Open fourDSum.s with nano. Scroll down to the .L7 label. This label represents the
start of the for loop that computes the sums. Scroll down to the .L6 tag. Notices
that this tag represents the end of the loop.

How many additions are performed in this loop using the statement: addq %rcx, %rax ?
Hint: these correspond to the additions in the last for loop of the program.

___________________________

What does addq do? Hint: see https://msdn.microsoft.com/en-us/library/aa258985%28v=vs.60%29.aspx

c. Compile the program using the following command, note that the -O3 option turns on
compiler optimization.

gcc fourDSum.c -std=c99 -O3 -o fourDSum.exe

Run the program to see what happens. What is the result? Does the program run faster?
Why?

d. Next, create assembly code from this program using the following command:

gcc -std=c99 -O3 -S -c fourDSum.c

The assembly code will be stored in a file named fourDSum.s

Open fourDSum.s with nano. Scroll down to the .L3 label. Look up the following
instructions:

movdqu
paddd

See the following sites:
http://x86.renejeschke.de/html/file_module_x86_id_184.html
http://www.jaist.ac.jp/iscenter-new/mpc/altix/altixdata/opt/intel/vtune/doc/users_guide/mergedProjects/analyzer_ec/mergedProjects/reference_olh/mergedProjects/instructions/instruct32_hh/vc223.htm

How many 32-bit integers can you add in parallel with paddd? ________

List an example of each of the types of instructions shown in Flynn's Taxonomy.
Briefly describe each example.

e. Add the following statement immediately before the for loop that computes the sum
in fourDSum.c.

#pragma omp parallel for reduction(+:sum0,sum1,sum2,sum3) num_threads(4)

The statement above will parallelize the for loop. Compile the program with the following command:

gcc fourDSum.c -std=c99 -fopenmp -O3 -o fourDSum.exe

Run the program to verify that it works. Note that the program may not appear to run
much faster because the memory allocation at the beginning of the program takes a long
time.

Run the following command:

gcc -fopenmp -std=c99 -O3 -S -c fourDSum.c

This will create the file fourDSum.s. Look at the .L7 label. Does the code here appear
to be the same as the code in the previous question?

Now look at the following code segment:

call GOMP_parallel_start
movq %rbx, %rdi
call main.omp_fn.0
call GOMP_parallel_end

This code should appear in the assembly file. Look for the main.omp_fn.0 label. This
label represents a function. Does .L7 appear to be in this function? Will the code
from .L7 be executed in multiple threads? If so, how many? _______

What function do you think will start these threads? ______________________

What function will end these threads?______________________

Hint: the function names are in the code above.

Provide examples of the following types of instructions:

f. SISD (hint: almost every MIPS instruction is a SISD instruction)

_____________________

g. SIMD (hint: see part d)

_____________________________

h. MIMD, don't provide the instructions, just describe them. (hint: what is the #pragma and the loop in fourDSum.c)

__________________________________________________________