Skip to content

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

Description

@softhack007

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions