Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(improvement idea) use GCC pragma for better optimization by the compiler #5

Open
softhack007 opened this issue Nov 4, 2021 · 0 comments

Comments

@softhack007
Copy link

softhack007 commented Nov 4, 2021

Hi,
thanks for creating this cool library - it is the fastest one i found so far 👍

One idea to make it even faster would be to turn on higher compiler optimisations for the core functions, see https://gcc.gnu.org/onlinedocs/gcc/Function-Specific-Option-Pragmas.html
I did some experiments, by adding the following to xtm1638.cpp

at the top of the file, just after comments and includes are done (i.e. , directly after #include "xtm1638.h")

#pragma GCC push_options
#pragma GCC optimize ("O2")
//#pragma GCC optimize ("O3")

at end of the file

#pragma GCC pop_options

Testcase:

"example04" on my MEGA2560 - default options, Port manipulation mode, cached segments enabled

  1. normal optimization without pragma:
  • program 4440 Bytes (1%), glabal data 298 Bytes (3%)
  • scores = 60003 (with LEDs), 27204 (no LEDs)
  1. more optimization (-O2):
  • program 4492 Bytes (1%), glabal data 298 bytes (3%) -> FLASH usage increase: 52 bytes
  • scores = 26143 (with LEDs), 15102 (no LEDs) -> speed gain: 2.3x / 1.8x
  1. even more optimization (-O3):
  • program 13402 Bytes (5%), glabal data 298 bytes (3%) -> FLASH usage increase: 9 Kbytes
  • scores = 24103 (with LEDs), 15280 (no LEDs) -> speed gain: 2.5x / 1.8x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant