Question: You need to write the assembly code for the C - based array multiplication, as shown in exercise 1 _ 2 . c , using

You need to write the assembly code for the C-based array multiplication, as shown in exercise1_2.c, using
the RV64I ISA. Besides, you should do the same as 3-1 pi calculation to collect performance data and derive
related performance statistics.
As shown in the arraymul_baseline() function, you are responsible for writing the assembly for the
for-loop code: for (...) y[i]= h[i]* x[i]+ c;.
NOTE: You should put your assembly code within the arraymul_baseline.c file, as indicated in
asm volatile( #include "arraymul_baseline.c" : [h]"+r"(p_h),...); within the
arraymul_baseline() function in exercise1_2.c.
The header file arraymul.h specifies the constants/variables used in this assignment. You are
allowed to change arr_size (array size) in arraymul.h to meet the exercise requirements.
NOTE: Please do not modify the rest of the header file.
Variables/Constants defined in the header files used in this exercise.
Var./Cons. Name Definition
x[] Input array 1 in arraymul.h
h[] Input array 2 in arraymul.h
y[] Output array in arraymul.h
arraymul_baseline_cycle_count Clock cycle in arraymul_baseline.c you need to calculate
cycle_time
The given clock cycle time of the target RISC-V processor
running at 2.6 GHz
arraymul_baseline_cpu_time
The CPU time in arraymul_baseline.c you need to
calculate
arr_size Size of the array
Your obtained scores of this exercise is determined by the correctness of your reported performance
data.
1. The values of seven counters. (28%)
add_cnt (4%)
sub_cnt (4%)
mul_cnt (4%)
div_cnt (4%)
lw_cnt (4%)
sw_cnt (4%)
others_cnt (4%)
2. The total cycle count (arraymul_baseline_cycle_count).(4%)
3. The CPU time (arraymul_baseline_cpu_time).(4%)
4. Choose any arr_size but log~2~(arr_size) must be a integer and answer the question: Is this
program a CPU bound or Memory bound program? (4%)
The arraymul_baseline() function in exercise1_2.c is as follows.
//The code snippet for arraymul_baseline() in exercise1_2.c
void arraymul_baseline(){
short int *p_h = h;
short int *p_x = x;
short int *p_y = y;
short int id = student_id; // id should be your_student_id %100, please check
the header file, arraymul.h.
/* original C code
for (int i =0; i < arr_size; i++){
p_y[i]= p_h[i]* p_x[i]+ 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 =%f 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,"%f", 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!