davidb 0 Posted June 14, 2007 Report Share Posted June 14, 2007 Hi, I am new to SourceBoost C (V6.70) and have been testing it with some simply code. If x is data type char why does x = ~x compile to COMF x,W MOVWF x instead of the more efficient COMF x,F ? short and long types seem to be OK. I looked through the archives and found a reference to this with trisc = ~trisc This now appears to work as expected but not with other variables. Am I missing something? davidb Quote Link to post Share on other sites
Dave 0 Posted June 14, 2007 Report Share Posted June 14, 2007 davidb, Hi, I am new to SourceBoost C (V6.70) and have been testing it with some simply code. If x is data type char why does x = ~x compile to COMF x,W MOVWF x instead of the more efficient COMF x,F ? short and long types seem to be OK. I looked through the archives and found a reference to this with trisc = ~trisc This now appears to work as expected but not with other variables. Am I missing something? I don't see the issue: void main() { unsigned char x; x = ~x; 0003 1283 BCF STATUS, RP0 0004 1303 BCF STATUS, RP1 0005 09BB COMF main_1_x, F while( 1 ); 0006 label268438757 0006 2806 GOTO label268438757 } Regards Dave Quote Link to post Share on other sites
emte 0 Posted June 15, 2007 Report Share Posted June 15, 2007 i think he may be refering to one of the new "extended instructions" which are not supported by BoostC. Quote Link to post Share on other sites
davidb 0 Posted June 15, 2007 Author Report Share Posted June 15, 2007 Dave, I agree it works as shown when x is unitialised but in a working program x would have value. If you assign a value to x before or strangely, after the expression you get a different result. It doesn't seem to matter if x is local or global. If you do this with tris, intcon or probably any of the other PIC registers it works as expected. e.g. void main( void ) { unsigned char x; x = ~x; 0003 1283 BCF STATUS, RP0 0004 1303 BCF STATUS, RP1 0005 0920 COMF main_1_x, W 0006 00A0 MOVWF main_1_x x = 0; 0007 01A0 CLRF main_1_x trisc = ~trisc; 0008 1683 BSF STATUS, RP0 0009 0987 COMF gbl_trisc, F intcon = ~intcon; 000A 098B COMF gbl_intcon, F while(1); 000B label268438907 000B 280B GOTO label268438907 } Take out the x =0; and it works as expected. I am new to SourceBoost C, so perhaps this is the way it is meant to work but I would like to understand why. BTW the target is the 16F874A. Thanks davidb Quote Link to post Share on other sites
Dave 0 Posted June 15, 2007 Report Share Posted June 15, 2007 davidb, Take out the x =0; and it works as expected. I am new to SourceBoost C, so perhaps this is the way it is meant to work but I would like to understand why. Yes this isn't the expected behaviour, I added it to the our bugs list. Regards Dave Quote Link to post Share on other sites
Pavel 0 Posted July 20, 2007 Report Share Posted July 20, 2007 Hi, I am new to SourceBoost C (V6.70) and have been testing it with some simply code. If x is data type char why does x = ~x compile to COMF x,W MOVWF x instead of the more efficient COMF x,F ? short and long types seem to be OK. I looked through the archives and found a reference to this with trisc = ~trisc This now appears to work as expected but not with other variables. Am I missing something? This is a good example to show why it's not that easy to implement such optimizations in compiler. It's not only the matter of finding and replacing these 2 instructions with one. This is easy part. The difficult part is when compiler should analyse code after the instructions and do checks like if this code does not rely on W and STATUS flags set by these 2. That's the reason we have to be very careful in adding any new such optimization. Regards, Pavel Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.