views:

45

answers:

2

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 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?

+1  A: 

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.

Nathan Fellman
Actually, I'm writing a compiler that *generates* the floating point instructions :)
George Edison
@George: is this a general purpose compiler, that can be expected to run on older systems without SSE support, or is it for a closed environment?
Nathan Fellman
@Nathan: It will (hopefully) be widely used, so it should be compatible with as many processors as possible.
George Edison
@George: Then I suggest some sort of dual compilation and use CPUID to see if SSE is supported or not. If not, use the x87 path, if it is, use the SSE path. If this is too much work, then you may have no choice but to use x87.
Nathan Fellman
A: 

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.

PhiS