[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

generating cache offsets



I have been examining the reasons that %LOGAND did not work well
in KCL for generating slot value cache offsets, and I no longer 
believe that the problem was with %LOGAND.  

Instead, I think the (cache collision) problem is that AKCL's implementation 
of SXHASH produces results with an unfortunate distribution.
AKCL builds a fixnum from the first, second, second last,
and last characters of the the symbol's print-name.  When PCL does %LOGAND
on this number, all that is left is bit positions 5 to 0 of the second last
character's code, and bit positions 7 to 2 of the last character's code.

I compared AKCL's SXHASH implementation with KCL's SXHASH implementation,
and noticed that KCL's implementation just returns (FLOOR (SI:ADDRESS x) 4),
when x is a symbol, in violation of CLtL's definition of SXHASH.

Fix:
 1) Either remove my changes to get-slot-value-1 and set-slot-value-1.
      (These changes were the only part of my message of November 7 that 
      affected implementations other than KCL.)
    Or change fixnum-cache-no to: 
     (defmacro fixnum-cache-no (mask fixnum)
       (unless (constantp mask)
         (error "FIXNUM-CACHE-NO requires its first argument (mask) to be a constant"))
       (let* ((mask-value (eval mask))
	      (lsize (integer-length mask-value))
	      (size (ash 1 lsize))
	      (words-per-entry (1+ (logxor mask-value (1- size))))
	      (lwords-per-entry (integer-length (1- words-per-entry))))
         `(%logand ,mask (%ash ,fixnum ,lwords-per-entry))))
    The usefulness of the %ash above depends on the sxhash implementation:
    it will help in KCL (otherwise slots named A and B will always collide),
    it (probably) will not help in Symbolics, and it will help in Lucid (SUN3)
    (otherwise slots named B and C will always collide).
 2) If you do have KCL, patch SXHASH:

;; in kcl-patches
(in-package "SYSTEM")

(eval-when (compile load eval)
(unless (fboundp 'sxhash-internal)
(setf (symbol-function 'sxhash-internal) (symbol-function 'sxhash)))
)

(defun sxhash (object)
  (if (symbolp object)
      (let* ((string (symbol-name object))
             (length (length string))
             (h 0))
	(declare (fixnum h length))
	(dotimes (i length h)
	  (declare (fixnum i))
	  (setq h (the fixnum (+ (the fixnum (+ (the fixnum (ash h 8))
						(the fixnum h)))
				 (the fixnum (char-code (aref string i))))))))
      (sxhash-internal object)))


Rick Harris