CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Code optimization

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
prondeau



Joined: 26 Mar 2008
Posts: 11

View user's profile Send private message

Code optimization
PostPosted: Wed Dec 12, 2012 2:41 pm     Reply with quote

I'm revisiting an older project that made use of an 18f45j10. With the changes I'm implementing I'm rapidly approaching the point where I'm going to run out of memory. I've been looking for areas where I can optimize the code to have a smaller footprint. I perform a lot of operations on 32bit integers where I need to access the four bytes individually. I've noticed that the resultant disassembly listing for this operation seems quite a bit larger than if I was to do this in pure assembly. I've tried masking and shifting as well as using pointers. Before I do any more work on this, is there a known method to get the tightest code out of this compiler for the desired operation?

Thanks!

Pete
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 12, 2012 2:56 pm     Reply with quote

Post the source code that shows how you are currently doing it. Ideally,
make it into a very small compilable test program. Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=49220&start=5
Also post your compiler version.
prondeau



Joined: 26 Mar 2008
Posts: 11

View user's profile Send private message

PostPosted: Wed Dec 12, 2012 3:26 pm     Reply with quote

fwiw, i'm using 4.076

I sat down to write a small program as requested to demonstrate what I was talking about and discovered the answer on my own.

What I was doing was something like this:
Code:
spi_write((TestVariable >>24) & 0xFF);


And found that it created 12 lines of assembly code.

I tried to simplify it for the example and just did something like this:
Code:
A= ((TestVariable >>24 )& 0xff);


I got back 1 line of assembly (as I expected and desired)

so I tried this
Code:
A= ((TestVariable >>24 )& 0xff);
spi_write(A);


And the result was 5 lines of assembly code.

That was one approach I hadn't tried.. So I guess I don't really need help with this anymore.

Thank you!

Pete
prondeau



Joined: 26 Mar 2008
Posts: 11

View user's profile Send private message

PostPosted: Wed Dec 12, 2012 3:34 pm     Reply with quote

Just to be thorough:

Code:
#include <18f45j10.H>

#use delay(clock=40M, oscillator=10M)

void main(void){

   long long TestVariable;
   int A;

   TestVariable = 01234567;

   spi_write((TestVariable >>24) & 0xff);

   A= ((TestVariable >>24) & 0xff);
   spi_write(A);

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19505

View user's profile Send private message

PostPosted: Wed Dec 12, 2012 4:06 pm     Reply with quote

Even better, use the CCS functions:
Code:

   signed int32 TestVariable; //better to use explicit sizes.
   TestVariable = 01234567;

   spi_write(make8(TestVariable,3)); //send 3rd byte of TestVariable

Less RAM, and similarly short assembler.

Best Wishes
prondeau



Joined: 26 Mar 2008
Posts: 11

View user's profile Send private message

PostPosted: Wed Dec 12, 2012 4:23 pm     Reply with quote

Oh! excellent!, much less cluttered too. Thanks for this, I had not seen it in the manual.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group