You are on page 1of 2

SCHOOL OF COMPUTER SCIENCE & ENGINEERING

Question :
Consider the following piece of code:

for (i = 0; i < 100; i ++)

A[i] = ((B[i] * C[i]) + D[i])/2;

(a) Translate the above code to perform scalar and vector processing with the vector length
of 64.

(b) Calculate the number of cycles required for scalar and vector processing by considering
the information given in the table.

Number of Cycles Description


2 Load and store instructions
4 Multiplication
4 Division
1 Addition

ANS :

Scalar Code:
Loop (1:100)
Load R1, @B-2 cycles
Load R2, @ C-2 cycles
Load R3, @ D—2 cycles
Mul R1,R2—4 cycles
Add R1,R3—1 cycle
Div R1, #2 ---4 cycles
Store R1,A—2 cycles
Total → 17 cycles * 100→ 1700 cycles
Vector Code:
Loop (1:2)
Vload V1(1:64),B(1:64) → 2 cycles
Vload V2(1:64),C(1:64) → 2 cycles
Vload V3(1:64),D(1:64) → 2 cycles
Vmul V1,V2→ 4 cycles
Vadd V1,V3→ 1 cycles

This study source was downloaded by 100000835168190 from CourseHero.com on 02-24-2022 23:24:22 GMT -06:00

https://www.coursehero.com/file/67052878/Vector-Processing-2pdf/
Vdiv V1,2 → 4 cycles
Vstore V1,A→ 2 cycles

Total 17 *2 =34 cycles ( 32 vector size )

For 64 , 17 cycles

This study source was downloaded by 100000835168190 from CourseHero.com on 02-24-2022 23:24:22 GMT -06:00

https://www.coursehero.com/file/67052878/Vector-Processing-2pdf/
Powered by TCPDF (www.tcpdf.org)

You might also like