1 ;;;; x86-64 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 ;;; Space optimization: As the upper 32 bits of (tagged or untagged)
15 ;;; characters are always zero many operations can be done on 32-bit
16 ;;; registers. This often leads to smaller encodings as the REX prefix
17 ;;; is then only needed if registers R8 - R15 are used.
19 ;;;; moves and coercions
21 ;;; Move a tagged char to an untagged representation.
23 (define-vop (move-to-character)
24 (:args (x :scs (any-reg descriptor-reg) :target y
25 :load-if (not (location= x y))))
26 (:results (y :scs (character-reg)
27 :load-if (not (location= x y))))
28 (:note "character untagging")
30 (let ((y-dword (make-dword-tn y)))
31 (move y-dword (make-dword-tn x))
32 (inst shr y-dword n-widetag-bits))))
34 (define-vop (move-to-character)
35 (:args (x :scs (any-reg control-stack)))
36 (:results (y :scs (character-reg #+nil character-stack)))
37 (:note "character untagging")
39 (let ((y-wide-tn (make-random-tn
41 :sc (sc-or-lose 'any-reg)
42 :offset (tn-offset y))))
44 (inst shr y-wide-tn 8)
45 (inst and y-wide-tn #xff))))
46 (define-move-vop move-to-character :move
47 (any-reg #!-sb-unicode control-stack)
50 ;;; Move an untagged char to a tagged representation.
52 (define-vop (move-from-character)
53 (:args (x :scs (character-reg) :target y))
54 (:results (y :scs (any-reg descriptor-reg)))
55 (:note "character tagging")
57 (let ((y-dword (make-dword-tn y)))
58 (unless (location= x y)
59 (inst mov y-dword (make-dword-tn x)))
60 (inst shl y-dword n-widetag-bits)
61 (inst or y-dword character-widetag))))
63 (define-vop (move-from-character)
64 (:args (x :scs (character-reg character-stack)))
65 (:results (y :scs (any-reg descriptor-reg #+nil control-stack)))
66 (:note "character tagging")
68 (move (make-random-tn :kind :normal :sc (sc-or-lose 'character-reg)
69 :offset (tn-offset y))
71 (inst shl y n-widetag-bits)
72 (inst or y character-widetag)
74 (define-move-vop move-from-character :move
76 (any-reg descriptor-reg #!-sb-unicode control-stack))
78 ;;; Move untagged character values.
79 (define-vop (character-move)
82 :load-if (not (location= x y))))
83 (:results (y :scs (character-reg character-stack)
84 :load-if (not (location= x y))))
85 (:note "character move")
90 (define-move-vop character-move :move
91 (character-reg) (character-reg character-stack))
93 ;;; Move untagged character arguments/return-values.
94 (define-vop (move-character-arg)
98 :load-if (not (sc-is y character-reg))))
100 (:note "character arg move")
108 ;; FIXME: naked 8 (should be... what? n-register-bytes?
109 ;; n-word-bytes? Dunno.
110 (make-ea :byte :base fp :disp (- (* (1+ (tn-offset y)) 8)))
113 (if (= (tn-offset fp) esp-offset)
114 (storew x fp (tn-offset y)) ; c-call
115 (storew x fp (- (1+ (tn-offset y)))))))))
116 (define-move-vop move-character-arg :move-arg
117 (any-reg character-reg) (character-reg))
119 ;;; Use standard MOVE-ARG + coercion to move an untagged character
120 ;;; to a descriptor passing location.
121 (define-move-vop move-arg :move-arg
122 (character-reg) (any-reg descriptor-reg))
124 ;;;; other operations
126 (define-vop (char-code)
127 (:translate char-code)
129 (:args #!-sb-unicode (ch :scs (character-reg character-stack))
130 #!+sb-unicode (ch :scs (character-reg character-stack) :target res))
131 (:arg-types character)
132 (:results (res :scs (unsigned-reg)))
133 (:result-types positive-fixnum)
141 (define-vop (code-char)
142 (:translate code-char)
144 (:args (code :scs (unsigned-reg unsigned-stack) :target res))
145 (:arg-types positive-fixnum)
146 (:results (res :scs (character-reg)))
147 (:result-types character)
151 (define-vop (code-char)
152 (:translate code-char)
154 (:args (code :scs (unsigned-reg unsigned-stack) :target eax))
155 (:arg-types positive-fixnum)
156 (:temporary (:sc unsigned-reg :offset rax-offset :target res
157 :from (:argument 0) :to (:result 0))
159 (:results (res :scs (character-reg)))
160 (:result-types character)
165 ;;; comparison of CHARACTERs
166 (define-vop (character-compare)
167 (:args (x :scs (character-reg character-stack))
168 (y :scs (character-reg)
169 :load-if (not (and (sc-is x character-reg)
170 (sc-is y character-stack)))))
171 (:arg-types character character)
175 (:note "inline comparison")
176 (:variant-vars condition not-condition)
179 (inst jmp (if not-p not-condition condition) target)))
181 (define-vop (fast-char=/character character-compare)
185 (define-vop (fast-char</character character-compare)
189 (define-vop (fast-char>/character character-compare)
193 (define-vop (character-compare/c)
194 (:args (x :scs (character-reg character-stack)))
195 (:arg-types character (:constant character))
197 (:info target not-p y)
199 (:note "inline constant comparison")
200 (:variant-vars condition not-condition)
202 (inst cmp x (sb!xc:char-code y))
203 (inst jmp (if not-p not-condition condition) target)))
205 (define-vop (fast-char=/character/c character-compare/c)
209 (define-vop (fast-char</character/c character-compare/c)
213 (define-vop (fast-char>/character/c character-compare/c)