INFO: How Windows NT and Windows 95 Handle Floating-Point Calculations

ID: Q102555


The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API), used with:
    • Microsoft Windows NT versions 3.51, 4.0
    • Microsoft Windows 95
    • Microsoft Windows 98
    • Microsoft Windows 2000


SUMMARY

Windows NT and Windows 95 provide environments to run Win32, Win16, and MS-DOS applications. Windows NT also supports POSIX and OS/2 applications. This article explains how each of these environments provides floating- point support to applications.


MORE INFORMATION

Win32

Both Windows 95 and Windows NT provide full floating-point support for Win32 applications, even on Intel x86 machines that don't have built-in floating-point support or floating-point coprocessors. Emulation is provided by the Win32 Kernel for machines that don't have floating-point hardware. Therefore, compilers do not need to provide their own floating- point emulation.

Each thread in a Win32 application has its own execution state that includes the general purpose registers and the floating-point registers. Thus, floating-point execution and exception handling are controlled on a per-thread basis. This allows individual threads in a process to adjust the behavior of the floating-point processor to use specialized rounding or precision control and exception handling.

Floating point exceptions are handled by the Win32 structured exception handling (SEH) mechanism built into the Win32 Kernel. When a thread causes a floating-point exception, the SEH mechanism looks for an exception handler registered by the thread to handle the exception. If the thread does not handle the exception, then the process that owns it is terminated.

Languages may have runtime libraries or runtime systems that provide default floating-point exception handlers. For example, Microsoft Visual C++ runtime library provides default floating-point exception handling and includes functions such as _controlfp() for determining and adjusting the floating-point hardware's behavior in rounding, precision control, and exception handling.

POSIX

Like Win32 applications, POSIX applications can assume that full floating- point support always exists.

The POSIX standard does not define a way to enable floating-point exceptions, so POSIX applications that use floating-point exceptions must rely on system-specific features. Under Windows NT, a POSIX application compiled with Microsoft Visual C++ can enable floating exceptions by using _controlfp(). Floating-point exceptions can then be caught by SIGFPE, or, if the application needs to do more than simply catch the exception, by fpieee_flt().

Win16

Both Windows 95 and Windows NT on Intel x86 processors provide a floating- point emulator named WIN87EM for Win16 applications. WIN87EM only runs when it is explicitly called; it does not intercept floating-point instructions being executed. Thus, Win16 applications technically need to be compiled to support emulation.

Win16 applications are normally compiled to have fixup records in their object code that contain actual floating-point instructions and calls to the emulator. If the machine's processor has floating-point support or a coprocessor is present, then the floating-point instructions will be executed; otherwise, the calls to WIN87EM will be executed.

Windows NT on RISC-based machines use Windows NT's Intel x86 emulation code. Windows NT 3.5 and 3.51 include 80286 and 80287 emulators; Windows NT 4.0 includes an i486 emulator. Win16 applications run as if the Intel floating-point coprocessors are present.

MS-DOS

Windows 95 and Windows NT on Intel x86 both run MS-DOS applications in the Intel x86 processor's Virtual-8086 mode. MS-DOS applications can access the floating-point hardware just as if they would in MS-DOS. If no floating- point hardware is present, no emulation is provided for the application. Thus, the application must provide its own emulation.

Windows NT on RISC-based machines use Windows NT's Intel x86 emulation code. Windows NT 3.5 and 3.51 include 80286 and 80287 emulators; Windows NT 4.0 includes an i486 emulator. MS-DOS applications run as if the Intel floating-point coprocessors are present.

OS/2 Subsystem

Floating-point support in this subsystem matches that of OS/2: if floating- point hardware is not installed, the OS/2 application must provide its own emulation. The OS/2 subsystem is supported only on Intel x86 Versions of Windows NT.

Device Drivers

Windows NT kernel-mode drivers cannot use floating-point instructions because kernel-mode stack switches don't preserve the floating-point registers. If a kernel-mode driver does use any floating-point instruction it could cause either corruption of the user-mode application's numeric state or a system crash. Windows 95 virtual device drivers (VxDs) can use floating-point instructions but must use the Virtual Math Coprocessor Device interface to save and restore the state of the floating-point coprocessor. The VxD must also register an exception handler for floating-point exceptions.

Additional query words:

Keywords : kbprg kbnokeyword kbFloatPoint kbKernBase kbWinOS2000 kbDSupport kbGrpKernBase
Version : winnt:3.51,4.0
Platform : winnt
Issue type : kbinfo


Last Reviewed: December 29, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.