1.0.19.8: SB-COVER:REPORT signals an error for non-directory pathnames
[sbcl/pkhuong.git] / src / compiler / ppc / cell.lisp
blobd44dc85971c337d432afb0cce70aa8df20f50e91
1 ;;;; the VM definition of various primitive memory access VOPs for the
2 ;;;; PPC
4 ;;;; This software is part of the SBCL system. See the README file for
5 ;;;; more information.
6 ;;;;
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
13 (in-package "SB!VM")
15 ;;;; Data object ref/set stuff.
17 (define-vop (slot)
18 (:args (object :scs (descriptor-reg)))
19 (:info name offset lowtag)
20 (:ignore name)
21 (:results (result :scs (descriptor-reg any-reg)))
22 (:generator 1
23 (loadw result object offset lowtag)))
25 (define-vop (set-slot)
26 (:args (object :scs (descriptor-reg))
27 (value :scs (descriptor-reg any-reg)))
28 (:info name offset lowtag)
29 (:ignore name)
30 (:results)
31 (:generator 1
32 (storew value object offset lowtag)))
35 ;;;; Symbol hacking VOPs:
37 ;;; The compiler likes to be able to directly SET symbols.
38 (define-vop (set cell-set)
39 (:variant symbol-value-slot other-pointer-lowtag))
41 ;;; Do a cell ref with an error check for being unbound.
42 (define-vop (checked-cell-ref)
43 (:args (object :scs (descriptor-reg) :target obj-temp))
44 (:results (value :scs (descriptor-reg any-reg)))
45 (:policy :fast-safe)
46 (:vop-var vop)
47 (:save-p :compute-only)
48 (:temporary (:scs (descriptor-reg) :from (:argument 0)) obj-temp))
50 ;;; With SYMBOL-VALUE, we check that the value isn't the trap object.
51 ;;; So SYMBOL-VALUE of NIL is NIL.
52 (define-vop (symbol-value checked-cell-ref)
53 (:translate symbol-value)
54 (:generator 9
55 (move obj-temp object)
56 (loadw value obj-temp symbol-value-slot other-pointer-lowtag)
57 (let ((err-lab (generate-error-code vop unbound-symbol-error obj-temp)))
58 (inst cmpwi value unbound-marker-widetag)
59 (inst beq err-lab))))
61 ;;; Like CHECKED-CELL-REF, only we are a predicate to see if the cell
62 ;;; is bound.
63 (define-vop (boundp-frob)
64 (:args (object :scs (descriptor-reg)))
65 (:conditional)
66 (:info target not-p)
67 (:policy :fast-safe)
68 (:temporary (:scs (descriptor-reg)) value))
70 (define-vop (boundp boundp-frob)
71 (:translate boundp)
72 (:generator 9
73 (loadw value object symbol-value-slot other-pointer-lowtag)
74 (inst cmpwi value unbound-marker-widetag)
75 (inst b? (if not-p :eq :ne) target)))
77 (define-vop (fast-symbol-value cell-ref)
78 (:variant symbol-value-slot other-pointer-lowtag)
79 (:policy :fast)
80 (:translate symbol-value))
82 (define-vop (symbol-hash)
83 (:policy :fast-safe)
84 (:translate symbol-hash)
85 (:args (symbol :scs (descriptor-reg)))
86 (:results (res :scs (any-reg)))
87 (:result-types positive-fixnum)
88 (:generator 2
89 ;; The symbol-hash slot of NIL holds NIL because it is also the
90 ;; cdr slot, so we have to strip off the two low bits to make sure
91 ;; it is a fixnum. The lowtag selection magic that is required to
92 ;; ensure this is explained in the comment in objdef.lisp
93 (loadw res symbol symbol-hash-slot other-pointer-lowtag)
94 (inst clrrwi res res n-fixnum-tag-bits)))
96 ;;;; Fdefinition (fdefn) objects.
98 (define-vop (fdefn-fun cell-ref)
99 (:variant fdefn-fun-slot other-pointer-lowtag))
101 (define-vop (safe-fdefn-fun)
102 (:args (object :scs (descriptor-reg) :target obj-temp))
103 (:results (value :scs (descriptor-reg any-reg)))
104 (:vop-var vop)
105 (:save-p :compute-only)
106 (:temporary (:scs (descriptor-reg) :from (:argument 0)) obj-temp)
107 (:generator 10
108 (move obj-temp object)
109 (loadw value obj-temp fdefn-fun-slot other-pointer-lowtag)
110 (inst cmpw value null-tn)
111 (let ((err-lab (generate-error-code vop undefined-fun-error obj-temp)))
112 (inst beq err-lab))))
114 (define-vop (set-fdefn-fun)
115 (:policy :fast-safe)
116 (:translate (setf fdefn-fun))
117 (:args (function :scs (descriptor-reg) :target result)
118 (fdefn :scs (descriptor-reg)))
119 (:temporary (:scs (interior-reg)) lip)
120 (:temporary (:scs (non-descriptor-reg)) type)
121 (:results (result :scs (descriptor-reg)))
122 (:generator 38
123 (let ((normal-fn (gen-label)))
124 (load-type type function (- fun-pointer-lowtag))
125 (inst cmpwi type simple-fun-header-widetag)
126 ;;(inst mr lip function)
127 (inst addi lip function
128 (- (ash simple-fun-code-offset word-shift) fun-pointer-lowtag))
129 (inst beq normal-fn)
130 (inst lr lip (make-fixup "closure_tramp" :foreign))
131 (emit-label normal-fn)
132 (storew lip fdefn fdefn-raw-addr-slot other-pointer-lowtag)
133 (storew function fdefn fdefn-fun-slot other-pointer-lowtag)
134 (move result function))))
136 (define-vop (fdefn-makunbound)
137 (:policy :fast-safe)
138 (:translate fdefn-makunbound)
139 (:args (fdefn :scs (descriptor-reg) :target result))
140 (:temporary (:scs (non-descriptor-reg)) temp)
141 (:results (result :scs (descriptor-reg)))
142 (:generator 38
143 (storew null-tn fdefn fdefn-fun-slot other-pointer-lowtag)
144 (inst lr temp (make-fixup "undefined_tramp" :foreign))
145 (storew temp fdefn fdefn-raw-addr-slot other-pointer-lowtag)
146 (move result fdefn)))
150 ;;;; Binding and Unbinding.
152 ;;; BIND -- Establish VAL as a binding for SYMBOL. Save the old value and
153 ;;; the symbol on the binding stack and stuff the new value into the
154 ;;; symbol.
156 (define-vop (bind)
157 (:args (val :scs (any-reg descriptor-reg))
158 (symbol :scs (descriptor-reg)))
159 (:temporary (:scs (descriptor-reg)) temp)
160 (:generator 5
161 (loadw temp symbol symbol-value-slot other-pointer-lowtag)
162 (inst addi bsp-tn bsp-tn (* 2 n-word-bytes))
163 (storew temp bsp-tn (- binding-value-slot binding-size))
164 (storew symbol bsp-tn (- binding-symbol-slot binding-size))
165 (storew val symbol symbol-value-slot other-pointer-lowtag)))
168 (define-vop (unbind)
169 (:temporary (:scs (descriptor-reg)) symbol value)
170 (:generator 0
171 (loadw symbol bsp-tn (- binding-symbol-slot binding-size))
172 (loadw value bsp-tn (- binding-value-slot binding-size))
173 (storew value symbol symbol-value-slot other-pointer-lowtag)
174 (storew zero-tn bsp-tn (- binding-symbol-slot binding-size))
175 (storew zero-tn bsp-tn (- binding-value-slot binding-size))
176 (inst subi bsp-tn bsp-tn (* 2 n-word-bytes))))
179 (define-vop (unbind-to-here)
180 (:args (arg :scs (descriptor-reg any-reg) :target where))
181 (:temporary (:scs (any-reg) :from (:argument 0)) where)
182 (:temporary (:scs (descriptor-reg)) symbol value)
183 (:generator 0
184 (let ((loop (gen-label))
185 (skip (gen-label))
186 (done (gen-label)))
187 (move where arg)
188 (inst cmpw where bsp-tn)
189 (inst beq done)
191 (emit-label loop)
192 (loadw symbol bsp-tn (- binding-symbol-slot binding-size))
193 (inst cmpwi symbol 0)
194 (inst beq skip)
195 (loadw value bsp-tn (- binding-value-slot binding-size))
196 (storew value symbol symbol-value-slot other-pointer-lowtag)
197 (storew zero-tn bsp-tn (- binding-symbol-slot binding-size))
199 (emit-label skip)
200 (storew zero-tn bsp-tn (- binding-value-slot binding-size))
201 (inst subi bsp-tn bsp-tn (* 2 n-word-bytes))
202 (inst cmpw where bsp-tn)
203 (inst bne loop)
205 (emit-label done))))
209 ;;;; Closure indexing.
211 (define-vop (closure-index-ref word-index-ref)
212 (:variant closure-info-offset fun-pointer-lowtag)
213 (:translate %closure-index-ref))
215 (define-vop (funcallable-instance-info word-index-ref)
216 (:variant funcallable-instance-info-offset fun-pointer-lowtag)
217 (:translate %funcallable-instance-info))
219 (define-vop (set-funcallable-instance-info word-index-set)
220 (:variant funcallable-instance-info-offset fun-pointer-lowtag)
221 (:translate %set-funcallable-instance-info))
223 (define-vop (closure-ref slot-ref)
224 (:variant closure-info-offset fun-pointer-lowtag))
226 (define-vop (closure-init slot-set)
227 (:variant closure-info-offset fun-pointer-lowtag))
230 ;;;; Value Cell hackery.
232 (define-vop (value-cell-ref cell-ref)
233 (:variant value-cell-value-slot other-pointer-lowtag))
235 (define-vop (value-cell-set cell-set)
236 (:variant value-cell-value-slot other-pointer-lowtag))
240 ;;;; Instance hackery:
242 (define-vop (instance-length)
243 (:policy :fast-safe)
244 (:translate %instance-length)
245 (:args (struct :scs (descriptor-reg)))
246 (:temporary (:scs (non-descriptor-reg)) temp)
247 (:results (res :scs (unsigned-reg)))
248 (:result-types positive-fixnum)
249 (:generator 4
250 (loadw temp struct 0 instance-pointer-lowtag)
251 (inst srwi res temp n-widetag-bits)))
253 (define-vop (instance-index-ref word-index-ref)
254 (:policy :fast-safe)
255 (:translate %instance-ref)
256 (:variant instance-slots-offset instance-pointer-lowtag)
257 (:arg-types instance positive-fixnum))
259 (define-vop (instance-index-set word-index-set)
260 (:policy :fast-safe)
261 (:translate %instance-set)
262 (:variant instance-slots-offset instance-pointer-lowtag)
263 (:arg-types instance positive-fixnum *))
268 ;;;; Code object frobbing.
270 (define-vop (code-header-ref word-index-ref)
271 (:translate code-header-ref)
272 (:policy :fast-safe)
273 (:variant 0 other-pointer-lowtag))
275 (define-vop (code-header-set word-index-set)
276 (:translate code-header-set)
277 (:policy :fast-safe)
278 (:variant 0 other-pointer-lowtag))
282 ;;;; raw instance slot accessors
284 (define-vop (raw-instance-ref/word)
285 (:translate %raw-instance-ref/word)
286 (:policy :fast-safe)
287 (:args (object :scs (descriptor-reg))
288 (index :scs (any-reg)))
289 (:arg-types * positive-fixnum)
290 (:results (value :scs (unsigned-reg)))
291 (:temporary (:scs (non-descriptor-reg)) offset)
292 (:result-types unsigned-num)
293 (:generator 5
294 (loadw offset object 0 instance-pointer-lowtag)
295 ;; offset = (offset >> n-widetag-bits) << 2
296 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
297 (inst subf offset index offset)
298 (inst addi
299 offset
300 offset
301 (- (* (1- instance-slots-offset) n-word-bytes)
302 instance-pointer-lowtag))
303 (inst lwzx value object offset)))
305 (define-vop (raw-instance-set/word)
306 (:translate %raw-instance-set/word)
307 (:policy :fast-safe)
308 (:args (object :scs (descriptor-reg))
309 (index :scs (any-reg))
310 (value :scs (unsigned-reg)))
311 (:arg-types * positive-fixnum unsigned-num)
312 (:results (result :scs (unsigned-reg)))
313 (:temporary (:scs (non-descriptor-reg)) offset)
314 (:result-types unsigned-num)
315 (:generator 5
316 (loadw offset object 0 instance-pointer-lowtag)
317 ;; offset = (offset >> n-widetag-bits) << 2
318 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
319 (inst subf offset index offset)
320 (inst addi
321 offset
322 offset
323 (- (* (1- instance-slots-offset) n-word-bytes)
324 instance-pointer-lowtag))
325 (inst stwx value object offset)
326 (move result value)))
328 (define-vop (raw-instance-ref/single)
329 (:translate %raw-instance-ref/single)
330 (:policy :fast-safe)
331 (:args (object :scs (descriptor-reg))
332 (index :scs (any-reg)))
333 (:arg-types * positive-fixnum)
334 (:results (value :scs (single-reg)))
335 (:temporary (:scs (non-descriptor-reg)) offset)
336 (:result-types single-float)
337 (:generator 5
338 (loadw offset object 0 instance-pointer-lowtag)
339 ;; offset = (offset >> n-widetag-bits) << 2
340 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
341 (inst subf offset index offset)
342 (inst addi
343 offset
344 offset
345 (- (* (1- instance-slots-offset) n-word-bytes)
346 instance-pointer-lowtag))
347 (inst lfsx value object offset)))
349 (define-vop (raw-instance-set/single)
350 (:translate %raw-instance-set/single)
351 (:policy :fast-safe)
352 (:args (object :scs (descriptor-reg))
353 (index :scs (any-reg))
354 (value :scs (single-reg) :target result))
355 (:arg-types * positive-fixnum single-float)
356 (:results (result :scs (single-reg)))
357 (:result-types single-float)
358 (:temporary (:scs (non-descriptor-reg)) offset)
359 (:generator 5
360 (loadw offset object 0 instance-pointer-lowtag)
361 ;; offset = (offset >> n-widetag-bits) << 2
362 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
363 (inst subf offset index offset)
364 (inst addi
365 offset
366 offset
367 (- (* (1- instance-slots-offset) n-word-bytes)
368 instance-pointer-lowtag))
369 (inst stfsx value object offset)
370 (unless (location= result value)
371 (inst frsp result value))))
373 (define-vop (raw-instance-ref/double)
374 (:translate %raw-instance-ref/double)
375 (:policy :fast-safe)
376 (:args (object :scs (descriptor-reg))
377 (index :scs (any-reg)))
378 (:arg-types * positive-fixnum)
379 (:results (value :scs (double-reg)))
380 (:temporary (:scs (non-descriptor-reg)) offset)
381 (:result-types double-float)
382 (:generator 5
383 (loadw offset object 0 instance-pointer-lowtag)
384 ;; offset = (offset >> n-widetag-bits) << 2
385 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
386 (inst subf offset index offset)
387 (inst addi
388 offset
389 offset
390 (- (* (- instance-slots-offset 2) n-word-bytes)
391 instance-pointer-lowtag))
392 (inst lfdx value object offset)))
394 (define-vop (raw-instance-set/double)
395 (:translate %raw-instance-set/double)
396 (:policy :fast-safe)
397 (:args (object :scs (descriptor-reg))
398 (index :scs (any-reg))
399 (value :scs (double-reg) :target result))
400 (:arg-types * positive-fixnum double-float)
401 (:results (result :scs (double-reg)))
402 (:result-types double-float)
403 (:temporary (:scs (non-descriptor-reg)) offset)
404 (:generator 5
405 (loadw offset object 0 instance-pointer-lowtag)
406 ;; offset = (offset >> n-widetag-bits) << 2
407 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
408 (inst subf offset index offset)
409 (inst addi
410 offset
411 offset
412 (- (* (- instance-slots-offset 2) n-word-bytes)
413 instance-pointer-lowtag))
414 (inst stfdx value object offset)
415 (unless (location= result value)
416 (inst fmr result value))))
418 (define-vop (raw-instance-ref/complex-single)
419 (:translate %raw-instance-ref/complex-single)
420 (:policy :fast-safe)
421 (:args (object :scs (descriptor-reg))
422 (index :scs (any-reg)))
423 (:arg-types * positive-fixnum)
424 (:results (value :scs (complex-single-reg)))
425 (:temporary (:scs (non-descriptor-reg)) offset)
426 (:result-types complex-single-float)
427 (:generator 5
428 (loadw offset object 0 instance-pointer-lowtag)
429 ;; offset = (offset >> n-widetag-bits) << 2
430 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
431 (inst subf offset index offset)
432 (inst addi
433 offset
434 offset
435 (- (* (- instance-slots-offset 2) n-word-bytes)
436 instance-pointer-lowtag))
437 (inst lfsx (complex-single-reg-real-tn value) object offset)
438 (inst addi offset offset n-word-bytes)
439 (inst lfsx (complex-single-reg-imag-tn value) object offset)))
441 (define-vop (raw-instance-set/complex-single)
442 (:translate %raw-instance-set/complex-single)
443 (:policy :fast-safe)
444 (:args (object :scs (descriptor-reg))
445 (index :scs (any-reg))
446 (value :scs (complex-single-reg) :target result))
447 (:arg-types * positive-fixnum complex-single-float)
448 (:results (result :scs (complex-single-reg)))
449 (:result-types complex-single-float)
450 (:temporary (:scs (non-descriptor-reg)) offset)
451 (:generator 5
452 (loadw offset object 0 instance-pointer-lowtag)
453 ;; offset = (offset >> n-widetag-bits) << 2
454 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
455 (inst subf offset index offset)
456 (inst addi
457 offset
458 offset
459 (- (* (- instance-slots-offset 2) n-word-bytes)
460 instance-pointer-lowtag))
461 (let ((value-real (complex-single-reg-real-tn value))
462 (result-real (complex-single-reg-real-tn result)))
463 (inst stfsx value-real object offset)
464 (unless (location= result-real value-real)
465 (inst frsp result-real value-real)))
466 (inst addi offset offset n-word-bytes)
467 (let ((value-imag (complex-single-reg-imag-tn value))
468 (result-imag (complex-single-reg-imag-tn result)))
469 (inst stfsx value-imag object offset)
470 (unless (location= result-imag value-imag)
471 (inst frsp result-imag value-imag)))))
473 (define-vop (raw-instance-ref/complex-double)
474 (:translate %raw-instance-ref/complex-double)
475 (:policy :fast-safe)
476 (:args (object :scs (descriptor-reg))
477 (index :scs (any-reg)))
478 (:arg-types * positive-fixnum)
479 (:results (value :scs (complex-double-reg)))
480 (:temporary (:scs (non-descriptor-reg)) offset)
481 (:result-types complex-double-float)
482 (:generator 5
483 (loadw offset object 0 instance-pointer-lowtag)
484 ;; offset = (offset >> n-widetag-bits) << 2
485 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
486 (inst subf offset index offset)
487 (inst addi
488 offset
489 offset
490 (- (* (- instance-slots-offset 4) n-word-bytes)
491 instance-pointer-lowtag))
492 (inst lfdx (complex-double-reg-real-tn value) object offset)
493 (inst addi offset offset (* 2 n-word-bytes))
494 (inst lfdx (complex-double-reg-imag-tn value) object offset)))
496 (define-vop (raw-instance-set/complex-double)
497 (:translate %raw-instance-set/complex-double)
498 (:policy :fast-safe)
499 (:args (object :scs (descriptor-reg))
500 (index :scs (any-reg))
501 (value :scs (complex-double-reg) :target result))
502 (:arg-types * positive-fixnum complex-double-float)
503 (:results (result :scs (complex-double-reg)))
504 (:result-types complex-double-float)
505 (:temporary (:scs (non-descriptor-reg)) offset)
506 (:generator 5
507 (loadw offset object 0 instance-pointer-lowtag)
508 ;; offset = (offset >> n-widetag-bits) << 2
509 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
510 (inst subf offset index offset)
511 (inst addi
512 offset
513 offset
514 (- (* (- instance-slots-offset 4) n-word-bytes)
515 instance-pointer-lowtag))
516 (let ((value-real (complex-double-reg-real-tn value))
517 (result-real (complex-double-reg-real-tn result)))
518 (inst stfdx value-real object offset)
519 (unless (location= result-real value-real)
520 (inst fmr result-real value-real)))
521 (inst addi offset offset (* 2 n-word-bytes))
522 (let ((value-imag (complex-double-reg-imag-tn value))
523 (result-imag (complex-double-reg-imag-tn result)))
524 (inst stfdx value-imag object offset)
525 (unless (location= result-imag value-imag)
526 (inst fmr result-imag value-imag)))))