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

source2il: implement alignment support #112

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Jan 26, 2025

Summary

Implement internal support for locations with an alignment requirement
greater than 1 byte. This is a preparation for the source language
gaining type alignment requirements.

Details

The alignment for numeric types (int and float) is equal to their size,
while for aggregate types (other than seq) it's that of their most
aligned constituent type.

The size of aggregate types is padded to be a multiple of their
alignment. This is so that their size matches the space they would take
up within an array, while still allowing copying size bytes from a
pointer to a location of said type to be valid, regardless of where the
location is located. Record fields are placed such that their relative
offset is a multiple of their alignment requirement.

The allocator procedures alloc and realloc take an additional
parameter specifying the allocation's required alignment. grow and
preparedAdd also take an additional parameter, which specifies the
alignment of the dynamic array's element type. The callsites of all
four procedures are updated accordingly.

Finally, the value rendering in vmexec is updated to take the new
object layout into account.


Notes For Reviewers

  • memory access of numeric types being well-aligned also eases implementation of the asm.js translation pass, as asm.js doesn't have native support for misaligned memory access

The `size` procedure also returns a `SizeUnit` (currently an alias of
`int`) now, making it clear what domain the result value is part of.
Aggregate types now respect the alignment requirement of their
constituent types. The IL type of aggregate types also uses the correct
alignment now, instead of always being 8.
* make the allocator alignment aware (`alloc` and `realloc` take an
  additional alignment parameter)
* update all calls to `alloc` and `realloc`
* update the payload size computation to take alignment into account
@zerbina zerbina added the enhancement New feature or request label Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant