RoyalIcing / Orb

Write WebAssembly with Elixir
https://useorb.dev
BSD 3-Clause "New" or "Revised" License
174 stars 1 forks source link

Allow specifying alignment to loads and stores #5

Open RoyalIcing opened 11 months ago

RoyalIcing commented 11 months ago

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))
RoyalIcing commented 5 months ago

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 commented 3 months ago

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.