Fix make-array transforms.
[sbcl.git] / src / compiler / x86 / char.lisp
1 ;;;; x86 definition of character operations
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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.
11
12 (in-package "SB!VM")
13 \f
14 ;;;; moves and coercions
15
16 ;;; Move a tagged char to an untagged representation.
17 #!+sb-unicode
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")
24   (:generator 1
25     (move y x)
26     (inst shr y n-widetag-bits)))
27 #!-sb-unicode
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)
32   (:ignore 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")
37   (:generator 1
38     (move eax-tn x)
39     (move y ah)))
40 (define-move-vop move-to-character :move
41   (any-reg #!-sb-unicode control-stack)
42   (character-reg #!-sb-unicode character-stack))
43
44 ;;; Move an untagged char to a tagged representation.
45 #!+sb-unicode
46 (define-vop (move-from-character)
47   (:args (x :scs (character-reg) :target y))
48   (:results (y :scs (any-reg descriptor-reg)))
49   (:note "character tagging")
50   (:generator 1
51     (move y x)
52     (inst shl y n-widetag-bits)
53     (inst or y character-widetag)))
54 #!-sb-unicode
55 (define-vop (move-from-character)
56   (:args (x :scs (character-reg character-stack) :target ah))
57   (:temporary (:sc byte-reg :offset al-offset :target y
58                    :from (:argument 0) :to (:result 0)) al)
59   (:temporary (:sc byte-reg :offset ah-offset
60                    :from (:argument 0) :to (:result 0)) ah)
61   (:results (y :scs (any-reg descriptor-reg control-stack)))
62   (:note "character tagging")
63   (:generator 1
64     (move ah x)                         ; Maybe move char byte.
65     (inst mov al character-widetag)     ; x86 to type bits
66     (inst and eax-tn #xffff)            ; Remove any junk bits.
67     (move y eax-tn)))
68 (define-move-vop move-from-character :move
69   (character-reg #!-sb-unicode character-stack)
70   (any-reg descriptor-reg #!-sb-unicode control-stack))
71
72 ;;; Move untagged character values.
73 (define-vop (character-move)
74   (:args (x :target y
75             :scs (character-reg)
76             :load-if (not (location= x y))))
77   (:results (y :scs (character-reg character-stack)
78                :load-if (not (location= x y))))
79   (:note "character move")
80   (:effects)
81   (:affected)
82   (:generator 0
83     (move y x)))
84 (define-move-vop character-move :move
85   (character-reg) (character-reg character-stack))
86
87 ;;; Move untagged character arguments/return-values.
88 (define-vop (move-character-arg)
89   (:args (x :target y
90             :scs (character-reg))
91          (fp :scs (any-reg)
92              :load-if (not (sc-is y character-reg))))
93   (:results (y))
94   (:note "character arg move")
95   (:generator 0
96     (sc-case y
97       (character-reg
98        (move y x))
99       (character-stack
100        #!-sb-unicode
101        (inst mov
102              ;; XXX: If the sb-unicode case needs to handle c-call,
103              ;; why does the non-unicode case not need to?
104              (make-ea :byte :base fp :disp (frame-byte-offset (tn-offset y)))
105              x)
106        #!+sb-unicode
107        (if (= (tn-offset fp) esp-offset)
108            (storew x fp (tn-offset y))  ; c-call
109            (storew x fp (frame-word-offset (tn-offset y))))))))
110 (define-move-vop move-character-arg :move-arg
111   (any-reg character-reg) (character-reg))
112
113 ;;; Use standard MOVE-ARG + coercion to move an untagged character
114 ;;; to a descriptor passing location.
115 (define-move-vop move-arg :move-arg
116   (character-reg) (any-reg descriptor-reg))
117 \f
118 ;;;; other operations
119
120 (define-vop (char-code)
121   (:translate char-code)
122   (:policy :fast-safe)
123   (:args #!-sb-unicode (ch :scs (character-reg character-stack))
124          #!+sb-unicode (ch :scs (character-reg character-stack) :target res))
125   (:arg-types character)
126   (:results (res :scs (unsigned-reg)))
127   (:result-types positive-fixnum)
128   (:generator 1
129     #!-sb-unicode
130     (inst movzx res ch)
131     #!+sb-unicode
132     (move res ch)))
133
134 #!+sb-unicode
135 (define-vop (code-char)
136   (:translate code-char)
137   (:policy :fast-safe)
138   (:args (code :scs (unsigned-reg unsigned-stack) :target res))
139   (:arg-types positive-fixnum)
140   (:results (res :scs (character-reg)))
141   (:result-types character)
142   (:generator 1
143     (move res code)))
144 #!-sb-unicode
145 (define-vop (code-char)
146   (:translate code-char)
147   (:policy :fast-safe)
148   (:args (code :scs (unsigned-reg unsigned-stack) :target eax))
149   (:arg-types positive-fixnum)
150   (:temporary (:sc unsigned-reg :offset eax-offset :target res
151                    :from (:argument 0) :to (:result 0))
152               eax)
153   (:results (res :scs (character-reg)))
154   (:result-types character)
155   (:generator 1
156     (move eax code)
157     (move res al-tn)))
158 \f
159 ;;; comparison of CHARACTERs
160 (define-vop (character-compare)
161   (:args (x :scs (character-reg character-stack))
162          (y :scs (character-reg)
163             :load-if (not (and (sc-is x character-reg)
164                                (sc-is y character-stack)))))
165   (:arg-types character character)
166   (:policy :fast-safe)
167   (:note "inline comparison")
168   (:generator 3
169     (inst cmp x y)))
170
171 (define-vop (fast-char=/character character-compare)
172   (:translate char=)
173   (:conditional :e))
174
175 (define-vop (fast-char</character character-compare)
176   (:translate char<)
177   (:conditional :b))
178
179 (define-vop (fast-char>/character character-compare)
180   (:translate char>)
181   (:conditional :a))
182
183 (define-vop (character-compare/c)
184   (:args (x :scs (character-reg character-stack)))
185   (:arg-types character (:constant character))
186   (:info y)
187   (:policy :fast-safe)
188   (:note "inline constant comparison")
189   (:generator 2
190     (inst cmp x (sb!xc:char-code y))))
191
192 (define-vop (fast-char=/character/c character-compare/c)
193   (:translate char=)
194   (:conditional :e))
195
196 (define-vop (fast-char</character/c character-compare/c)
197   (:translate char<)
198   (:conditional :b))
199
200 (define-vop (fast-char>/character/c character-compare/c)
201   (:translate char>)
202   (:conditional :a))