Fix prior change for non-x86
[sbcl.git] / src / assembly / arm64 / array.lisp
blob6028d55dc88ebe5bc8edcbefe5db116ec65eccdd
1 ;;;; various array operations that are too expensive (in space) to do
2 ;;;; inline
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 (define-assembly-routine (allocate-vector-on-heap
16 (:policy :fast-safe)
17 (:arg-types positive-fixnum
18 positive-fixnum
19 positive-fixnum))
20 ((:arg type any-reg r0-offset)
21 (:arg length any-reg r1-offset)
22 (:arg words any-reg r2-offset)
23 (:res result descriptor-reg r0-offset)
25 (:temp ndescr non-descriptor-reg nl2-offset)
26 (:temp pa-flag non-descriptor-reg nl3-offset)
27 (:temp lra-save non-descriptor-reg nl5-offset)
28 (:temp vector descriptor-reg r8-offset)
29 (:temp lr interior-reg lr-offset))
30 (pseudo-atomic (pa-flag)
31 (inst lsl ndescr words (- word-shift n-fixnum-tag-bits))
32 (inst add ndescr ndescr (* (1+ vector-data-offset) n-word-bytes))
33 (inst and ndescr ndescr (bic-mask lowtag-mask)) ; double-word align
34 (move lra-save lr) ;; The call to alloc_tramp will overwrite LR
35 (allocation vector ndescr other-pointer-lowtag :flag-tn pa-flag
36 :lip nil) ;; keep LR intact as per above
38 (move lr lra-save)
39 (inst lsr ndescr type n-fixnum-tag-bits)
40 (storew ndescr vector 0 other-pointer-lowtag)
41 ;; Touch the last element, to ensure that null-terminated strings
42 ;; passed to C do not cause a WP violation in foreign code.
43 ;; Do that before storing length, since nil-arrays don't have any
44 ;; space, but may have non-zero length.
45 #!-gencgc
46 (storew zr-tn pa-flag -1)
47 (storew length vector vector-length-slot other-pointer-lowtag)
48 (move result vector)))
50 (define-assembly-routine (allocate-vector-on-stack
51 (:policy :fast-safe)
52 (:arg-types positive-fixnum
53 positive-fixnum
54 positive-fixnum))
55 ((:arg type any-reg r0-offset)
56 (:arg length any-reg r1-offset)
57 (:arg words any-reg r2-offset)
58 (:res result descriptor-reg r0-offset)
60 (:temp temp non-descriptor-reg nl0-offset))
61 (pseudo-atomic (temp)
62 (inst lsr temp type n-fixnum-tag-bits)
63 (inst lsl words words (- word-shift n-fixnum-tag-bits))
64 (inst add words words (* (1+ vector-data-offset) n-word-bytes))
65 (inst and words words (bic-mask lowtag-mask)) ; double-word align
66 (allocation result words nil :stack-allocate-p t)
68 (inst stp temp length (@ result))
69 ;; Zero fill
70 (assemble ()
71 ;; The header word has already been set, skip it.
72 (inst add temp result (* n-word-bytes 2))
73 (inst add words result words)
74 LOOP
75 (inst stp zr-tn zr-tn (@ temp (* n-word-bytes 2) :post-index))
76 (inst cmp temp words)
77 (inst b :lt LOOP))
78 (inst orr result result other-pointer-lowtag)))