Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted

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

Posted

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 :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...