Jump to content
Sign in to follow this  
djulien

Extra Bank Selects Being Generated At Start Of Functions

Recommended Posts

Bug description:

Whenever a new function is started, a bank select is generated for any RAM usage. This is not necessary

if the caller already had the correct bank already selected.

 

The compiler already maintains a call graph internally to decide where it can re-allocate RAM for mutually exclusive variables, so it should also be able to check whether all of the callers of a function have the correct bank already selected.

 

Example code:

#include <system.h>

typedef unsigned char uint8;

uint8 var0 @ 0x20; //bank 0
uint8 var1 @ 0xa1; //bank 1
uint8 var2 @ 0x122; //bank 2

void func1(void)
{
var0 = 5; //this var is in bank 0
}

void main(void)
{
var0 = 0; //this var is in bank 0
func1();
var0 = 1; //this var is in bank 0

var1 = 2;
//etc.
}

 

The code generated for func1 is:

MOVLW 0x05
MOVLB 0x00		;//this bank select is not needed
MOVWF gbl_var0
RETURN

 

The code generated for main is:

MOVLB 0x00	    ;//bank select generated here
CLRF gbl_var0
CALL func1_00000
MOVLW 0x01
MOVWF gbl_var0	;//compiler knows that bank 0 is still selected here

 

The example above is a trivial example, but in a large program with many small functions, the extra bank selects all add up.

 

If it is not feasible for the compiler to check this, then another approach would be to allow the "bank affinity" of a function to be specified manually. Something like a #pragma to tell the compiler which bank is already selected at a given place would solve this. For example:

 

#pragma Bank 0

ahead of the func1 definition above could tell the compiler to assume that Bank 0 is already selected upon entry into the function. Then it would know that another bank select is not needed within func1.

 

Expected behavior:

Avoid extra bank selects.

 

Is the problem 100% reproduceable:

yes

 

Compiler:

BoostC

 

Compiler version:

7.10

 

Target device:

PIC16F1827, '1823, '688, etc.

 

OS:

Windows XP

thanks

 

don

Share this post


Link to post
Share on other sites

don,

Bug description:

Whenever a new function is started, a bank select is generated for any RAM usage. This is not necessary

if the caller already had the correct bank already selected.

This is not how it is intentended to work, there is meant to be minimal bank switching.

I need to investigate.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
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  

×