1 ;;;; unknown-values VOPs for the x86 VM
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.
14 (define-vop (reset-stack-pointer)
15 (:args
(ptr :scs
(any-reg)))
19 (define-vop (%%nip-values
)
20 (:args
(last-nipped-ptr :scs
(any-reg) :target rdi
)
21 (last-preserved-ptr :scs
(any-reg) :target rsi
)
22 (moved-ptrs :scs
(any-reg) :more t
))
23 (:results
(r-moved-ptrs :scs
(any-reg) :more t
)
26 (:temporary
(:sc any-reg
:offset rsi-offset
) rsi
)
27 (:temporary
(:sc any-reg
:offset rdi-offset
) rdi
)
28 (:ignore r-moved-ptrs
)
30 (move rdi last-nipped-ptr
)
31 (move rsi last-preserved-ptr
)
32 (inst sub rsi n-word-bytes
)
33 (inst sub rdi n-word-bytes
)
43 (inst lea rsp-tn
(make-ea :qword
:base rdi
:disp n-word-bytes
))
45 (loop for moved
= moved-ptrs then
(tn-ref-across moved
)
47 do
(inst add
(tn-ref-tn moved
) rdi
))))
49 ;;; Push some values onto the stack, returning the start and number of values
50 ;;; pushed as results. It is assumed that the Vals are wired to the standard
51 ;;; argument locations. Nvals is the number of values to push.
53 ;;; The generator cost is pseudo-random. We could get it right by defining a
54 ;;; bogus SC that reflects the costs of the memory-to-memory moves for each
55 ;;; operand, but this seems unworthwhile.
56 (define-vop (push-values)
57 (:args
(vals :more t
))
58 (:temporary
(:sc unsigned-reg
:to
(:result
0) :target start
) temp
)
59 (:results
(start) (count))
62 (move temp rsp-tn
) ; WARN pointing 1 below
63 (do ((val vals
(tn-ref-across val
)))
65 (inst push
(tn-ref-tn val
)))
67 (inst mov count
(fixnumize nvals
))))
69 ;;; Push a list of values on the stack, returning Start and Count as used in
70 ;;; unknown values continuations.
71 (define-vop (values-list)
72 (:args
(arg :scs
(descriptor-reg) :target list
))
75 (:results
(start :scs
(any-reg))
76 (count :scs
(any-reg)))
77 (:temporary
(:sc descriptor-reg
:from
(:argument
0) :to
(:result
1)) list
)
78 (:temporary
(:sc dword-reg
:offset eax-offset
:to
(:result
1)) eax
)
81 (:save-p
:compute-only
)
84 (move start rsp-tn
) ; WARN pointing 1 below
87 (inst cmp list nil-value
)
89 (pushw list cons-car-slot list-pointer-lowtag
)
90 (loadw list list cons-cdr-slot list-pointer-lowtag
)
91 (%test-lowtag list LOOP nil list-pointer-lowtag
)
92 (cerror-call vop
'bogus-arg-to-values-list-error list
)
95 (inst mov count start
) ; start is high address
96 (inst sub count rsp-tn
) ; stackp is low address
97 #!-
#.
(cl:if
(cl:= sb
!vm
:word-shift sb
!vm
:n-fixnum-tag-bits
) '(and) '(or))
98 (inst shr count
(- word-shift n-fixnum-tag-bits
))))
100 ;;; Copy the more arg block to the top of the stack so we can use them
101 ;;; as function arguments.
103 ;;; Accepts a context as produced by more-arg-context; points to the first
104 ;;; value on the stack, not 4 bytes above as in other contexts.
106 ;;; Return a context that is 4 bytes above the first value, suitable for
107 ;;; defining a new stack frame.
108 (define-vop (%more-arg-values
)
109 (:args
(context :scs
(descriptor-reg any-reg
) :target src
)
110 (skip :scs
(any-reg immediate
))
111 (num :scs
(any-reg) :target count
))
112 (:arg-types
* positive-fixnum positive-fixnum
)
113 (:temporary
(:sc any-reg
:offset rsi-offset
:from
(:argument
0)) src
)
114 (:temporary
(:sc descriptor-reg
:offset rax-offset
) temp
)
115 (:temporary
(:sc unsigned-reg
:offset rcx-offset
) loop-index
)
116 (:results
(start :scs
(any-reg))
117 (count :scs
(any-reg)))
121 (if (zerop (tn-value skip
))
123 (inst lea src
(make-ea :dword
:base context
124 :disp
(- (* (tn-value skip
)
127 (cond ((= word-shift n-fixnum-tag-bits
)
131 ;; TODO: Reducing CALL-ARGUMENTS-LIMIT to something reasonable to
132 ;; allow DWORD ops without it looking like a bug would make sense.
133 ;; With a stack size of about 2MB, the limit is absurd anyway.
136 (make-ea :qword
:base context
:index skip
137 :scale
(ash 1 (- word-shift n-fixnum-tag-bits
))))
141 (inst lea loop-index
(make-ea :byte
:index count
142 :scale
(ash 1 (- word-shift n-fixnum-tag-bits
))))
143 (inst mov start rsp-tn
)
144 (inst jrcxz DONE
) ; check for 0 count?
146 (inst sub rsp-tn loop-index
)
147 (inst sub src loop-index
)
150 (inst mov temp
(make-ea :qword
:base src
:index loop-index
))
151 (inst sub loop-index n-word-bytes
)
152 (inst mov
(make-ea :qword
:base rsp-tn
:index loop-index
) temp
)