From c4ee759adf765707fba62c154315f0ed3e9036db Mon Sep 17 00:00:00 2001
From: Raymond Toy <toy.raymond@gmail.com>
Date: Thu, 24 May 2012 20:27:37 -0700
Subject: [PATCH] Clear matching current exceptions when enabling new
 exceptions.  This prevents the exception from being resignaled immediately.

src/code/float-trap.lisp:
o Clear current and accrued exception bits that match any new enabled
  exceptions specified by :traps.

src/general-info/release-20d.txt:
o Update.
---
 src/code/float-trap.lisp         | 15 ++++++++++++++-
 src/general-info/release-20d.txt |  9 ++++++++-
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/code/float-trap.lisp b/src/code/float-trap.lisp
index d800e1486..661614670 100644
--- a/src/code/float-trap.lisp
+++ b/src/code/float-trap.lisp
@@ -155,7 +155,19 @@
    currently in effect."
   (let ((modes (floating-point-modes)))
     (when traps-p
-      (setf (ldb float-traps-byte modes) (float-trap-mask traps)))
+      (let ((trap-mask-bits (float-trap-mask traps)))
+	(setf (ldb float-traps-byte modes) trap-mask-bits)
+	#+(and x86 sse2)
+	(progn
+	  ;; Clear out any current or accrued exceptions that match
+	  ;; the traps that we are enabling.  If we don't then
+	  ;; enabling the traps causes the exceptions to be signaled
+	  ;; immediately.  This is a bit annoying.  If the user really
+	  ;; wants to resignal the exceptions, he can do that himself.
+	  (setf (ldb float-sticky-bits modes)
+		(logandc2 (ldb float-sticky-bits modes) trap-mask-bits))
+	  (setf (ldb float-exceptions-byte modes)
+		(logandc2 (ldb float-exceptions-byte modes) trap-mask-bits)))))
     (when round-p
       (setf (ldb float-rounding-mode modes)
 	    (or (cdr (assoc rounding-mode rounding-mode-alist))
@@ -175,6 +187,7 @@
       (when (member :invalid current-exceptions)
  	;; Clear out the bits for the detected invalid operation
  	(setf (ldb vm:float-invalid-op-1-byte modes) 0)))
+
     (when fast-mode-p
       (if fast-mode
 	  (setq modes (logior float-fast-bit modes))
diff --git a/src/general-info/release-20d.txt b/src/general-info/release-20d.txt
index 0a5c2246e..9dbf560b4 100644
--- a/src/general-info/release-20d.txt
+++ b/src/general-info/release-20d.txt
@@ -42,7 +42,14 @@ New in this release:
     * Updated to Unicode 6.1.0.
     * Many additional aliases for external formats added that match
       the glibc iconv aliases.
-    * Implement faster LOGCOUNT function, if :SSE3 feature is available.
+    * Implement faster LOGCOUNT function on x86, if :SSE3 feature is
+      available.  (Only applies to new uses of LOGCOUNT.  The core
+      uses the default version.)
+    * On x86, SET-FLOATING-POINT-MODES clears any current and accrued
+      exceptions that match exceptions in :TRAPS.  Previously,
+      enabling a trap when the current exception also listed that trap
+      caused the exception to be immediately signaled.  This no longer
+      happens and now matches how ppc and sparc behave.
       
   * ANSI compliance fixes:
     * CMUCL was not printing pathnames like (make-pathname :directory
-- 
GitLab