if I do:
int x = 4;
pow(2, x);
Is that really that much less efficient than just doing:
1 << 4
?
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.
Yes. An easy way to show this is to compile the following two functions that do the same thing and then look at the disassembly.
cc -arch armv7 -O3 -S -o - shift.c(I happen to find ARM asm easier to read but if you want x86 just remove the arch flag)You can see
foo2only takes 2 instructions vsfoo1which takes several instructions. It has to move the data to the FP HW registers (vmov), convert the integer to a float (vcvt.f64.u32) call theexpfunction and then convert the answer back to an uint (vcvt.u32.f64) and move it from the FP HW back to the GP registers.