CS433ug Quiz 1: Predicated Execution, Vector Encoding, Condition Codes, Addressing Modes, Quizzes of Computer Architecture and Organization

Solutions to quiz 1 for cs433ug (computer system organization) at the university of texas at austin. It covers topics such as predicated execution, vector encoding, condition codes, and addressing modes. Students are expected to understand concepts related to conditional encoding, vector encoding, condition codes, and addressing modes in computer systems.

Typology: Quizzes

Pre 2010

Uploaded on 03/16/2009

koofers-user-hb7
koofers-user-hb7 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Name: _________________
NetId: _________________
CS433ug: Computer System Organization
Quiz 1
Show all of your work.
If you believe a problem is incorrectly or incompletely specified, make a reasonable
assumption and solve the problem. The assumption should not result in a trivial solution. In
all cases, clearly state any assumptions that you make in your answers.
1. [15 pts] Conditional Encoding
a) [10 pts] Predication. Consider the following proposed format for predicated MIPS
instructions:
(pA) ADD R1, R2, R3
where the ADD instruction is predicated on the predicate register pA. Assume a set of 2 1-bit
predicate registers (pA, pB) that are set by a compare instruction of the form:
CMP.eq pA, pB, R8, R0
The above compare sets the 1-bit predicate registers as follows:
pA = (R8 == R0)
pB = (R8 != R0)
Rewrite the following code into code that uses no branches and that has as few instructions as
possible. Do NOT make any assumption about initial values of pA and pB. Both predicated
version and unpredicated version of CMP.eq, LD, and ADD are available for your use.
BNE nonzero R1, #0 ; if R1 != 0, jump to nonzero
LD R2, R3;
ADD R4, R2, R6
JMP done;
nonzero:
ADD R7, R8, R9;
done:
ADD R7, R4, R5;
Solution:
CMP.eq pA, pB, R1, #0 ; or CMP.eq pA, pB, R1, R0, assuming R0 = 0
(pA) LD R2, R3
(pA) ADD R4, R2, R6
(pB) ADD R7, R8, R9
ADD R7, R4, R5;
pf3
pf4

Partial preview of the text

Download CS433ug Quiz 1: Predicated Execution, Vector Encoding, Condition Codes, Addressing Modes and more Quizzes Computer Architecture and Organization in PDF only on Docsity!

Name: _________________ NetId: _________________

CS433ug: Computer System Organization

Quiz 1

Show all of your work.

If you believe a problem is incorrectly or incompletely specified, make a reasonable assumption and solve the problem. The assumption should not result in a trivial solution. In all cases, clearly state any assumptions that you make in your answers.

1. [15 pts] Conditional Encoding a) [10 pts] Predication. Consider the following proposed format for predicated MIPS instructions:

(pA) ADD R1, R2, R

where the ADD instruction is predicated on the predicate register pA. Assume a set of 2 1-bit predicate registers (pA, pB) that are set by a compare instruction of the form:

CMP.eq pA, pB, R8, R

The above compare sets the 1-bit predicate registers as follows: pA = (R8 == R0) pB = (R8 != R0)

Rewrite the following code into code that uses no branches and that has as few instructions as possible. Do NOT make any assumption about initial values of pA and pB. Both predicated version and unpredicated version of CMP.eq, LD, and ADD are available for your use.

BNE nonzero R1, #0 ; if R1 != 0, jump to nonzero LD R2, R3; ADD R4, R2, R JMP done; nonzero: ADD R7, R8, R9; done: ADD R7, R4, R5;

Solution: CMP.eq pA, pB, R1, #0 ; or CMP.eq pA, pB, R1, R0, assuming R0 = 0 (pA) LD R2, R (pA) ADD R4, R2, R (pB) ADD R7, R8, R ADD R7, R4, R5;

b) [5pts] Give one significant advantage and disadvantage of predicated execution/instructions.

Solution: Advantage: Predicated execution can reduce execution times by eliminating branches, which tend to be long-latency operations.

Disadvantage: Operations whose predicates are not true, causing them not to be executed, must still be fetched from the instruction cache, and may take up space in the pipeline, depending on how predication is implemented.

Any reasonable advantage and disadvantage will work.

2. [5 pts] Vector Encoding Dual register files can be used for vector operations. Having each instruction operate on both register files, we can implement vector instruction with regular instruction encoding. For example, with two register files X and Y that each has 8 registers, we can write regular instructions Rc = Ra OP Rb to achieve the functionality of both xRc = xRa OP xRb and yRc = yRa OP yRb. Here only 3 bits are needed to encode a register pair.

Given 128 registers divided into 4 register files, how many bits are needed to encode each register 4-tuple in an instruction?

Solution: 5 bits because 128/4 = 32 = 2^5

3. [10 pts] Condition Codes Suppose a machine has N, Z, V, and C condition code bits and that in a branching instruction, any Boolean expression over the N, Z, V, and C bits can be written using NOT, AND, and OR.

For signed comparisons: A < B: (N ⊕V) = 1 A ≤B: ((N ⊕V) ∨Z) = 1 A > B: ((N ⊕V) ∨Z) = 0 A ≥B: (N ⊕V) = 0

The following is a code sequence. if (a == b) a = b+2; else a = a + b;

Translate the above code sequence into assembly, using the condition code bits. Use as few instructions as possible. Assume a and b are signed integers.

b) [8 pts] For each instruction set architecture, write the best equivalent assembly code sequence. You can only use the assembly language mnemonics given above. Use as few instructions as possible.

Solution: Load-store: LOAD R2, B LOAD R3, C SUB R1, R2, R STORE A, R

Memory-memory: SUB A, B, C