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

@sertonix sertonix commented Mar 15, 2026

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 is needed for GCC to properly optimize the code.

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.

Ref #2983

@sertonix sertonix marked this pull request as ready for review March 15, 2026 01:35
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 is needed for GCC to properly optimize the code.

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.

Ref WebAssembly#2983
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