Forum > FPC development
Div operation for AVR target includes exception related code
(1/1)
ccrause:
When including a div operation in a calculation the generated code size increases dramatically (in terms of memory generally available on an embedded target). It appears that the compiler uses generic software math routines from the rtl/inc folder (generic.inc and int64.inc). These routines includes an error check (HandleErrorAddrFrameInd) which pulls in a bunch of code (get_caller_frame, pushexceptionobject, dounhandledexception, raiseexception etc.).
I've adapted (formerly) Atmel's application note AVR200 div routines to fpc to get a comparison between fpc's build-in code and an alternative approach without exception handling (see attached demo program). I've compiled the example with
--- Code: ---ppcrossavr -Tembedded -Wpatmega328p -Cpavr5 -Pavr -O3 -g -a -al -XPavr-
--- End code ---
Compiling attached example with build-in div :
67 lines compiled, 0.1 sec, 2630 bytes code, 310 bytes data
Compiling attached example with custom div function:
67 lines compiled, 0.1 sec, 290 bytes code, 0 bytes data
1st question - is exception handling code required (by language convention) on embedded targets?
2nd question - is there a need for more compact math routines for the AVR embedded target?
Thaddy:
1. They are not part of the language, but part of the implementation. Based on the algorithmic descriptions in e.g. http://www.atmel.com/Images/doc0936.pdf they are not necessary at all.
2. In my opinion: yes, of course.
ccrause:
I've got 8, 16 and 32 bit unsigned div functions so far, how do I include them in the embedded avr target RTL? I am not familiar with writing code for the compiler or RTL.
Thaddy:
I would create a patch and submit it on the bug tracker.
If you are unable to do that, I would still create a suggestion on the bugtracker and provide the code as an attachment.
Note it would be useful for mul too as that suffers the same...
The devs will pick it up.
ccrause:
Issue reported...
Navigation
[0] Message Index