开发者

What instructions should I be using for floating point operations?

开发者 https://www.devze.com 2023-01-15 13:44 出处:网络
I\'m somewhat familiar with the x87 instructions for manipulating floating point numbers in x86 assembly. However, I read somewhere that these were seldom used anymore. (And weren\'t allowed in 64-bit

I'm somewhat familiar with the x87 instructions for manipulating floating point numbers in x86 assembly. However, I read somewhere that these were seldom used anymore. (And weren't allowed in 64-bit Windows drivers)[1]

If that's the case, what instructions should I be using? I saw something开发者_JAVA百科 about SSE, but unless I'm mistaken, those instructions were added much more recently and won't be available on older chips. (Like the Pentium II, etc.)

What instructions should I be using?


If you're willing to forget about backwards compatibility, SSE is the way to go. It has a richer instruction set and vector support. If you want to be optimized for whatever processor is running, you should try writing in a higher level language and compiling with ICC, which checks the processor is currently running and executes code that's optimized for that.

At the end of the day it depends on the expected users of your software.


If you need to be backwards compatible, you'll have to use x87 instructions. Otherwise, as Nathan Fellman says, SSE# instructions may be the way to go, also because code for them is somewhat easier to write (they use a normal register model, whereas x87 uses a stack).

Having said that, there are several reasons why you might want to use x87 code (or mixing x87/SSE code):

(1) x87 offers a higher precision, i.e. 80-bit floating point computation. (Both, x87/SSE offer 32-bit and 64-bit floats.) This is potentially an issue with e.g. some scientific code that may need the extra precision.

(2) x87 offers some operations that are not covered by the SSE# instruction sets, namely instructions for triogonometric operations (sin, cos, ...) and logarithms.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号