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

Use function for KEYCODE2 routines instead of macro. #8101

Merged
merged 3 commits into from
Feb 7, 2020

Conversation

kitlaan
Copy link
Contributor

@kitlaan kitlaan commented Feb 5, 2020

Description

Convert the KEYCODE2SYSTEM and KEYCODE2CONSUMER macros to functions,
defaulting to using the macros. The function form allows the compiler
to optimize the switch statement itself, over the macro nested
ternaries.

To enable this feature, #define USE_KEYCODE2_FUNCTION.

Testing against a random selection of avr-based keyboards, this
increased available flash by ~500 bytes. For arm-based keyboards,
the available flash increased by ~400 bytes.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Convert the KEYCODE2SYSTEM and KEYCODE2CONSUMER macros to functions,
defaulting to using the macros.  The function form allows the compiler
to optimize the switch statement itself, over the macro nested
ternaries.

To enable this feature, #define USE_KEYCODE2_FUNCTION.

Testing against a random selection of avr-based keyboards, this
increased available flash by ~500 bytes. For arm-based keyboards,
the available flash increased by ~400 bytes.
@zvecr zvecr requested a review from a team February 6, 2020 01:00
Copy link
Member

@zvecr zvecr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could be bold here, and just remove the USE_KEYCODE2_FUNCTION logic and make it just always be a function. What do the @qmk/collaborators think?

@fauxpark
Copy link
Member

fauxpark commented Feb 6, 2020

Wow, nice!

jj4x4 (vusb)
	before: 19086
	after:  18576 (-510)

gh60/satan (lufa)
	before: 18568
	after:  18142 (-426)

planck/rev6 (chibios)
	before: 55168
	after:  54784 (-384)

I agree with @zvecr, we should just turn it into a function instead.

As zvecr states, go bold and just commit to using the function instead
of the macro.
@kitlaan kitlaan changed the title Option to use function for KEYCODE2 routines instead of macro. Use function for KEYCODE2 routines instead of macro. Feb 6, 2020
Copy link
Member

@noroadsleft noroadsleft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@noroadsleft noroadsleft requested a review from a team February 6, 2020 08:25
Copy link
Member

@zvecr zvecr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format changes the structure of the new functions, we may need the clang-format on/off comments or accept the post formatting structure

/* keycode to consumer usage */
static inline uint16_t KEYCODE2CONSUMER(uint8_t key) {
    switch (key) {
        case KC_AUDIO_MUTE:
            return AUDIO_MUTE;
        case KC_AUDIO_VOL_UP:
            return AUDIO_VOL_UP;
        case KC_AUDIO_VOL_DOWN:
            return AUDIO_VOL_DOWN;
        case KC_MEDIA_NEXT_TRACK:
            return TRANSPORT_NEXT_TRACK;
        case KC_MEDIA_PREV_TRACK:
...
        case KC_WWW_FAVORITES:
            return AC_BOOKMARKS;
        default:
            return 0;
    }
}

@fauxpark
Copy link
Member

fauxpark commented Feb 6, 2020

I prefer to let clang-format do its thing.

Verified against clang-format output.
@fauxpark
Copy link
Member

fauxpark commented Feb 7, 2020

Thanks!

@fauxpark fauxpark merged commit d84eb14 into qmk:master Feb 7, 2020
Shinichi-Ohki added a commit to Shinichi-Ohki/qmk_firmware that referenced this pull request Feb 7, 2020
* 'master' of https://github.com/qmk/qmk_firmware:
  [Keyboard] adding keyboard: tkl30 (qmk#7979)
  Move Grave Escape, Lock and Leader keycodes into their own sect… (qmk#8093)
  Committing fix to info.json for wsk/jerkin (qmk#8110)
  Use function for KEYCODE2 routines instead of macro. (qmk#8101)
  [keyboard] adding keyboard: jerkin (qmk#7975)
  Ergosaurus Configurator support bugfix (qmk#8104)
  Xelus Dawn60: layout macro update and Configurator layout support (qmk#8102)
  VIA Support: 1upkeyboards 1up60rgb (qmk#8097)
  [Keymap] User keymap for AKB/Raine (qmk#8081)
  VIA Support: KBD67 mkii v1/v2 (qmk#8085)
  fixup keymap for 65_ansi_blocker (qmk#8099)
  [Keyboard] manta60 (qmk#8068)
  [Keyboard] add Infinity CE (qmk#8067)
  [Keyboard] Added Atreus Pro Micro variant (qmk#8059)
  Add Uni660 Keyboard (qmk#8018)
@kitlaan kitlaan deleted the flashsize_keycode2_macro branch February 9, 2020 01:12
drashna pushed a commit to zsa/qmk_firmware that referenced this pull request Feb 12, 2020
* Option to use function for KEYCODE2 routines.

Convert the KEYCODE2SYSTEM and KEYCODE2CONSUMER macros to functions,
defaulting to using the macros.  The function form allows the compiler
to optimize the switch statement itself, over the macro nested
ternaries.

To enable this feature, #define USE_KEYCODE2_FUNCTION.

Testing against a random selection of avr-based keyboards, this
increased available flash by ~500 bytes. For arm-based keyboards,
the available flash increased by ~400 bytes.

* Replace macro with function entirely.

As zvecr states, go bold and just commit to using the function instead
of the macro.

* Reformat whitespace now that functional review is done

Verified against clang-format output.
fdidron pushed a commit to zsa/qmk_firmware that referenced this pull request Feb 14, 2020
* Option to use function for KEYCODE2 routines.

Convert the KEYCODE2SYSTEM and KEYCODE2CONSUMER macros to functions,
defaulting to using the macros.  The function form allows the compiler
to optimize the switch statement itself, over the macro nested
ternaries.

To enable this feature, #define USE_KEYCODE2_FUNCTION.

Testing against a random selection of avr-based keyboards, this
increased available flash by ~500 bytes. For arm-based keyboards,
the available flash increased by ~400 bytes.

* Replace macro with function entirely.

As zvecr states, go bold and just commit to using the function instead
of the macro.

* Reformat whitespace now that functional review is done

Verified against clang-format output.
HokieGeek pushed a commit to HokieGeek/qmk_firmware that referenced this pull request Feb 21, 2020
* Option to use function for KEYCODE2 routines.

Convert the KEYCODE2SYSTEM and KEYCODE2CONSUMER macros to functions,
defaulting to using the macros.  The function form allows the compiler
to optimize the switch statement itself, over the macro nested
ternaries.

To enable this feature, #define USE_KEYCODE2_FUNCTION.

Testing against a random selection of avr-based keyboards, this
increased available flash by ~500 bytes. For arm-based keyboards,
the available flash increased by ~400 bytes.

* Replace macro with function entirely.

As zvecr states, go bold and just commit to using the function instead
of the macro.

* Reformat whitespace now that functional review is done

Verified against clang-format output.
fdidron pushed a commit to zsa/qmk_firmware that referenced this pull request Feb 26, 2020
* Option to use function for KEYCODE2 routines.

Convert the KEYCODE2SYSTEM and KEYCODE2CONSUMER macros to functions,
defaulting to using the macros.  The function form allows the compiler
to optimize the switch statement itself, over the macro nested
ternaries.

To enable this feature, #define USE_KEYCODE2_FUNCTION.

Testing against a random selection of avr-based keyboards, this
increased available flash by ~500 bytes. For arm-based keyboards,
the available flash increased by ~400 bytes.

* Replace macro with function entirely.

As zvecr states, go bold and just commit to using the function instead
of the macro.

* Reformat whitespace now that functional review is done

Verified against clang-format output.
c0psrul3 pushed a commit to c0psrul3/qmk_firmware that referenced this pull request Mar 23, 2020
* Option to use function for KEYCODE2 routines.

Convert the KEYCODE2SYSTEM and KEYCODE2CONSUMER macros to functions,
defaulting to using the macros.  The function form allows the compiler
to optimize the switch statement itself, over the macro nested
ternaries.

To enable this feature, #define USE_KEYCODE2_FUNCTION.

Testing against a random selection of avr-based keyboards, this
increased available flash by ~500 bytes. For arm-based keyboards,
the available flash increased by ~400 bytes.

* Replace macro with function entirely.

As zvecr states, go bold and just commit to using the function instead
of the macro.

* Reformat whitespace now that functional review is done

Verified against clang-format output.
kylekuj pushed a commit to kylekuj/qmk_firmware that referenced this pull request Apr 21, 2020
* Option to use function for KEYCODE2 routines.

Convert the KEYCODE2SYSTEM and KEYCODE2CONSUMER macros to functions,
defaulting to using the macros.  The function form allows the compiler
to optimize the switch statement itself, over the macro nested
ternaries.

To enable this feature, #define USE_KEYCODE2_FUNCTION.

Testing against a random selection of avr-based keyboards, this
increased available flash by ~500 bytes. For arm-based keyboards,
the available flash increased by ~400 bytes.

* Replace macro with function entirely.

As zvecr states, go bold and just commit to using the function instead
of the macro.

* Reformat whitespace now that functional review is done

Verified against clang-format output.
BorisTestov pushed a commit to BorisTestov/qmk_firmware that referenced this pull request May 23, 2024
* Option to use function for KEYCODE2 routines.

Convert the KEYCODE2SYSTEM and KEYCODE2CONSUMER macros to functions,
defaulting to using the macros.  The function form allows the compiler
to optimize the switch statement itself, over the macro nested
ternaries.

To enable this feature, #define USE_KEYCODE2_FUNCTION.

Testing against a random selection of avr-based keyboards, this
increased available flash by ~500 bytes. For arm-based keyboards,
the available flash increased by ~400 bytes.

* Replace macro with function entirely.

As zvecr states, go bold and just commit to using the function instead
of the macro.

* Reformat whitespace now that functional review is done

Verified against clang-format output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants