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

Large offset memory accesses in stackalloc #875

Open
sarranz opened this issue Aug 13, 2024 · 0 comments
Open

Large offset memory accesses in stackalloc #875

sarranz opened this issue Aug 13, 2024 · 0 comments
Assignees
Labels
arm Related to the arm port bug

Comments

@sarranz
Copy link
Collaborator

sarranz commented Aug 13, 2024

If the stack is big, Stack Allocation will introduce memory accesses with big offsets that are not valid in ARM. For instance,

// Stack allocation needs to split the array set and get operations into several
// instructions to that the immediates fit in one instruction.

// The LDR/STR instructions take an immediate of up to 12 bits.
// Since elements are 4 bytes, we the size limit for an array is 2^12 / 4.
param int LIMIT = 1024;

export
fn large_array() -> reg u32 {
    reg u32 r;
    stack u32[LIMIT + 1] a;

    r = 0;
    a[LIMIT] = r;
    r = a[LIMIT];

    return r;
}

Also, this generates invalid assembly

export
fn main(reg u32 p) -> reg u32 {
    reg u32 x;
    x = #LDR([p + 4097]);
    return x;
}

I will add a new extra_op that gets compiled to several instructions to load the offset and perform the load.

@sarranz sarranz added bug arm Related to the arm port labels Aug 13, 2024
@sarranz sarranz self-assigned this Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arm Related to the arm port bug
Projects
None yet
Development

No branches or pull requests

1 participant