Skip to content

Instantly share code, notes, and snippets.

@rhysd

rhysd/sqrt.wast Secret

Created March 24, 2016 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhysd/d60105a4a24746cb5deb to your computer and use it in GitHub Desktop.
Save rhysd/d60105a4a24746cb5deb to your computer and use it in GitHub Desktop.
(module
(memory 1)
(export "memory" memory)
(export "abs" $abs)
(export "sqrt2" $sqrt2)
(export "sqrt" $sqrt)
(func $abs (param $$0 f64) (result f64)
(block $label$0
(br_if $label$0
(i32.or
(f64.gt
(get_local $$0)
(f64.const 0)
)
(f64.ne
(get_local $$0)
(get_local $$0)
)
)
)
(set_local $$0
(f64.neg
(get_local $$0)
)
)
)
(return
(get_local $$0)
)
)
(func $sqrt2 (param $$0 f64) (param $$1 f64) (param $$2 f64) (result f64)
(block $label$0
(br_if $label$0
(f64.ge
(call $abs
(f64.sub
(get_local $$0)
(get_local $$1)
)
)
(f64.const 1e-05)
)
)
(return
(get_local $$1)
)
)
(return
(call $sqrt2
(get_local $$1)
(f64.add
(get_local $$1)
(f64.div
(f64.sub
(f64.mul
(get_local $$1)
(get_local $$1)
)
(get_local $$2)
)
(f64.mul
(get_local $$1)
(f64.const -2)
)
)
)
(get_local $$2)
)
)
)
(func $sqrt (param $$0 f64) (result f64)
(return
(call $sqrt2
(f64.const 0)
(get_local $$0)
(get_local $$0)
)
)
)
)
;; METADATA: { "asmConsts": {},"staticBump": 7 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment