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

PIC18 Optimization

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







PIC18 Optimization
PostPosted: Tue Mar 25, 2003 9:59 am     Reply with quote

Has anyone seen the code generated for an if(...) statement in the pic18 series? It seems like the compiler generates the same code as if it were a pic16 series. They are not taking advantage of the newer instructions.
___________________________
This message was ported from CCS's old forum
Original Post ID: 13051
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: PIC18 Optimization
PostPosted: Tue Mar 25, 2003 11:10 am     Reply with quote

:=Has anyone seen the code generated for an if(...) statement in the pic18 series? It seems like the compiler generates the same code as if it were a pic16 series. They are not taking advantage of the newer instructions.

I have looked at it and think their is an issue with else statements. The compiler will generate goto statements that goto other goto statements. I think that as part of the final pass of optimization the this should be checked for and optimized.

I don't see any other room for improvement.
___________________________
This message was ported from CCS's old forum
Original Post ID: 13053
Tomi
Guest







Re: PIC18 Optimization
PostPosted: Tue Mar 25, 2003 12:52 pm     Reply with quote

:=Has anyone seen the code generated for an if(...) statement in the pic18 series? It seems like the compiler generates the same code as if it were a pic16 series. They are not taking advantage of the newer instructions.

Of course not Smile . Currently a 18F compiler's main task is to help us to migrate from 16F series to 18F chips. Mine does it very well Smile
I hope CCS will continue developing about 18Fxx2(0) parts, especially:
1. Ability to use pointers to const structures. Currently the compiler uses the old method (call a function, calculate the address and read data, inherited from 16F) with that ugly preamble just before the data table. It would be better to store the addresses at compile time and to read direct ROM addresses by the TBLRD*(+/-) instructions. Of course CCS C already uses this instruction but the _access_ of the const starts with a CALL instead of a simple read. I have posted a code snippet to demonstrate how to retrieve a string from a dedicated ROM address with 18F series.
2. 18Fxx20 brings up an additional feature: the internal 21-bit address bus (found also in 18Fxx2, used only for internal ROM) is wired out from the PIC so we were able to connect an external RAM to the PIC. Then we could read or write this RAM by single instructions (TBLRD*, TBLWT*) so it would be easy to use the external RAM as memory for both code and data.
Currently I use something like this:

void ReadStructure(void *p, int32 address, unsigned long length)
{
#byte addressL = address
#byte addressH = address+1
#byte addressU = address+2
#byte pH = p
#byte pL = p+1

TBLPTRU = addressU;
TBLPTRH = addressH;
TBLPTRL = addressL;
FSR1L = pL;
FSR1H = pH;
do {
#asm
TBLRD*+
#endasm
POSTINC1 = TABLAT;
} while (--length);
}

void WriteStructure(void *p, int32 address, char length)
{
#byte addressL = address
#byte addressH = address+1
#byte addressU = address+2
#byte pH = p
#byte pL = p+1

TBLPTRU = addressU;
TBLPTRH = addressH;
TBLPTRL = addressL;
FSR1L = pL;
FSR1H = pH;
do {
TABLAT = POSTINC1;
#asm
TBLWT*+
#endasm
} while (--length);
}

Usage:
unsigned long lvar;
float fvar;

ReadStructure(&lvar,0x000000,sizeof(unsigned long));
WriteStructure(&fvar,0x000002,sizeof(float));

It would be nice if we were able to declare variables in that RAM. A compiler knows -at compile time- the addresses and the size of the variable.
And -as the final step- we could have a software stack at top of the RAM (e.g. 1kbyte from the 2MB address space Smile ).

Well... Maybe in the next year... ;)
___________________________
This message was ported from CCS's old forum
Original Post ID: 13056
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