Open Bug 1641570 Opened 4 years ago Updated 3 years ago

Align wasm v128 data and use aligned access instructions

Categories

(Core :: JavaScript: WebAssembly, enhancement, P5)

x86_64
All
enhancement

Tracking

()

People

(Reporter: lth, Unassigned)

References

(Blocks 2 open bugs)

Details

Attachments

(1 file)

On x86 and x64 we got away without aligning wasm v128 locals, parameters, locals, and spill slots for the first landing because the architecture has unaligned-access instructions. But the guidance in the Intel optimization manual is unequivocally that one should align data when possible and use the aligned-access instructions. Furthermore, aligned-access instructions will open up the possibility for using memory operands to SIMD instructions, thus saving registers. It may also be that aligning these data will simplify arm64/arm/mips work in the future.

Constants that are emitted as part of the instruction stream are already aligned.

There's an ifdef in CodeGenerator.cpp that checks for alignment, currently it's disabled but it should be re-enabled.

As part of landing SIMD, all(?) the accesses were rewritten in terms of loadUnalignedSimd128 and storeUnalignedSimd128 porting interfaces. It may be a good start to search for instances of these instructions.

Blocks: 1641589
Attached file simd-access.tar

A quick experiment. This adds a patch so that if the env var SIMD_ALIGN is defined then aligned-access instructions are used for heap loads and stores always. Then there's a simple wasm program that loads and stores SIMD data from the heap. There's no meaningful performance difference on my Xeon between aligned and unaligned instructions. This is only a proxy for the effect we would get from aligning locals and parameters, but it shows that performance is not disastrously bad from using unaligned accesses everywhere.

(Aligning locals and parameters would still allow us to use memory operands with SIMD ops, which would in itself be a win - reduced register pressure, fewer instructions.)

See Also: → 1747787
Priority: P3 → P5
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: