1 ;;;; x86 definition of character operations
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 ;;;; moves and coercions
16 ;;; Move a tagged char to an untagged representation.
18 (define-vop (move-to-character)
19 (:args (x :scs (any-reg descriptor-reg) :target y
20 :load-if (not (location= x y))))
21 (:results (y :scs (character-reg)
22 :load-if (not (location= x y))))
23 (:note "character untagging")
26 (inst shr y n-widetag-bits)))
28 (define-vop (move-to-character)
29 (:args (x :scs (any-reg control-stack)))
30 (:results (y :scs (character-reg #+nil character-stack)))
31 (:note "character untagging")
33 (let ((y-wide-tn (make-random-tn
35 :sc (sc-or-lose 'any-reg)
36 :offset (tn-offset y))))
38 (inst shr y-wide-tn 8)
39 (inst and y-wide-tn #xff))))
40 (define-move-vop move-to-character :move
41 (any-reg #!-sb-unicode control-stack)
44 ;;; Move an untagged char to a tagged representation.
46 (define-vop (move-from-character)
47 (:args (x :scs (character-reg)))
48 (:results (y :scs (any-reg descriptor-reg)))
49 (:note "character tagging")
51 (inst imul y x (ash 1 n-widetag-bits))
52 (inst or y character-widetag)))
54 (define-vop (move-from-character)
55 (:args (x :scs (character-reg character-stack)))
56 (:results (y :scs (any-reg descriptor-reg #+nil control-stack)))
57 (:note "character tagging")
59 (move (make-random-tn :kind :normal :sc (sc-or-lose 'character-reg)
60 :offset (tn-offset y))
62 (inst shl y n-widetag-bits)
63 (inst or y character-widetag)
65 (define-move-vop move-from-character :move
67 (any-reg descriptor-reg #!-sb-unicode control-stack))
69 ;;; Move untagged character values.
70 (define-vop (character-move)
73 :load-if (not (location= x y))))
74 (:results (y :scs (character-reg character-stack)
75 :load-if (not (location= x y))))
76 (:note "character move")
81 (define-move-vop character-move :move
82 (character-reg) (character-reg character-stack))
84 ;;; Move untagged character arguments/return-values.
85 (define-vop (move-character-arg)
89 :load-if (not (sc-is y character-reg))))
91 (:note "character arg move")
99 ;; FIXME: naked 8 (should be... what? n-register-bytes?
100 ;; n-word-bytes? Dunno.
101 (make-ea :byte :base fp :disp (- (* (1+ (tn-offset y)) 8)))
104 (if (= (tn-offset fp) esp-offset)
105 (storew x fp (tn-offset y)) ; c-call
106 (storew x fp (- (1+ (tn-offset y)))))))))
107 (define-move-vop move-character-arg :move-arg
108 (any-reg character-reg) (character-reg))
110 ;;; Use standard MOVE-ARG + coercion to move an untagged character
111 ;;; to a descriptor passing location.
112 (define-move-vop move-arg :move-arg
113 (character-reg) (any-reg descriptor-reg))
115 ;;;; other operations
117 (define-vop (char-code)
118 (:translate char-code)
120 (:args (ch :scs (character-reg character-stack)))
121 (:arg-types character)
122 (:results (res :scs (unsigned-reg)))
123 (:result-types positive-fixnum)
131 (define-vop (code-char)
132 (:translate code-char)
134 (:args (code :scs (unsigned-reg unsigned-stack)))
135 (:arg-types positive-fixnum)
136 (:results (res :scs (character-reg)))
137 (:result-types character)
139 (inst mov res code)))
141 (define-vop (code-char)
142 (:translate code-char)
144 (:args (code :scs (unsigned-reg unsigned-stack) :target eax))
145 (:arg-types positive-fixnum)
146 (:temporary (:sc unsigned-reg :offset rax-offset :target res
147 :from (:argument 0) :to (:result 0))
149 (:results (res :scs (character-reg)))
150 (:result-types character)
155 ;;; comparison of CHARACTERs
156 (define-vop (character-compare)
157 (:args (x :scs (character-reg character-stack))
158 (y :scs (character-reg)
159 :load-if (not (and (sc-is x character-reg)
160 (sc-is y character-stack)))))
161 (:arg-types character character)
165 (:note "inline comparison")
166 (:variant-vars condition not-condition)
169 (inst jmp (if not-p not-condition condition) target)))
171 (define-vop (fast-char=/character character-compare)
175 (define-vop (fast-char</character character-compare)
179 (define-vop (fast-char>/character character-compare)
183 (define-vop (character-compare/c)
184 (:args (x :scs (character-reg character-stack)))
185 (:arg-types character (:constant character))
187 (:info target not-p y)
189 (:note "inline constant comparison")
190 (:variant-vars condition not-condition)
192 (inst cmp x (sb!xc:char-code y))
193 (inst jmp (if not-p not-condition condition) target)))
195 (define-vop (fast-char=/character/c character-compare/c)
199 (define-vop (fast-char</character/c character-compare/c)
203 (define-vop (fast-char>/character/c character-compare/c)