x87

Instruction FYL2XP1

自闭症网瘾萝莉.ら 提交于 2021-01-23 06:33:47
问题 I'm wondering why the instruction FYL2XP1 on x86-architecture computes exactly the mathematical formula y · log 2 ( x + 1). What's special with this formula? 回答1: The y operand is usually a compile time constant, for the moment forget about the x + 1 . Since log_b(x) = log_b(2) * log_2(x) the instruction allows to compute the logarithm in any base of x + 1 . Note that log_b(2) is a constant since it is seldom necessary to compute the logarithm with a degree of freedom in the base. FYL2XP1 and

How to move ST(0) to EAX?

自作多情 提交于 2020-07-18 06:38:52
问题 Hullo, I am learning x86 FPU assembly, and I have got a simple question I cannot find answer for: How to move value from ST(0) ( top of the FPU stack ) to EAX ? also: is this code correct: ; multiply (dot) two vectors of 3 floats passed by pointers as arg 1 arg 2 ; passings are ok I think, but not sure if multiplies-adds are ok push ebp mov ebp, esp mov eax, dword [ebp+8H] mov edx, dword [ebp+0CH] fld qword [eax] fmul qword [edx] fld qword [eax+4H] fmul qword [edx+4H] fld qword [eax+8H] fmul

How to write a several values on the screen using C printf function?

梦想与她 提交于 2020-05-24 05:34:12
问题 I have a program that counts root of quadratic equation. And I have a problem with printing the results on the screen, because I can print only one value. This is my code below, could you please tell me what should I do to pass two result to expression "x1 = ... ". [bits 32] call getaddr format db "x1 = %lf, x2 = %lf", 0xA, 0 offset equ $ - format a dq 1.0 ; b dq -11.0 c dq 28.0 minusfour dq -4.0 getaddr: finit mov eax, [esp] lea eax, [eax+offset] ; eax = a mov edx, [esp] lea edx, [edx+offset

Return a float from a 64-bit assembly function that uses x87 FPU

隐身守侯 提交于 2020-02-20 11:43:50
问题 I am trying to make a program that calculates equations (what equation doesn't matter currently) that use 64-bit registers, floats, and coprocessor instructions. Unfortunately I don't know how to access the final outcome of the equation as a float. I can do: fist qword ptr [bla] mov rax,bla and change the function type to INT and get my value, but I cannot access it as a FLOAT. Even when I leave the result in ST(0) (the top of the coprocessor stack) it doesn't work as expected and my C++

FPTAN Example x86

僤鯓⒐⒋嵵緔 提交于 2020-02-05 06:15:07
问题 According to Intel documentation, this is what FPTAN does: Replace ST(0) with its approximate tangent and push 1 onto the FPU stack. And this is a code I wrote in NASM: section .data fVal: dd 4 fSt0: dq 0.0 fSt1: dq 0.0 section .text fldpi fdiv dword[fVal] ; divide pi by 4 and store result in ST(0). fptan fstp qword[fSt0] ; store ST(0) fstp qword[fSt1] ; store ST(1) At this point the values of fSt0 and fSt1 , I find are: fSt0 = 5.60479e+044 fSt1 = -1.#IND But, shouldn't fSt0 and fSt1 be both

Cube root on x87 FPU using Newton-Raphson method

纵饮孤独 提交于 2019-12-31 02:18:25
问题 I am trying to write an assembly program using the 8086 processor that will find the cube root of a number. Obviously I am using floating points. Algorithm based upon Newton-Raphson method: root := 1.0; repeat oldRoot := root; root := (2.0*root + x/(root*root)) / 3.0 until ( |root – oldRoot| < 0.001; How do I divide (2*root + x) by (root*root)? .586 .MODEL FLAT .STACK 4096 .DATA root REAL4 1.0 oldRoot REAL4 2.0 Two REAL4 2.0 inttwo DWORD 2 itThree DWORD 3 three REAL4 3.0 x DOWRD 27 .CODE main

Why do x86 FP compares set CF like unsigned integers, instead of using signed conditions?

时光毁灭记忆、已成空白 提交于 2019-12-31 01:56:32
问题 The following documentation is provided in the Intel Instruction Reference for the COMISD instruction: Compares the double-precision floating-point values in the low quadwords of operand 1 (first operand) and operand 2 (second operand), and sets the ZF , PF , and CF flags in the EFLAGS register according to the result (unordered, greater than, less than, or equal). The CF 's flag point is not really clear here since it is related to arithmetic operations on unsigned integers. By contrast, the

Benefits of x87 over SSE

此生再无相见时 提交于 2019-12-20 11:15:28
问题 I know that x87 has higher internal precision, which is probably the biggest difference that people see between it and SSE operations. But I have to wonder, is there any other benefit to using x87? I have a habit of typing -mfpmath=sse automatically in any project, and I wonder if I'm missing anything else that the x87 FPU offers. 回答1: For hand-written asm, x87 has some instructions that don't exist in the SSE instruction set. Off the top of my head, it's all trigonometric stuff like fsin,

Using FPU return values in c++ code

萝らか妹 提交于 2019-12-20 07:27:15
问题 I have an x86 NASM program which seems to work perfectly. I have problems using the values returned from it. This is 32-Bit Windows using MSVC++. I expect the return value in ST0 . A minimal example demonstrating the problem with the returned values can be seen in this C++ and NASM assembly code: #include <iostream> extern "C" float arsinh(float); int main() { float test = arsinh(5.0); printf("%f\n", test); printf("%f\n", arsinh(5.0)); std::cout << test << std::endl; std::cout << arsinh(5.0)