-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 PROGMEM for lookup tables on AVR platforms #202
base: master
Are you sure you want to change the base?
Conversation
Hi @StarGate01 and thanks for your interest in contributing :) I feel that this change is a bit too platform-specific and conflicts a bit with the "portable"-part of the description. I see the point for sure, but I'd rather not support platform-specific code. |
Note that this was valuable for us when we did it in OTAESGCM for AVR and it may be useful in other MCUs where you can keep the constants in Flash rather than copying them to RAM. Maybe if this was reworked into something a bit more generic for that wider set of cases, which just happens to come with a first full implementation for AVR? Rgds Damon |
Hi @DamonHD - long time since our last encounter :) I hope you're well and good and that the pandemic hasn't messed up your Christmas. I assume you're thinking of some macro, like when a project defines "API_CALL" and puts it in front of the public/exported functions, to define calling-conventions etc.? I see the point and could probably be convinced to change my mind, but I can't quickly come up with something good myself. |
Hi! Covid is definitely still complicating my life generally, including Christmas, but I am still alive and well: thank you! That is indeed the sort of thing I had in mind, and no I don't know what it should look like to cover more than the AVR case. However I can say that our code builds and runs on AVR and non-AVR (eg on our laptops for unit tests), and pretty much the only kludge required is like this IIRC:
See:
With use of PROGMEM etc where needed. That may then be a clean enough cut for you now, and allow another more general scheme to be wedged in later if needed. Rgds Damon |
I'm glad to hear you're coping @DamonHD :) Denmark (where I live) has been setting infection "high-scores" almost daily for a few weeks. Hope they figure something out soon 🤞 But hey I can still work and buy groceries etc. so I shouldn't really complain... It's not a bad idea at all, but I would like to reduce the number of Assuming you understood my "explanation" of the idea/concept, would you be willing to give it a shot @StarGate01 ? |
Thank you for the suggestions! I agree that a platform-specific implementation kind of goes against the idea of being portable. However, I think we can work out a solution that we can all agree on. The implementation by @DamonHD is cool, because specialized code has to be implemented in one place only - as opposed to my initial implementation. I don't think the generic implementation of I suggest to create an additional header file (e.g. What do you think? I'll go ahead and update this PR. |
I think we should keep the macro in |
2ed7c0f
to
81c76a9
Compare
I implemented the macro in Other platforms that wish to optimize memory use could then define the I successfully ran the tests on my host machine (64bit x86), and checked the generated assembly to verify the inlining. |
Looking good @StarGate01 - thanks for contributing :)
I intend to do the same for ARM (thumb/thumb2) just FYI, but otherwise I think this looks very good now. |
This PR moves the static
sbox
,rsbox
andRcon
substitution boxes from the SRAM into the Flash memory on AVR microcontrollers, which is typically larger. This frees up half a kilobyte of RAM.The
PROGMEM
attribute is used to specify the memory location, and thepgm_read_byte
to access the Flash memory.