X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Fgeneric%2Fvm-macs.lisp;h=ef031a952cbe5a3af01ff4b5bca8e82f527fdf73;hb=4af254de85367806d14ccafc4dfbe79a235b926d;hp=2984db4948b97926052abe1fe2aaf5865c958f4f;hpb=98743008038a932dc6b53560d121df69c40e40ad;p=sbcl.git diff --git a/src/compiler/generic/vm-macs.lisp b/src/compiler/generic/vm-macs.lisp index 2984db4..ef031a9 100644 --- a/src/compiler/generic/vm-macs.lisp +++ b/src/compiler/generic/vm-macs.lisp @@ -152,10 +152,18 @@ ;;; Modular functions -;;; hash: name -> ({(width . fun)}*) +;;; For a documentation, see CUT-TO-WIDTH. + +;;; hash: name -> { :GOOD | optimizer | ({modular-fun-info}*)} (defvar *modular-funs* (make-hash-table :test 'eq)) +;;; hash: modular-variant -> (prototype width) +;;; +;;; FIXME: Reimplement with generic function names of kind +;;; (MODULAR-VERSION prototype width) +(defvar *modular-versions* (make-hash-table :test 'eq)) + ;;; List of increasing widths (defvar *modular-funs-widths* nil) (defstruct modular-fun-info @@ -166,9 +174,15 @@ (defun find-modular-version (fun-name width) (let ((infos (gethash fun-name *modular-funs*))) - (find-if (lambda (item-width) (>= item-width width)) - infos - :key #'modular-fun-info-width))) + (if (listp infos) + (find-if (lambda (item-width) (>= item-width width)) + infos + :key #'modular-fun-info-width) + infos))) + +;;; Return (VALUES prototype-name width) +(defun modular-version-info (name) + (values-list (gethash name *modular-versions*))) (defun %define-modular-fun (name lambda-list prototype width) (let* ((infos (the list (gethash prototype *modular-funs*))) @@ -189,7 +203,9 @@ :lambda-list lambda-list :prototype prototype)) infos - #'< :key #'modular-fun-info-width)))) + #'< :key #'modular-fun-info-width) + (gethash name *modular-versions*) + (list prototype width)))) (setq *modular-funs-widths* (merge 'list (list width) *modular-funs-widths* #'<))) @@ -206,3 +222,30 @@ (defknown ,name ,(mapcar (constantly 'integer) lambda-list) (unsigned-byte ,width) (foldable flushable movable)))) + +(defun %define-good-modular-fun (name) + (setf (gethash name *modular-funs*) :good) + name) + +(defmacro define-good-modular-fun (name) + (check-type name symbol) + `(%define-good-modular-fun ',name)) + +(defmacro define-modular-fun-optimizer + (name ((&rest lambda-list) &key (width (gensym "WIDTH"))) + &body body) + (check-type name symbol) + (dolist (arg lambda-list) + (when (member arg lambda-list-keywords) + (error "Lambda list keyword ~S is not supported for ~ + modular function lambda lists." arg))) + (with-unique-names (call args) + `(setf (gethash ',name *modular-funs*) + (lambda (,call ,width) + (declare (type basic-combination ,call) + (type (integer 0) width)) + (let ((,args (basic-combination-args ,call))) + (when (= (length ,args) ,(length lambda-list)) + (destructuring-bind ,lambda-list ,args + (declare (type lvar ,@lambda-list)) + ,@body)))))))