PICmicro & dsPIC >> PIC W.I.P. (Work In Progress)

Pages: 1
Fil



Reged: May 24 2005
Posts: 1
Optimisations in PICC compiler
      #78302 - Fri Oct 10 2008 08:05 AM

I like to research disasm lstings...
I'm testing PICC 9.60 PL3

1.
Disasm code 1:
Code:
 
21: b = a > 1 ? 1 : 0;
01E 3002 MOVLW 0x2
01F 0220 SUBWF 0x20, W
020 3000 MOVLW 0
021 1803 BTFSC 0x3, 0
022 3001 MOVLW 0x1
023 00A1 MOVWF 0x21


I think it's good optimization.

Disasm code 2:
Code:
 
21: b = a > 1 ? 4 : 0;
01E 3002 MOVLW 0x2
01F 0220 SUBWF 0x20, W
020 1803 BTFSC 0x3, 0
021 2824 GOTO 0x24
022 3000 MOVLW 0
023 2825 GOTO 0x25
024 3004 MOVLW 0x4
025 00A1 MOVWF 0x21


But it's no good. Why? If I compare 0 and 1 - it's good, but for another constants it not so.

2.
Code:
 
20 013 2814 GOTO 0x14
21 014 1283 BCF STATUS, 0x5
22 015 1303 BCF STATUS, 0x6


goto on next address
It's goto from end of startup.as to main. Optimiser must remove it.

3.
Begin of interrupt handler:
Code:
 
6 005 0803 MOVF STATUS, W
7 006 0183 CLRF STATUS <- Status cleared
8 007 00A4 MOVWF 0x24
9 008 190B isr BTFSC INTCON, 0x2
10 009 110B BCF INTCON, 0x2
11 00A 3010 MOVLW 0x10
12 00B 1283 BCF STATUS, 0x5 <-and two bits of Status cleared again (no need)
13 00C 1303 BCF STATUS, 0x6



4. IRP tracking
Code:

unsigned char *iter;
unsigned char arr[10];
iter = arr;
*iter = 5;
++iter;
*iter = 7;


and disasm:
Code:

39 026 3025 MOVLW 0x25
40 027 00A4 MOVWF iter
41 028 0084 MOVWF FSR
42 029 1383 BCF STATUS, 0x7 <- clear IRP
43 02A 3005 MOVLW 0x5
44 02B 0080 MOVWF INDF
45 02C 0AA4 INCF iter, F
46 02D 0824 MOVF iter, W
47 02E 0084 MOVWF FSR
48 02F 1383 BCF STATUS, 0x7 <- clear IRP again (no need)
49 030 3007 MOVLW 0x7
50 031 0080 MOVWF INDF


If program use only banks 0 and 1 (OCG may ckeck it) IRP may be cleared only 1 time on startup.


Post Extras: Print Post   Remind Me!   Notify Moderator  
Sonny06
stranger


Reged: Dec 11 2008
Posts: 1
Re: Optimisations in PICC compiler [Re: Fil]
      #89072 - Thu Dec 11 2008 03:00 AM

Wow!

I really liked your post, interesting perspective. I was looking out for the same kind of information. Thanks a lot for sharing it.

--------------------
http://www.jeffotto.com/affiliates/sr.php?uid=sonnex_1


Post Extras: Print Post   Remind Me!   Notify Moderator  
pzak
stranger


Reged: Dec 18 2008
Posts: 2
Re: Optimisations in PICC compiler [Re: Fil]
      #89982 - Thu Dec 18 2008 09:22 PM

I was surprised at what I would consider a lack of optimization....

I am using the demo version of PICC Pro 9.60PL3, which the website claims has a "very high" level of optimization. The first thing I tried to build was one of the included samples, A2Demo. I was discouraged by the result. I've included an example below.


The C code for the function init_a2d():

void init_a2d(void){
ADCON0=0;
ADCON1=0;
ADON=1;
}

The compiled result: (assembly)

_init_a2d:
;a2demo.c: 21: ADCON0=0;
clrc
movlw 0
btfsc status,0
movlw 1
movwf (31) ;volatile

;a2demo.c: 22: ADCON1=0;
clrc
bsf status, 5 ;RP0=1, select bank1
bcf status, 6 ;RP2=0, select bank1
movlw 0
btfsc status,0
movlw 1
movwf (159)^080h ;volatile

;a2demo.c: 23: ADON=1;
setc
btfsc status,0
goto u111
goto u110
bcf status, 5 ;RP0=0, select bank0
bcf status, 6 ;RP2=0, select bank0
u111:
bsf (248/8),(248)&7
goto u124
u110:
bcf (248/8),(248)&7
u124:
;a2demo.c: 24: }
l1:
return

I can do it by hand much faster: The compiled version seems to assume it starts in BANK0, so I'll do the same.

_init_a2d:
clrf ADCON0
bsf status, 5 ; BANK1
clrf ADCON1
bcf status, 5 ; BANK0
bsf ADCON0, ADON
return


By the way, I ran the compiler with --opt=all for anyone who is thinking thats my problem. I'm looking for something silly that I neglected to do that would make this compiler seem like less of a rip off. Any ideas????


Post Extras: Print Post   Remind Me!   Notify Moderator  
luckyAdministrator
Microchip staff
*****

Reged: Oct 06 2003
Posts: 1184
Loc: Brisbane, Australia
Re: Optimisations in PICC compiler [Re: pzak]
      #89992 - Fri Dec 19 2008 12:04 AM

Quote:


I can do it by hand much faster: The compiled version seems to assume it starts in BANK0, so I'll do the same.

Code:

_init_a2d:
clrf ADCON0
bsf status, 5 ; BANK1
clrf ADCON1
bcf status, 5 ; BANK0
bsf ADCON0, ADON
return


Any ideas????




I suspect you are running the compiler in lite mode. I compiled your example and it produced exactly the same output as your hand-optimized version:
Code:

opt.c: 7: ADCON0=0;
clrf 31 ;volatile
;opt.c: 8: ADCON1=0;
bsf 3,5 ;RP0=1, select bank1
clrf 31 ;volatile
;opt.c: 9: ADON=1;
bcf 3,5 ;RP0=0, select bank0
bsf 31,0



--------------------
Matt Luckman
Microchip Technology Inc.


Post Extras: Print Post   Remind Me!   Notify Moderator  
pzak
stranger


Reged: Dec 18 2008
Posts: 2
Re: Optimisations in PICC compiler [Re: lucky]
      #90012 - Fri Dec 19 2008 01:21 AM

@Matt: Thanks for the quick reply. You suspicions were correct. I re-ran the installer and entered "demo" mode, and now the compiler produces exactly what I had hoped for! I must have selected "lite" mode by mistake.

Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 3 anonymous users are browsing this forum.

Moderator:  lucky, Andrew L 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is enabled
      UBBCode is enabled

Rating:
Topic views: 3628

Rate this topic

Jump to

Contact Us | Privacy statement HI-TECH Software

Powered by UBB.threads™ 6.5.5