Skip to content

fix: AVR 16-bit int breaks large left-shifts in some implementations of fixed_point types - #2176

Closed
sutaburosu wants to merge 1 commit into
FastLED:masterfrom
sutaburosu:AVR_fixed_point_fixes
Closed

sutaburosu wants to merge 1 commit into
FastLED:masterfrom
sutaburosu:AVR_fixed_point_fixes

Conversation

@sutaburosu

Copy link
Copy Markdown
Contributor

I'm hoping this fixes #2174. I think an extensive test suite would improve my confidence.

@sutaburosu

sutaburosu commented Feb 13, 2026 •

Copy link
Copy Markdown
Contributor Author

It just occurred to me that it might be preferable to also apply this pattern to the other fixed_point implementations, i.e. those which currently work correctly on AVR without needing this change.

For the sake of clarity, I'm considering converting all variants of (1 << FRAC_BITS) to using a constexpr of an appropriate fl::i16/32/64 type, named SCALE.

It should be noted that there are places where an unsigned type is static_cast to a signed fl::i16/32. I propose changing those to be signed too. e.g. this

Thoughts?

@zackees

zackees commented Feb 13, 2026 •

Copy link
Copy Markdown
Member

Thanks for this, yeah address sanitizer caught it too and had some similar fixes. You said you didn't the run tests?

So I'm going to take these fixes and feed them into the AI so it can generation additional unit tests so that I can ensure this corner case is under validation.

FYI

git clone https://github.com/fastled/fastled
cd fastled
bash test  # all dependencies automatically installed

@sutaburosu

Copy link
Copy Markdown
Contributor Author

Ah, so there is a test suite I can easily run locally. Thanks for the pointer.

Any thoughts on applying the same pattern to the other implementations? I only changed the 3 that are buggy on AVR, but I'm happy to do the same for the others if only so they more closely resemble one another.

@zackees

zackees commented Feb 13, 2026

Copy link
Copy Markdown
Member

Yeah, I think this issue affects the other types.

See this test path tests/fl/fixed_point/

Today i'm going do a pass where I test all the fixed point types through the common test class using the template. I think there's some operators missing that aren't being caught in the fixed point specific non template classes.

@sutaburosu

Copy link
Copy Markdown
Contributor Author

OK. I'm super tired. I'll extend the fix to the other types after some sleep.

@zackees

zackees commented Feb 13, 2026 •

Copy link
Copy Markdown
Member

It will be fixed when you wake up. I'm going to make a template test and just fix it for everything and make sure all optimizations are optimized. I'm wondering if some of the divides can be eliminated. I'll see.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problems with fixed_point on AVR

2 participants