Detecting Presence of 80x87 Math Coprocessor

ID: Q38285

5.10 6.00 6.00a 6.00ax 7.00 | 5.10 6.00 6.00a | 1.00 1.50

MS-DOS                      | OS/2            | WINDOWS
kbprg

The information in this article applies to:

SUMMARY

There is no direct way to query the Microsoft C floating-point libraries to determine whether a math coprocessor is being used. Compiling using /FPi indicates that you don't want to worry about whether a coprocessor is present. Consequently, the compiler generates code that will do the following:

1. Checks to see if a 80x87 coprocessor is present.

2. If so, uses it.

3. If not, emulates it with software routines.

There is nothing in this algorithm to tell your program what it found. The only way you'll know it's emulating the coprocessor is by observing how slowly your program runs.

MORE INFORMATION

If you want to know whether a coprocessor is present, you'll have to test it yourself. For more information on how to test for the presence of an 80x87 coprocessor, please consult Intel's "80286 and 80287 Programmer's Reference Manual," pages 3-2 and 3-3 (in the second half of the book). This section is titled "System-Level Numeric Programming," and states that your program can detect the presence of the 80287 NPX. It then gives an assembly-language example that works correctly for both 8086- and 80286-based machines.

You can use this routine in your program as follows:

1. During initialization of your program, call the short Intel routine

   to see if a coprocessor is present.

2. If there is a coprocessor, proceed normally.

3. If there is no coprocessor, put up a message box explaining the

   following to the user:

   Your computer lacks a coprocessor, but <my_app> will emulate it in
   software; this emulation will slow down the calculations that
   <my_app> needs to perform. To increase the performance of <my_app>,
   as well as other programs, add a numeric coprocessor to your
   system.

4. Proceed with your program as you normally would. The C run-time
   libraries will automatically adjust for the presence or lack of an
   80x87.

Additional reference words: kbinf 1.00 1.50 5.10 6.00 6.00a 6.00ax 7.00 8087 80287 80387 KBCategory: kbprg KBSubcategory: CLngIss Keywords : kb16bitonly

Last Reviewed: July 18, 1997