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