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) :target al))
30 (:temporary (:sc byte-reg :offset al-offset
31 :from (:argument 0) :to (:eval 0)) al)
33 (:temporary (:sc byte-reg :offset ah-offset :target y
34 :from (:argument 0) :to (:result 0)) ah)
35 (:results (y :scs (character-reg character-stack)))
36 (:note "character untagging")
40 (define-move-vop move-to-character :move
41 (any-reg #!-sb-unicode control-stack)
42 (character-reg #!-sb-unicode character-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 ;; FIXME: is this inefficient? Is there a better way of writing
52 ;; it? (fixnum tagging is done with LEA). We can't use SHL
53 ;; because we either scribble over the source register or briefly
54 ;; have a non-descriptor in a descriptor register, unless we
55 ;; introduce a temporary.
56 (inst imul y x (ash 1 n-widetag-bits))
57 (inst or y character-widetag)))
59 (define-vop (move-from-character)
60 (:args (x :scs (character-reg character-stack) :target ah))
61 (:temporary (:sc byte-reg :offset al-offset :target y
62 :from (:argument 0) :to (:result 0)) al)
63 (:temporary (:sc byte-reg :offset ah-offset
64 :from (:argument 0) :to (:result 0)) ah)
65 (:results (y :scs (any-reg descriptor-reg control-stack)))
66 (:note "character tagging")
68 (move ah x) ; Maybe move char byte.
69 (inst mov al character-widetag) ; x86 to type bits
70 (inst and eax-tn #xffff) ; Remove any junk bits.
72 (define-move-vop move-from-character :move
73 (character-reg #!-sb-unicode character-stack)
74 (any-reg descriptor-reg #!-sb-unicode control-stack))
76 ;;; Move untagged character values.
77 (define-vop (character-move)
80 :load-if (not (location= x y))))
81 (:results (y :scs (character-reg character-stack)
82 :load-if (not (location= x y))))
83 (:note "character move")
88 (define-move-vop character-move :move
89 (character-reg) (character-reg character-stack))
91 ;;; Move untagged character arguments/return-values.
92 (define-vop (move-character-arg)
96 :load-if (not (sc-is y character-reg))))
98 (:note "character arg move")
106 (make-ea :byte :base fp :disp (- (* (1+ (tn-offset y)) 4)))
109 (if (= (tn-offset fp) esp-offset)
110 (storew x fp (tn-offset y)) ; c-call
111 (storew x fp (- (1+ (tn-offset y)))))))))
112 (define-move-vop move-character-arg :move-arg
113 (any-reg character-reg) (character-reg))
115 ;;; Use standard MOVE-ARG + coercion to move an untagged character
116 ;;; to a descriptor passing location.
117 (define-move-vop move-arg :move-arg
118 (character-reg) (any-reg descriptor-reg))
120 ;;;; other operations
122 (define-vop (char-code)
123 (:translate char-code)
125 (:args (ch :scs (character-reg character-stack)))
126 (:arg-types character)
127 (:results (res :scs (unsigned-reg)))
128 (:result-types positive-fixnum)
136 (define-vop (code-char)
137 (:translate code-char)
139 (:args (code :scs (unsigned-reg unsigned-stack)))
140 (:arg-types positive-fixnum)
141 (:results (res :scs (character-reg)))
142 (:result-types character)
144 (inst mov res code)))
146 (define-vop (code-char)
147 (:translate code-char)
149 (:args (code :scs (unsigned-reg unsigned-stack) :target eax))
150 (:arg-types positive-fixnum)
151 (:temporary (:sc unsigned-reg :offset eax-offset :target res
152 :from (:argument 0) :to (:result 0))
154 (:results (res :scs (character-reg)))
155 (:result-types character)
160 ;;; comparison of CHARACTERs
161 (define-vop (character-compare)
162 (:args (x :scs (character-reg character-stack))
163 (y :scs (character-reg)
164 :load-if (not (and (sc-is x character-reg)
165 (sc-is y character-stack)))))
166 (:arg-types character character)
170 (:note "inline comparison")
171 (:variant-vars condition not-condition)
174 (inst jmp (if not-p not-condition condition) target)))
176 (define-vop (fast-char=/character character-compare)
180 (define-vop (fast-char</character character-compare)
184 (define-vop (fast-char>/character character-compare)
188 (define-vop (character-compare/c)
189 (:args (x :scs (character-reg character-stack)))
190 (:arg-types character (:constant character))
192 (:info target not-p y)
194 (:note "inline constant comparison")
195 (:variant-vars condition not-condition)
197 (inst cmp x (sb!xc:char-code y))
198 (inst jmp (if not-p not-condition condition) target)))
200 (define-vop (fast-char=/character/c character-compare/c)
204 (define-vop (fast-char</character/c character-compare/c)
208 (define-vop (fast-char>/character/c character-compare/c)