- (move boxed boxed-arg)
- (inst add boxed (fixnumize (1+ code-trace-table-offset-slot)))
- (inst and boxed (lognot lowtag-mask))
- (move unboxed unboxed-arg)
- (inst shr unboxed word-shift)
- (inst add unboxed lowtag-mask)
- (inst and unboxed (lognot lowtag-mask))
- (pseudo-atomic
- ;; comment from CMU CL code:
- ;; now loading code into static space cause it can't move
- ;;
- ;; KLUDGE: What? What's all the cruft about saving fixups for then?
- ;; I think what's happened is that ALLOCATE-CODE-OBJECT is the basic
- ;; CMU CL primitive; this ALLOCATE-CODE-OBJECT was hacked for
- ;; static space only in a simple-minded port to the X86; and then
- ;; in an attempt to improve the port to the X86,
- ;; ALLOCATE-DYNAMIC-CODE-OBJECT was defined. If that's right, I'd like
- ;; to know why not just go back to the basic CMU CL behavior of
- ;; ALLOCATE-CODE-OBJECT, where it makes a relocatable code object.
- ;; -- WHN 19990916
- ;;
- ;; FIXME: should have a check for overflow of static space
- (load-symbol-value temp sb!vm:*static-space-free-pointer*)
- (inst lea result (make-ea :byte :base temp :disp other-pointer-type))
- (inst add temp boxed)
- (inst add temp unboxed)
- (store-symbol-value temp sb!vm:*static-space-free-pointer*)
- (inst shl boxed (- type-bits word-shift))
- (inst or boxed code-header-type)
- (storew boxed result 0 other-pointer-type)
- (storew unboxed result code-code-size-slot other-pointer-type)
- (inst mov temp nil-value)
- (storew temp result code-entry-points-slot other-pointer-type))
- (storew temp result code-debug-info-slot other-pointer-type)))
-
-(define-vop (allocate-dynamic-code-object)
+ (let ((size (sc-case words
+ (immediate
+ (logandc2 (+ (fixnumize (tn-value words))
+ (+ (1- (ash 1 n-lowtag-bits))
+ (* vector-data-offset n-word-bytes)))
+ lowtag-mask))
+ (t
+ (inst lea result (make-ea :byte :base words :disp
+ (+ (1- (ash 1 n-lowtag-bits))
+ (* vector-data-offset
+ n-word-bytes))))
+ (inst and result (lognot lowtag-mask))
+ result))))
+ (pseudo-atomic
+ (allocation result size)
+ (inst lea result (make-ea :byte :base result :disp other-pointer-lowtag))
+ (sc-case type
+ (immediate
+ (aver (typep (tn-value type) '(unsigned-byte 8)))
+ (storeb (tn-value type) result 0 other-pointer-lowtag))
+ (t
+ (storew type result 0 other-pointer-lowtag)))
+ (sc-case length
+ (immediate
+ (let ((fixnum-length (fixnumize (tn-value length))))
+ (typecase fixnum-length
+ ((unsigned-byte 8)
+ (storeb fixnum-length result
+ vector-length-slot other-pointer-lowtag))
+ (t
+ (storew fixnum-length result
+ vector-length-slot other-pointer-lowtag)))))
+ (t
+ (storew length result vector-length-slot other-pointer-lowtag)))))))
+
+(define-vop (allocate-vector-on-stack)
+ (:args (type :scs (unsigned-reg immediate))
+ (length :scs (any-reg))
+ (words :scs (any-reg) :target ecx))
+ (:temporary (:sc any-reg :offset ecx-offset :from (:argument 2)) ecx)
+ (:temporary (:sc any-reg :offset eax-offset :from (:argument 2)) zero)
+ (:temporary (:sc any-reg :offset edi-offset :from (:argument 0)) res)
+ (:results (result :scs (descriptor-reg) :from :load))
+ (:arg-types positive-fixnum
+ positive-fixnum
+ positive-fixnum)
+ (:translate allocate-vector)
+ (:policy :fast-safe)
+ (:node-var node)
+ (:generator 100
+ (inst lea result (make-ea :byte :base words :disp
+ (+ (1- (ash 1 n-lowtag-bits))
+ (* vector-data-offset n-word-bytes))))
+ (inst and result (lognot lowtag-mask))
+ ;; FIXME: It would be good to check for stack overflow here.
+ (move ecx words)
+ (inst shr ecx n-fixnum-tag-bits)
+ (allocation result result node t)
+ (inst cld)
+ (inst lea res
+ (make-ea :byte :base result :disp (* vector-data-offset n-word-bytes)))
+ (inst lea result (make-ea :byte :base result :disp other-pointer-lowtag))
+ (sc-case type
+ (immediate
+ (aver (typep (tn-value type) '(unsigned-byte 8)))
+ (storeb (tn-value type) result 0 other-pointer-lowtag))
+ (t
+ (storew type result 0 other-pointer-lowtag)))
+ (storew length result vector-length-slot other-pointer-lowtag)
+ (inst xor zero zero)
+ (inst rep)
+ (inst stos zero)))
+
+(in-package "SB!C")
+
+(defoptimizer (allocate-vector stack-allocate-result)
+ ((type length words) node)
+ (ecase (policy node stack-allocate-vector)
+ (0 nil)
+ ((1 2)
+ ;; a vector object should fit in one page
+ (values-subtypep (lvar-derived-type words)
+ (load-time-value
+ (specifier-type `(integer 0 ,(- (/ sb!vm::*backend-page-size*
+ sb!vm:n-word-bytes)
+ sb!vm:vector-data-offset))))))
+ (3 t)))
+
+(defoptimizer (allocate-vector ltn-annotate) ((type length words) call ltn-policy)
+ (let ((args (basic-combination-args call))
+ (template (template-or-lose (if (awhen (node-lvar call)
+ (lvar-dynamic-extent it))
+ 'sb!vm::allocate-vector-on-stack
+ 'sb!vm::allocate-vector-on-heap))))
+ (dolist (arg args)
+ (setf (lvar-info arg)
+ (make-ir2-lvar (primitive-type (lvar-type arg)))))
+ (unless (is-ok-template-use template call (ltn-policy-safe-p ltn-policy))
+ (ltn-default-call call)
+ (return-from allocate-vector-ltn-annotate-optimizer (values)))
+ (setf (basic-combination-info call) template)
+ (setf (node-tail-p call) nil)
+
+ (dolist (arg args)
+ (annotate-1-value-lvar arg))))
+
+(in-package "SB!VM")
+
+;;;
+(define-vop (allocate-code-object)