e.g.
movr8d,dword ptr [rax]addrax,4movr8d,r8d ; pointless mov ...movzxeax,byte ptr [rax]moveax,eax ; pointless mov
Example
The Checksum routine Magma.Common/Checksum.cs
// Internet Checksum as defined by RFC 791, RFC 793, RFC 1071, RFC 1141, RFC 1624publicstaticushortCalcuate(refbytebuffer,intlength){refvarcurrent=refbuffer;ulongsum=0;while(length>=sizeof(ulong)){length-=sizeof(ulong);varulong0=Unsafe.As<byte,ulong>(refcurrent);current=refUnsafe.Add(refcurrent,sizeof(ulong));// Add with carrysum+=ulong0;if(sum<ulong0){sum++;}}if((length&sizeof(uint))!=0){varuint0=Unsafe.As<byte,uint>(refcurrent);current=refUnsafe.Add(refcurrent,sizeof(uint));// Add with carrysum+=uint0;if(sum<uint0){sum++;}}if((length&sizeof(ushort))!=0){varushort0=Unsafe.As<byte,ushort>(refcurrent);current=refUnsafe.Add(refcurrent,sizeof(ushort));// Add with carrysum+=ushort0;if(sum<ushort0){sum++;}}if((length&sizeof(byte))!=0){varbyte0=current;// Add with carrysum+=byte0;if(sum<byte0){sum++;}}// Fold down to 16 bitsvaruint1=(uint)(sum>>32);varuint2=(uint)sum;// Add with carryuint1+=uint2;if(uint1<uint2){uint1++;}varushort2=(ushort)uint1;varushort1=(ushort)(uint1>>16);// Add with carryushort1=(ushort)(ushort1+ushort2);if(ushort1<ushort2){ushort1++;}// Invert to get ones-complement result return(ushort)~ushort1;}Generates asm with 3 pointless movs
movrax,rcxxorecx,ecxcmpedx,8jl 00007FFB767741B4 addedx,0FFFFFFF8hmovr8,qword ptr [rax]addrax,8addrcx,r8cmprcx,r8jae 00007FFB767741AF incrcxcmpedx,8jge 00007FFB7677419A testdl,4je 00007FFB767741CE movr8d,dword ptr [rax]addrax,4movr8d,r8d ; pointless mov addrcx,r8cmprcx,r8jae 00007FFB767741CE incrcxtestdl,2je 00007FFB767741E9 movzxr8d,word ptr [rax]addrax,2movr8d,r8d ; pointless mov addrcx,r8cmprcx,r8jae 00007FFB767741E9 incrcxtestdl,1je 00007FFB767741FE movzxeax,byte ptr [rax]moveax,eax ; pointless mov addrcx,raxcmprcx,raxjae 00007FFB767741FE incrcxmovrax,rcxshrrax,20haddeax,ecxcmpeax,ecxjae 00007FFB7677420D inceaxmovzxedx,axshreax,10hmovzxeax,axaddeax,edxmovzxeax,axcmpeax,edxjge 00007FFB76774224 inceaxmovzxeax,axnoteaxmovzxeax,axret
category:cq
theme:basic-cq
skill-level:intermediate
cost:medium
impact:medium
e.g.
Example
The Checksum routine Magma.Common/Checksum.cs
Generates asm with 3 pointless movs
category:cq
theme:basic-cq
skill-level:intermediate
cost:medium
impact:medium