Doing this saves a few bytes, and it does work. So if anyone has any tricks for saving memory space and speed, I think we should share our ideas (that is, if you want).
Good idea, Davey. I'll try to make a note of some typical ones I take for granted and add to the list.
Strangely enough, I think your example may end up costing you more than it helps and is not necessarily equivalent without context. I currently use the % operator for SLOW_BG_PATTERNS in Platz and you can see just how badly it affects performance. I'm going to change this to the if,then format in a future version because it increases performance massively. Sometimes % is needed, but usually when counting up to a limit, the other is better. I imagine X%(2^n) is an exception because you can perform it as X&(2^n-1). Also, you probably have to include library code for that % operator if you have not used it elsewhere in similar circumstances. It's one of the main reasons I want to learn asm - a lot of the time I use relatively terse C syntax without realizing the compiler may have turned it into unwieldy asm. I'm also keen to investigate the emulator scene, and a good grasp of asm over a range of platforms appears to be a prerequisite.
As paul says, mod is a very expensive operation (unless you're doing mod with a power of 2!). What it saves you in memory is more then made up for in loss of speed!
That being said, does it really save you a few bytes? It may save a few bytes in the C source code, but when it compiles, the expansion of that routine seems like it would likely be pretty big (maybe this is compiled in even if you don't use it?)... Also seems like if it is a few bytes smaller that it may take up more ram during execution where it stores temporary information trying to solve the problem (or at least some some looping construct)...
Doing this saves a few bytes, and it does work. So if anyone has any tricks for saving memory space and speed, I think we should share our ideas (that is, if you want).
Good idea!
Hey Deavey
can you give me solution for swapping two variables without using 3rd temporary variable.
Last edited by smith2287 on Thu Oct 22, 2009 1:52 pm, edited 1 time in total.
I've a non-debug build of a simple test app and was wondering if anyone might know why I find malloc and free lurking in my lss file... I don't call them and can't find any kernel sources that use them. How are these clib routines getting linked in there?
avr-size reports that my build uses 3352 bytes of 'data' and 10746 bytes of 'program' - this is confusing. Where should I look to determine how much space is left on the chip?
Has anyone worked on a handle-based un/lock memory system for this little guy?
avr-size reports that my build uses 3352 bytes of 'data' and 10746 bytes of 'program' - this is confusing. Where should I look to determine how much space is left on the chip?
For the '644 it would just be 4k(4096-3352)=744 data free and 64k(65535-10746)=54789 program free, if you don't mind manually figuring it out. Otherwise I'm not sure.