X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Ffloat-trap.lisp;h=6a021397486de60ffb3a4a0a448425dcaea5f22d;hb=5877e8c2334bd87490be385af21ed9bc494f19e2;hp=dca677141af9e5fa12302d1c48c7d771a358e94f;hpb=8197ef56f02105dfe825b976f5bf74285a767b42;p=sbcl.git diff --git a/src/code/float-trap.lisp b/src/code/float-trap.lisp index dca6771..6a02139 100644 --- a/src/code/float-trap.lisp +++ b/src/code/float-trap.lisp @@ -47,8 +47,8 @@ ;;; interpreter stubs for floating point modes get/setters for the ;;; alpha have been removed to alpha-vm.lisp, as they are implemented -;;; in C rather than as VOPs. -#!-(or alpha x86-64) +;;; in C rather than as VOPs. Likewise for x86-64 and mips. +#!-(or alpha x86-64 mips) (progn (defun floating-point-modes () (floating-point-modes)) @@ -118,7 +118,8 @@ in effect." (or (cdr (assoc precision *precision-mode-alist*)) (error "unknown precision mode: ~S" precision)))) ;; FIXME: This apparently doesn't work on Darwin - #!-darwin (setf (floating-point-modes) modes)) + #!-(and darwin ppc) + (setf (floating-point-modes) modes)) (values)) (defun get-floating-point-modes () @@ -158,7 +159,7 @@ sets the floating point modes to their current values (and thus is a no-op)." ;;; disabled by default. Joe User can explicitly enable them if ;;; desired. (defvar *saved-floating-point-modes* - '(:traps (:overflow #!-netbsd :invalid :divide-by-zero) + '(:traps (:overflow #!-(or netbsd ppc) :invalid :divide-by-zero) :rounding-mode :nearest :current-exceptions nil :accrued-exceptions nil :fast-mode nil #!+x86 :precision #!+x86 :53-bit)) @@ -175,33 +176,27 @@ sets the floating point modes to their current values (and thus is a no-op)." `(not (zerop (logand ,(dpb (float-trap-mask traps) float-traps-byte 0) (floating-point-modes))))) +;;; SIGFPE code to floating-point error +#!-win32 +(defparameter *sigfpe-code-error-alist* + (list (cons sb!unix::fpe-intovf 'floating-point-overflow) + (cons sb!unix::fpe-intdiv 'division-by-zero) + (cons sb!unix::fpe-fltdiv 'division-by-zero) + (cons sb!unix::fpe-fltovf 'floating-point-overflow) + (cons sb!unix::fpe-fltund 'floating-point-underflow) + (cons sb!unix::fpe-fltres 'floating-point-inexact) + (cons sb!unix::fpe-fltinv 'floating-point-invalid-operation) + (cons sb!unix::fpe-fltsub 'floating-point-exception))) + ;;; Signal the appropriate condition when we get a floating-point error. #!-win32 (defun sigfpe-handler (signal info context) - (declare (ignore signal info)) - (declare (type system-area-pointer context)) - (let* ((modes (context-floating-point-modes - (sb!alien:sap-alien context (* os-context-t)))) - (traps (logand (ldb float-exceptions-byte modes) - (ldb float-traps-byte modes)))) + (declare (ignore signal context)) + (declare (type system-area-pointer info)) + (let ((code (sb!unix::siginfo-code info))) (with-interrupts - (cond ((not (zerop (logand float-divide-by-zero-trap-bit traps))) - (error 'division-by-zero)) - ((not (zerop (logand float-invalid-trap-bit traps))) - (error 'floating-point-invalid-operation)) - ((not (zerop (logand float-overflow-trap-bit traps))) - (error 'floating-point-overflow)) - ((not (zerop (logand float-underflow-trap-bit traps))) - (error 'floating-point-underflow)) - ((not (zerop (logand float-inexact-trap-bit traps))) - (error 'floating-point-inexact)) - #!+freebsd - ((zerop (ldb float-exceptions-byte modes)) - ;; I can't tell what caused the exception!! - (error 'floating-point-exception - :traps (getf (get-floating-point-modes) :traps))) - (t - (error 'floating-point-exception)))))) + (error (or (cdr (assoc code *sigfpe-code-error-alist*)) + 'floating-point-exception))))) ;;; Execute BODY with the floating point exceptions listed in TRAPS ;;; masked (disabled). TRAPS should be a list of possible exceptions