Skip to content

Instantly share code, notes, and snippets.

@johnchandlerburnham
Last active December 5, 2019 00:48
Show Gist options
  • Save johnchandlerburnham/45e3df164b15087a4430d3a20d9fbdfb to your computer and use it in GitHub Desktop.
Save johnchandlerburnham/45e3df164b15087a4430d3a20d9fbdfb to your computer and use it in GitHub Desktop.
wasm i64 and f64 ops

i64, 29 ops

Op Signature
i64.eqz [i64] -> i32
i64.eq [i64,i64] -> i32
i64.ne [i64,i64] -> i32
i64.lt_s [i64,i64] -> i32
i64.lt_u [i64,i64] -> i32
i64.gt_s [i64,i64] -> i32
i64.gt_u [i64,i64] -> i32
i64.le_s [i64,i64] -> i32
i64.le_u [i64,i64] -> i32
i64.ge_s [i64,i64] -> i32
i64.ge_u [i64,i64] -> i32
i64.clz [i64] -> i32
i64.ctz [i64] -> i32
i64.popcnt [i64] -> i32
i64.add [i64,i64] -> i64
i64.sub [i64,i64] -> i64
i64.mul [i64,i64] -> i64
i64.div_s [i64,i64] -> i64
i64.div_u [i64,i64] -> i64
i64.rem_s [i64,i64] -> i64
i64.rem_u [i64,i64] -> i64
i64.and [i64,i64] -> i64
i64.or [i64,i64] -> i64
i64.xor [i64,i64] -> i64
i64.shl [i64,i64] -> i64
i64.shr_s [i64,i64] -> i64
i64.shr_u [i64,i64] -> i64
i64.rotl [i64,i64] -> i64
i64.rotr [i64,i64] -> i64

f64, 19 ops

Op Signature
f64.eq [f64,f64] -> i32
f64.ne [f64,f64] -> i32
f64.lt [f64,f64] -> i32
f64.gt [f64,f64] -> i32
f64.le [f64,f64] -> i32
f64.ge [f64,f64] -> i32
f64.abs [f64] -> f64
f64.neg [f64] -> f64
f64.ceil [f64] -> f64
f64.floor [f64] -> f64
f64.trunc [f64] -> f64
f64.nearest [f64] -> f64
f64.sqrt [f64] -> f64
f64.add [f64,f64] -> f64
f64.sub [f64,f64] -> f64
f64.mul [f64,f64] -> f64
f64.div [f64,f64] -> f64
f64.min [f64,f64] -> f64
f64.max [f64,f64] -> f64
f64.copysign [f64,f64] -> f64

casting, 6 ops

Op Signature
i64.trunc_f64_s [f64] -> i64
i64.trunc_f64_u [f64] -> i64
f64.convert_i64_s [i64] -> f64
f64.convert_i64_u [i64] -> f64
f64.reinterpret_i64 [i64] -> f64
i64.reinterpret_f64 [f64] -> i64
@johnchandlerburnham
Copy link
Author

johnchandlerburnham commented Dec 5, 2019

wasm minimalest

Op Signature Description
UNA [i64, i64] -> i64 see UNA
UNA [i64, f64] -> i64 see UNA
UNA [i64, i64] -> f64 see UNA
UNA [i64, f64] -> f64 see UNA
CMP [i64,i64] -> f64 see CMP
CMP [f64,f64] -> f64 see CMP
ADD [i64,i64] -> i64 i64.add
ADD [f64,f64] -> f64 f64.add
SUB [i64,i64] -> i64 i64.add
SUB [f64,f64] -> f64 f64.sub
MUL [i64,i64] -> i64 i64.mul
MUL [f64,f64] -> f64 f64.mul
DIV [i64,i64] -> i64 i64.div_u
DIV [f64,f64] -> f64 f64.div
NOR [i64,i64] -> i64 i64.neg (i64.or x y)
XOR [i64,i64] -> i64 i64.xor

CMP

EQ = 0
LT = 1
GT = 2
NANA = 3
NANB = 4
CMP(a : i64, b : i64) : i64
  if   i64.eq a b then EQ
  elif i64.lt_u a then LT
  else GT
CMP(a : f64, b : f64) : i64
  if   f64.ne a a then NANA
  if   f64.ne b b then NANB
  elif f64.eq a b then EQ
  elif f64.lt a b then LT
  else GT

UNA

CODE Signature Description
CNVU i64 -> f64 f64.convert_i64_u
CNVS i64 -> f64 f64.convert_i64_s
TRNU f64 -> i64 i64.trunc_f64_u
TRNS f64 -> i64 i64.trunc_f64_s
CAST f64 -> i64 i64.reinterpret_f64
CAST i64 -> f64 f64.reinterpret_i64
NRST f64 -> f64 f64.nearest
SQRT f64 -> f64 f64.sqrt
FEXP f64 -> f64 e^x
FLOG f64 -> f64 ln(x)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment