X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Fgeneric%2Futils.lisp;h=7b433a21b61c2dcdb62c140b2efe469ffce09a6c;hb=45bc305be4e269d2e1a477c8e0ae9a64df1ccd1c;hp=38fa31cd57452ab83c6140ef2a2fb75c0c7af069;hpb=27a028cff1559dec1cb1faaee01659ade816c908;p=sbcl.git diff --git a/src/compiler/generic/utils.lisp b/src/compiler/generic/utils.lisp index 38fa31c..7b433a2 100644 --- a/src/compiler/generic/utils.lisp +++ b/src/compiler/generic/utils.lisp @@ -14,9 +14,19 @@ ;;; Make a fixnum out of NUM. (I.e. shift by two bits if it will fit.) (defun fixnumize (num) - (if (<= #x-20000000 num #x1fffffff) - (ash num 2) + (if (fixnump num) + (ash num (1- n-lowtag-bits)) (error "~W is too big for a fixnum." num))) + +;;; Determining whether a constant offset fits in an addressing mode. +#!+(or x86 x86-64) +(defun foldable-constant-offset-p (element-size lowtag data-offset offset) + (if (< element-size n-byte-bits) + nil + (multiple-value-bind (min max) + (sb!impl::displacement-bounds lowtag element-size data-offset) + (<= min offset max)))) + ;;;; routines for dealing with static symbols @@ -28,11 +38,11 @@ (defun static-symbol-offset (symbol) (if symbol (let ((posn (position symbol *static-symbols*))) - (unless posn (error "~S is not a static symbol." symbol)) - (+ (* posn (pad-data-block symbol-size)) - (pad-data-block (1- symbol-size)) - other-pointer-lowtag - (- list-pointer-lowtag))) + (unless posn (error "~S is not a static symbol." symbol)) + (+ (* posn (pad-data-block symbol-size)) + (pad-data-block (1- symbol-size)) + other-pointer-lowtag + (- list-pointer-lowtag))) 0)) ;;; Given a byte offset, OFFSET, return the appropriate static symbol. @@ -40,18 +50,18 @@ (if (zerop offset) nil (multiple-value-bind (n rem) - (truncate (+ offset list-pointer-lowtag (- other-pointer-lowtag) - (- (pad-data-block (1- symbol-size)))) - (pad-data-block symbol-size)) - (unless (and (zerop rem) (<= 0 n (1- (length *static-symbols*)))) - (error "The byte offset ~W is not valid." offset)) - (elt *static-symbols* n)))) + (truncate (+ offset list-pointer-lowtag (- other-pointer-lowtag) + (- (pad-data-block (1- symbol-size)))) + (pad-data-block symbol-size)) + (unless (and (zerop rem) (<= 0 n (1- (length *static-symbols*)))) + (error "The byte offset ~W is not valid." offset)) + (elt *static-symbols* n)))) ;;; Return the (byte) offset from NIL to the start of the fdefn object ;;; for the static function NAME. (defun static-fun-offset (name) (let ((static-syms (length *static-symbols*)) - (static-fun-index (position name *static-funs*))) + (static-fun-index (position name *static-funs*))) (unless static-fun-index (error "~S isn't a static function." name)) (+ (* static-syms (pad-data-block symbol-size))