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

Fix pgm_read_float_unaligned macro #6593

Merged
merged 2 commits into from Oct 3, 2019

Conversation

earlephilhower
Copy link
Collaborator

Fixes #6590

The ASM block that implements the read-uint32-unaligned returns a
uint32_t. The old code was doing a cast like `(float)(uint32_t ret)
which actually goes and creates a new float of the positive uint value
(approx, of course due to exponent and sign bits) which is not correct.

C and C++ don't have a concise way to convert the bits in a register
from int to float interpretation, so avoid the whole issue by making a
new function which uses the same ASM block as the read-uint32-unaligned,
just make the destination and return values as floats.

Fixes esp8266#6590

The ASM block that implements the read-uint32-unaligned returns a
uint32_t.  The old code was doing a cast like `(float)(uint32_t ret)
which actually goes and creates a new float of the positive uint value
(approx, of course due to exponent and sign bits) which is not correct.

C and C++ don't have a concise way to convert the bits in a register
from int to float interpretation, so avoid the whole issue by making a
new function which uses the same ASM block as the read-uint32-unaligned,
just make the destination and return values as floats.
@earlephilhower
Copy link
Collaborator Author

Good catch, @maxint-rd!

@earlephilhower earlephilhower merged commit fb2cbe3 into esp8266:master Oct 3, 2019
@earlephilhower earlephilhower deleted the floatsstink branch October 3, 2019 15:21
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.

pgm_read_float alignment issue when reading from an array of floats
1 participant