Cómo: pow (real, real) en x86
Estoy buscando la implementación de pow(real, real)
en el ensamblado x86. También me gustaría entender cómo funciona el algoritmo.
28
2 answers
Simplemente cómpralo como 2^(y*log2(x))
.
Hay una instrucción x86 FYL2X para calcular y*log2(x) y una instrucción x86 F2XM1 para hacer exponenciación. F2XM1 requiere un argumento en el rango [-1,1], por lo que tendría que agregar algún código en el medio para extraer la parte entera y el resto, exponenciar el resto, usar FSCALE para escalar el resultado por una potencia apropiada de 2.
60
Author: Eugene Smith,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-01-09 09:34:57
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-01-09 09:34:57
OK, implementé power(double a, double b, double * result);
en x86 tal como lo recomendaste.
Código: http://pastebin.com/VWfE9CZT
%define a QWORD [ebp+8]
%define b QWORD [ebp+16]
%define result DWORD [ebp+24]
%define ctrlWord WORD [ebp-2]
%define tmp DWORD [ebp-6]
segment .text
global power
power:
push ebp
mov ebp, esp
sub esp, 6
push ebx
fstcw ctrlWord
or ctrlWord, 110000000000b
fldcw ctrlWord
fld b
fld a
fyl2x
fist tmp
fild tmp
fsub
f2xm1
fld1
fadd
fild tmp
fxch
fscale
mov ebx, result
fst QWORD [ebx]
pop ebx
mov esp, ebp
pop ebp
ret
15
Author: Maciej Ziarko,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-06-06 10:16:19
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-06-06 10:16:19