浮点运算如何在软件中模拟? [英] How are floating point operations emulated in software?

查看:941
本文介绍了浮点运算如何在软件中模拟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当CPU没有(或错误)浮点单元时,软件如何进行浮点运算?例如PIC,AVR和8051微控制器架构。

How does software perform floating point arithmetic when the CPU has no (or buggy) floating point unit? Examples would be the PIC, AVR, and 8051 microcontrollers architectures.

推荐答案

Emulated是在PIC,AVR和8051的上下文中出现错误的术语。浮点仿真是指在具有FPU选项但并非所有部件都包含FPU的架构上对FPU硬件的仿真。这允许包含浮点指令的二进制文件在没有FPU的情况下运行。在使用的地方,FPU仿真实现为无效指令异常处理程序;当遇到FPU指令但没有FPU时,发生异常,处理程序读取指令值并以软件实现操作。

"Emulated" is the wrong term in the context of PIC, AVR and 8051. Floating-point emulation refers to the emulation of FPU hardware on architectures that have an FPU option but for which not all parts include the FPU. This allows a binary containing floating point instructions to run on a variant without an FPU. Where used, FPU emulation is implemented as an invalid-instruction exception handler; when an FPU instruction is encountered but no FPU is present, an exception occurs, and the handler reads the instruction value and implements the operation in software.

但是没有一个架构您已经列出了define和FPU或FPU指令,所以没有什么可以模拟。相反,在这些情况下,浮点运算完全由软件实现,编译器根据需要生成调用浮点例程的代码。例如,表达式 x = y * z; 将生成等效于函数调用 x = _fmul(y,z); 。实际上,如果您查看来自包含浮点运算的构建的链接器映射输出,您可能会看到常规的符号名称,例如 _fmul _fdiv 等 - 这些函数是编译器的内在。

However none of the architectures you have listed define and FPU or FPU instructions so there is nothing to emulate. Instead in these cases floating-point operations are implemented entirely in software, and the compiler generates code to invoke floating-point routines as necessary. For example the expression x = y * z ; will generate code that is equivalent to a function call x = _fmul( y, z ) ;. In fact if you look at the linker map output from a build containg floating point operations you will probably see routine symbol names such as _fmul, _fdiv and the like - these functions are intrinsic to the compiler.

这篇关于浮点运算如何在软件中模拟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆