1 ;;;; allocation VOPs for Mips
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
16 (defoptimizer (list stack-allocate-result
) ((&rest args
))
18 (defoptimizer (list* stack-allocate-result
) ((&rest args
))
19 (not (null (rest args
))))
21 (define-vop (list-or-list*)
22 (:args
(things :more t
))
23 (:temporary
(:scs
(descriptor-reg) :type list
) ptr
)
24 (:temporary
(:scs
(descriptor-reg)) temp
)
25 (:temporary
(:scs
(descriptor-reg) :type list
:to
(:result
0) :target result
)
27 (:temporary
(:sc non-descriptor-reg
:offset nl4-offset
) pa-flag
)
29 (:results
(result :scs
(descriptor-reg)))
35 (move result null-tn
))
37 (move result
(tn-ref-tn things
)))
40 ((store-car (tn list
&optional
(slot cons-car-slot
))
43 ((any-reg descriptor-reg zero null
)
46 (load-stack-tn temp
,tn
)
48 (storew reg
,list
,slot list-pointer-lowtag
))))
49 (let* ((dx-p (node-stack-allocate-p node
))
50 (cons-cells (if star
(1- num
) num
))
51 (alloc (* (pad-data-block cons-size
) cons-cells
)))
52 (pseudo-atomic (pa-flag :extra
(if dx-p
0 alloc
))
55 (inst srl res
(if dx-p csp-tn alloc-tn
) n-lowtag-bits
)
56 (inst sll res n-lowtag-bits
)
57 (inst or res list-pointer-lowtag
)
59 (inst addu csp-tn alloc
))
61 (dotimes (i (1- cons-cells
))
62 (store-car (tn-ref-tn things
) ptr
)
63 (setf things
(tn-ref-across things
))
64 (inst addu ptr ptr
(pad-data-block cons-size
))
66 (- cons-cdr-slot cons-size
)
68 (store-car (tn-ref-tn things
) ptr
)
70 (setf things
(tn-ref-across things
))
71 (store-car (tn-ref-tn things
) ptr cons-cdr-slot
))
74 cons-cdr-slot list-pointer-lowtag
)))
75 (aver (null (tn-ref-across things
)))
76 (move result res
))))))))
78 (define-vop (list list-or-list
*)
81 (define-vop (list* list-or-list
*)
85 ;;;; Special purpose inline allocators.
87 (define-vop (allocate-code-object)
88 (:args
(boxed-arg :scs
(any-reg))
89 (unboxed-arg :scs
(any-reg)))
90 (:results
(result :scs
(descriptor-reg)))
91 (:temporary
(:scs
(non-descriptor-reg)) ndescr
)
92 (:temporary
(:scs
(any-reg) :from
(:argument
0)) boxed
)
93 (:temporary
(:scs
(non-descriptor-reg) :from
(:argument
1)) unboxed
)
94 (:temporary
(:sc non-descriptor-reg
:offset nl4-offset
) pa-flag
)
96 (inst li ndescr
(lognot lowtag-mask
))
97 (inst addu boxed boxed-arg
98 (fixnumize (1+ code-trace-table-offset-slot
)))
99 (inst and boxed ndescr
)
100 (inst srl unboxed unboxed-arg word-shift
)
101 (inst addu unboxed unboxed lowtag-mask
)
102 (inst and unboxed ndescr
)
103 (inst sll ndescr boxed
(- n-widetag-bits word-shift
))
104 (inst or ndescr code-header-widetag
)
106 (pseudo-atomic (pa-flag)
107 (inst or result alloc-tn other-pointer-lowtag
)
108 (inst addu alloc-tn boxed
)
109 (storew ndescr result
0 other-pointer-lowtag
)
110 (storew unboxed result code-code-size-slot other-pointer-lowtag
)
111 (inst addu alloc-tn unboxed
)
112 (storew null-tn result code-entry-points-slot other-pointer-lowtag
)
113 (storew null-tn result code-debug-info-slot other-pointer-lowtag
))))
115 (define-vop (make-fdefn)
117 (:translate make-fdefn
)
118 (:args
(name :scs
(descriptor-reg) :to
:eval
))
119 (:temporary
(:scs
(non-descriptor-reg)) temp
)
120 (:temporary
(:sc non-descriptor-reg
:offset nl4-offset
) pa-flag
)
121 (:results
(result :scs
(descriptor-reg) :from
:argument
))
123 (with-fixed-allocation (result pa-flag temp fdefn-widetag fdefn-size
)
124 (inst li temp
(make-fixup "undefined_tramp" :foreign
))
125 (storew name result fdefn-name-slot other-pointer-lowtag
)
126 (storew null-tn result fdefn-fun-slot other-pointer-lowtag
)
127 (storew temp result fdefn-raw-addr-slot other-pointer-lowtag
))))
129 (define-vop (make-closure)
130 (:args
(function :to
:save
:scs
(descriptor-reg)))
131 (:info length stack-allocate-p
)
132 (:temporary
(:scs
(non-descriptor-reg)) temp
)
133 (:temporary
(:sc non-descriptor-reg
:offset nl4-offset
) pa-flag
)
134 (:results
(result :scs
(descriptor-reg)))
136 (let* ((size (+ length closure-info-offset
))
137 (alloc-size (pad-data-block size
)))
138 (pseudo-atomic (pa-flag :extra
(if stack-allocate-p
0 alloc-size
))
139 (cond (stack-allocate-p
141 (inst srl result csp-tn n-lowtag-bits
)
142 (inst addu csp-tn alloc-size
))
144 (inst srl result alloc-tn n-lowtag-bits
)))
145 (inst sll result n-lowtag-bits
)
146 (inst or result fun-pointer-lowtag
)
147 (inst li temp
(logior (ash (1- size
) n-widetag-bits
)
148 closure-header-widetag
))
149 (storew temp result
0 fun-pointer-lowtag
))
150 (storew function result closure-fun-slot fun-pointer-lowtag
))))
152 ;;; The compiler likes to be able to directly make value cells.
153 (define-vop (make-value-cell)
154 (:args
(value :to
:save
:scs
(descriptor-reg any-reg null zero
)))
155 (:temporary
(:scs
(non-descriptor-reg)) temp
)
156 (:temporary
(:sc non-descriptor-reg
:offset nl4-offset
) pa-flag
)
157 (:info stack-allocate-p
)
158 (:ignore stack-allocate-p
)
159 (:results
(result :scs
(descriptor-reg)))
161 (with-fixed-allocation (result pa-flag temp value-cell-header-widetag value-cell-size
)
162 (storew value result value-cell-value-slot other-pointer-lowtag
))))
165 ;;;; Automatic allocators for primitive objects.
167 (define-vop (make-unbound-marker)
169 (:results
(result :scs
(any-reg)))
171 (inst li result unbound-marker-widetag
)))
173 (define-vop (make-funcallable-instance-tramp)
175 (:results
(result :scs
(any-reg)))
177 (inst li result
(make-fixup "funcallable_instance_tramp" :foreign
))))
179 (define-vop (fixed-alloc)
181 (:info name words type lowtag
)
183 (:results
(result :scs
(descriptor-reg)))
184 (:temporary
(:scs
(non-descriptor-reg)) temp
)
185 (:temporary
(:sc non-descriptor-reg
:offset nl4-offset
) pa-flag
)
187 (pseudo-atomic (pa-flag :extra
(pad-data-block words
))
188 (inst or result alloc-tn lowtag
)
190 (inst li temp
(logior (ash (1- words
) n-widetag-bits
) type
))
191 (storew temp result
0 lowtag
)))))
193 (define-vop (var-alloc)
194 (:args
(extra :scs
(any-reg)))
195 (:arg-types positive-fixnum
)
196 (:info name words type lowtag
)
198 (:results
(result :scs
(descriptor-reg)))
199 (:temporary
(:scs
(any-reg)) bytes
)
200 (:temporary
(:scs
(non-descriptor-reg)) header
)
201 (:temporary
(:sc non-descriptor-reg
:offset nl4-offset
) pa-flag
)
203 (inst addu bytes extra
(* (1+ words
) n-word-bytes
))
204 (inst sll header bytes
(- n-widetag-bits
2))
205 (inst addu header header
(+ (ash -
2 n-widetag-bits
) type
))
206 (inst srl bytes bytes n-lowtag-bits
)
207 (inst sll bytes bytes n-lowtag-bits
)
208 (pseudo-atomic (pa-flag)
209 (inst or result alloc-tn lowtag
)
210 (storew header result
0 lowtag
)
211 (inst addu alloc-tn alloc-tn bytes
))))