X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fpcl%2Fcache.lisp;h=11659226a160638915212a61b60b9ce1f94ad2e1;hb=b83353d9f998e5c0e34604b5593df70c66d2c510;hp=e7f60e4d6502f28b7319652849c274c9c99cc9f4;hpb=db770d287bb64a58967d08fdd8225c02cdd4d45a;p=sbcl.git diff --git a/src/pcl/cache.lisp b/src/pcl/cache.lisp index e7f60e4..1165922 100644 --- a/src/pcl/cache.lisp +++ b/src/pcl/cache.lisp @@ -53,7 +53,7 @@ ;;;; ;;;; * Since the cache is used for memoization only we don't need to ;;;; worry about which of simultaneous replacements (when expanding -;;;; the cache) takes place: the loosing one will have its work +;;;; the cache) takes place: the losing one will have its work ;;;; redone later. This also allows us to drop entries when the ;;;; cache is about to grow insanely huge. ;;;; @@ -104,11 +104,6 @@ ;; bits at the low end. (logand (1- vector-length) (- line-size))) -;;; The smallest power of two that is equal to or greater then X. -(declaim (inline power-of-two-ceiling)) -(defun power-of-two-ceiling (x) - (ash 1 (integer-length (1- x)))) - (defun cache-statistics (cache) (let* ((vector (cache-vector cache)) (size (length vector)) @@ -322,8 +317,6 @@ ;; Make a smaller one, then (make-cache :key-count key-count :value value :size (ceiling size 2))))) -(defconstant n-fixnum-bits #.(integer-length most-positive-fixnum)) - ;;;; Copies and expands the cache, dropping any invalidated or ;;;; incomplete lines. (defun copy-and-expand-cache (cache layouts value) @@ -343,8 +336,8 @@ (cache-mask copy) (compute-cache-mask length (cache-line-size cache)) (cache-limit copy) (compute-limit (/ length (cache-line-size cache)))) ;; First insert the new one -- if we don't do this first and - ;; the cache has reached it's maximum size we may end up - ;; looping in FILL-CACHE. + ;; the cache has reached its maximum size we may end up looping + ;; in FILL-CACHE. (unless (try-update-cache copy layouts value) (bug "Could not insert ~S:~S to supposedly empty ~S." layouts value copy)) (map-cache (if drop-random-entries @@ -355,25 +348,15 @@ ;; rut: add A causing B to drop, then add B ;; causing A to drop... repeat ad nauseam, ;; spending most of the time here instead of - ;; doing real work. 50% because if we drop to + ;; doing real work. 50% because if we drop too ;; few we need to do this almost right away - ;; again, and if we drop to many, we need to + ;; again, and if we drop too many, we need to ;; recompute more then we'd like. ;; _Experimentally_ 50% seems to perform the ;; best, but it would be nice to have a proper ;; analysis... - (flet ((random-fixnum () - (random (1+ most-positive-fixnum)))) - (let ((drops (random-fixnum)) - (drop-pos n-fixnum-bits)) - (declare (fixnum drops) - (type (integer 0 #.n-fixnum-bits) drop-pos)) - (lambda (layouts value) - (when (logbitp (the unsigned-byte (decf drop-pos)) drops) - (try-update-cache copy layouts value)) - (when (zerop drop-pos) - (setf drops (random-fixnum) - drop-pos n-fixnum-bits))))) + (randomly-punting-lambda (layouts value) + (try-update-cache copy layouts value)) (lambda (layouts value) (unless (try-update-cache copy layouts value) ;; Didn't fit -- expand the cache, or drop