Which one is faster –
val = val*10;
or
val = (val<<3) + (val<<2);
How many clock cycles does imul take when compared to shift instruction?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In this case they probably take the same amount of cycles, though your manual “optimization” needs one more register (which can slow down the surrounding code):
vs
The compiler knows how to do strength reduction, and probably much better than you. Also, when you port your code to other platform (say, ARM), the compiler knows how to do strenght reduction on that platform too (x86’s
LEAprovides different optimization opportunities than ARM’sADDandRSB).