X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Faliencomp.lisp;h=5ff94274b2120d8c146061843b9aa481611d66a7;hb=d1441ffce0db0043ccbcb27fa5ab590e44a85994;hp=697410a8f05eb8c9b7afd67753b88fe698159ea9;hpb=57e21c4b62e8c1a1ee7ef59ed2abb0c864fb06bc;p=sbcl.git diff --git a/src/compiler/aliencomp.lisp b/src/compiler/aliencomp.lisp index 697410a..5ff9427 100644 --- a/src/compiler/aliencomp.lisp +++ b/src/compiler/aliencomp.lisp @@ -61,9 +61,9 @@ (flushable movable)) (defknown deport (alien alien-type) t (flushable movable)) -(defknown extract-alien-value (system-area-pointer index alien-type) t +(defknown extract-alien-value (system-area-pointer unsigned-byte alien-type) t (flushable)) -(defknown deposit-alien-value (system-area-pointer index alien-type t) t +(defknown deposit-alien-value (system-area-pointer unsigned-byte alien-type t) t ()) (defknown alien-funcall (alien-value &rest *) * @@ -520,7 +520,8 @@ (count-low-order-zeros (lvar-value thing)) (count-low-order-zeros (lvar-uses thing)))) (combination - (case (lvar-fun-name (combination-fun thing)) + (case (let ((name (lvar-fun-name (combination-fun thing)))) + (or (modular-version-info name) name)) ((+ -) (let ((min most-positive-fixnum) (itype (specifier-type 'integer))) @@ -553,15 +554,18 @@ (do ((result 0 (1+ result)) (num thing (ash num -1))) ((logbitp 0 num) result)))) + (cast + (count-low-order-zeros (cast-value thing))) (t 0))) (deftransform / ((numerator denominator) (integer integer)) + "convert x/2^k to shift" (unless (constant-lvar-p denominator) (give-up-ir1-transform)) (let* ((denominator (lvar-value denominator)) (bits (1- (integer-length denominator)))) - (unless (= (ash 1 bits) denominator) + (unless (and (> denominator 0) (= (ash 1 bits) denominator)) (give-up-ir1-transform)) (let ((alignment (count-low-order-zeros numerator))) (unless (>= alignment bits) @@ -570,20 +574,29 @@ (deftransform ash ((value amount)) (let ((value-node (lvar-uses value))) - (unless (and (combination-p value-node) - (eq (lvar-fun-name (combination-fun value-node)) - 'ash)) + (unless (combination-p value-node) (give-up-ir1-transform)) - (let ((inside-args (combination-args value-node))) - (unless (= (length inside-args) 2) - (give-up-ir1-transform)) - (let ((inside-amount (second inside-args))) - (unless (and (constant-lvar-p inside-amount) - (not (minusp (lvar-value inside-amount)))) - (give-up-ir1-transform))))) - (extract-fun-args value 'ash 2) - '(lambda (value amount1 amount2) - (ash value (+ amount1 amount2)))) + (let ((inside-fun-name (lvar-fun-name (combination-fun value-node)))) + (multiple-value-bind (prototype width) + (modular-version-info inside-fun-name) + (unless (eq (or prototype inside-fun-name) 'ash) + (give-up-ir1-transform)) + (when (and width (not (constant-lvar-p amount))) + (give-up-ir1-transform)) + (let ((inside-args (combination-args value-node))) + (unless (= (length inside-args) 2) + (give-up-ir1-transform)) + (let ((inside-amount (second inside-args))) + (unless (and (constant-lvar-p inside-amount) + (not (minusp (lvar-value inside-amount)))) + (give-up-ir1-transform))) + (extract-fun-args value inside-fun-name 2) + (if width + `(lambda (value amount1 amount2) + (logand (ash value (+ amount1 amount2)) + ,(1- (ash 1 (+ width (lvar-value amount)))))) + `(lambda (value amount1 amount2) + (ash value (+ amount1 amount2))))))))) ;;;; ALIEN-FUNCALL support