Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Add Python pseudocode to memory operations #107

Merged
merged 7 commits into from
Nov 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions proposals/simd/SIMD.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,11 @@ natural alignment.

Load a `v128` vector from the given heap address.

```python
def S.load(memarg):
return S.from_bytes(memory[memarg.offset:memarg.offset + 16])
```

### Load and Splat

* `v8x16.load_splat(memarg) -> v128`
Expand All @@ -674,6 +679,12 @@ Load a `v128` vector from the given heap address.

Load a single element and splat to all lanes of a `v128` vector.

```python
def S.load_splat(memarg):
val_bytes = memory[memarg.offset:memarg.offset + S.LaneBytes])
return S.splat(S.LaneType.from_bytes(val_bytes))
```

### Load and Extend

* `i16x8.load8x8_u(memarg) -> v128`: load eight 8-bit integers and zero extend each one to a 16-bit lane
Expand All @@ -685,12 +696,32 @@ Load a single element and splat to all lanes of a `v128` vector.

Fetch consequtive integers up to 32-bit wide and produce a vector with lanes up to 64 bits.

```python
def S.load_extend(ext, memarg):
result = S.New()
bytes = memory[memarg.offset:memarg.offset + 8])
for i in range(S.Lanes):
result[i] = ext(S.LaneType.from_bytes(bytes[(i * S.LaneBytes/2):((i+1) * S.LaneBytes/2)]))
return result

def S.load_extend_s(memarg):
return S.load_extend(Sext, memarg)

def S.load_extend_u(memarg):
return S.load_extend(Zext, memarg)
```

### Store

* `v128.store(memarg, data: v128)`

Store a `v128` vector to the given heap address.

```python
def S.store(memarg, a):
memory[memarg.offset:memarg.offset + 16] = bytes(a)
```

## Floating-point sign bit operations

These floating point operations are simple manipulations of the sign bit. No
Expand Down