Changeset 7839
- Timestamp:
- Dec 6, 2007, 8:32:49 PM (17 years ago)
- File:
-
- 1 edited
-
branches/working-0711/ccl/level-1/l1-dcode.lisp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/working-0711/ccl/level-1/l1-dcode.lisp
r7837 r7839 186 186 Returns NIL - without storing anything - if the value already in DT 187 187 at INDEX is non-NIL at the time of the store." 188 (%store-node-conditional (+ (ash (%i+ index %gf-dispatch-table-first-data) 189 target::word-shift) 190 target::misc-data-offset) 191 dt nil new)) 188 (let ((offset (+ (ash (%i+ index %gf-dispatch-table-first-data) 189 target::word-shift) 190 target::misc-data-offset))) 191 (or (%store-node-conditional offset dt nil new) 192 (%store-node-conditional offset dt *gf-dispatch-bug* new)))) 192 193 193 194 (defun grow-gf-dispatch-table (gf-or-cm wrapper table-entry &optional obsolete-wrappers-p) … … 682 683 (setf contains-obsolete-wrappers-p t 683 684 (%gf-dispatch-table-ref dt index) *obsolete-wrapper* 684 (%gf-dispatch-table-ref dt (1+ index)) 685 #'(lambda (&rest rest) 686 (declare (ignore rest)) 687 (error "Generic-function dispatch bug."))) 685 (%gf-dispatch-table-ref dt (1+ index)) *gf-dispatch-bug*) 688 686 (setq count (%i+ count 1))))) 689 687 (setq index (%i+ index 2))) … … 854 852 (combined-method (compute-1st-arg-combined-method gf arg wrapper))) 855 853 (multiple-value-bind (index obsolete-wrappers-p) 856 (find-gf-dispatch-table-index table wrapper)854 (find-gf-dispatch-table-index table wrapper) 857 855 (if index 858 (if (%gf-dispatch-table-store-conditional table (%i+ index 1) combined-method)859 (setf (%gf-dispatch-table-ref table index) wrapper))860 (grow-gf-dispatch-table gf wrapper combined-method obsolete-wrappers-p)))856 (if (%gf-dispatch-table-store-conditional table (%i+ index 1) combined-method) 857 (setf (%gf-dispatch-table-ref table index) wrapper)) 858 (grow-gf-dispatch-table gf wrapper combined-method obsolete-wrappers-p))) 861 859 combined-method)) 862 860 … … 1249 1247 wrapper) 1250 1248 (multiple-value-bind (index obsolete-wrappers-p) 1251 ( find-gf-dispatch-table-index table wrapper)1249 (find-gf-dispatch-table-index table wrapper) 1252 1250 (if index 1253 1251 (if (%gf-dispatch-table-store-conditional table (%i+ index 1) combined-method) 1254 (setf (%gf-dispatch-table-ref table index) wrapper))1252 (setf (%gf-dispatch-table-ref table index) wrapper)) 1255 1253 (grow-gf-dispatch-table gf-or-cm wrapper combined-method obsolete-wrappers-p))) 1256 1254 (if sub-dispatch? … … 1336 1334 1337 1335 1338 1339 ;;; This needs to be updated to use a linear search in a vector changing to 1340 ;;; a hash table when the number of entries crosses some threshold. 1336 (defun compute-eql-combined-method-hash-table-threshold (&optional (iters 1000000) (max 200)) 1337 (flet ((time-assq (cnt iters) 1338 (let ((alist (loop for i from 1 to cnt collect (cons i i))) 1339 (start-time (get-internal-run-time)) 1340 (j 0) 1341 res) 1342 (declare (fixnum j)) 1343 (dotimes (i iters) 1344 (declare (fixnum i)) 1345 (setq res (cdr (assq j alist))) 1346 (when (>= (incf j) cnt) (setq j 0))) 1347 (values (- (get-internal-run-time) start-time) res))) 1348 (time-hash (cnt iters) 1349 (let ((hash (make-hash-table :test 'eq)) 1350 start-time 1351 (j 0) 1352 res) 1353 (declare (fixnum j)) 1354 (dotimes (i cnt) 1355 (setf (gethash i hash) i)) 1356 (assert-hash-table-readonly hash) 1357 (setq start-time (get-internal-run-time)) 1358 (dotimes (i iters) 1359 (declare (fixnum i)) 1360 (setq res (gethash i hash)) 1361 (when (>= (incf j) cnt) (setq j 0))) 1362 (values (- (get-internal-run-time) start-time) res)))) 1363 (dotimes (i max) 1364 (let ((time-assq (time-assq i iters)) 1365 (time-hash (time-hash i iters))) 1366 (format t "i: ~d, assq: ~d, hash: ~d~%" i time-assq time-hash) 1367 (when (> time-assq time-hash) (return i)))))) 1368 1369 ;; Value computed on a dual-core 2.4 GHz AMD Opteron running FC3 1370 ;; This isn't the result of compute-eql-combined-method-hash-table-threshold, 1371 ;; it's the value at which assq takes 3/4 the time of hash, which weights 1372 ;; towards the worst case of the eql method, not the average for uniform inputs. 1373 (defparameter *eql-combined-method-hash-table-threshold* 45) 1374 1375 ;;; A vector might be a little faster than an alist, but the hash table case 1376 ;;; will speed up large numbers of methods. 1341 1377 (defun make-eql-combined-method (eql-methods methods cpls gf argnum sub-dispatch? &optional 1342 1378 (method-combination *standard-method-combination*)) … … 1408 1444 real-gf method-combination methods))))) 1409 1445 (if eql-method-alist 1410 (%cons-combined-method 1411 gf (cons argnum (cons eql-method-alist default-method)) 1412 (if can-use-eq? 1413 #'%%assq-combined-method-dcode 1414 #'%%assoc-combined-method-dcode)) 1446 (if (> (length eql-method-alist) *eql-combined-method-hash-table-threshold*) 1447 (let ((hash (make-hash-table :test (if can-use-eq? 'eq 'eql)))) 1448 (dolist (pair eql-method-alist) 1449 (setf (gethash (car pair) hash) (cdr pair))) 1450 (assert-hash-table-readonly hash) 1451 (%cons-combined-method 1452 gf (cons argnum (cons hash default-method)) 1453 #'%%hash-table-combined-method-dcode)) 1454 (%cons-combined-method 1455 gf (cons argnum (cons eql-method-alist default-method)) 1456 (if can-use-eq? 1457 #'%%assq-combined-method-dcode 1458 #'%%assoc-combined-method-dcode))) 1415 1459 default-method)))) 1416 1417 1418 1460 1419 1461 … … 1460 1502 (%apply-lexpr (cdr thing) args) 1461 1503 (%apply-lexpr (cddr stuff) args)))))) 1504 1505 1506 (defun %%hash-table-combined-method-dcode (stuff args) 1507 ;; stuff is (argnum eql-hash-table . default-method) 1508 ;(declare (dynamic-extent args)) 1509 (if (listp args) 1510 (let* ((args-len (list-length args)) 1511 (argnum (car stuff))) 1512 (when (>= argnum args-len)(signal-program-error "Too few args to ~s." (%method-gf (cddr stuff)))) 1513 (let* ((arg (nth argnum args))) 1514 (apply (gethash arg (cadr stuff) (cddr stuff)) args))) 1515 (let* ((args-len (%lexpr-count args)) 1516 (argnum (car stuff))) 1517 (when (>= argnum args-len)(signal-program-error "Too few args to ~s." (%method-gf (cddr stuff)))) 1518 (let* ((arg (%lexpr-ref args args-len argnum))) 1519 (%apply-lexpr (gethash arg (cadr stuff) (cddr stuff)) args))))) 1462 1520 1463 1521
Note:
See TracChangeset
for help on using the changeset viewer.
