User's Manual

PROGRAMMING NUMERIC APPLICATIONS
Case 1:
M 0 V I ,
F I L D I
MOV
AX,I
FISTP
I
Case
2:
F IL D
FWAIT
M 0 V I., 5
F
1ST P
FWAIT
MOV
AX,I
Figure 2-9. Synchronizing References
to
Shared Data
The data-synchronization function of any FW AIT
or
numeric instruction must
be
well-documented,
as
shown
in
figure 2-10. Otherwise, a change to the program at a later time may remove the synchronizing
numeric instruction and cause program failure.
High-level languages automatically establish data synchronization and manage it, but there may be
applications where a high-level language may not be appropriate.
For assembly-language programmers,
automatic data synchronization can be obtained using the assem-
bler, although concurrency of execution
is
lost
as
a result. To perform automatic data synchronization,
the assembler can be changed to always place a WAIT instruction after the
ESCAPE instruction.
Figure
2-11
shows an example of
how
to change the ASM286 Code Macro for the FIST instruction
to
automatically place
aWAIT
instruction after the ESCAPE instruction. This Code Macro
is
included
in
the ASM286 source module. The price paid for this automatic data synchronization
is
the lack of
any possible concurrency between the
CPU and NPX.
Error Synchronization
Almost any numeric instruction can, under the wrong circumstances, produce a numeric error. Concur-
rent execution of the CPU and
NPX
requires synchronization for these errors just
as
it does for data
references and numeric instructions. In fact, the synchronization required for data and instructions
automatically provides error synchronization.
However, incorrect data or instruction synchronization may not be discovered until a numeric error
occurs. A further complication
is
that a programmer may not expect his numeric program to cause
numeric errors, but in some systems, they may regularly happen.
To
better understand these points,
let's look at what can happen when the
NPX
detects an error.
T!!e
NPX
t:'~_!!
l'"rfnrm one of
two
things when a numeric exception occurs:
The
NPX
can provide a default fix-up for selected numeric errors. Programs can mask individual
error types to indicate that the
NPX
should generate a safe, reasonable result whenever that error
occurs. The default error fix-up activity
is
treated by the
NPX
as
part of the instruction causing
the error;
no
external indication of the error
is
given. When errors are detected, a flag
is
set
in
the
numeric status register, but
no
information regarding where
or
when
is
available.
If
the NPX performs
its default action for all errors, then error synchronization
is
never exercised. This
is
no
reason to
ignore error synchronization, however.
2-50