Doubles present in a loop are reloaded repeatedly. Instead they can be set just once out of loop and use it inside the loop.
private static double Process(double n)
{
double res;
res = 1;
while (n > 0.0)
{
res *= n;
// User might not write such code, but here it is written merely to show that same constants are re-loaded in assembly code.
n -= 1.0;
n -= 2.0;
n -= 1.0;
n -= 2.0;
}
return res;
}
G_M15653_IG03:
1E600A10 fmul d16, d16, d0
1E6E1011 fmov d17, #1.0000
1E713800 fsub d0, d0, d17
1E601011 fmov d17, #2.0000
1E713800 fsub d0, d0, d17
1E6E1011 fmov d17, #1.0000
1E713800 fsub d0, d0, d17
1E601011 fmov d17, #2.0000
1E713800 fsub d0, d0, d17
4F00E411 movi v17.16b, #0x00
1E712000 fcmp d0, d17
54FFFEAC bgt G_M15653_IG03
category:cq
theme:cse
skill-level:expert
cost:medium
impact:medium
Doubles present in a loop are reloaded repeatedly. Instead they can be set just once out of loop and use it inside the loop.
category:cq
theme:cse
skill-level:expert
cost:medium
impact:medium