-
Notifications
You must be signed in to change notification settings - Fork 135
Fix floats on Wasm #2041
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
base: main
Are you sure you want to change the base?
Fix floats on Wasm #2041
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2396,16 +2396,18 @@ static inline term term_from_float(avm_float_t f, Heap *heap) | |
| term *boxed_value = memory_heap_alloc(heap, FLOAT_SIZE); | ||
| boxed_value[0] = ((FLOAT_SIZE - 1) << 6) | TERM_BOXED_FLOAT; | ||
|
|
||
| float_term_t *boxed_float = (float_term_t *) (boxed_value + 1); | ||
| boxed_float->f = f; | ||
|
|
||
| // For wasm32, alignof(avm_float_t) = 8 and alignof(term) = 4 | ||
| // `memory_heap_alloc` returns memory aligned to term size. | ||
| memcpy(boxed_value + 1, &f, sizeof(avm_float_t)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, but sadly there is a know ESP32 GCC bug that I opened 2 years ago: https://gcc.gnu.org/pipermail/gcc-bugs/2023-October/839353.html Can you keep also the old code and use it with such a similar macro? |
||
| return ((term) boxed_value) | TERM_PRIMARY_BOXED; | ||
| } | ||
|
|
||
| static inline avm_float_t term_to_float(term t) | ||
| { | ||
| const float_term_t *boxed_float = (float_term_t *) (term_to_const_term_ptr(t) + 1); | ||
| return boxed_float->f; | ||
| avm_float_t result; | ||
| // see `term_from_float` | ||
| memcpy(&result, term_to_const_term_ptr(t) + 1, sizeof(avm_float_t)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as the previous comment. |
||
| return result; | ||
| } | ||
|
|
||
| static inline bool term_is_number(term t) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
This comment is somehow slightly misleading, this is not just an issue for wasm32.
It should be rephrased as:
// alignof(avm_float_t) might be != alignof(term)