Jump to content
Sign in to follow this  
davidb

Complement

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

i think he may be refering to one of the new "extended instructions" which are not supported by BoostC.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...