[mikroC PIC 8.1] hazardous optimization

Discuss about beta versions of mikroC compiler.
Post Reply
Author
Message
bruno
Posts: 767
Joined: 10 Sep 2005 02:10
Location: Lyon, France
Contact:

[mikroC PIC 8.1] hazardous optimization

#1 Post by bruno » 17 Mar 2008 12:06

Hello,

can you please consider this part of code :

Code: Select all

void    radio_ISR()
        {
        if(INTCON.INT0IE)
                {
                if(INTCON.INT0IF)
                        {
                        unsigned char i ;
                        unsigned char s ;
                        unsigned long   t ;

                        linkLEDtimer = 1 ;

                        t = 0 ;

                        for(i = 0 ; i < 32 ; i++)
                                {
                                Delay_us(20) ;

                                RADIO_CLK_OUT = 1 ;
                                Delay_us(10) ;

                                t <<= 1 ;
                                t |= RADIO_DATA_IN ;

                                Delay_us(10) ;
                                RADIO_CLK_OUT = 0 ;
                                }

                        s = Lo(t) ;        // status
                        
                        /*
                         * remise en ordre du numéro de capteur
                         */
                        Lo(t) = Highest(t) ;
                        i = Hi(t) ;
                        Hi(t) = Higher(t) ;
                        Higher(t) = i ;
                        Highest(t) = 0 ;
                        
                        // bouton d'appel
                        if(s == 0x41)
                                {
                                if(help != 255)
                                        {
                                        ALARM_LED = 1 ;
                                        help++ ;
                                        }
                                }

                        pushIsrEvent(EVENT_RADIO, t, s) ;
                        }
                        
                INTCON.INT0IF = 0 ;
                }
        }
the test

Code: Select all

                        if(s == 0x41)
does not work as expected, because optimizer did not take t bytes swap into account :

Code: Select all

;radio.c,228 :: 			if(s == 0x41)
$23DA	$51C0	    			MOVF	radio_ISR_t_L2, 0, 1
$23DC	$0A41	    			XORLW	65
$23DE	$E106	    			BNZ	L_radio_ISR_5
the test is on Lo(t) instead of s

turning s as volatile fixes the problem :

Code: Select all

;radio.c,228 :: 			if(s == 0x41)
$23DA	$51BF	    			MOVF	radio_ISR_s_L2, 0, 1
$23DC	$0A41	    			XORLW	65
$23DE	$E106	    			BNZ	L_radio_ISR_5
hoo what a vicious one :mrgreen: :!:
Bruno
Bored with 7-segment ? Try the [url=http://www.micro-examples.com/public/microex-navig/doc/079-touchclock.html]TouchClock[/url]

User avatar
rajkovic
mikroElektronika team
Posts: 694
Joined: 16 Aug 2004 12:40

Re: [mikroC PIC 8.1] hazardous optimization

#2 Post by rajkovic » 17 Mar 2008 13:53

bruno wrote:Hello,

can you please consider this part of code :

Code: Select all

void    radio_ISR()
        {
        if(INTCON.INT0IE)
                {
                if(INTCON.INT0IF)
                        {
                        unsigned char i ;
                        unsigned char s ;
                        unsigned long   t ;

                        linkLEDtimer = 1 ;

                        t = 0 ;

                        for(i = 0 ; i < 32 ; i++)
                                {
                                Delay_us(20) ;

                                RADIO_CLK_OUT = 1 ;
                                Delay_us(10) ;

                                t <<= 1 ;
                                t |= RADIO_DATA_IN ;

                                Delay_us(10) ;
                                RADIO_CLK_OUT = 0 ;
                                }

                        s = Lo(t) ;        // status
                        
                        /*
                         * remise en ordre du numéro de capteur
                         */
                        Lo(t) = Highest(t) ;
                        i = Hi(t) ;
                        Hi(t) = Higher(t) ;
                        Higher(t) = i ;
                        Highest(t) = 0 ;
                        
                        // bouton d'appel
                        if(s == 0x41)
                                {
                                if(help != 255)
                                        {
                                        ALARM_LED = 1 ;
                                        help++ ;
                                        }
                                }

                        pushIsrEvent(EVENT_RADIO, t, s) ;
                        }
                        
                INTCON.INT0IF = 0 ;
                }
        }
the test

Code: Select all

                        if(s == 0x41)
does not work as expected, because optimizer did not take t bytes swap into account :

Code: Select all

;radio.c,228 :: 			if(s == 0x41)
$23DA	$51C0	    			MOVF	radio_ISR_t_L2, 0, 1
$23DC	$0A41	    			XORLW	65
$23DE	$E106	    			BNZ	L_radio_ISR_5
the test is on Lo(t) instead of s

turning s as volatile fixes the problem :

Code: Select all

;radio.c,228 :: 			if(s == 0x41)
$23DA	$51BF	    			MOVF	radio_ISR_s_L2, 0, 1
$23DC	$0A41	    			XORLW	65
$23DE	$E106	    			BNZ	L_radio_ISR_5
hoo what a vicious one :mrgreen: :!:
thanks we will see how this could happend... :oops:

Post Reply

Return to “mikroC Beta testing”