Orb icon indicating copy to clipboard operation
Orb copied to clipboard

Allow specifying alignment to loads and stores

Open RoyalIcing opened this issue 2 years ago • 2 comments
trafficstars

e.g.

(i32.load align=1 (i32.const 0))
(i32.load align=4 (i32.const 0))

(i32.store align=4 (i32.const 0) (i32.const 1))
(i64.store align=8 (i32.const 0) (i64.const 1))
(f32.store align=4 (i32.const 0) (f32.const 1.0))

The default alignment when loading i32.load is 4, should we change this for I32.UnsafePointer?

I32.UnsafePointer.alignment() # 1
I32.UnsafeAlignedPointer.alignment() # 4

some_address: I32.UnsafePointer
Memory.load(I32, some_address) # (i32.load (i32.const 0))

some_address2: I32.UnsafeAlignedPointer
Memory.load(I32, some_address) # (i32.load align=4 (i32.const 0))
  • https://rsms.me/wasm-intro#addressing-memory
  • https://github.com/WebAssembly/testsuite/blob/main/align.wast

RoyalIcing avatar Aug 21 '23 07:08 RoyalIcing

Aligns could be defined when defining a SilverOrb Arena, and so you know for example that loads/store to your particular arena is 32-bit aligned.

RoyalIcing avatar Jan 29 '24 04:01 RoyalIcing

Some progress has been made on this. I just need to decide whether I32.UnsafePointer should be aligned by default or not. If it should be aligned perhaps it should be renamed to I32.UnsafeAlignedPointer to reflect this. I think it partly depends on which pointer types should be built-in.

RoyalIcing avatar Apr 08 '24 13:04 RoyalIcing