News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Fast Exp approximation

Started by guga, August 12, 2020, 12:29:23 AM

Previous topic - Next topic

InfiniteLoop

edit:
Improved version:
.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.


.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

Quote from: InfiniteLoop on August 15, 2020, 11:20:48 PM
Here's my rough & ready effort.


.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.