BruNews
Messages postés
21040
Date d'inscription
jeudi 23 janvier 2003
Statut
Modérateur
Dernière intervention
21 août 2019
12 déc. 2010 à 10:56
Les traitements lourds de type pow() et/ou nombre de taille indéterminée ne se font qu'en langage compilé (C et ASM).
Exemple d'une fonction pow() qui prend float32 en base et exponentielle en mode x64.
Cette pow() est très rapide mais APPROCHEE à quelques millièmes prés.
Pour du float64 ce sera nettement plus compliqué, si taille indéterminée alors...
bnPowF PROC ; XMM0 float fVal, XMM1 float fexp
lea rdx, [rsp - 24]
xorps xmm5, xmm5
movd xmm2, dword ptr BNPACKinv_mant_mask
movaps [rdx], xmm7
cmpss xmm5, xmm0, 1
maxss xmm0, dword ptr BNPACKmin_norm_pos
movd xmm7, dword ptr BNPACK1PZ
movaps xmm3, xmm0
movaps [rdx - 16], xmm6
andps xmm0, xmm2
orps xmm0, xmm7
movd eax, xmm5
movaps xmm4, xmm0
movd xmm2, dword ptr BNPACKDW7F
subss xmm0, xmm7
addss xmm4, xmm7
psrld xmm3, 23
rcpss xmm4, xmm4
mulss xmm0, xmm4
psubd xmm3, xmm2
addss xmm0, xmm0
movaps xmm2, xmm0
mulss xmm0, xmm0
movd xmm4, dword ptr BNPACKlog_p0
movd xmm6, dword ptr BNPACKlog_q0
mulss xmm4, xmm0
movss xmm5, dword ptr BNPACKlog_p1
mulss xmm6, xmm0
movd xmm7, dword ptr BNPACKlog_q1
addss xmm4, xmm5
addss xmm6, xmm7
movd xmm5, dword ptr BNPACKlog_p2
mulss xmm4, xmm0
movd xmm7, dword ptr BNPACKlog_q2
mulss xmm6, xmm0
addss xmm4, xmm5
movd xmm5, dword ptr BNPACKlog2_c0
addss xmm6, xmm7
cvtdq2ps xmm7, xmm3
mulss xmm0, xmm4
rcpss xmm6, xmm6
mulss xmm0, xmm6
movd xmm4, dword ptr BNPACKexp2_hi
mulss xmm0, xmm2
movd xmm6, dword ptr BNPACKexp2_lo
mulss xmm2, xmm5
mulss xmm0, xmm5
addss xmm2, xmm7
movd xmm3, dword ptr BNPACKZP5
addss xmm0, xmm2
xorps xmm2, xmm2
movd xmm5, dword ptr BNPACKDW1
mulss xmm0, xmm1
minss xmm0, xmm4
movd xmm4, dword ptr BNPACKexp2_p0
maxss xmm0, xmm6
movd xmm6, dword ptr BNPACKexp2_q0
addss xmm3, xmm0
cmpnltss xmm2, xmm3
pand xmm2, xmm5
cvttps2dq xmm3, xmm3
psubd xmm3, xmm2
cvtdq2ps xmm2, xmm3
subss xmm0, xmm2
movaps xmm2, xmm0
mulss xmm0, xmm0
paddd xmm3, BNPACKDW7F
mulss xmm4, xmm0
mulss xmm6, xmm0
addss xmm4, dword ptr BNPACKexp2_p1
addss xmm6, dword ptr BNPACKexp2_q1
mulss xmm4, xmm0
addss xmm4, dword ptr BNPACKexp2_p2
mulss xmm2, xmm4
movd xmm0, dword ptr BNPACK1PZ
subss xmm6, xmm2
pslld xmm3, 23
rcpss xmm6, xmm6
movd xmm5, eax
mulss xmm2, xmm6
andps xmm3, xmm5
movaps xmm7, [rdx]
addss xmm2, xmm2
movaps xmm6, [rdx - 16]
addss xmm0, xmm2
mulss xmm0, xmm3
ret 0
bnPowF ENDP
ciao...
BruNews, MVP VC++