original code
while(i<30){
// do something
i++;
}
unrolled while loop
while(i<15){
// do something twice
i+=2;
}
Cant we unroll it as shown above. Do we always have to do it like http://en.wikipedia.org/wiki/Loop_unrolling ?
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 general, the answer is no. It works for 30 and 15 because 30 is even, but it would not work as easily for odd numbers. “Duff’s device” was invented to deal with general case. It is quite ugly, though.