Jump to content
Sign in to follow this  
LASTBOLT

excessive bank switching

Recommended Posts

Help excessive bank switching....

compiler optimizer option set to mode 2

 

 if(++dittercounter == 1000){dittercounter=0;gotonewrd;}

 

   bcf STATUS, RP0  <----------------

   bcf STATUS, RP1  <------------------

   incf _dittercounter, F

   btfsc STATUS, Z

   incf _dittercounter+1, F

   movf _dittercounter, W

   sublw D'232'

   btfsc STATUS, Z

   goto label_0007

   movlw 0

   goto label_0008

label_0007

   bcf STATUS, RP0  <--------------------

   bcf STATUS, RP1  <------------------------

   movf _dittercounter+1, W

   sublw D'3'

   btfss STATUS, Z

   clrw

label_0008

   btfsc STATUS, Z

   goto label_0006

   bcf STATUS, RP0 <---------------------

   bcf STATUS, RP1  <----------------------

   clrf _dittercounter

   clrf _dittercounter+D'1'

   goto _newrd

Share this post


Link to post
Share on other sites
Guest Malcolm White

I noticed this as well... I tried to create an optimisation script for these instances, but that doesn't work for some reason.

 

The assembled code looks like this...

 

;;;;;;;; if(!(pir1&(1<<0x0005))) return; // If bit set, we can go
bcf STATUS, RP0
bcf STATUS, RP1
btfsc _pir1, D'5'
goto label_0004
return
;;;;;;;;
;;;;;;;; if((rcsta&(1<<0x0001))) { // If there is an overrun error
label_0004
bcf STATUS, RP0
bcf STATUS, RP1
btfss _rcsta, D'1'

 

So I came up with...

 

Pattern:
00.	btfsc %v0%, %v1%
01.	goto %v2%
02.	return
03.%v2%

Action:
change 00 "\tbtfss %v0%, %v1%"
delete 01
delete 03

 

But it seems not to recognise it. With four for five of these in a row, there is a lot of wasted code space and ticks in jumps.

 

If any knows how to correct this, or make the script work, any help would be appreciated.

Share this post


Link to post
Share on other sites

I have noticed this issue too. It's not only excessive switching, theres also gotos not needed as well in some cases. I tried writing an optimisation script, but that seems to not want to work either.

 

The source code looks like this...

;;;;;;;; if(!(pir1&(1<<0x0005))) return; // If bit set, we can go
bcf STATUS, RP0
bcf STATUS, RP1
btfsc _pir1, D'5'
goto label_0004
return
;;;;;;;;
;;;;;;;; if((rcsta&(1<<0x0001))) { // If there is an overrun error
label_0004
bcf STATUS, RP0
bcf STATUS, RP1

 

...so I wrote the following script

////////////////////////////////////////////
// Bit Test Jump Optimisation #1
////////////////////////////////////////////

Name: "Bit Test Jump Optimization #1"
Debug: on

Pattern:
00.	btfsc %v0%, %v1%
01.	goto %v2%
02.	return
03.%v2%

Action:
change 00 "\tbtfss %v0%, %v1%"
delete 01
delete 03

 

But it doesn't seem to work. :)

If anyone knows how it can be recoded so it doesn't do this, or how to get the optimisation script working, it would be greatly appreciated.

 

With four or five of these in a row, there is a 3 lines that could be removed each time... 15 lines doesn't sound like much, but the more efficient the better, right?  ???

Share this post


Link to post
Share on other sites
Guest Pavel
Help excessive bank switching....

I've already put this work in my todo list. Will try to make it by the next compiler release. This kind of optimization will require a much more intelligent optimizer but the win is big too.

 

Regards,

Pavel

 

PS: Optimization (.pat) scripts won't help since they are processed before any bank instruction processing.

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