Recent

Author Topic: Div operation for AVR target includes exception related code  (Read 3823 times)

ccrause

  • Hero Member
  • *****
  • Posts: 845
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: [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

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Div operation for AVR target includes exception related code
« Reply #1 on: July 02, 2017, 08:33:58 am »
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.
Specialize a type, not a var.

ccrause

  • Hero Member
  • *****
  • Posts: 845
Re: Div operation for AVR target includes exception related code
« Reply #2 on: July 03, 2017, 11:24:45 am »
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

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Div operation for AVR target includes exception related code
« Reply #3 on: July 03, 2017, 12:12:35 pm »
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.
Specialize a type, not a var.

ccrause

  • Hero Member
  • *****
  • Posts: 845

 

TinyPortal © 2005-2018