浮点堆栈操作

floating-point stack operation

我必须阅读一个综合基准的程序。我不熟悉浮点堆栈。代码如下。下面的代码是在for statement.I 中不要写for 语句,因为它非常大。每个循环似乎都修改了 FP 堆栈,并且每个循环都必须在下一个循环开始之前恢复 FP 堆栈。

//since the synthetic will be run (probably) multiple times, the FP stack needs to be clear

           if(floatStackSize > 6)
           {
                 initializeFPStack();
                 floatStackSize = 0;
           }
           else
           {
                 while(floatStackSize > 0)
                 {
                    adjustFPStack(floatStackSize);
                    floatStackSize = floatStackSize - 1;
                 }
           }

initializeFPStack和adjustFPStack函数代码如下

//initializeFPStack
    void initializeFPStack(void) //needed
    {
        string fileName = outputFileName;

        ofstream outputFile(fileName.c_str(), ios::app);        //open a file for writing (append the current contents)

        if(!outputFile)  //check to be sure file is open
            cout << "Error opening file.";

        outputFile << "   __asm__ __volatile__ (\"fninit " << "\");\n";

        outputFile.close();
    }

//adjustFPStack
void adjustFPStack(size_t floatStackSizE) //needed
{
    string fileName = outputFileName;

    ofstream outputFile(fileName.c_str(), ios::app);        //open a file for writing (append the current contents)

    if(!outputFile)  //check to be sure file is open
        cout << "Error opening file.";

    outputFile << "\n   __asm__ __volatile__ (\"fcomp " << "%st" << "\");\n";

    outputFile.close();
}

有人可以给我教程或 link 教浮点堆栈吗?另外,我想知道上面的代码做了什么以及为什么它必须执行上面的操作。

"floating point stack" 是 x86 处理器的一个特性。它包含八个浮点寄存器,外加一个堆栈指针,对这些寄存器进行操作的指令将它们视为一个堆栈。这些寄存器和指令统称为x87。您可以在 Intel 64 和 IA-32 架构软件开发人员手册 中找到完整的详细信息。 Volume 1 describes the architecture and general principles. Volume 2 的第 8 章描述了每条指令的作用。

现代处理器包含额外的浮点寄存器和对这些其他寄存器进行操作的不同指令。这些寄存器和指令统称为SSE。它们通常比 x87 更高效。