I would have to look at the compiler's source code for details. What should work is to group the variables into a structure like

struct {
char counter;
short NCO;
short SPEED;
short OLDV;
/*... */
} grp;

and to access them via

grp .NCO += grp.SPEED;

You could of course introduce macros to hide the structure access like

#define NCO grp.NCO

after declaring/defining the struct.

Hope that helps,

On Jun 23, 2014 6:01 AM, "Kustaa Nyholm" <Kustaa.Nyholm@planmeca.com> wrote:

I'm trying to optimise a critical section of my code
and to get rid of the BANKSEL instructions I would
like to place variables on the same bank.

I tried:

#pragma udata bank2 COUNTER NCO SPEED OLDV
short NCO;
short SPEED;
short OLDV;

   NCO += SPEED;

But this compiles to:

                      06931 ;       .line   91; stepperirq.c        NCO +=
00003E 51??           06932         MOVF    _SPEED, W, B
000040 ????           06933         BANKSEL _NCO
000042 27??           06934         ADDWF   _NCO, F, B
000044 ????           06935         BANKSEL (_SPEED + 1)
000046 51??           06936         MOVF    (_SPEED + 1), W, B
000048 ????           06937         BANKSEL (_NCO + 1)
00004A 23??           06938         ADDWFC  (_NCO + 1), F, B

so there are three BANKSEL instructions, all of which are basically
unnecessary as the correct bank was already chose in the previous
code (not shown).

I do see a bunch of

                      06686 ; removed redundant BANKSEL

so obviously sometimes the compiler knows to remove redundant BANKSELs,
but what do I need to do 'help' it to do in this case?

br Kusti

This e-mail may contain confidential or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. We will not be liable for direct, indirect, special or consequential damages arising from alteration of the contents of this message by a third party or as a result of any virus being passed on or as of transmission of this e-mail in general.

HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
Sdcc-user mailing list