evmone icon indicating copy to clipboard operation
evmone copied to clipboard

Force aligned access for EVM stack

Open chfast opened this issue 1 year ago • 2 comments

Compilers generate vector instructions with unaligned access to access elements on the EVM stack. Inform compiler that the stack memory is 32-byte aligned.

chfast avatar Oct 10 '24 15:10 chfast

Would that mean hinting something like:

    #ifdef __MSC_VER
        StackTop* st = static_cast<StackTop*>(__builtin_assume_aligned(&state.stack, 256));
    #else
        StackTop* st = std::assume_aligned<256>(&state.stack);
    #endif
    CoreFn(*st);
    state.adjust_stack_size(instr::traits[Op].stack_height_change);

?

I'm not sure whether there's a quick way to check on goldbolt or something.

Raneet10 avatar Jan 18 '25 17:01 Raneet10

You can solely rely on standard std::assume_aligned. But I was thinking if this can be done more elegantly by annotating the type with alignas.

chfast avatar Jan 20 '25 18:01 chfast

I believe this was done in https://github.com/ipsilon/evmone/pull/1233.

chfast avatar Nov 03 '25 12:11 chfast