mP PRO v 7.00 command-line compiler fixes

General discussion on mikroPascal PRO for PIC.
Post Reply
Author
Message
janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

mP PRO v 7.00 command-line compiler fixes

#1 Post by janni » 29 Dec 2016 02:29

For some reason fixes to command-line compiler in v 7.00 were not listed in release description, but from the tests I've had time to run, several fixes were in fact applied :) . Maybe the developers are too modest to boast about it, but they made the command-line compiler noticeably safer :D .

So far I found the following errors removed:
  • - when one appends constant string to string with '+' operator compiler forgets to add terminator,
    - linker may introduce bank switching instruction without checking whether previous bit testing instruction may skip over it,
    - division by a constant being a power of 2 is optimized to right shifting which produces errors for negative dividends (-3/2 gives -2!) for all signed types (short, integer, longint) when dividend is not a multiple of divisor,
    - modulo operations with power of 2 (x mod 2^n) are optimized to 'AND' operations with wrong parameters (for bytes higher then least significant one),
    - negation of HiWord, LoWord applied to a constant produces wrong results for some arguments (like not HiWord($00FF0000)=$0000),
    - letting compiler extend type in expression may lead to incorrect results (PIC16 & enhanced only).
Adding to that correction of processor definition files with wrong 'badram' locations or lacking Mapped Memory declarations (I checked only few files, but assume all had been modified) one has a reason to feel much more confident while programming under the newest version.

To avoid accusation of being uncharacteristically pleasant :wink: , I have to add that the compiler became slightly over-aggressive in replacing local variables, which sometimes leads to marginally bigger code and RAM use. Local variables are being replaced by hidden ones - not compiler's internal ones, which would be understandable and saved RAM, but by new variables that use the same amount of space or more. Here's an example:

Code: Select all

  older compiler version                                           v 7.00
____________________________________________________________________________________
;S547.mpas,534 :: 		tempw:=time/60;             ;S547.mpas,534 :: 		tempw:=time/60;
  	MOVLW       60                                  	MOVLW       60
  	MOVWF       R4                                  	MOVWF       R4 
  	MOVLW       0                                   	MOVLW       0
  	MOVWF       R5                                  	MOVWF       R5 
  	MOVWF       R6                                  	MOVWF       R6 
  	MOVWF       R7                                  	MOVWF       R7 
  	MOVFF       FARG_showTime_time, R0              	MOVFF       FARG_showTime_time, R0
  	MOVFF       FARG_showTime_time+1, R1            	MOVFF       FARG_showTime_time+1, R1
  	MOVFF       FARG_showTime_time+2, R2            	MOVFF       FARG_showTime_time+2, R2
  	MOVFF       FARG_showTime_time+3, R3            	MOVFF       FARG_showTime_time+3, R3
  	CALL        _Div_32x32_U, 0                     	CALL        _Div_32x32_U, 0
  	MOVFF       R0, showTime_tempw                  	MOVFF       R0, FLOC__showTime
  	MOVFF       R1, showTime_tempw+1                	MOVFF       R1, FLOC__showTime+1
		                                               	MOVFF       R2, FLOC__showTime+2   \ superfluous
		                                               	MOVFF       R3, FLOC__showTime+3   /
;S547.mpas,535 :: 		time:=time-60*tempw;        
  	MOVLW       0                                   	MOVLW       60                     | not optimal
  	MOVWF       R2                                  	MOVWF       R0 
  	MOVWF       R3                                  	MOVLW       0
  	MOVLW       60                                  	MOVWF       R1 
  	MOVWF       R4                                  	MOVWF       R2 
  	MOVLW       0                                   	MOVWF       R3 
  	MOVWF       R5                                  	MOVFF       FLOC__showTime, R4
  	MOVWF       R6                                  	MOVFF       FLOC__showTime+1, R5
  	MOVWF       R7                                  	MOVLW       0
  	CALL        _Mul_32x32_U, 0                    	 MOVWF       R6 
		                                               	MOVWF       R7 
		                                               	CALL        _Mul_32x32_U, 0
		                                              ;S547.mpas,535 :: 		time:=time-60*tempw;
A word local variable, tempw, is with no apparent reason replaced by dword hidden variable, FLOC__showTime. Furthermore, in preparation to 32-bit multiplication, code becomes actually less optimal than without optimization. As a side effect optimizer moves Pascal instruction in list file below the code that represents it.

I cannot write much about the IDE - after discovering quirks that make its use too cumbersome for me, I reverted to IDE from v6.61 and didn't continue testing the new version. The other reason that I stayed with older version is malfunction of Package Manager that makes restoring previously installed library packages impossible. Hopefully, these issues will be soon fixed by a minor revision that will not require full installation and release of new version of Package Manager.

IDE quirks that made me revert to older IDE:
- in Output Settings: 'Include sorce lines in output files', 'Generate COFF file', and 'Long HEX format' are always cleared on start-up
- in Editor Settings: 'Show Indent Guides' option always starts unchecked and one cannot turn it on without first checking 'Enable code folding' ('Allow wildcard character' always starts checked but that's no bother).

BTW, there's now an option to switch off automatic appearance of Code Assistant window. Unfortunately, one cannot then invoke Code Assistant manually either.

chimimic
Posts: 178
Joined: 29 Sep 2007 14:35
Location: France
Contact:

Re: mP PRO v 7.00 command-line compiler fixes

#2 Post by chimimic » 29 Dec 2016 12:24

Thanks Janni to have taken time for this feedback :D

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: mP PRO v 7.00 command-line compiler fixes

#3 Post by filip » 29 Dec 2016 14:45

Hi,

Thank you janni for your opinion and feedback, we will correct the IDE quirks that you reported :
- in Output Settings: 'Include sorce lines in output files', 'Generate COFF file', and 'Long HEX format' are always cleared on start-up
- in Editor Settings: 'Show Indent Guides' option always starts unchecked and one cannot turn it on without first checking 'Enable code folding' ('Allow wildcard character' always starts checked but that's no bother).
As for the over-aggresive compiler, could you please post the code snippet that represents this issue ?

Regards,
Filip.

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: mP PRO v 7.00 command-line compiler fixes

#4 Post by janni » 29 Dec 2016 16:33

The code snippet I posted above came from a large program but it wasn't hard to recreate the same effect in a simple program:

Code: Select all

program test127;

var txt: string[30];
    Averlim:byte;
    Delta:real;
  
procedure showTime(time:dword);
 var tempw:word; 
 begin
  tempw:=time/60;
  time:=time-60*tempw;
  WordToStr(tempw,txt);
 End;{showTime}

function newAver(inp:real):boolean;
 var tempr:real;
 begin
  result:=true;
  tempr:=5.0*inp;
  if tempr>real(Averlim)*Delta then result:=false;
 End;{newAver}

begin
  showTime(400);
  //newAver(1.0);
end.
Procedure showTime reflects increase in code and RAM size due to local variable replacement by a larger hidden one. Function newAver (when uncommented) illustrates unnecessary replacement of local variable by a hidden one without side effects - apart from making the variable inaccessible for a user during simulation.

One may block the optimizer by declaring local variable volatile but obviously optimizer is over-aggressive here as its actions do not decrease RAM or program memory use.

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

Re: mP PRO v 7.00 command-line compiler fixes

#5 Post by rajkovic » 30 Dec 2016 10:10

Jani,
thanks for feedback on optimization, we will investigate it and it will be fixed (reverted) to more optimal case.
As always your feedback valuable. We have already fixed most of IDE reported issues, now in test phase, and hopefully
if there is no new arrivals there should be maintenance release sometime during January.

PS.
you are more than nice even when you point on our mistakes,
most of your comments and critics of common value for us and other users also.
Thanks for your time and effort, we have really invested a lot in this merge and apparently
missed to test some unexpected side-effects.

Ivan

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: mP PRO v 7.00 command-line compiler fixes

#6 Post by janni » 30 Dec 2016 16:47

rajkovic wrote:Jani,
thanks for feedback on optimization, we will investigate it and it will be fixed (reverted) to more optimal case.
The job done on the latest version of command-line compiler outshines any little quirks :) . Even some of the discrepancies between runtime and compile-time calculations were removed. What will I do without problems to point out :cry: ? (Wait, list of those isn't empty yet :!: :mrgreen: )
PS.
you are more than nice even when you point on our mistakes,
Hah! I know my sardonic nature and sarcasm is too good a tool when driving a point - no pleasantries will change that :!:
(Only my wife knows when to hit me on the head and could thus survived around :lol: .)

Post Reply

Return to “mikroPascal PRO for PIC General”