robinfawell Posted November 15, 2006 Report Share Posted November 15, 2006 Thorsten kindly provided me with code to address Bankstick memory locations. Part of this code includes the following line.unsigned int addr = dump_table[dump_index*3 + 1];Bearing in mind that multiplying gobbles up bytes. Would the following work? And would it be more efficient?unsigned int addr = dump_table[dump_index*2 +dump index + 1]; unsigned int addr = dump_table[(dump_index << 1) + dump_index + 1];Or would the compiler carry out the *3 function efficiently in any case?Robin Quote Link to comment Share on other sites More sharing options...
stryd_one Posted November 15, 2006 Report Share Posted November 15, 2006 Bitshift operations are most useful on the PIC18s for divide operations, because of the hardware multiply module used for MULWF they can actually be slower for multiplications.It depends on the size of the multiples and how it's done in ASM after the compilation... the 18f will do MULWF in a single cycle just like a bitshift, so it might not be any faster provided that the multiples are <=8 bits long, and the compiler uses MULWF. You'll just have to try both methods and check out the code.Still, it's always good to consider another way to do things in your code :) You never know what you'll think up. Quote Link to comment Share on other sites More sharing options...
robinfawell Posted November 17, 2006 Author Report Share Posted November 17, 2006 Thanks for your comments Stryd_One.Using your tip regarding the Project Map, I changed the function using my alternative *3 code. The result is that the function grew from 140 to 142 bytes.You don't always get what you want!Robin Quote Link to comment Share on other sites More sharing options...
stryd_one Posted November 17, 2006 Report Share Posted November 17, 2006 Well, I must admit that I would probably give better advice if I read your post correctly the first time! I gave advice about how *fast* it would be, rather than how *big* ..derrr... I guess code optimising is getting to me :-\At least it's a good reminder that 'efficient' often means a tradeoff :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.