Author Topic: Fast Exp approximation  (Read 1799 times)

InfiniteLoop

  • Regular Member
  • *
  • Posts: 9
Re: Fast Exp approximation
« Reply #60 on: August 15, 2020, 11:20:48 PM »
edit:
Improved version:
Code: [Select]
.data
E_1 REAL4 1.0000
E_2 REAL4 0.5000
E_3 REAL4 0.16666
E_4 REAL4 0.04166
E_5 REAL4 0.00833
.code
ASM_Exp_2 proc
movss xmm4, xmm0
movss xmm1, xmm0
addss xmm1, E_1
mulss xmm4, xmm0
movss xmm2, E_2
vfmadd231ss xmm1, xmm2, xmm4
mulss xmm4, xmm0
movss xmm3, E_3
vfmadd231ss xmm1, xmm3, xmm4
mulss xmm4, xmm0
movss xmm2, E_4
vfmadd231ss xmm1, xmm2, xmm4
mulss xmm4, xmm0
movss xmm3, E_5
vfmadd231ss xmm1, xmm3, xmm4
movss xmm0, xmm1
ret
ASM_Exp_2 endp

end
Here's my rough & ready effort.

Code: [Select]
.data
N_1 REAL4 1.000000000000000
N_2 REAL4 2.000000000000000
N_3 REAL4 6.000000000000000
N_4 REAL4 24.000000000000000
N_5 REAL4 120.000000000000000
.code
ASM_Exp proc
movss xmm1, N_1
movss xmm2, xmm0
movss xmm3, xmm1
movss xmm5, xmm1
addss xmm1, xmm0    ;x+1
movss xmm4, N_2
divss xmm3, xmm4    ;1/n!
mulss xmm2, xmm0    ;x^n
vfmadd231ss xmm1, xmm2, xmm3
movss xmm3, xmm5
movss xmm4, N_3
divss xmm3, xmm4    ;1/n!
mulss xmm2, xmm0    ;x^n
vfmadd231ss xmm1, xmm2, xmm3
movss xmm3, xmm5
movss xmm4, N_4
divss xmm3, xmm4    ;1/n!
mulss xmm2, xmm0    ;x^n
vfmadd231ss xmm1, xmm2, xmm3
movss xmm3, xmm5
movss xmm4, N_5
divss xmm3, xmm4    ;1/n!
mulss xmm2, xmm0    ;x^n
vfmadd231ss xmm1, xmm2, xmm3
movss xmm0, xmm1
ret
ASM_Exp endp

end

Siekmanski

  • Member
  • *****
  • Posts: 2377
Re: Fast Exp approximation
« Reply #61 on: August 15, 2020, 11:46:18 PM »
Here's my rough & ready effort.

Code: [Select]
.data
N_1 REAL4 1.000000000000000
N_2 REAL4 2.000000000000000
N_3 REAL4 6.000000000000000
N_4 REAL4 24.000000000000000
N_5 REAL4 120.000000000000000
.code
ASM_Exp proc
movss xmm1, N_1
movss xmm2, xmm0
movss xmm3, xmm1
movss xmm5, xmm1
addss xmm1, xmm0    ;x+1
movss xmm4, N_2
divss xmm3, xmm4    ;1/n!
mulss xmm2, xmm0    ;x^n
vfmadd231ss xmm1, xmm2, xmm3
movss xmm3, xmm5
movss xmm4, N_3
divss xmm3, xmm4    ;1/n!
mulss xmm2, xmm0    ;x^n
vfmadd231ss xmm1, xmm2, xmm3
movss xmm3, xmm5
movss xmm4, N_4
divss xmm3, xmm4    ;1/n!
mulss xmm2, xmm0    ;x^n
vfmadd231ss xmm1, xmm2, xmm3
movss xmm3, xmm5
movss xmm4, N_5
divss xmm3, xmm4    ;1/n!
mulss xmm2, xmm0    ;x^n
vfmadd231ss xmm1, xmm2, xmm3
movss xmm0, xmm1
ret
ASM_Exp endp

end

My computer is to old, can't handle FMA instructions.  :sad:
Creative coders use backward thinking techniques as a strategy.