Skip to content

Conversation

@jgonet
Copy link
Contributor

@jgonet jgonet commented Dec 17, 2025

On wasm32, terms are aligned by 4 bytes. memory_heap_allocation returns a pointer for n terms. We used float_term_t to create an union between a term and float. However, floats are aligned to 8 bytes which made casting between union and term pointers unsafe.

We replaced union usage to memcpy which allows unaligned memory access. The true solution would be to return correctly aligned memory from memory_heap_alloc but fix for that would need a lot more testing.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

@jgonet jgonet force-pushed the jgonet/fix-floats-upstream branch from d288f4c to 086c903 Compare January 13, 2026 11:04
@jgonet
Copy link
Contributor Author

jgonet commented Jan 13, 2026

Back from holiday break! I added section for Xtensa and updated comment.

On wasm32, terms are aligned by 4 bytes. `memory_heap_allocation` returns a pointer for `n` terms.
We used float_term_t to create an union between a term and float. However, floats are aligned to 8 bytes which made
casting between union and term pointers unsafe.

We replaced union usage to `memcpy` which allows unaligned memory access. The true solution would be to return
correctly aligned memory from memory_heap_alloc but fix for that would need a lot more testing.

Signed-off-by: Jakub Gonet <[email protected]>
@jgonet jgonet force-pushed the jgonet/fix-floats-upstream branch from 086c903 to da5a126 Compare January 13, 2026 11:13
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.

2 participants