-
-
Notifications
You must be signed in to change notification settings - Fork 39.8k
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
Reduce PROGMEM usage for sendstring LUT #8109
Conversation
Bit-pack the keycode bool array to gain back a small amount of flash space. The trade-off is an increase in runtime instructions when running macros. It does make the code a bit harder to read, as well as maintain. For configs that use send_string() et al, it saves ~100 bytes.
Could we perhaps leverage something like the following, to simplify the conversion? #define LUT_BYTE(a, b, c, d, e, f, g, h) \
( ((a) ? 1 : 0) << 7 \
| ((b) ? 1 : 0) << 6 \
| ((c) ? 1 : 0) << 5 \
| ((d) ? 1 : 0) << 4 \
| ((e) ? 1 : 0) << 3 \
| ((f) ? 1 : 0) << 2 \
| ((g) ? 1 : 0) << 1 \
| ((h) ? 1 : 0) << 0 ) We'd then be able to do this, which is a lot closer to what we had before: const uint8_t ascii_to_shift_lut[16] PROGMEM = {
LUT_BYTE(0, 0, 0, 0, 0, 0, 0, 0),
LUT_BYTE(0, 0, 0, 0, 0, 0, 0, 0),
LUT_BYTE(0, 0, 0, 0, 0, 0, 0, 0),
LUT_BYTE(0, 0, 0, 0, 0, 0, 0, 0),
LUT_BYTE(0, 0, 0, 0, 0, 1, 0, 0),
LUT_BYTE(0, 0, 1, 1, 0, 0, 1, 1),
LUT_BYTE(1, 1, 1, 1, 1, 1, 1, 1),
LUT_BYTE(1, 1, 0, 0, 0, 0, 1, 1),
LUT_BYTE(0, 1, 1, 1, 1, 1, 1, 1),
LUT_BYTE(1, 1, 1, 1, 1, 1, 1, 1),
LUT_BYTE(1, 1, 1, 1, 1, 1, 1, 1),
LUT_BYTE(1, 1, 1, 0, 0, 0, 0, 1),
LUT_BYTE(0, 0, 0, 0, 0, 0, 0, 0),
LUT_BYTE(0, 0, 0, 0, 0, 0, 0, 0),
LUT_BYTE(0, 0, 0, 0, 0, 0, 0, 0),
LUT_BYTE(0, 0, 0, 0, 0, 0, 0, 0)
}; |
I had considered it but didn't really think it through. Actually seeing it typed out, I should have tried it! I'll update the branch and see if I can clean it up even further. |
Did some changes, and things are looking promising. Much cleaner and "easier" to maintain. I'll finish it up shortly and push, and see if folks like it better. Now that I have my board running properly, I can finally test and see if there are any real performance differences. Even if there aren't, keeping both flows "for a while" still seems wise. Reminder: resync master and make the same edits to the new sendstring LUTs. |
Rewrite the array declarations so both the unpacked (original) and packed LUT arrays can use the same value definitions. This is done by defining a macro that "knows what to do". This makes the code much easier to read and maintain.
A question I was pondering is if there are any folks that have their own LUT definitions. If there are, then changing to packed-always would hopefully compile error (type redefinition?) if we kept the old variable name. Or they'd silently go back to the default LUT without warning if we changed variable names. Is that reasonable to do? Or is it a breaking change? Or an I just being over-cautious? |
Pack the bits in a more efficient order for extraction. And also fix the copy/paste error in the macro...
Discussed with the others, the general feeling is that we'll go with the bitmasks and drop the full-size arrays. Makes no sense to have it configurable. If we can get the other languages sorted as well, I think we'll be much closer to merge! |
Some minor reformatting. Compile tested all sendstring_xyz.h to make sure they were converted properly. Also checked that an unconverted version would generate a compile error.
All updated, and gave all the headers a quick compile-smoketest. I believe there' still the Hungarian pull request pending, so once that's merged, I'll update my branch. And hopefully that's it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really unsure if this is even worth it given the annoyance...
I did NOT test this, other than compiling a few random user keyboard configs to see for size differences. For example, kyria:drashna moved from a failed build to just back under the line.
lol. Yeah, My keymaps tend to run very close to the line, and depending on which compiler version you're using, may actually go over it. :D
For the most part, as long as the default keymap compiles, and nothing is broken, that's fine. And in the case of my keymaps, as long as it compiles, even if it's over, that's fine.
And in this case, testing locally, looks good! No issues from what I am seeing (namely, my make and version commands)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A spot of prettifying
Co-Authored-By: Ryan <[email protected]>
Hungarian can get sorted out later. Merging. |
* 'master' of https://github.com/qmk/qmk_firmware: (37 commits) Update Hungarian keymap and add sendstring LUT (qmk#8220) Remove "ugly hack in usb_main.c" comments (qmk#8296) Update encoder functions for Iris VIA keymap (qmk#8295) Reduce PROGMEM usage for sendstring LUT (qmk#8109) [Docs] Update ISP Flashing guide (qmk#8149) Rewrite the Bathroom Epiphanies Frosty Flake matrix and LED handling (qmk#8243) Add onekey keymap for testing reset to bootloader. (qmk#8288) Get the direction right on the S75 encoder (qmk#8287) Prune out pure software pwm && custom driver && remove wrapping BACKLIGHT_PIN (qmk#8041) Make a fix to savage65 and tmov2 for via (qmk#8286) format code according to conventions [skip ci] Short term fix for conflicting types for 'tfp_printf' (qmk#8157) Fix recent clang-format breaking quantum.c (qmk#8282) format code according to conventions [skip ci] Remove duplicate BRTG case (qmk#8277) Clean up includes for glcdfont headers (qmk#7745) Fix the Breaking Changes doc again [Docs] translated 'feature_tap_dance.md' to japanese. (qmk#8137) PWM DMA based RGB Underglow for STM32 (qmk#7928) Add VIA support to Prime_M. Clean up all files (qmk#8247) ...
* Reduce PROGMEM usage for keycode map Bit-pack the keycode bool array to gain back a small amount of flash space. The trade-off is an increase in runtime instructions when running macros. It does make the code a bit harder to read, as well as maintain. For configs that use send_string() et al, it saves ~100 bytes. * Switch to macro and common definition Rewrite the array declarations so both the unpacked (original) and packed LUT arrays can use the same value definitions. This is done by defining a macro that "knows what to do". This makes the code much easier to read and maintain. * Fix macro typos and improve perf Pack the bits in a more efficient order for extraction. And also fix the copy/paste error in the macro... * Switch fully to packed LUT Some minor reformatting. Compile tested all sendstring_xyz.h to make sure they were converted properly. Also checked that an unconverted version would generate a compile error. * Apply whitespace suggestions from code review Co-Authored-By: Ryan <[email protected]> Co-authored-by: Ryan <[email protected]>
* upstream/master: (37 commits) Add RGB lighting through one of the free pins (qmk#8294) [Keymap] Adding the 4sStylZ xd75 (qmk#8285) YD60MQ refactor and Configurator layout support (qmk#8313) [Keyboard] Forget to ifdef Super16 led config (qmk#8314) [Keyboard] Switch to RGB Matrix for Super16 (qmk#8305) [Keymap] Keymap Update (qmk#8309) New Keyboard: SiddersKB Majbritt (Pronounced My Brit) (qmk#8260) [Keyboard] VIA Support: Tada68 (qmk#8289) [Keyboard] LFK78 refactor (qmk#7835) [Keymap] new userspace for ibnuda (qmk#8221) [Keymap] Add crd's equinox keymap (qmk#8251) [Keymap] Feature/alfrdmalr/keymap update (qmk#8174) Fix bootloader definition for namecard2x4 (qmk#8301) Update Hungarian keymap and add sendstring LUT (qmk#8220) Remove "ugly hack in usb_main.c" comments (qmk#8296) Update encoder functions for Iris VIA keymap (qmk#8295) Reduce PROGMEM usage for sendstring LUT (qmk#8109) [Docs] Update ISP Flashing guide (qmk#8149) Rewrite the Bathroom Epiphanies Frosty Flake matrix and LED handling (qmk#8243) Add onekey keymap for testing reset to bootloader. (qmk#8288) ...
* Reduce PROGMEM usage for keycode map Bit-pack the keycode bool array to gain back a small amount of flash space. The trade-off is an increase in runtime instructions when running macros. It does make the code a bit harder to read, as well as maintain. For configs that use send_string() et al, it saves ~100 bytes. * Switch to macro and common definition Rewrite the array declarations so both the unpacked (original) and packed LUT arrays can use the same value definitions. This is done by defining a macro that "knows what to do". This makes the code much easier to read and maintain. * Fix macro typos and improve perf Pack the bits in a more efficient order for extraction. And also fix the copy/paste error in the macro... * Switch fully to packed LUT Some minor reformatting. Compile tested all sendstring_xyz.h to make sure they were converted properly. Also checked that an unconverted version would generate a compile error. * Apply whitespace suggestions from code review Co-Authored-By: Ryan <[email protected]> Co-authored-by: Ryan <[email protected]>
* Reduce PROGMEM usage for keycode map Bit-pack the keycode bool array to gain back a small amount of flash space. The trade-off is an increase in runtime instructions when running macros. It does make the code a bit harder to read, as well as maintain. For configs that use send_string() et al, it saves ~100 bytes. * Switch to macro and common definition Rewrite the array declarations so both the unpacked (original) and packed LUT arrays can use the same value definitions. This is done by defining a macro that "knows what to do". This makes the code much easier to read and maintain. * Fix macro typos and improve perf Pack the bits in a more efficient order for extraction. And also fix the copy/paste error in the macro... * Switch fully to packed LUT Some minor reformatting. Compile tested all sendstring_xyz.h to make sure they were converted properly. Also checked that an unconverted version would generate a compile error. * Apply whitespace suggestions from code review Co-Authored-By: Ryan <[email protected]> Co-authored-by: Ryan <[email protected]>
* Reduce PROGMEM usage for keycode map Bit-pack the keycode bool array to gain back a small amount of flash space. The trade-off is an increase in runtime instructions when running macros. It does make the code a bit harder to read, as well as maintain. For configs that use send_string() et al, it saves ~100 bytes. * Switch to macro and common definition Rewrite the array declarations so both the unpacked (original) and packed LUT arrays can use the same value definitions. This is done by defining a macro that "knows what to do". This makes the code much easier to read and maintain. * Fix macro typos and improve perf Pack the bits in a more efficient order for extraction. And also fix the copy/paste error in the macro... * Switch fully to packed LUT Some minor reformatting. Compile tested all sendstring_xyz.h to make sure they were converted properly. Also checked that an unconverted version would generate a compile error. * Apply whitespace suggestions from code review Co-Authored-By: Ryan <[email protected]> Co-authored-by: Ryan <[email protected]>
* Reduce PROGMEM usage for keycode map Bit-pack the keycode bool array to gain back a small amount of flash space. The trade-off is an increase in runtime instructions when running macros. It does make the code a bit harder to read, as well as maintain. For configs that use send_string() et al, it saves ~100 bytes. * Switch to macro and common definition Rewrite the array declarations so both the unpacked (original) and packed LUT arrays can use the same value definitions. This is done by defining a macro that "knows what to do". This makes the code much easier to read and maintain. * Fix macro typos and improve perf Pack the bits in a more efficient order for extraction. And also fix the copy/paste error in the macro... * Switch fully to packed LUT Some minor reformatting. Compile tested all sendstring_xyz.h to make sure they were converted properly. Also checked that an unconverted version would generate a compile error. * Apply whitespace suggestions from code review Co-Authored-By: Ryan <[email protected]> Co-authored-by: Ryan <[email protected]>
* Reduce PROGMEM usage for keycode map Bit-pack the keycode bool array to gain back a small amount of flash space. The trade-off is an increase in runtime instructions when running macros. It does make the code a bit harder to read, as well as maintain. For configs that use send_string() et al, it saves ~100 bytes. * Switch to macro and common definition Rewrite the array declarations so both the unpacked (original) and packed LUT arrays can use the same value definitions. This is done by defining a macro that "knows what to do". This makes the code much easier to read and maintain. * Fix macro typos and improve perf Pack the bits in a more efficient order for extraction. And also fix the copy/paste error in the macro... * Switch fully to packed LUT Some minor reformatting. Compile tested all sendstring_xyz.h to make sure they were converted properly. Also checked that an unconverted version would generate a compile error. * Apply whitespace suggestions from code review Co-Authored-By: Ryan <[email protected]> Co-authored-by: Ryan <[email protected]>
* Reduce PROGMEM usage for keycode map Bit-pack the keycode bool array to gain back a small amount of flash space. The trade-off is an increase in runtime instructions when running macros. It does make the code a bit harder to read, as well as maintain. For configs that use send_string() et al, it saves ~100 bytes. * Switch to macro and common definition Rewrite the array declarations so both the unpacked (original) and packed LUT arrays can use the same value definitions. This is done by defining a macro that "knows what to do". This makes the code much easier to read and maintain. * Fix macro typos and improve perf Pack the bits in a more efficient order for extraction. And also fix the copy/paste error in the macro... * Switch fully to packed LUT Some minor reformatting. Compile tested all sendstring_xyz.h to make sure they were converted properly. Also checked that an unconverted version would generate a compile error. * Apply whitespace suggestions from code review Co-Authored-By: Ryan <[email protected]> Co-authored-by: Ryan <[email protected]>
* Reduce PROGMEM usage for keycode map Bit-pack the keycode bool array to gain back a small amount of flash space. The trade-off is an increase in runtime instructions when running macros. It does make the code a bit harder to read, as well as maintain. For configs that use send_string() et al, it saves ~100 bytes. * Switch to macro and common definition Rewrite the array declarations so both the unpacked (original) and packed LUT arrays can use the same value definitions. This is done by defining a macro that "knows what to do". This makes the code much easier to read and maintain. * Fix macro typos and improve perf Pack the bits in a more efficient order for extraction. And also fix the copy/paste error in the macro... * Switch fully to packed LUT Some minor reformatting. Compile tested all sendstring_xyz.h to make sure they were converted properly. Also checked that an unconverted version would generate a compile error. * Apply whitespace suggestions from code review Co-Authored-By: Ryan <[email protected]> Co-authored-by: Ryan <[email protected]>
Description
Bit-pack the keycode bool array to gain back a small amount of flash space.
The trade-off is an increase in runtime instructions when running macros.
It does make the code a bit harder to read, as well as maintain.
For configs that use send_string() et al, it saves ~100 bytes.
I'm really unsure if this is even worth it given the annoyance...compiling a few random user keyboard configs to see for size differences. For example, kyria:drashna moved from a failed build to just back under the line.I did NOT test this, other than
Also note: When I run clang-format on quantum.c, it decides to do some weird reformatting. So I didn't run it here.
Types of Changes
Checklist