I don't agree with Optimizer ...

Discuss about beta versions of mikroPascal compiler.
Post Reply
Author
Message
yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

I don't agree with Optimizer ...

#1 Post by yo2lio » 21 Sep 2007 16:23

In this situation :

Code: Select all

program test;

var d1,d2,d3 : dWord;

procedure interrupt;
begin
// type of interrupt ...
  d1 := 2048;
  d2 := 128000;
end;

begin
  while true do
    begin
      d1 := 1024;
      d2 := 65536;
// maybe interrupt happened here ....... and d1, d2 change .... values
      d3 := d2 div d1;
    end;
end.
I got this ASM code : :?

Code: Select all

; ----------------------------------------------
$0000	$EF2C	F000			GOTO	_main
$0008	$	_interrupt:
$0008	$CFE9	F015			MOVFF	FSR0L, ?saveFSR0
$000C	$CFEA	F016			MOVFF	FSR0H, ?saveFSR0+1
$0010	$CFE1	F017			MOVFF	FSR1L, ?saveFSR1
$0014	$CFE2	F018			MOVFF	FSR1H, ?saveFSR1+1
$0018	$CFD9	F019			MOVFF	FSR2L, ?saveFSR2
$001C	$CFDA	F01A			MOVFF	FSR2H, ?saveFSR2+1
;test.ppas,6 :: 			begin
;test.ppas,8 :: 			d1 := 2048;
$0020	$0E00	    			MOVLW	0
$0022	$6E1B	    			MOVWF	_d1, 0
$0024	$0E08	    			MOVLW	8
$0026	$6E1C	    			MOVWF	_d1+1, 0
$0028	$0E00	    			MOVLW	0
$002A	$6E1D	    			MOVWF	_d1+2, 0
$002C	$6E1E	    			MOVWF	_d1+3, 0
;test.ppas,9 :: 			d2 := 128000;
$002E	$0E00	    			MOVLW	0
$0030	$6E1F	    			MOVWF	_d2, 0
$0032	$0EF4	    			MOVLW	244
$0034	$6E20	    			MOVWF	_d2+1, 0
$0036	$0E01	    			MOVLW	1
$0038	$6E21	    			MOVWF	_d2+2, 0
$003A	$0E00	    			MOVLW	0
$003C	$6E22	    			MOVWF	_d2+3, 0
$003E	$	test_L_0:
;test.ppas,10 :: 			end;
$003E	$	L_Interrupt_end:
$003E	$C015	FFE9			MOVFF	?saveFSR0, FSR0L
$0042	$C016	FFEA			MOVFF	?saveFSR0+1, FSR0H
$0046	$C017	FFE1			MOVFF	?saveFSR1, FSR1L
$004A	$C018	FFE2			MOVFF	?saveFSR1+1, FSR1H
$004E	$C019	FFD9			MOVFF	?saveFSR2, FSR2L
$0052	$C01A	FFDA			MOVFF	?saveFSR2+1, FSR2H
$0056	$0011	    			RETFIE
$0058	$	_main:
;test.ppas,12 :: 			begin
;test.ppas,13 :: 			while true do
$0058	$	test_L_3:
;test.ppas,15 :: 			d1 := 1024;
$0058	$0E00	    			MOVLW	0
$005A	$6E1B	    			MOVWF	_d1, 0
$005C	$0E04	    			MOVLW	4
$005E	$6E1C	    			MOVWF	_d1+1, 0
$0060	$0E00	    			MOVLW	0
$0062	$6E1D	    			MOVWF	_d1+2, 0
$0064	$6E1E	    			MOVWF	_d1+3, 0
;test.ppas,16 :: 			d2 := 65536;
$0066	$0E00	    			MOVLW	0
$0068	$6E1F	    			MOVWF	_d2, 0
$006A	$0E00	    			MOVLW	0
$006C	$6E20	    			MOVWF	_d2+1, 0
$006E	$0E01	    			MOVLW	1
$0070	$6E21	    			MOVWF	_d2+2, 0
$0072	$0E00	    			MOVLW	0
$0074	$6E22	    			MOVWF	_d2+3, 0
;test.ppas,18 :: 			d3 := d2 div d1;
$0076	$0E40	    			MOVLW	64
$0078	$6E23	    			MOVWF	_d3, 0
$007A	$0E00	    			MOVLW	0
$007C	$6E24	    			MOVWF	_d3+1, 0
$007E	$0E00	    			MOVLW	0
$0080	$6E25	    			MOVWF	_d3+2, 0
$0082	$0E00	    			MOVLW	0
$0084	$6E26	    			MOVWF	_d3+3, 0
;test.ppas,19 :: 			end;
$0086	$D7E8	    			BRA	test_L_3
;test.ppas,20 :: 			end.
$0088	$D7FF	    			BRA	$
I change d1 and d2 in interrupt ....
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: I don't agree with Optimizer ...

#2 Post by zristic » 24 Sep 2007 08:48

We will check this.
Thanks.

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: I don't agree with Optimizer ...

#3 Post by zristic » 25 Sep 2007 08:35

I do not quite understand what is the problem with the assembly above. Instead of pasting 50 lines of asm code you can help me with saying which lines in assembly are not correct according to you.

If interrupt happens during division of two constants which you want to change then you have a bad habit of not taking care about your global variables.

Still, I am waiting for further explanation from your side what you see wrong in this code.

And please, do not paste tons of ASM code without any guides where to look for a problem.

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#4 Post by yo2lio » 25 Sep 2007 10:01

Excuse me please, I had to explain this thing.

The problem is the optimizer had put the result directly into the d3 global variable but the values of d1 and d2 (global variables) could be change by in interrupt.
In my opinion it would be nice to check if the global variables are changed (used) in interrupt.
The expected generated code would been this one ( compile and check the asm ).

Code: Select all

program test;

var d1,d2,d3 : dWord;

procedure interrupt;
begin
// type of interrupt ...
  d1 := 2048;
  d2 := 128000;
end;

begin
  while true do
    begin
      d1 := 1024;
      d2 := 65536;
      asm nop end; // STOP OPTIMIZER
// maybe interrupt happened here ....... and d1, d2 change .... values
      d3 := d2 div d1;
    end;
end.
Is just a suggestion .... maybe i'm wrong ...

If you want, I can send to you an email with more info.

Thanks .
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

Post Reply

Return to “mikroPascal Beta testing”