Skip to content

Instantly share code, notes, and snippets.

@clausecker
Created July 6, 2017 19:53
Show Gist options
  • Save clausecker/b0ceb54c42a6d4b0add1684ecc3abf80 to your computer and use it in GitHub Desktop.
Save clausecker/b0ceb54c42a6d4b0add1684ecc3abf80 to your computer and use it in GitHub Desktop.
Compute exp() in i386 assembly
.text
.globl exp
.type exp,@function
.align 16
exp:
fldt 4(%esp) # x
fldl2e # log2(e) x
fmulp # x' (= log2(e) * x)
fld %st(0) # x' x'
frndint # round(x') x'
fsubr %st(0),%st(1) # round(x') x'-round(x')
fxch # x'-round(x') round(x')
f2xm1 # 2^(x'-round(x'))-1 round(x')
fld1 # 1 2^(x'-round(x'))-1 round(x')
faddp # 2^(x'-round(x')) round(x')
fscale # 2^(x'-round(x'))*2^round(x') (= 2^x' = e^x) round(x')
fstp %st(1) # e^x
ret
.size exp,.-exp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment