question about optimizing code and the code generator

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

question about optimizing code and the code generator

Post by Jerry Messina » Fri Jan 07, 2011 1:43 pm

I'm trying to optimize some code, and I ran across some things that puzzled me while looking at the generated asm code...

Code: Select all

?I000291_F005_000142_P000064 ; L#MK IF (RCIF = 1) THEN
        BTFSS PIR1,5,0
        BRA ENDIF_59


?I000294_F005_000150_P000064 ; L#MK IF (RXSTAT.OERR = 1) THEN
        BCF STATUS,3,0
        BTFSS M71_U01,1
        BSF STATUS,3,0
        BOV ENDIF_60


?I000301_F005_000165_P000064 ; L#MK IF (NEWPACKET = FALSE) THEN
        BCF STATUS,3,0
        BTFSC M61_U01,0
        BSF STATUS,3,0
        BTFSC STATUS,3,0
        BRA ENDIF_61

The first case makes perfect sense to me. Short and sweet. Test the bit.

The thing I don't understand is all of the instructions dealing with the STATUS register bit 3 (the OV bit??) in the second and third cases. Why is the third case so complicated?

Can't it just test the bit like is done in the first case?


Both variables involved are module-level declared as:

Code: Select all

public dim NewPacket as boolean           // packet available flag

public structure rcsta_reg_t
    b as byte
    spen    as b.bits(7)
    rx9     as b.bits(6)
    sren    as b.bits(5)
    cren    as b.bits(4)
    adden   as b.bits(3)
    ferr    as b.bits(2)
    oerr    as b.bits(1)
    rx9d    as b.bits(0)
end structure
public dim rxstat as rcsta_reg_t

They're both located in bank 0

Is there any way to optimize the tests?

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Fri Jan 07, 2011 4:56 pm

I guess there's more to it than meets the eye.

If I put together a simple program with just those few declarations and statements, all the tests end up being very simple 'btfss' type instructions.

As I add variables and move stuff around in memory banks, things get a bit more complicated, and I begin to see sequences like that shown. I guess it's related to whether or not the access bank ends up getting used.

I still can't quite figure out the STATUS register manipulations, though.

Rickado
Registered User
Registered User
Posts: 17
Joined: Tue Apr 28, 2009 9:43 pm
Location: Dunedin, New Zealand

Post by Rickado » Sat Jan 08, 2011 4:36 am

I'm with you Jerry. Could it be something to do with the different PIC18 out there? The only thing is when you tested it with only few declarations and statements, all the tests ended up being very simple 'btfss' type instructions.
Another though is as Status can be seen anywhere (ie it doesn't matter which BSR you're in) and If statements can go to function routines then that routine can check the Status.bit no matter which BSR its in ??

Post Reply