A
Consider an algorithm for transposing a square matrix in-place by swapping rows and columns. Below, you will find the C code for this operation, and it is important to note that the matrix elements are 32-bit integers.
Next, we utilize vector-style instructions to implement the transposition. Below, you will find an abbreviated listing of potentially relevant vector load/store instructions.
Vector Load/Store Instructions
instruction | definition |
---|---|
vsetvli rd, rs, eN, mX, tP, mP |
This instruction updates rd with the vector length computed; rs is an input register operand that contains the application vector length (AVL) which represents the vector length the program wants to use.N in eN is the sew (8, 16, 32, 64, …); X in mX is the lmul (spelled as fY for 1/Y cases); P is the policy for tail (t) and mask (m): u for undisturbed, a for agnostic |
vle32.v vd, (rs1), vm |
vd[i] = mem[(rs1) + i*4] |
vse32.v vs3, (rs1), vm |
mem[(rs1) + i*4] = vs3[i] |
vlse32.v vd, (rs1), rs2, vm |
vd[i] = mem[(rs1) + i*rs2] |
vsse32.v vs3, (rs1), rs2, vm |
mem[(rs1) + i*rs2] = vs3[i] |
vluxei32.v vd, (rs1), vs2, vm |
vd[i] = mem[(rs1) + vs2[i]] (unordered) |
vsuxei32.v vs3, (rs1), vs2, vm |
mem[(rs1) + vs2[i]] = vs3[i] (unordered) |
vloxei32.v vd, (rs1), vs2, vm |
vd[i] = mem[(rs1) + vs2[i]] (ordered) |
vsoxei32.v vs3, (rs1), vs2, vm |
mem[(rs1) + vs2[i]] = vs3[i] (ordered) |
See also: RISC-V "V" Vector Extension
Complete the vector code provided below to vectorize the matrix transpose operation.
- A01 = ?
- A02 = ?
- A03 = ?
- A04 = ?
- A05 = ?
B
Consider REV
as a macro-operation fusion instruction that reverses a linked list in memory. The rs1 operand for this instruction is the memory address of a pointer to the first node in the linked list, which is essentially a pointer to a pointer.
Each node in the linked list has the following structure. In this architecture, assume that pointers are 32 bits wide. The 'next' pointer can either hold the memory address of the next node in the list or be set to 0 (NULL
) to indicate the end of the linked list.
To provide a point of reference, we have included both the C and assembly code equivalents for this instruction below.
Let's analyze the execution of the assembly code for linked list reversal on an unpipelined RISC-V core. In this core, each instruction has a CPI (Cycles Per Instruction) of 1, except for load and store instructions, which require 2 cycles each. How many instructions are needed to reverse a linked list with a length of 4 using this program? (Fill in the numbers)
- B01 = ?
- B02 = ?
- B03 = ?
- B04 = ?
- B05 = ?
- B06 = ?
A garage door will initiate its opening sequence when it detects the password '011' in a transmission. To put it formally, this Finite State Machine (FSM) accepts a bitstring composed of 0's and 1's as input and produces a continuous stream of 0's until it encounters the substring '011,' at which point it begins generating a continuous stream of 1's. Below are examples of how this FSM operates:
Mark the correct FSM state transition for each numbered arrow.
__ C01 __
__ C02 __
__ C03 __
__ C04 __
- C01 = ?
- C02 = ?
- C03 = ?
- C04 = ?
Take a look at the circuit diagram below along with the delays of its components:
What is the smallest combinational delay of all paths in this circuit, in picoseconds? __ D01 __
- D01 = ?
What is the maximum hold time the registers can have so that there are no hold time violations in the circuit above? __ D02 __
- D02 = ?
What is the minimum allowable clock period for this circuit to function properly?
- D03 = ? __ D03 __
Decode the following RISC-V instruction. You can use online RISC-V Instruction Encoder/Decoder.
which is mapped to
E01 should start with x
.
- E01 = ?
- E02 = ?
Examine the circuit diagram presented below. SEL is a single-bit control signal that undergoes instantaneous updates at the rising edge of each clock cycle, maintaining stability throughout each clock cycle. You can make the assumption that Input will not result in any hold time violations.
The combinational logic block on the left performs a left shift operation on the top input by the number of bits specified by the bottom input. In the diagram, the shifter connected to the register on the left shifts its output to the left by 1 bit.
Suppose we want to maximize the circuit's frequency without altering its behavior, and we are not allowed to modify the delays of any component.
The most significantly slow component in this context is the multiplier, and addressing this issue is necessary. Specifically, if our sole multiplication requirement is doubling numbers, we do not require a versatile multiplier capable of multiplying any two inputs together.
What is the minimum clock period after implementing the above change? __ F01 __
- F01 = ?
The function add_even
is specified as follows:
Input:
Example: Let's consider an input where a0 points to , and a1 holds the value 4
. In this case, the output in a0 will be 10
(4 + 6).
Complete the missing sections in the RISC-V code provided below. Each line should consist of exactly one instruction or pseudo-instruction.
- G01 = ?
- G02 = ?
A Hamming Error Correcting Code is capable of rectifying single-bit errors. In scenarios where data is susceptible to errors, such as in satellite communication or L1 caches, it's advantageous to employ Hamming codes to store data blocks. These codes can internally correct errors during memory retrieval.
In this context, we will examine a (7,4) Hamming Code with even parity. This code utilizes 7 bits in total to store 4 data bits. Please refer to the following bit pattern for the (7,4) Hamming Code:
We follow the convention where the first bit is considered the most significant in the data, and the seventh bit is the least significant. Then, we create a circuit that, when provided with a (7,4) Hamming Code, produces a corrected nibble of data. What components should be placed in the labeled boxes? Assume that multiple-input gates are created by connecting two-input gates.
It is known that both Box I and Box II belong to this category. Please provide answers accordingly.
- H01 = ?
- H02 = ?
- H03 = ?
- H04 = ?
The function verify_password
is defined as follows:
You have access to the following externally defined labels:
password
: This is a pointer to a statically stored string "secretpass."getchars
: This function is defined as follows:
Effect: It reads characters from stdin and populates the buffer pointed to by a0 with the read data, null-terminating the string. Your code can assume that the input consists of a maximum of 19 characters, not including the null-terminator.
In your current role as a hacker, your objective is to target the implementation of verify_password
.
During your testing, you have uncovered an intriguing revelation: the function getchars
does not function as originally intended. Instead of truncating at the 20th character, getchar
continues writing data until it encounters the first null terminator within its input. Just as before, verify_password
resides at memory address 0x1000
, and getchars
is situated at address 0x0F00. Additionally, assume that the stack pointer is initially positioned at 0xBFFF F800 when verify_password
begins execution. Our page size is 4 KiB, and we are currently operating on a little-endian system.
- I01 = ?
- I02 = ?
- I03 = ?
- I04 = ?
- I05 = ?
getchars
; our goal is to have a valid RISC-V jump instruction. Additionally, please take note that +3840 is equivalent to 0x00000F00. Select all possible choices. __ I06 __ret
jalr x0, t1, -256
jalr s0, t1, -256
jalr ra, t2, -256
jalr ra, t0, 16
jalr s0, x0, 3840
- I06 = ?
Examine the provided RISC-V code snippet:
bltu
instruction?
- J01 = ?
jalr s0, s1, MAX_POS_IMM
, where MAX_POS_IMM
represents the maximum possible positive immediate value for jalr
. After this instruction executes, what will be the values in the following registers? (Provide your answers in hexadecimal.)
s0
= J02s1
= J03PC
= J04
- J02 = ?
- J03 = ?
- J04 = ?
K
Let's examine the program that recursively calculates the Fibonacci sequence. On the left, you will find the C code, and on the right, you can see its corresponding translation into RISC-V assembly. It's important to note that the execution has been paused just before executing the 'ret' instruction. The 'SP' label on the stack frame (part 3) indicates the location where the stack pointer is pointing when the execution was halted.
Complete the missing portion of the ble
instruction to make the assembly implementation match the C code.
- K01 = ?
How many unique words will be reserved and pushed onto the stack each time the fib
function is called?
- K02 = ?
Kindly provide the values to replace the blank spaces in the stack trace below. Present the values in hexadecimal format.
Notation | address |
---|---|
Smaller address | 0x280 |
0x1 | |
K03 | |
SP | K04 |
K05 | |
0x0 | |
0x280 | |
0x3 | |
0x0 | |
0x2108 | |
0x4 | |
0x6 | |
Larger address | 0x1 |
- K03 = ?
- K04 = ?
- K05 = ?
What is the hex address of the done
label? (Answer in hexadecimal format)
- K06 = ?
What was the address of the original function call to fib
? (Answer in hexadecimal format)
- K07 = ?