Search code examples
floating-pointx86stackarminline-assembly

change floating-point operation in x86 system to the one in armv8 system


I read some inline assembly c code about floating-point operation. The code is as follows.

__asm__ __volatile__ ("fninit);
//There are some other in line assembly here, I omit them because they have nothing to do with my question.
__asm__ __volatile__ ("fcomp %st");

These codes are run in x86 system. However, I want to change these code to the one that can run in armv8 system.

First, I want to know what is meaning of the above code. Second, I want to know how I can change the above code to make it run in armv8 system.


Solution

  • https://masm32.com/masmcode/rayfil/tutorial/ explains how the x87 FPU works, and is a useful reference when the Intel insn ref manuals don't tell you how the pieces fit together. I'll add it to the x86 tag wiki.

    You're on your own for ARM asm.

    Are you sure you even need to write anything in asm, instead of just letting the compiler do it? If you don't need to set the rounding mode, or set limited precision, or anything, just use C double or float.


    As @Notlikethat commented: You can't port individual instructions in isolation. That's not going to be useful, especially for quirky instructions like fninit that are highly specific to managing the register state on a specific architecture. And x87 being a register stack vs. everything else using a flat set of registers is a huge difference. (Like SSE2 on x86 and VFP or NEON on ARM)