Question: The following code performs matrix multiplication in c + + . float dot _ product _ f ( float * m 1 , float *
The following code performs matrix multiplication in c
float dotproductffloat m float m int r int c int l
float product ;
forint i; i l; i
float a mi r l;
float b mc i l;
product a b;
printfff a b;
printf
;
return product;
The following is the assembly for the above c code. The requirement is to remove redundant instructions to improve performance. Please provide new working assembly file with improved code. Thanks.
text
file dpfloat.cpp
globl ZdotproductfPfSiii # Begin function ZdotproductfPfSiii
palign x
type ZdotproductfPfSiii,@function
ZdotproductfPfSiii: # @ZdotproductfPfSiii
cfistartproc
# bb:
pushq rbp
cfidefcfaoffset
cfioffset rbp
movq rsprbp
cfidefcfaregister rbp
movq rdi, rbp
movq rsi, rbp
movl edx, rbp
movl ecx, rbp
movl rdrbp
xorps xmmxmm
movss xmmrbp
movl $rbp
LBB: # This Inner Loop Header: Depth
movl rbpeax
cmpl rbpeax
jge LBB
# bb: # in Loop: HeaderBB Depth
movq rbprax
movl rbpecx
movl rbpedx
imull rbpedx
addl edx, ecx
movslq ecx, rcx
movss rax,rcxxmm # xmm memzero,zero,zero
movss xmmrbp
movq rbprax
movl rbpecx
movl rbpedx
imull rbpedx
addl edx, ecx
movslq ecx, rcx
movss rax,rcxxmm # xmm memzero,zero,zero
movss xmmrbp
movss rbpxmm # xmm memzero,zero,zero
movss rbpxmm # xmm memzero,zero,zero
movss rbpxmm # xmm memzero,zero,zero
mulss xmmxmm
addss xmmxmm
movss xmmrbp
# bb: # in Loop: HeaderBB Depth
movl rbpeax
addl $eax
movl eax, rbp
jmp LBB
LBB:
movss rbpxmm # xmm memzero,zero,zero
popq rbp
cfidefcfa rsp
retq
Lfuncend:
size ZdotproductfPfSiii, LfuncendZdotproductfPfSiii
cfiendproc
# End function
ident "clang version CentOS el
section note.GNUstack","",@progbits
addrsig
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
