Div operation for AVR target includes exception related code lazarus / 64-FPC development ---------------------------------------------------------------------- ccrause · 2017-07-02 06:20 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 withCode: [Select]ppcrossavr -Tembedded -Wpatmega328p -Cpavr5 -Pavr -O3 -g -a -al -XPavr- 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 · 2017-07-02 06:33 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 · 2017-07-03 09:24 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 · 2017-07-03 10:12 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 · 2017-07-03 19:47 Issue reported...