Jump to content
Sign in to follow this  
chrisassall

Not   'test_bit'   built-in function

Recommended Posts

Got Single User license for the C2C++ compiler version:

1.2

as: Christian Assall

last week.

It really fun only to look what the compiler makes with your C-Code!  :-)

But then the shock!

Where is a test_bit() function!

 

If you  want to test in the intterupt the int flags you must use

 

if ((_INTCON & _T0IF) != 0)

 

 

and you will get:

 

movf __INTCON, W

andlw D'4'

sublw D'0'

movlw 1

btfsc STATUS, Z

clrw

sublw 0

btfsc STATUS, Z

goto label_0000

 

 

but if you made this in assembler you will made this of course

 

btfss  INTCON,T0IF

goto   handle_int

test_next_int:

 

 

ooops !

 

CCS also generates:

 

if ((INTCON & _T0IF) != 0)  

00AD:  MOVF   INTCON,W

00AE:  ANDLW  04

00AF:  XORLW  00

00B0:  BTFSC  STATUS.2

00B1:  GOTO   0B4

....................       {  

....................       erg=1;  

00B2:  MOVLW  01

00B3:  MOVWF  erg

....................       }  

....................  

....................  

 

but if you use the bit_test() function it will do want we want!

 

....................    if(bit_test(INTCON,T0IF))  

00B4:  BTFSS  INTCON.2

00B5:  GOTO   0B8

....................       {  

....................       erg=2;  

00B6:  MOVLW  02

00B7:  MOVWF  erg

....................       }  

 

Any idea (except inline assembler - yes you can make this - but then I will better use the pure mplab assembler,

because the I could use my macro LIB which make assembler at this point as easy as C.

I had the idea to put my used macros in the used P16CXXX.INC files   -

that's because you could not make it that the compiler put any

asm  line before the interrupt code where I want to use the macros.

Also it's impossible to define the macros in the C-source because the Compiler will make some code checks which

will crash with the most macros!

But that isn't all really satisfying

 

 

Any idea ?  

It's a pity - the compiler does so great work in the most aspects but in some details it failed a little bit :-(

 

Regards Chris Assall

Share this post


Link to post
Share on other sites
Guest Pavel

The philosophy behind the compiler is to create better optimizer rather than introduce new built-in functions.

 

Soon I will release new compiler versions (both c2c and c2c++) that have better assembly code generation and this is another good candidate for the compiler optimizer.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
Guest Pavel

Don't make expressions more complicated than necessary.

For example instead of "if( (led & 1) != 0 )" that generates

6 assembly instructions use "if( led & 1 )" that generates

only 2 instructions.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

What about the script optimization ?

 

if ((INTCON & _T0IF) != 0)  

00AD:  MOVF   INTCON,W

00AE:  ANDLW  04

00AF:  XORLW  00

00B0:  BTFSC  STATUS.2

00B1:  GOTO   0B4

 

with 8 patterns, for all the single bit values ( 1, 2, 4, 8, 16, 32, 64, 128 )values could be tested for and optimised to

BTFSC INTCON, BITX

GOTO ???

 

couldn't they ?

Share this post


Link to post
Share on other sites

Thanks Admin for the Tip -- but the expression

 

if ((INTCON & _T0IF) != 0)  

 

is extracted of your example  

 

Sample #4 that outputs a string to serial line using interrupts.

http://www.picant.com/c2c/examples.html

 

As I have the compiler only a short time I thought that this example was exemplarily  

and it makes no difference to give the compiler the complicated expression or the simple.

 

Normally I prefer the complicated expression - because then I had not to bear in mind how is the logic in C.

(is 0 true or is it false ? .... :) )   ((INTCON & _T0IF) != 0) is more self-explanatory.

If you program in different langues you easy forget such facts and my  experience shows that such little

things are always a hidden sources of error  !

So I prefer the long expressions if this makes no difference for the compiler!  

 

I have also thought about a script solution - but since now I haven't the time to work into this!

Besides I maybe assume that there must be a problem with this, because there was no ready made script for this

obvious  problem.

 

Regards Chris

 

PS.: I also agree with the Admin that  special functions are not a good solution of such things.

But I thought that on this way this feature maybe could be implemented easier and

quicker when you gave the compiler a little tip what he should do :)

Share this post


Link to post
Share on other sites
Guest Pavel
Thanks Admin for the Tip -- but the expression

 

if ((INTCON & _T0IF) != 0) 

 

is extracted of your example 

 

Sample #4 that outputs a string to serial line using interrupts.

http://www.picant.com/c2c/examples.html

Chris, thanks for pointing out on the sample code. I need to correct it.

 

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...