F-3
GUIDELINES FOR WRITING SIMD FLOATING-POINT EXCEPTION
Example F-1. SIMD Floating-Point Exception Handler
SIMD_FP_EXC_HANDLER PROC
;
;;; PROLOGUE
; SAVE REGISTERS
PUSH EBP
; SAVE EBP
PUSH EAX
; SAVE EAX
...
MOV EBP, ESP
; SAVE ESP in EBP
SUB ESP, 512
; ALLOCATE 512 BYTES
AND ESP, 0fffffff0h
; MAKE THE ADDRESS 16-BYTE ALIGNED
FXSAVE [ESP]
; SAVE FP, MMX, AND SIMD FP STATE
PUSH [EBP+EFLAGS_OFFSET]; COPY OLD EFLAGS TO STACK TOP
POPD
;RESTORE THE INTERRUPT ENABLE FLAG IF
;TO VALUE BEFORE SIMD FP EXCEPTION
;
;;; BODY
; APPLICATION-DEPENDENT EXCEPTION HANDLING CODE GOES HERE
LDMXCSR LOCAL_MXCSR
; LOAD LOCAL FPU CW IF NEEDED
...
...
;
;;; EPILOGUE
FXRSTOR [ESP]
; RESTORE MODIFIED STATE IMAGE
MOV ESP, EBP
; DE-ALLOCATE STACK SPACE
...
POP EAX
; RESTORE EAX
POP EBP
; RESTORE EBP
IRET
; RETURN TO INTERRUPTED CALCULATION
SIMD_FP_EXC_HANDLER ENDP
F.3.EXCEPTION SYNCHRONIZATION
A Streaming SIMD Extensions instruction can execute in parallel with other similar instruc-
tions, with integer instructions, and with floating-point or MMX instructions. Exception syn-
chronization may therefore be necessary, similarly to the situation described in Section E.3.3.,
Synchronization Required for Use of FPU Exception Handlers in Appendix E, Guidelines for
Writing FPU Exceptions Handlers). Careful coding will ensure proper synchronization in case
a floating-point exception handler is invoked, and will lead to reliable performance.