Question: Question 1 - 2 : Please provide the assembly code for the C - based array multiplication using the RV 6 4 I ISA. Your

Question 1-2:
Please provide the assembly code for the C-based array multiplication using the RV64I ISA. Your assembly code should be integrated into the arraymul_baseline.c file within the arraymul_baseline() function in exercise 1-2.c. Specifically, you are tasked with writing assembly code for the for-loop section where each element y[i] is calculated as h[i]* x[i]+ c.
The header file arraymul.h specifies the constants/variables used in this assignment. You can adjust the arr_size variable in arraymul.h to meet the exercise requirements, but please refrain from modifying the rest of the header file.
Variables/Constants defined in the header files used in this exercise:
x[]: Input array 1
h[]: Input array 2
y[]: Output array
arraymul_baseline_cycle_count: Clock cycle count in arraymul_baseline.c (you need to calculate this)
cycle_time: Given clock cycle time of the target RISC-V processor running at 2.6 GHz
arraymul_baseline_cpu_time: CPU time in arraymul_baseline.c (you need to calculate this)
arr_size: Size of the array
Your obtained scores for this exercise are determined by the correctness of your reported performance data and statistics.
The values of seven counters:
add_cnt: Add counter
sub_cnt: Subtract counter
mul_cnt: Multiply counter
div_cnt: Divide counter
lw_cnt: Load counter
sw_cnt: Store counter
others_cnt: Other operations counter
The total cycle count (arraymul_baseline_cycle_count).
The CPU time (arraymul_baseline_cpu_time).
Choose any arr_size, but log2(arr_size) must be an integer and answer the question: Is this program CPU-bound or Memory-bound?
The arraymul_baseline() function in exercise 1-2.c is provided below:
void arraymul_baseline(){
short int *p_h = h;
short int *p_x = x;
short int *p_y = y;
short int id = student_id;
asm volatile(
#include "arraymul_baseline.c"
: [h]"+r"(p_h),
[x]"+r"(p_x),
[y]"+r"(p_y),
[add_cnt]"+r"(add_cnt),
[sub_cnt]"+r"(sub_cnt),
[mul_cnt]"+r"(mul_cnt),
[div_cnt]"+r"(div_cnt),
[lw_cnt]"+r"(lw_cnt),
[sw_cnt]"+r"(sw_cnt),
[others_cnt]"+r"(others_cnt)
: [id]"r"(id),
[arr_size]"r"(arr_size)
: "t0","t1"
);
printf("==== Question 1-2====
");
printf("output: ");
for (int i =0; i < arr_size; i++){
printf("%d ", y[i]);
}
printf("
");
printf("add counter used: %d
", add_cnt);
printf("sub counter used: %d
", sub_cnt);
printf("mul counter used: %d
", mul_cnt);
printf("div counter used: %d
", div_cnt);
printf("lw counter used: %d
", lw_cnt);
printf("sw counter used: %d
", sw_cnt);
printf("others counter used: %d
", others_cnt);
macro_arraymul_baseline_cycle_count printf("The total cycle count in this program: %.0f
", arraymul_baseline_cycle_count);
macro_arraymul_baseline_cpu_time printf("CPU time =%.2f us
", arraymul_baseline_cpu_time);
macro_calc_arraymul_baseline_ratio if (arraymul_baseline_ratio >0.5)
printf("This program is a CPU bound task.
");
else
printf("This program is a Memory bound task.
");
// Record the CPU time
FILE *fp;
fp = fopen("arraymul_baseline_cpu_time.txt","w");
fprintf(fp,"%.2f", arraymul_baseline_cpu_time);
fclose(fp);
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!