minor wasm optimizations

post/wasm-gol-2
Ashelyn Dawn 1 year ago
parent 394b3642a0
commit b9a7ca4aef

@ -61,62 +61,39 @@
(func $getBoardPtr (result i32)
global.get $currentBuffer
i32.eqz
if (result i32)
global.get $buffer0ptr
else
global.get $buffer1ptr
end
global.get $boardBufferLength
i32.mul
)
(func $swapBoards
global.get $currentBuffer
i32.eqz
if (result i32)
i32.const 1
else
i32.const 0
end
global.set $currentBuffer
)
(func $positionInRange (param $position i32) (param $min i32) (param $max i32) (result i32)
(func $positionOutOfRange (param $position i32) (param $max i32) (result i32)
local.get $position
local.get $min
i32.lt_s
if
i32.const 0
return
end
i32.lt_s
local.get $position
local.get $max
i32.ge_s
if
i32.const 0
return
end
i32.const 1
return
i32.or
)
(func $getIndexForPosition (param $row i32) (param $column i32) (result i32)
(local $result i32)
local.get $row
i32.const 0
global.get $boardHeight
call $positionInRange
call $positionOutOfRange
local.get $column
i32.const 0
global.get $boardWidth
call $positionInRange
call $positionOutOfRange
i32.and
i32.eqz
if
i32.const -1
return

Loading…
Cancel
Save