Skip to content

Add and use readLE/writeLE helpers#8470

Open
sertonix wants to merge 1 commit intoWebAssembly:mainfrom
sertonix:be
Open

Add and use readLE/writeLE helpers#8470
sertonix wants to merge 1 commit intoWebAssembly:mainfrom
sertonix:be

Conversation

@sertonix
Copy link

According to godbolt.org these functions optimize to a simple *(T *)ptr in many cases while ensuring that memory alignment requirements and endianess does not effect the behavior.

The unroll pragma seems to unfortunately be needed for gcc and clang to correctly optimize uint32_t and larger types.

The approach of using bit shifts is also used in multiple other parts of binaryen (eg. WasmBinaryReader::getInt16) but usage of the helper function doesn't seem to be that easy there.

Unfortunately std::array and uint8_t required some special casing in the templates :(

Ref #2983

According to godbolt.org these functions optimize to a simple *(T *)ptr
in many cases while ensuring that memory alignment requirements and
endianess does not effect the behavior.

The unroll pragma seems to unfortunately be needed for gcc and clang to
correctly optimize uint32_t and larger types.

The approach of using bit shifts is also used in multiple other parts
of binaryen (eg. WasmBinaryReader::getInt16) but usage of the helper
function doesn't seem to be that easy there.

Unfortunately std::array and uint8_t required some special casing in
the templates :(

Ref WebAssembly#2983
@sertonix sertonix marked this pull request as ready for review March 15, 2026 01:35
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.

1 participant