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 Native type for loops that have large interations to save code size #813

Open
Makuna opened this issue Jul 13, 2024 · 3 comments
Open
Assignees
Labels
investigating Currently under investigation for more understanding of the problem.

Comments

@Makuna
Copy link
Owner

Makuna commented Jul 13, 2024

Is your feature request related to a problem? Please describe.
WLED developers have found that using a native size type to the uC (ESP32 would be 32 bit) on loops can reduce code size.

Describe the solution you'd like
Define a NeoPixelBus wide type like uintLoop_t and intLoop_t (alternate of uintNative_t or others?) that then get used throughout NeoPixelBus. They get defined based on the microcontrollers platforms size. (using int and unsigned int?)

Additional context
This seems to be a bigger issue (using smaller size than the native uC size) for larger chips as they then need to inject code on every increment or test to convert a native register to the size the code defined.

@Makuna Makuna added the investigating Currently under investigation for more understanding of the problem. label Jul 13, 2024
@Makuna Makuna self-assigned this Jul 13, 2024
@blazoncek
Copy link

blazoncek commented Jul 13, 2024

Perhaps just size_t would do when you only need positive numbers.

EDIT: the issue (but that is generic) is that it is only guaranteed to have 16 bits at least. IMO if you do not need maximum range (i.e. INTxx_MAX) in your loops then it may be best to use native size which is (more often than not) int or unsigned.

@blazoncek
Copy link

@softhack007
Copy link
Contributor

You could use the "fast" types like uint_fast16_t or int_fast32_t (see list in the link posted by @blazoncek).

Some people consider these make code look "nerdy" however it's the most portable solution. Like uint_fast8_t is "the fastest (native) unsigned that can hold at least 8 bits".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigating Currently under investigation for more understanding of the problem.
Projects
None yet
Development

No branches or pull requests

3 participants