|Re: C compiler for HP calcs (long)|
Message #16 Posted by Al on 2 Nov 2004, 3:22 a.m.,
in response to message #15 by Raymond Del Tondo
(replying to Raymond and 'unspellable' at once)
(regarding size of C programs vs RPL)
"This because the excutable commands will be in the form of pointers that point to the routine in PROM."
Yes, using built in routines makes the final binary smaller. At present, C programs have to contain most of the library calls within the binary. There are some simple OS calls which are in the ROM that don't consume space, but these are not terribly helpful for the average program.
"It came as rather a shock to me in the begining days of my first C class to see a program intended to display "Hello World" on the screen compile into more than 10 Kbytes of executable code."
I hope you remembered to turn on optimizations. Even so, alot of that is unused bloat. The executable format has alot of slack. Considering the average cluster size on hard drives these days, there is no difference between a 1 byte and a 1kb file. They consume the same amount of hard drive space.
"Hello World" with HPGCC takes less then 1kb. 1kb is still huge for "hello world". Why is it so big?
Basically it has to run in a vacume. The binary must set up the MMU, allocate itself memory, and do many other tasks that really should be handled by an OS. I'm guessing this accounts for half of the 1kb. Also, as you mentioned, there is no runtime library to use. All functions currently have to be provided in the binary.
There are 2 ways to fix this though: Firstly, it is entirely possible to just have one copy of the runtime in memory, as a library. This should cut down code bloat considerably.
Secondly, the binaries are currently compiled as true ARM instructions. With a little tweaking they could be compiled for Thumb mode. This should reduce the size by about 30-40 percent on average.
" If you have memory to burn this is no big deal, but in a calculator you do not have memory to burn."
Considering you can have hundreds of megabytes on an SD card, I'd say there is memory to burn. Even without an SD card, you have 450kb of RAM and 600kb or flash ROM to use.
"Maybe someone should try to write a program like SpeedMiner
(available on hpcalc.org for the HP-48 and 49g)
in C...it won't have a much faster feel,
but occupy multiples of memory of the original SpeedMiner,
I'm sure a C speedminer would be perhaps 5 times the size of the asm version. I also bet it would be much quicker to write :-)
"and will be likely to consume more battery power.""
Why would it use more battery power? If anything, it would use far less. With an emulated Saturn program, the CPU runs at 75MHz - you can't control it. 75MHz is extreme overkill for a simple game.
Using a C program, you have the power to adjust the clock. You could easily underclock to 12MHz or less. This should save battery power.