From 029dde7c3c08acf8338a07f5ddfb0e57e2833163 Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Fri, 14 Sep 2018 01:25:31 +0200 Subject: [PATCH] Add raw buffer experiment to tests --- tests/compiler/std/buffer.optimized.wat | 247 ++++++++++++++++++ tests/compiler/std/buffer.ts | 40 +++ tests/compiler/std/buffer.untouched.wat | 327 ++++++++++++++++++++++++ 3 files changed, 614 insertions(+) create mode 100644 tests/compiler/std/buffer.optimized.wat create mode 100644 tests/compiler/std/buffer.ts create mode 100644 tests/compiler/std/buffer.untouched.wat diff --git a/tests/compiler/std/buffer.optimized.wat b/tests/compiler/std/buffer.optimized.wat new file mode 100644 index 00000000..b3339f65 --- /dev/null +++ b/tests/compiler/std/buffer.optimized.wat @@ -0,0 +1,247 @@ +(module + (type $iifv (func (param i32 i32 f32))) + (type $iif (func (param i32 i32) (result f32))) + (type $iiiiv (func (param i32 i32 i32 i32))) + (type $v (func)) + (type $FUNCSIG$i (func (result i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) + (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) + (global $std/buffer/buf (mut i32) (i32.const 0)) + (memory $0 1) + (data (i32.const 8) "\0d\00\00\00s\00t\00d\00/\00b\00u\00f\00f\00e\00r\00.\00t\00s") + (export "memory" (memory $0)) + (start $start) + (func $std/buffer/Buffer.from (; 1 ;) (; has Stack IR ;) (type $FUNCSIG$i) (result i32) + (i32.const 0) + ) + (func $std/buffer/Buffer#set (; 2 ;) (; has Stack IR ;) (type $iifv) (param $0 i32) (param $1 i32) (param $2 f32) + (f32.store + (i32.add + (get_local $0) + (i32.shl + (get_local $1) + (i32.const 2) + ) + ) + (get_local $2) + ) + ) + (func $std/buffer/Buffer#get (; 3 ;) (; has Stack IR ;) (type $iif) (param $0 i32) (param $1 i32) (result f32) + (f32.load + (i32.add + (get_local $0) + (i32.shl + (get_local $1) + (i32.const 2) + ) + ) + ) + ) + (func $std/buffer/Buffer#slice (; 4 ;) (; has Stack IR ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (i32.add + (get_local $0) + (i32.const 4) + ) + ) + (func $start (; 5 ;) (; has Stack IR ;) (type $v) + (set_global $std/buffer/buf + (call $std/buffer/Buffer.from) + ) + (call $std/buffer/Buffer#set + (get_global $std/buffer/buf) + (i32.const 0) + (f32.const 1.100000023841858) + ) + (call $std/buffer/Buffer#set + (get_global $std/buffer/buf) + (i32.const 1) + (f32.const 1.2000000476837158) + ) + (if + (f32.ne + (call $std/buffer/Buffer#get + (get_global $std/buffer/buf) + (i32.const 0) + ) + (f32.const 1.100000023841858) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 26) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (f32.ne + (call $std/buffer/Buffer#get + (get_global $std/buffer/buf) + (i32.const 1) + ) + (f32.const 1.2000000476837158) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 27) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (f32.ne + (f32.load + (get_global $std/buffer/buf) + ) + (f32.const 1.100000023841858) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 29) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (f32.ne + (f32.load + (i32.add + (get_global $std/buffer/buf) + (i32.const 4) + ) + ) + (f32.const 1.2000000476837158) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 30) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (f32.ne + (f32.load + (i32.const 0) + ) + (f32.const 1.100000023841858) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 32) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (f32.ne + (f32.load + (i32.const 4) + ) + (f32.const 1.2000000476837158) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 33) + (i32.const 0) + ) + (unreachable) + ) + ) + (f32.store + (i32.add + (get_global $std/buffer/buf) + (i32.const 8) + ) + (f32.const 1.2999999523162842) + ) + (if + (f32.ne + (call $std/buffer/Buffer#get + (get_global $std/buffer/buf) + (i32.const 2) + ) + (f32.const 1.2999999523162842) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 36) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (f32.ne + (f32.load + (i32.add + (get_global $std/buffer/buf) + (i32.const 8) + ) + ) + (f32.const 1.2999999523162842) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 37) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (f32.ne + (f32.load + (i32.const 8) + ) + (f32.const 1.2999999523162842) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 38) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.ne + (call $std/buffer/Buffer#slice + (get_global $std/buffer/buf) + ) + (i32.const 4) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 40) + (i32.const 0) + ) + (unreachable) + ) + ) + ) +) diff --git a/tests/compiler/std/buffer.ts b/tests/compiler/std/buffer.ts new file mode 100644 index 00000000..f3830aeb --- /dev/null +++ b/tests/compiler/std/buffer.ts @@ -0,0 +1,40 @@ +class Buffer { + + static from(ptr: usize): Buffer { + return changetype>(ptr); + } + + @operator("[]") @inline get(index: i32): T { + return load(changetype(this) + (index << alignof())); + } + + @operator("[]=") @inline set(index: i32, value: T): void { + store(changetype(this) + (index << alignof()), value); + } + + slice(startIndex: i32): Buffer { + return changetype>(changetype(this) + (startIndex << alignof())); + } + + // ... +} + +var buf = Buffer.from(0); +buf[0] = 1.1; +buf[1] = 1.2; + +assert(buf[0] == 1.1); +assert(buf[1] == 1.2); + +assert(buf.get(0) == 1.1); +assert(buf.get(1) == 1.2); + +assert(load(0) == 1.1); +assert(load(4) == 1.2); + +buf.set(2, 1.3); +assert(buf[2] == 1.3); +assert(buf.get(2) == 1.3); +assert(load(8) == 1.3); + +assert(buf.slice(1) === changetype>(4)); diff --git a/tests/compiler/std/buffer.untouched.wat b/tests/compiler/std/buffer.untouched.wat new file mode 100644 index 00000000..d08715e0 --- /dev/null +++ b/tests/compiler/std/buffer.untouched.wat @@ -0,0 +1,327 @@ +(module + (type $ii (func (param i32) (result i32))) + (type $iifv (func (param i32 i32 f32))) + (type $iif (func (param i32 i32) (result f32))) + (type $iiiiv (func (param i32 i32 i32 i32))) + (type $iii (func (param i32 i32) (result i32))) + (type $v (func)) + (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) + (global $std/buffer/buf (mut i32) (i32.const 0)) + (global $HEAP_BASE i32 (i32.const 40)) + (memory $0 1) + (data (i32.const 8) "\0d\00\00\00s\00t\00d\00/\00b\00u\00f\00f\00e\00r\00.\00t\00s\00") + (export "memory" (memory $0)) + (start $start) + (func $std/buffer/Buffer.from (; 1 ;) (type $ii) (param $0 i32) (result i32) + (get_local $0) + ) + (func $std/buffer/Buffer#set (; 2 ;) (type $iifv) (param $0 i32) (param $1 i32) (param $2 f32) + (f32.store + (i32.add + (get_local $0) + (i32.shl + (get_local $1) + (i32.const 2) + ) + ) + (get_local $2) + ) + ) + (func $std/buffer/Buffer#get (; 3 ;) (type $iif) (param $0 i32) (param $1 i32) (result f32) + (f32.load + (i32.add + (get_local $0) + (i32.shl + (get_local $1) + (i32.const 2) + ) + ) + ) + ) + (func $std/buffer/Buffer#slice (; 4 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (i32.add + (get_local $0) + (i32.shl + (get_local $1) + (i32.const 2) + ) + ) + ) + (func $start (; 5 ;) (type $v) + (local $0 i32) + (local $1 i32) + (local $2 f32) + (set_global $std/buffer/buf + (call $std/buffer/Buffer.from + (i32.const 0) + ) + ) + (call $std/buffer/Buffer#set + (get_global $std/buffer/buf) + (i32.const 0) + (f32.const 1.100000023841858) + ) + (call $std/buffer/Buffer#set + (get_global $std/buffer/buf) + (i32.const 1) + (f32.const 1.2000000476837158) + ) + (if + (i32.eqz + (f32.eq + (call $std/buffer/Buffer#get + (get_global $std/buffer/buf) + (i32.const 0) + ) + (f32.const 1.100000023841858) + ) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 26) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (f32.eq + (call $std/buffer/Buffer#get + (get_global $std/buffer/buf) + (i32.const 1) + ) + (f32.const 1.2000000476837158) + ) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 27) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (f32.eq + (block $std/buffer/Buffer#get|inlined.0 (result f32) + (set_local $0 + (get_global $std/buffer/buf) + ) + (set_local $1 + (i32.const 0) + ) + (f32.load + (i32.add + (get_local $0) + (i32.shl + (get_local $1) + (i32.const 2) + ) + ) + ) + ) + (f32.const 1.100000023841858) + ) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 29) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (f32.eq + (block $std/buffer/Buffer#get|inlined.1 (result f32) + (set_local $1 + (get_global $std/buffer/buf) + ) + (set_local $0 + (i32.const 1) + ) + (f32.load + (i32.add + (get_local $1) + (i32.shl + (get_local $0) + (i32.const 2) + ) + ) + ) + ) + (f32.const 1.2000000476837158) + ) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 30) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (f32.eq + (f32.load + (i32.const 0) + ) + (f32.const 1.100000023841858) + ) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 32) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (f32.eq + (f32.load + (i32.const 4) + ) + (f32.const 1.2000000476837158) + ) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 33) + (i32.const 0) + ) + (unreachable) + ) + ) + (block $std/buffer/Buffer#set|inlined.0 + (set_local $0 + (get_global $std/buffer/buf) + ) + (set_local $1 + (i32.const 2) + ) + (set_local $2 + (f32.const 1.2999999523162842) + ) + (f32.store + (i32.add + (get_local $0) + (i32.shl + (get_local $1) + (i32.const 2) + ) + ) + (get_local $2) + ) + ) + (if + (i32.eqz + (f32.eq + (call $std/buffer/Buffer#get + (get_global $std/buffer/buf) + (i32.const 2) + ) + (f32.const 1.2999999523162842) + ) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 36) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (f32.eq + (block $std/buffer/Buffer#get|inlined.2 (result f32) + (set_local $1 + (get_global $std/buffer/buf) + ) + (set_local $0 + (i32.const 2) + ) + (f32.load + (i32.add + (get_local $1) + (i32.shl + (get_local $0) + (i32.const 2) + ) + ) + ) + ) + (f32.const 1.2999999523162842) + ) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 37) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (f32.eq + (f32.load + (i32.const 8) + ) + (f32.const 1.2999999523162842) + ) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 38) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (call $std/buffer/Buffer#slice + (get_global $std/buffer/buf) + (i32.const 1) + ) + (i32.const 4) + ) + ) + (block + (call $~lib/env/abort + (i32.const 0) + (i32.const 8) + (i32.const 40) + (i32.const 0) + ) + (unreachable) + ) + ) + ) +)