0.9.3.32:
[sbcl.git] / src / compiler / mips / alloc.lisp
1 ;;;; allocation VOPs for Mips
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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.
11
12 (in-package "SB!VM")
13
14 \f
15 ;;;; LIST and LIST*
16
17 (define-vop (list-or-list*)
18   (:args (things :more t))
19   (:temporary (:scs (descriptor-reg) :type list) ptr)
20   (:temporary (:scs (descriptor-reg)) temp)
21   (:temporary (:scs (descriptor-reg) :type list :to (:result 0) :target result)
22               res)
23   (:temporary (:sc non-descriptor-reg :offset nl4-offset) pa-flag)
24   (:info num)
25   (:results (result :scs (descriptor-reg)))
26   (:variant-vars star)
27   (:policy :safe)
28   (:generator 0
29     (cond ((zerop num)
30            (move result null-tn))
31           ((and star (= num 1))
32            (move result (tn-ref-tn things)))
33           (t
34            (macrolet
35                ((store-car (tn list &optional (slot cons-car-slot))
36                   `(let ((reg
37                           (sc-case ,tn
38                             ((any-reg descriptor-reg) ,tn)
39                             (zero zero-tn)
40                             (null null-tn)
41                             (control-stack
42                              (load-stack-tn temp ,tn)
43                              temp))))
44                      (storew reg ,list ,slot list-pointer-lowtag))))
45              (let ((cons-cells (if star (1- num) num)))
46                (pseudo-atomic (pa-flag
47                                :extra (* (pad-data-block cons-size)
48                                          cons-cells))
49                  (inst or res alloc-tn list-pointer-lowtag)
50                  (move ptr res)
51                  (dotimes (i (1- cons-cells))
52                    (store-car (tn-ref-tn things) ptr)
53                    (setf things (tn-ref-across things))
54                    (inst addu ptr ptr (pad-data-block cons-size))
55                    (storew ptr ptr
56                            (- cons-cdr-slot cons-size)
57                            list-pointer-lowtag))
58                  (store-car (tn-ref-tn things) ptr)
59                  (cond (star
60                         (setf things (tn-ref-across things))
61                         (store-car (tn-ref-tn things) ptr cons-cdr-slot))
62                        (t
63                         (storew null-tn ptr
64                                 cons-cdr-slot list-pointer-lowtag)))
65                  (aver (null (tn-ref-across things)))
66                  (move result res))))))))
67
68 (define-vop (list list-or-list*)
69   (:variant nil))
70
71 (define-vop (list* list-or-list*)
72   (:variant t))
73
74 \f
75 ;;;; Special purpose inline allocators.
76
77 (define-vop (allocate-code-object)
78   (:args (boxed-arg :scs (any-reg))
79          (unboxed-arg :scs (any-reg)))
80   (:results (result :scs (descriptor-reg)))
81   (:temporary (:scs (non-descriptor-reg)) ndescr)
82   (:temporary (:scs (any-reg) :from (:argument 0)) boxed)
83   (:temporary (:scs (non-descriptor-reg) :from (:argument 1)) unboxed)
84   (:temporary (:sc non-descriptor-reg :offset nl4-offset) pa-flag)
85   (:generator 100
86     (inst li ndescr (lognot lowtag-mask))
87     (inst addu boxed boxed-arg
88           (fixnumize (1+ code-trace-table-offset-slot)))
89     (inst and boxed ndescr)
90     (inst srl unboxed unboxed-arg word-shift)
91     (inst addu unboxed unboxed lowtag-mask)
92     (inst and unboxed ndescr)
93     (inst sll ndescr boxed (- n-widetag-bits word-shift))
94     (inst or ndescr code-header-widetag)
95
96     (pseudo-atomic (pa-flag)
97       (inst or result alloc-tn other-pointer-lowtag)
98       (storew ndescr result 0 other-pointer-lowtag)
99       (storew unboxed result code-code-size-slot other-pointer-lowtag)
100       (storew null-tn result code-entry-points-slot other-pointer-lowtag)
101       (inst addu alloc-tn boxed)
102       (inst addu alloc-tn unboxed))
103
104     (storew null-tn result code-debug-info-slot other-pointer-lowtag)))
105
106 (define-vop (make-fdefn)
107   (:policy :fast-safe)
108   (:translate make-fdefn)
109   (:args (name :scs (descriptor-reg) :to :eval))
110   (:temporary (:scs (non-descriptor-reg)) temp)
111   (:temporary (:sc non-descriptor-reg :offset nl4-offset) pa-flag)
112   (:results (result :scs (descriptor-reg) :from :argument))
113   (:generator 37
114     (with-fixed-allocation (result pa-flag temp fdefn-widetag fdefn-size)
115       (storew name result fdefn-name-slot other-pointer-lowtag)
116       (storew null-tn result fdefn-fun-slot other-pointer-lowtag)
117       (inst li temp (make-fixup "undefined_tramp" :foreign))
118       (storew temp result fdefn-raw-addr-slot other-pointer-lowtag))))
119
120 (define-vop (make-closure)
121   (:args (function :to :save :scs (descriptor-reg)))
122   (:info length stack-allocate-p)
123   (:ignore stack-allocate-p)
124   (:temporary (:scs (non-descriptor-reg)) temp)
125   (:temporary (:sc non-descriptor-reg :offset nl4-offset) pa-flag)
126   (:results (result :scs (descriptor-reg)))
127   (:generator 10
128     (let ((size (+ length closure-info-offset)))
129       (inst li temp (logior (ash (1- size) n-widetag-bits) closure-header-widetag))
130       (pseudo-atomic (pa-flag :extra (pad-data-block size))
131         (inst or result alloc-tn fun-pointer-lowtag)
132         (storew temp result 0 fun-pointer-lowtag))
133       (storew result result closure-self-slot fun-pointer-lowtag)
134       (storew function result closure-fun-slot fun-pointer-lowtag))))
135
136 ;;; The compiler likes to be able to directly make value cells.
137 ;;;
138 (define-vop (make-value-cell)
139   (:args (value :to :save :scs (descriptor-reg any-reg null zero)))
140   (:temporary (:scs (non-descriptor-reg)) temp)
141   (:temporary (:sc non-descriptor-reg :offset nl4-offset) pa-flag)
142   (:results (result :scs (descriptor-reg)))
143   (:generator 10
144     (with-fixed-allocation (result pa-flag temp value-cell-header-widetag value-cell-size)
145       (storew value result value-cell-value-slot other-pointer-lowtag))))
146
147 \f
148 ;;;; Automatic allocators for primitive objects.
149
150 (define-vop (make-unbound-marker)
151   (:args)
152   (:results (result :scs (any-reg)))
153   (:generator 1
154     (inst li result unbound-marker-widetag)))
155
156 (define-vop (fixed-alloc)
157   (:args)
158   (:info name words type lowtag)
159   (:ignore name)
160   (:results (result :scs (descriptor-reg)))
161   (:temporary (:scs (non-descriptor-reg)) temp)
162   (:temporary (:sc non-descriptor-reg :offset nl4-offset) pa-flag)
163   (:generator 4
164     (pseudo-atomic (pa-flag :extra (pad-data-block words))
165       (inst or result alloc-tn lowtag)
166       (when type
167         (inst li temp (logior (ash (1- words) n-widetag-bits) type))
168         (storew temp result 0 lowtag)))))
169
170 (define-vop (var-alloc)
171   (:args (extra :scs (any-reg)))
172   (:arg-types positive-fixnum)
173   (:info name words type lowtag)
174   (:ignore name)
175   (:results (result :scs (descriptor-reg)))
176   (:temporary (:scs (any-reg)) bytes)
177   (:temporary (:scs (non-descriptor-reg)) header)
178   (:temporary (:sc non-descriptor-reg :offset nl4-offset) pa-flag)
179   (:generator 6
180     (inst addu bytes extra (* (1+ words) n-word-bytes))
181     (inst sll header bytes (- n-widetag-bits 2))
182     (inst addu header header (+ (ash -2 n-widetag-bits) type))
183     (inst srl bytes bytes n-lowtag-bits)
184     (inst sll bytes bytes n-lowtag-bits)
185     (pseudo-atomic (pa-flag)
186       (inst or result alloc-tn lowtag)
187       (storew header result 0 lowtag)
188       (inst addu alloc-tn alloc-tn bytes))))
189