|The Journey to SDCC 3.0.0|
| || |
|Nov 23, 2010|
|It took the SDCC team 19 months travelling from 2.9.0 to 3.0.0 release on Nov 1, seems that they had done many house keeping work during this time. The items in release note directly related with our AR1688 Z80 are:
* changed z80 and gb targets object file extension to .rel
* special sdcc keywords which are not preceded by a double underscore are deprecated in sdcc version 3.0.0 and higher. See section ANSI-Compliance in sdccman
* asxxxx / aslink renamed to sdas / sdld and synchronized with ASXXXX V2.0
Obviously those changes mean lots of changes in our source code and related makefiles. Partly because of I was busy with PA6488 work,
partly because of I was lazy to fork a test version, I ignored the test phase of release candidate 1 & 2. But as soon as I started testing 3.0.0, I realized that I had made a mistake.
Most other Z80 users in the world are as lazy as me! So the Z80 port was not tested as good as the 8051 port. The first problem I met was inline asm not working any more, the SDCC mailing list soon replied it was a known bug already,
and fixed in recent snapshot. Then I met another known problem, sometimes jp instruction was optimized into jr incorrectly, this time no ready fix yet, although somebody had already posted a workaround in the bug tracking system.
With hundreds changes in my code, I do not hope to change back and wait. I started to try the workaround myself, but this need to recompile SDCC. As I had tried VC2008 to compile 2.9.0 and failed,
I started to learn other ways to compile SDCC on my Windows Vista.
At first I installed Cygwin, after several hours I got error messages gcc options -mno-cygwin not used any more. I realized that Cygwin compile was discarded the same way as MSVC. The only way is to use MinGW on Linux now.
I downloaded VirtualBox and installed it. It asked me for Linux install DVD when I tried to add a Linux visual machine.
Then I downloaded DAEMON Tools Lite to simulate DVD drive and ubuntu-10.10-dvd-i386.iso as Linux install file.
The installation process was smoother than I expected. After another several hours time I was able to compile and try the workaround myself. Finally I used a safer workaround, which is now working together with AR1688 software 0.49.007.
The result is good, SDCC 3.0.0 generated 5% less code than 2.9.0, with Z80 usually it means 5% performance improve as well.
SDCC 3.0.0 hates bad code. I added hundreds of (UCHAR) before const char like 'T', and adjusted many const string point declare.
In rc4.c, a line originally as x = x + something can not be compiled until I change it to x += something.
The most fatal experience was with my own crt0.s, an empty call was made to a non used section, it works on 2.9.0 but 3.0.0 compiled the call to an unexpected address and destroyed safe mode booting process.
I lost 2 phones before I figured out the problem.
With so many changes along with SDCC 3.0.0, we plan to release 0.50 software in the near future. Software API 0.49.007 as 0.50 release candidate 1 is available at the snapshot part now.
Hope our customers are not so lazy as Z80 SDCC users like me. Due to lots of file names changes, I suggest to remove old API completely before extract the new API package.
The new API package is much larger than before, mostly because MinGW compiled sdcc.exe 3.0.0 is now 2.3M bytes, while VC6 compiled sdcc.exe 2.9.0 only 0.8M bytes. And other SDCC related tools in bin directory are also much larger than before.
The 8051 example code to work with AR168M in mcs51 directory is also updated and now compiled with SDCC 3.0.0.
Updated on Dec 7, 2010
Philipp is currently the major SDCC Z80 port developer. When I found he is updating C99 bool with his own Z80 project,
I thought it was worth to try it with AR1688.
In SDCC\inc\type.h, we have defined BOOLEAN as unsigned char all the time.
Since SDCC 3.0.0 supports bool from stdbool.h, I changed BOOLEAN to _Bool according to it, added --std-c99 compiler option, and compiled a SIP version.
To my surprise, the compiled code was larger than before. Then I made test and confirmed that --std-c99 option only related with bool changes. As I am willing to get faster speed for larger code size, I continue to test the speed.
I wrote the test function below in icmp.c, called it before ICMP response, so I can get the running time using ping:
BOOLEAN TestBoolean(BOOLEAN b1)
BOOLEAN b3 = IsHighSpeed();
for (s = 0; s < 30000; s ++) b2 = b1 ? b3 : FALSE;
When BOOLEAN as unsigned char, the running time of this function is 137ms, and code generated is less by 4 bytes.
When as _Bool, using bit related instructions, this function need 167ms to run.
Again we can see that for Z80, smaller code usually means faster code. As the C99 bool resulted with larger code and slower speed, I decided not to use it now.
Here are other updated information about SDCC 3.0.0 compared with 2 weeks ago:
1. The jp to jr optimization bug and rc4.c x = x + something bug fixed by Philipp.
2. Another active developer Borut pointed out Cygwin contains both gcc-3 (the good old version with -mno-cygwin) and gcc-4. You probably installed gcc-4. You can also install both versions and switch between then using set-gcc-default-3.sh and set-gcc-default-4.sh commands.
As I am glad with the Linux virtual machine, I did not try Cygwin further more.
3. I did not use MinGW strip tool when talking about sdcc.exe size, I ignored it because it was a coincidence that download snapshot build with all ports and my own built with Z80 and 8051 only are both 2.3M bytes.
After strip, Z80 and 8051 build only is 1.0M bytes, just slightly larger than 2.9.0 VC6 build.
Updated on Dec 8, 2010
Philipp added a patch in #6078 soon after I posted my TestBoolean function test result in SDCC user mailing list yesterday. I tested it today and find the code size is the same now,
and with BOOLEAN as _Bool, the running time is now 133ms, 4ms faster than unsigned char.
But with overall AR1688 software, _Bool still results in a little larger code size than unsigned char.
However Philipp suggested to keep _Bool and I am going to follow his expert advice.
Starting from current 0.49.026 version, --std-c99 option is added in all makefiles to support C99 bool, and BOOLEAN is defined as _Bool in type.h.
Because there is so little users testing current 0.49 with SDCC 3.0.0, we decided to delay 0.50 software release until it is fully tested.
Instead, I added a separate 0.49 web page for easy access of testing software.
Updated on July 19, 2012
Now VirtualBox can read .iso file directly, no more DVD simulation needed.
No comments for this page yet.