Volume 1 Application Programming (794095), страница 70
Текст из файла (страница 70)
Thus,FSTENV (but not FNSTENV) reports pending unmasked x87 floating-point exceptions before storingthe status word.The x87 environment includes the x87 control word register, x87 status word register, x87 tag word,last x87 instruction pointer, last x87 data pointer, and last x87 opcode. See “Media and x87 ProcessorState” in Volume 2 for details on how the x87 environment is stored in memory.276x87 Floating-Point Programming24592—Rev.
3.13—July 2007AMD64 TechnologySave and Restore x87 and 64-Bit Media State• FSAVE—Save x87 and MMX State.• FNSAVE—Save No-Wait x87 and MMX State.• FRSTOR—Restore x87 and MMX State.These instructions save and restore the entire processor state for x87 floating-point instructions and64-bit media instructions. The instructions save and restore either 94 or 108 bytes of data, dependingon the effective operand size.Assemblers issue FSAVE as an FWAIT instruction followed by an FNSAVE instruction. Thus, FSAVE(but not FNSAVE) reports pending unmasked x87 floating-point exceptions before saving the state.After saving the state, the processor initializes the x87 state by performing the equivalent of an FINITinstruction.
For details, see “State-Saving” on page 291.Save and Restore x87, 128-Bit, and 64-Bit State• FXSAVE—Save XMM, MMX, and x87 State.• FXRSTOR—Restore XMM, MMX, and x87 State.The FXSAVE and FXRSTOR instructions save and restore the entire 512-byte processor state for 128bit media instructions, 64-bit media instructions, and x87 floating-point instructions. The architecturesupports two memory formats for FXSAVE and FXRSTOR, a 512-byte 32-bit legacy format and a512-byte 64-bit format. Selection of the 32-bit or 64-bit format is determined by the effective operandsize for the FXSAVE and FXRSTOR instructions. For details, see “Media and x87 Processor State” inVolume 2.FXSAVE and FXRSTOR execute faster than FSAVE/FNSAVE and FRSTOR.
However, unlikeFSAVE and FNSAVE, FXSAVE does not initialize the x87 state, and like FNSAVE it does not reportpending unmasked x87 floating-point exceptions. For details, see “State-Saving” on page 291.6.5Instruction Effects on rFLAGSThe rFLAGS register is described in “Flags Register” on page 33. Table 6-16 on page 278 summarizesthe effect that x87 floating-point instructions have on individual flags within the rFLAGS register.Only instructions that access the rFLAGS register are shown—all other x87 instructions have no effecton rFLAGS.The following codes are used within the table:•••Mod—The flag is modified.Tst—The flag is tested.Gray shaded cells indicate the flag is not affected by the instruction.x87 Floating-Point Programming277AMD64 Technology24592—Rev.
3.13—July 2007Table 6-16.InstructionMnemonic6.6Instruction Effects on rFLAGSrFLAGS Mnemonic and Bit NumberOF11SF7ZF6AF4PF2CF0FCMOVccTstTstTstFCOMIFCOMIPFUCOMIFUCOMIPModModModInstruction PrefixesInstruction prefixes, in general, are described in “Instruction Prefixes” on page 71. The followingrestrictions apply to the use of instruction prefixes with x87 instructions.Supported Prefixes. The following prefixes can be used with x87 instructions:••••Operand-Size Override—The 66h prefix affects only the FLDENV, FSTENV, FNSTENV,FSAVE, FNSAVE, and FRSTOR instructions, in which it selects between a 16-bit and 32-bitmemory-image format.
The prefix is ignored by all other x87 instructions.Address-Size Override—The 67h prefix affects only operands in memory, in which it selectsbetween a 16-bit and 32-bit addresses. The prefix is ignored by all other x87 instructions.Segment Overrides—The 2Eh (CS), 36h (SS), 3Eh (DS), 26h (ES), 64h (FS), and 65h (GS)prefixes specify a segment. They affect only operands in memory. In 64-bit mode, the CS, DS, ES,SS segment overrides are ignored.REX—The REX.W bit affects the FXSAVE and FXRSTOR instructions, in which it selectsbetween two types of 512-byte memory-image formats, as described in "Saving Media and x87Processor State" in Volume 2.
The REX.W bit also affects the FLDENV, FSTENV, FSAVE, andFRSTOR instructions, in which it selects the 32-bit memory-image format. The REX.R, REX.X,and REX.B bits only affect operands in memory, in which they are used to find the memoryoperand.Ignored Prefixes. The following prefixes are ignored by x87 instructions:•REP—The F3h and F2h prefixes.Prefixes That Cause Exceptions. The following prefixes cause an exception:•LOCK—The F0h prefix causes an invalid-opcode exception when used with x87 instructions.278x87 Floating-Point Programming24592—Rev.
3.13—July 20076.7AMD64 TechnologyFeature DetectionBefore executing x87 floating-point instructions, software should determine if the processor supportsthe technology by executing the CPUID instruction. “Feature Detection” on page 74 describes howsoftware uses the CPUID instruction to detect feature support. For full support of the x87 floatingpoint features, the following feature must be present:••On-Chip Floating-Point Unit, indicated by bit 0 of CPUID function 1 and CPUID function8000_0001h.CMOVcc (conditional moves), indicated by bit 15 of CPUID function 1 and CPUID function8000_0001h.
This bit indicates support for x87 floating-point conditional moves (FCMOVcc)whenever the On-Chip Floating-Point Unit bit (bit 0) is also set.Software may also wish to check for the following support, because the FXSAVE and FXRSTORinstructions execute faster than FSAVE and FRSTOR:•FXSAVE and FXRSTOR, indicated by bit 24 of CPUID function 1 and function 8000_0001h.Software that runs in long mode should also check for the following support:•Long Mode, indicated by bit 29 of CPUID function 8000_0001h.See “Processor Feature Identification” in Volume 2 for a full description of the CPUID instruction andits function codes.6.8ExceptionsTypes of Exceptions.
x87 instructions can generate two types of exceptions:••General-Purpose Exceptions, described below in “General-Purpose Exceptions”x87 Floating-Point Exceptions (#MF), described in “x87 Floating-Point Exception Causes” onpage 280Relation to 128-Bit Media Exceptions. Although the x87 floating-point instructions and the 128-bitmedia instructions each have certain exceptions with the same names, the exception-reporting andexception-handling methods used by the two instruction subsets are distinct and independent of eachother. If procedures using both types of instructions are run in the same operating environment,separate service routines should be provided for the exceptions of each type of instruction subset.6.8.1 General-Purpose ExceptionsThe sections below list general-purpose exceptions generated and not generated by x87 floating-pointinstructions. For a summary of the general-purpose exception mechanism, see “Interrupts andExceptions” on page 86.
For details about each exception and its potential causes, see “Exceptions andInterrupts” in Volume 2.Exceptions Generated. x87 instructions can generate the following general-purpose exceptions:x87 Floating-Point Programming279AMD64 Technology•••••••••••24592—Rev. 3.13—July 2007#DB—Debug Exception (Vector 1)#BP—Breakpoint Exception (Vector 3)#UD—Invalid-Opcode Exception (Vector 6)#NM—Device-Not-Available Exception (Vector 7)#DF—Double-Fault Exception (Vector 8)#SS—Stack Exception (Vector 12)#GP—General-Protection Exception (Vector 13)#PF—Page-Fault Exception (Vector 14)#MF—x87 Floating-Point Exception-Pending (Vector 16)#AC—Alignment-Check Exception (Vector 17)#MC—Machine-Check Exception (Vector 18)For details on #MF exceptions, see “x87 Floating-Point Exception Causes” below.Exceptions Not Generated.
x87 instructions do not generate the following general-purposeexceptions:••••#DE—Divide-by-zero-error exception (Vector 0)Non-Maskable-Interrupt Exception (Vector 2)#OF—Overflow exception (Vector 4)#BR—Bound-range exception (Vector 5)•••••Coprocessor-segment-overrun exception (Vector 9)#TS—Invalid-TSS exception (Vector 10)#NP—Segment-not-present exception (Vector 11)#MC—Machine-check exception (Vector 18)#XF—SIMD floating-point exception (Vector 19)For details on all general-purpose exceptions, see “Exceptions and Interrupts” in Volume 2.6.8.2 x87 Floating-Point Exception CausesThe x87 floating-point exception-pending (#MF) exception listed above in “General-PurposeExceptions” is actually the logical OR of six exceptions that can be caused by x87 floating-pointinstructions.
Each of the six exceptions has a status flag in the x87 status word and a mask bit in thex87 control word. A seventh exception, stack fault (SF), is reported together with one of the sixmaskable exceptions and does not have a mask bit.If a #MF exception occurs when its mask bit is set to 1 (masked), the processor responds in a defaultway that does not invoke the #MF exception service routine. If an exception occurs when its mask bit iscleared to 0 (unmasked), the processor suspends processing of the faulting instruction (if possible) and,at the boundary of the next non-control x87 or 64-bit media instruction (see “Control” on page 274),280x87 Floating-Point Programming24592—Rev.