*** empty log message ***
[deliverable/binutils-gdb.git] / cpu / cris.cpu
CommitLineData
68800d83
HPN
1; CRIS CPU description. -*- Scheme -*-
2;
3; Copyright 2003, 2004 Free Software Foundation, Inc.
4;
5; Contributed by Axis Communications AB.
6;
7; This file is part of the GNU Binutils.
8;
9; This program is free software; you can redistribute it and/or modify
10; it under the terms of the GNU General Public License as published by
11; the Free Software Foundation; either version 2 of the License, or
12; (at your option) any later version.
13;
14; This program is distributed in the hope that it will be useful,
15; but WITHOUT ANY WARRANTY; without even the implied warranty of
16; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17; GNU General Public License for more details.
18;
19; You should have received a copy of the GNU General Public License
20; along with this program; if not, write to the Free Software
21; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23(include "simplify.inc")
24
25;;;;;;;;;;;;;;;;;; -pmacro (generic ones)
26
27(define-pmacro (.car2 l) (.apply (.pmacro (a b) a) l))
28(define-pmacro (.cadr2 l) (.apply (.pmacro (a b) b) l))
29(define-pmacro (SI-ext x) "How to sign-extend a dword to dword (a nop)" x)
30(define-pmacro (HI-ext x) "How to sign-extend a word to dword" (ext SI x))
31(define-pmacro (QI-ext x) "How to sign-extend a byte to dword" (ext SI x))
32(define-pmacro (SI-zext x) "How to zero-extend a dword to dword (a nop)" x)
33(define-pmacro (HI-zext x) "How to zero-extend a word to dword" (zext SI x))
34(define-pmacro (QI-zext x) "How to zero-extend a byte to dword" (zext SI x))
35(define-pmacro
36 (define-pmacro-map x)
37 "On a list ((x0 y0) .. (xN yN)), 0 <= m <= N, (define-pmacro xm ym)"
38 (.splice
39 begin
40 (.unsplice
41 (.map
42 (.pmacro (l) (.apply (.pmacro (xm ym) (define-pmacro xm ym)) l)) x)))
43)
44
45;;;;;;;;;;;;;;;;;; -arch -isa -cpu -model
46
47(define-arch
48 (name cris)
49 (comment "Axis Communications CRIS")
50 (default-alignment unaligned)
51 (insn-lsb0? #t)
52 (machs crisv0 crisv3 crisv8 crisv10 crisv32)
53 (isas cris)
54)
55
56(define-isa
57 (name cris)
58 (base-insn-bitsize 16)
59 (liw-insns 1)
60 (parallel-insns 1)
61)
62
63(define-pmacro
64 (define-cpu-cris x-suffix x-comment)
65 "Define a CRIS CPU family"
66 (define-cpu
67 (name (.sym cris x-suffix f))
68 (comment x-comment)
69 (endian little)
70 ; CGEN-FIXME: Should be deduced from the default?
71 (word-bitsize 32)
72 (file-transform (.str x-suffix))
73 )
74)
75
76; Useful when there's a need to iterate over all models.
77(define-pmacro (cris-cpu-model-numbers)
78 "List of CRIS CPU model numbers (version register contents)"
79 (0 3 8 10 32)
80)
81
82(define-pmacro (cris-cpu-models)
83 "List of CRIS CPU model names"
84 (.map (.pmacro (n) (.sym v n)) (cris-cpu-model-numbers))
85)
86
87; Mapping from model name to number.
88(define-pmacro-map
89 (.map (.pmacro (n) ((.sym v n -number) n))
90 (cris-cpu-model-numbers)))
91
92; FIXME: Rationalize these rules.
93; CPU names must be distinct from the architecture name and machine names.
94; The "b" suffix stands for "base" and is the convention.
95; The "f" suffix stands for "family" and is the convention.
96; We ignore the "b" convention, partly because v0 isn't really a "base", at
97; least not for some aspects of v32.
98(define-cpu-cris v0 "CRIS base family")
99(define-cpu-cris v3 "CRIS v3 family")
100(define-cpu-cris v8 "CRIS v8 family")
101(define-cpu-cris v10 "CRIS v10 family")
102(define-cpu-cris v32 "CRIS v32 family")
103
104(define-pmacro MACH-PRE-V32 (MACH crisv0,crisv3,crisv8,crisv10))
105(define-pmacro MACH-V3-UP (MACH crisv3,crisv8,crisv10,crisv32))
106(define-pmacro MACH-V32 (MACH crisv32))
107(define-pmacro MACH-PC MACH-PRE-V32)
108(define-pmacro MACH-ACR MACH-V32)
109(define-pmacro MACH-BRANCH-OFFSET-AT-INSN MACH-V32)
110(define-pmacro MACH-BRANCH-OFFSET-AFTER-INSN MACH-PRE-V32)
111
112(define-pmacro
113 current-mach-is-v32
114 "Whether the generated code is for V32. See comment at h-v32."
115 (reg h-v32)
116)
117
118(define-pmacro (define-mach-cris x-suffix x-comment x-name)
119 "Define a CRIS mach"
120 (define-mach
121 (name (.sym cris x-suffix))
122 ; They're all called "cris" in bfd. Watch out for breakages for some
123 ; uses.
124 (bfd-name x-name)
125 (comment x-comment)
126 (cpu (.sym cris x-suffix f)))
127)
128
129(define-mach-cris v0 "Generic CRIS v0 CPU, ETRAX 1 .. 3" "cris")
130(define-mach-cris v3 "Generic CRIS v3 CPU, ETRAX 4" "cris")
131(define-mach-cris v8 "Generic CRIS v8 CPU, ETRAX 100" "cris")
132(define-mach-cris v10 "Generic CRIS v10 CPU, ETRAX 100 LX" "cris")
133(define-mach-cris v32 "Generic CRIS v32 CPU, ETRAX FS" "crisv32")
134
135(define-pmacro (define-model-simplecris x-name x-comment)
136 "Define a simple CRIS model"
137 (define-model
138 (name (.sym cris x-name))
139 (comment x-comment)
140 (mach (.sym cris x-name))
141
142 (unit u-exec "Execution Unit" () 1 1 () () () ())
143 (unit u-mem "Memory Unit" () 1 1 () () () ())
144
145 (unit u-const16 "Fetch 16-bit operand" () 1 1 () () () ())
146 (unit u-const32 "Fetch 32-bit operand" () 1 1
147 () () () ())
148 ; Used in special-case insn, for example arithmetic with PC destination.
149 (unit u-stall "Stall unit" () 1 1 () () () ())
150 (unit u-skip4 "Skip 4 bytes" () 1 1 () () () ())
151 (unit u-multiply "Multiply Unit" () 1 1 ((MACH crisv10)) () () ())
152 (unit u-movem "Movem Unit" () 1 1 ()
153 ((Rd INT -1))
154 () ()))
155)
156
157(define-model-simplecris v0 "Model of CRIS v0, ETRAX 1 .. 3")
158(define-model-simplecris v3 "Model of CRIS v3, ETRAX 4")
159(define-model-simplecris v8 "Model of CRIS v8, ETRAX 100")
160(define-model-simplecris v10 "Model of CRIS v10, ETRAX 100 LX")
161
162; For some reason, we get an error:
163; Generating arch.h ...
164; ERROR: In procedure vector-ref:
165; ERROR: Wrong type argument in position 1: ()
166; if we include timings for machs that we don't generate sims for.
167; Last checked: CVS as of 2004-11-18.
168; CGEN-FIXME: Looks like another CGEN bug. When it's fixed (or when
169; generating sims for v0, v3 or v8), add 0, 3 and 8 to
170; simplecris-timing-models. But before that, simplecris-timing-x has to
171; be rewritten to work on a multiple-element-list, not assume a single
172; element. (A change which seems likely to depend on lexical scoping for
173; macros to be introduced: try the obvious implementation.)
174(define-pmacro simplecris-timing-models (10))
175(define-pmacro (simplecris-common-timing x-units)
176 "Make timing models, using x-units for all simplecris-timing-models"
177 ; CGEN-FIXME: Another CGEN bug: the part (.unsplice (10)) will remain
178 ; unexpanded in (.sym crisv (.unsplice (10)) if we write this as
179 ; ((.splice (.sym crisv (.unsplice simplecris-timing-models))
180 ; (.unsplice x-units)))
181 ((.splice (.sym crisv (.apply (.pmacro (x) x) simplecris-timing-models))
182 (.unsplice x-units)))
183)
184
185(define-pmacro-map
186 (
187 ; Timing for memory instructions running on a simple cris model.
188 ((simplecris-mem-timing) (simplecris-common-timing
189 ((unit u-mem) (unit u-exec))))
190 ; Timing for movem instructions running on a simple cris model.
191 ((simplecris-movem-timing) (simplecris-common-timing
192 ((unit u-movem) (unit u-exec))))
193 ; Similar, for an 8- or 16-bit constant ([PC+]) operand.
194 ((simplecris-const-timing-HI)
195 (simplecris-common-timing
196 ((unit u-const16) (unit u-exec))))
197 ; Similar, for a 32-bit constant ([PC+]) operand.
198 ((simplecris-const-timing-SI)
199 (simplecris-common-timing
200 ((unit u-const32) (unit u-exec))))
201 ; Similar, no particular operand.
202 ((simplecris-timing) (simplecris-common-timing
203 ((unit u-exec)))))
204)
205
206(define-model
207 (name crisv32)
208 (comment "Model of CRISv32")
209 (mach crisv32)
210
211 (state
212 ; Bitmask of h-gr register (0..15) and h-sr register (17..31)
213 ; modified by 3rd previous insn, updated by the u-exec unit.
214 ; Because there's no need to mark writes to special registers BZ and
215 ; WZ, bit 16 is for jump mark and bit 20 for memory-write mark.
216 (prev-prev-prev-modf-regs UINT)
217
218 ; Ditto for the 2nd previous insn.
219 (prev-prev-modf-regs UINT)
220
221 ; Ditto for the previous insn.
222 (prev-modf-regs UINT)
223
224 ; Bit-mask for regs modified by the current insn, propagated to
225 ; prev-modf-regs.
226 (modf-regs UINT)
227
228 ; Registers loaded by movem are not forwarded to the execution
229 ; stage, so we need to insert stall-cycles for ordinary insns
230 ; accessing such registers. In addition to the *modf-regs
231 ; above, these are set to tell *ordinary* insns which registers
232 ; are inaccessible.
233
234 (prev-prev-prev-movem-dest-regs UINT)
235
236 ; Ditto for the 2nd previous insn.
237 (prev-prev-movem-dest-regs UINT)
238
239 ; Ditto for the previous insn.
240 (prev-movem-dest-regs UINT)
241
242 ; Bit-mask for regs modified by the current insn, propagated to
243 ; prev-movem-dest-regs.
244 (movem-dest-regs UINT))
245
246 ; It seems this pipeline description isn't used at all; this is just
247 ; for show.
248 ; Noteworthy is the placement of the memory stage before the execute stage.
249 (pipeline all "" () ((fetch) (decode) (memory) (execute) (writeback)))
250
251 ; Units that contribute only a constant pipeline delay are not included.
252 (unit u-mem "Memory Unit" () 1 1 ()
253 ((Rs INT -1))
254 () ())
255
256 ; Artificial units for read/write-related hazard accounting.
257 (unit u-mem-r "Memory Unit Read" () 1 1 () () () ())
258 (unit u-mem-w "Memory Unit Write" () 1 1 () () () ())
259
260 (unit u-movem-rtom "Movem-to-memory Unit" () 1 1 ()
261 ((Rs INT -1) (Rd INT -1))
262 () ())
263 (unit u-movem-mtor "Movem-to-register Unit" () 1 1 ()
264 ((Rs INT -1) (Rd INT -1))
265 () ())
266 (unit u-multiply "Multiply Unit" () 1 1 ()
267 ((Rs INT -1) (Rd INT -1))
268 () ())
269 (unit u-branch "Branch Unit" () 1 1 ()
270 ()
271 () ())
272 (unit u-jump-r "Jump-to-register Unit" () 1 1 ()
273 ((Rs INT -1))
274 () ())
275 (unit u-jump-sr "Jump-to-special-register Unit" () 1 1 ()
276 ((Ps INT -1))
277 () ())
278 (unit u-jump "JAS/BAS Unit, saving PC" () 1 1 ()
279 ()
280 ((Pd INT -1)) ())
281
282 ; To keep track of PC; not really functional units.
283 (unit u-const16 "Fetch 16-bit operand" () 1 1 () () () ())
284 (unit u-const32 "Fetch 32-bit operand" () 1 1 () () () ())
285 (unit u-skip4 "Skip 4 bytes" () 1 1 () () () ())
286
287 ; For v32, we need to keep track of inputs (for movem destination
288 ; cycle penalties) and output (for e.g. memory source and jump
289 ; source cycle penalties).
290 (unit u-exec "Execution Unit" () 1 1 ()
291 ((Rd INT -1) (Rs INT -1))
292 ((Rd INT -1))
293 ())
294
295 ; Special case of u-exec for movem: don't treat Rd as an incoming
296 ; parameter.
297 (unit u-exec-movem "Execution Unit" () 1 1 ()
298 ((Rs INT -1))
299 ((Rd INT -1))
300 ())
301
302 ; Special case of u-exec when the destination is a special
303 ; register.
304 (unit u-exec-to-sr "Execution Unit" () 1 1 ()
305 ((Rs INT -1))
306 ((Pd INT -1)) ())
307)
308
309(define-pmacro (crisv32-timing-destreg d)
310 "Timing for instructions running on a crisv32 model"
311 ((crisv32
312 (.splice unit u-exec (.unsplice d))))
313)
314(define-pmacro (crisv32-timing) (crisv32-timing-destreg ()))
315
316(define-pmacro (cris-timing-Rd-sfield)
317 (crisv32-timing-destreg ((out Rd Rd-sfield)))
318)
319
320(define-pmacro (crisv32-timing-c-HI)
321 ((crisv32 (unit u-const16) (unit u-exec)))
322)
323
324(define-pmacro-map
325 ((crisv32-timing-c-QI crisv32-timing-c-HI)
326 ((crisv32-timing-c-SI) ((crisv32 (unit u-const32) (unit u-exec))))
327 ((crisv32-timing-c-sr-SI) ((crisv32 (unit u-const32) (unit u-exec-to-sr))))
328 ((crisv32-reg-sr-timing) ((crisv32 (unit u-exec-to-sr))))
329 ((crisv32-mem-sr-timing)
330 ((crisv32 (unit u-mem) (unit u-mem-r) (unit u-exec-to-sr))))
331 ((crisv32-mem-timing) ((crisv32 (unit u-mem) (unit u-mem-r) (unit u-exec))))
332 ((crisv32-mem-write-timing) ((crisv32 (unit u-mem) (unit u-exec) (unit u-mem-w)))))
333)
334
335(define-pmacro-map
336 (
337 ; Timing for instructions using memory operands.
338 ((cris-mem-timing) (.splice (.unsplice (simplecris-mem-timing))
339 (.unsplice (crisv32-mem-timing))))
340 ; Timing for instructions using memory operands.
341 ((cris-mem-write-timing) (.splice
342 (.unsplice (simplecris-mem-timing))
343 (.unsplice (crisv32-mem-write-timing))))
344 ; Timing for moves from general register to special register.
345 ((cris-reg-sr-timing) (.splice (.unsplice (simplecris-timing))
346 (.unsplice (crisv32-reg-sr-timing))))
347 ; Timing for moves from memory to special register.
348 ((cris-mem-sr-timing) (.splice (.unsplice (simplecris-mem-timing))
349 (.unsplice (crisv32-mem-sr-timing))))
350 ; Timing for non-mul, non-memory, non-special-register, 16-bit instructions.
351 ((cris-timing) (.splice (.unsplice (simplecris-timing))
352 (.unsplice (crisv32-timing))))
353 ; Timing for instructions with 8- or 16-bit constant operand ([PC+]).
354 ((cris-timing-const-HI) (.splice
355 (.unsplice (simplecris-const-timing-HI))
356 (.unsplice (crisv32-timing-c-HI))))
357 ; Timing for instructions with a 32-bit constant operand ([PC+]).
358 ((cris-timing-const-SI) (.splice
359 (.unsplice (simplecris-const-timing-SI))
360 (.unsplice (crisv32-timing-c-SI))))
361 ; Like cris-timing-const-SI, but destination special register.
362 ((cris-timing-const-sr-SI) (.splice
363 (.unsplice (simplecris-const-timing-SI))
364 (.unsplice (crisv32-timing-c-sr-SI))))
365 ; Like cris-timing-const-HI, but destination special register.
366 ((cris-timing-const-sr-HI) (.splice
367 (.unsplice (simplecris-const-timing-HI))
368 (.unsplice (crisv32-timing-c-sr-SI)))))
369)
370
371(define-pmacro cris-timing-const-QI cris-timing-const-HI)
372(define-pmacro cris-timing-const-sr-QI cris-timing-const-sr-HI)
373
374(define-pmacro (simplecris-common-specregs)
375 "The common special registers in pre-v32 models."
376 ((QI 0) (QI 1) (HI 4) (HI 5)
377 (SI 8) (SI 9) (SI 10) (SI 11) (SI 12) (SI 13))
378)
379
380(define-pmacro (cris-implemented-specregs-v0)
381 "Special registers in v0 and their sizes"
382 (.splice (.unsplice (simplecris-common-specregs)) (HI 6) (HI 7))
383)
384(define-pmacro
385 cris-implemented-specregs-const-v0
386 cris-implemented-specregs-v0
387)
388
389(define-pmacro (cris-implemented-specregs-v3)
390 "Special registers in v3 and their sizes"
391 (.splice (.unsplice (cris-implemented-specregs-v0)) (SI 14))
392)
393(define-pmacro
394 cris-implemented-specregs-const-v3
395 cris-implemented-specregs-v3
396)
397
398(define-pmacro (cris-implemented-specregs-v8)
399 "Special registers in v8 and their sizes"
400 (.splice (.unsplice (simplecris-common-specregs)) (SI 14))
401)
402(define-pmacro
403 cris-implemented-specregs-const-v8
404 cris-implemented-specregs-v8
405)
406
407(define-pmacro (cris-implemented-specregs-v10)
408 "Special registers in v10 and their sizes"
409 (.splice (.unsplice (simplecris-common-specregs)) (SI 7) (SI 14) (SI 15))
410)
411(define-pmacro
412 cris-implemented-specregs-const-v10
413 cris-implemented-specregs-v10
414)
415
416(define-pmacro (cris-implemented-specregs-v32)
417 "Special registers in v32 and their sizes"
418 ((QI 0) (QI 1) (QI 2) (QI 3) (HI 4)
419 (SI 5) (SI 6) (SI 7) (SI 8) (SI 9)
420 (SI 10) (SI 11) (SI 12) (SI 13) (SI 14) (SI 15))
421)
422; For v32, all special register operations on constants (that is,
423; move) take 32-bit operands, not the real size of the register, as in
424; other move operations.
425(define-pmacro (cris-implemented-specregs-const-v32)
426 (.map (.pmacro (regno) (SI regno)) (.iota 16))
427)
428
429(define-pmacro cris-swap-codes
430 "CRIS Swap codes in numeric order (no zero)"
431 ( r b br w wr wb wbr
432 n nr nb nbr nw nwr nwb nwbr)
433)
434
435(define-pmacro cris-flagnames
436 "CRIS flag field values, dest and src fields concatenated"
437 (c v z n x i u p) ; ... b m for pre-v32
438)
439
440(define-pmacro-map
441 ; Bitnumber for each respective flag.
442 (.map (.pmacro (x num) ((.sym x -bitnumber) num))
443 cris-flagnames (.iota 8))
444)
445
446; I give up. Here's a perl-script to get the values I want for this macro
447; (not working along list principles, though). You can run this region.
448; perl -e '$x = "cvznxiup"; for ($i = 0; $i < 256; $i++) { $s = "";
449; for ($j = 0; $j < 8; $j++) { if ($i & (1 << $j)) {
450; $s .= substr ($x, $j, 1);}}
451; printf ("%s%s", $s eq "" ? "_" : $s, (($i + 1) % 8) == 0 ? "\n " : " "); }'
452(define-pmacro cris-flag-combinations
453 "Combinations of flags in numeric order"
454 (_ c v cv z cz vz cvz
455 n cn vn cvn zn czn vzn cvzn
456 x cx vx cvx zx czx vzx cvzx
457 nx cnx vnx cvnx znx cznx vznx cvznx
458 i ci vi cvi zi czi vzi cvzi
459 ni cni vni cvni zni czni vzni cvzni
460 xi cxi vxi cvxi zxi czxi vzxi cvzxi
461 nxi cnxi vnxi cvnxi znxi cznxi vznxi cvznxi
462 u cu vu cvu zu czu vzu cvzu
463 nu cnu vnu cvnu znu cznu vznu cvznu
464 xu cxu vxu cvxu zxu czxu vzxu cvzxu
465 nxu cnxu vnxu cvnxu znxu cznxu vznxu cvznxu
466 iu ciu viu cviu ziu cziu vziu cvziu
467 niu cniu vniu cvniu zniu czniu vzniu cvzniu
468 xiu cxiu vxiu cvxiu zxiu czxiu vzxiu cvzxiu
469 nxiu cnxiu vnxiu cvnxiu znxiu cznxiu vznxiu cvznxiu
470 p cp vp cvp zp czp vzp cvzp
471 np cnp vnp cvnp znp cznp vznp cvznp
472 xp cxp vxp cvxp zxp czxp vzxp cvzxp
473 nxp cnxp vnxp cvnxp znxp cznxp vznxp cvznxp
474 ip cip vip cvip zip czip vzip cvzip
475 nip cnip vnip cvnip znip cznip vznip cvznip
476 xip cxip vxip cvxip zxip czxip vzxip cvzxip
477 nxip cnxip vnxip cvnxip znxip cznxip vznxip cvznxip
478 up cup vup cvup zup czup vzup cvzup
479 nup cnup vnup cvnup znup cznup vznup cvznup
480 xup cxup vxup cvxup zxup czxup vzxup cvzxup
481 nxup cnxup vnxup cvnxup znxup cznxup vznxup cvznxup
482 iup ciup viup cviup ziup cziup vziup cvziup
483 niup cniup vniup cvniup zniup czniup vzniup cvzniup
484 xiup cxiup vxiup cvxiup zxiup czxiup vzxiup cvzxiup
485 nxiup cnxiup vnxiup cvnxiup znxiup cznxiup vznxiup cvznxiup
486 )
487)
488
489(define-pmacro cc-condition (not cbit))
490(define-pmacro cs-condition cbit)
491(define-pmacro ne-condition (not zbit))
492(define-pmacro eq-condition zbit)
493(define-pmacro vc-condition (not vbit))
494(define-pmacro vs-condition vbit)
495(define-pmacro pl-condition (not nbit))
496(define-pmacro mi-condition nbit)
497(define-pmacro ls-condition (or cbit zbit))
498(define-pmacro hi-condition (not (or cbit zbit)))
499(define-pmacro ge-condition (not (xor vbit nbit)))
500(define-pmacro lt-condition (xor vbit nbit))
501(define-pmacro gt-condition (not (or (xor vbit nbit) zbit)))
502(define-pmacro le-condition (or (xor vbit nbit) zbit))
503(define-pmacro a-condition 1)
504
505; FIXME: define this properly for v10 and pre-v10.
506(define-pmacro wf-condition pbit)
507
508(define-pmacro (cris-condition condno)
509 "Return condition state for condition number CONDNO"
510 (sequence
511 BI
512 ((SI tmpcond) (BI condres))
513 (set tmpcond condno)
514 (.splice
515 cond
516 (.unsplice
517 (.map
518 (.pmacro
519 (condn condc)
520 ((eq tmpcond condn) (set condres (.sym condc -condition))))
521 (.iota 16)
522 cris-condition-codes)))
523 condres)
524)
525
526;;;;;;;;;;;;;;;;;; -keyword
527
528; General registers.
529(define-pmacro (cris-general-gregs)
530 (.splice (SP 14) (.unsplice (.map (.pmacro (n) ((.sym R n) n)) (.iota 15))))
531)
532
533; Can't keep more than one gr-names definition at the same time;
534; generated enum declarations in sim/cris/cris-desc.h will collide.
535; FIXME: (include "different-mach-parts")
536
537(define-keyword
538 (name gr-names-pcreg)
539 (attrs MACH-PC)
540 (print-name h-gr-real-pc)
541 ; Put PC first so it is preferred over r15.
542 (.splice values (PC 15) (.unsplice (cris-general-gregs)))
543)
544
545(define-keyword
546 (name gr-names-acr)
547 (attrs MACH-ACR)
548 ; The print-name directive will control the enum prefix. With the
549 ; arguably more appropriate h-gr-v32 or h-gr-acr, we'd get names like
550 ; H_GR_ACR_R0 instead of H_GR_R0. Since we have to choose something for
551 ; unprefixed names, we use the CRISv32 names. FIXME: All users should
552 ; change to use H_GR_V32_R0 (etc.), then change this to h-gr-v32.
553 (print-name h-gr)
554 ; Put ACR first so it is preferred over r15.
555 (.splice values (ACR 15) (.unsplice (cris-general-gregs)))
556)
557
558(define-keyword
559 (name gr-names-v32)
560 (attrs MACH-V32)
561 ; In preparation for implementing the FIXME above.
562 (print-name h-gr-v32)
563 ; Put ACR first so it is preferred over r15.
564 (.splice values (ACR 15) (.unsplice (cris-general-gregs)))
565)
566
567; Special registers with names common to all.
568(define-pmacro (cris-general-pregs)
569 (.splice
570 (VR 1)
571 (SRP 11)
572 (.unsplice (.map (.pmacro (n) ((.sym P n) n)) (.iota 15))))
573)
574
575(define-keyword
576 (name p-names-v10)
577 (attrs MACH-PRE-V32)
578 (print-name h-sr-pre-v32)
579 (.splice
580 values
581 (CCR 5)
582 (MOF 7)
583 (IBR 9)
584 (IRP 10)
585 (BAR 12)
586 (DCCR 13)
587 (BRP 14)
588 (USP 15)
589 (.unsplice (cris-general-pregs)))
590)
591
592(define-keyword
593 (name p-names-v32)
594 (attrs MACH-V32)
595 ; See comment for gr-names-acr.
596 (print-name h-sr)
597 (.splice
598 values
599 (BZ 0)
600 (PID 2)
601 (SRS 3)
602 (WZ 4)
603 (EXS 5)
604 (EDA 6)
605 (MOF 7)
606 (DZ 8)
607 (EBP 9)
608 (ERP 10)
609 (NRP 12)
610 (CCS 13)
611 (USP 14)
612 (SPC 15)
613 (.unsplice (cris-general-pregs)))
614)
615
616; Similarly as for h-gr-v32, in preparation.
617(define-keyword
618 (name p-names-v32-x)
619 (attrs MACH-V32)
620 ; See comment for gr-names-acr.
621 (print-name h-sr-v32)
622 (.splice
623 values
624 (BZ 0)
625 (PID 2)
626 (SRS 3)
627 (WZ 4)
628 (EXS 5)
629 (EDA 6)
630 (MOF 7)
631 (DZ 8)
632 (EBP 9)
633 (ERP 10)
634 (NRP 12)
635 (CCS 13)
636 (USP 14)
637 (SPC 15)
638 (.unsplice (cris-general-pregs)))
639)
640
641(define-pmacro p0 (reg h-sr 0))
642(define-pmacro vr (reg h-sr 1))
643(define-pmacro pid (reg h-sr 2))
644(define-pmacro srs (reg h-sr 3))
645(define-pmacro p4 (reg h-sr 4))
646(define-pmacro ccr (reg h-sr 5))
647(define-pmacro mof (reg h-sr 7))
648(define-pmacro p8 (reg h-sr 8))
649(define-pmacro ibr (reg h-sr 9))
650(define-pmacro ebp (reg h-sr 9))
651(define-pmacro erp (reg h-sr 10))
652(define-pmacro srp (reg h-sr 11))
653(define-pmacro ccs (reg h-sr 13))
654(define-pmacro dccr (reg h-sr 13))
655(define-pmacro usp (reg h-sr 14))
656(define-pmacro spc (reg h-sr 15))
657
658(define-pmacro sp (reg h-gr 14))
659(define-pmacro acr (reg h-gr 15))
660
661(define-pmacro cris-condition-codes
662 "CRIS condition codes in numeric order"
663 (cc cs ne eq vc vs pl mi ls hi ge lt gt le a wf)
664)
665
666; No use having different lists; this is the only CC that
667; differs between v10 and v32, and mostly in the name.
668(define-pmacro sb wf)
669
670
671;;;;;;;;;;;;;;;;;; -hardware
672
673;; Various constant generators.
674
675(define-hardware
676 (name h-inc)
677 (comment "autoincrement-bit syntax specifier")
678 (type immediate (UINT 1))
679 (values keyword "" (("" 0) ("+" 1)))
680)
681
682(define-hardware
683 (name h-ccode)
684 (comment "Condition code specifier")
685 (type immediate (UINT 4))
686 (values keyword ""
687 (.map (.pmacro (x y) ((.str x) y))
688 cris-condition-codes (.iota 16)))
689)
690
691(define-hardware
692 (name h-swap)
693 (comment "Swap option specifier")
694 (type immediate (UINT 4))
695 (values
696 keyword ""
697 (.splice
698 (" " 0)
699 (.unsplice
700 (.map
701 (.pmacro (x y) ((.str x) y)) cris-swap-codes (.iota 15 1)))))
702)
703
704(define-hardware
705 (name h-flagbits)
706 (comment "Flag bits specifier")
707 (type immediate (UINT 8))
708 (values
709 keyword ""
710 (.map (.pmacro (x y) ((.str x) y)) cris-flag-combinations (.iota 256)))
711)
712
713; Apparently, the semantic-name isn't used for accessors, so external
714; users like the sim glue and SID sees the -v32 and -pre-v32 munged names.
715; Defining "dispatchers"; virtual registers whose getter and setter works
716; on the "real" mach variants, seems to help. CGEN-FIXME: Make
717; semantic-name set the generated names.
718(define-pmacro (cris-d-hwreg x-name x-type)
719 (define-hardware
720 (name x-name)
721 (comment (.str "Dispatcher for " x-name))
722 (attrs VIRTUAL)
723 (type register x-type)
724 (get () (reg (.sym x-name -x)))
725 (set (val) (set (reg (.sym x-name -x)) val)))
726)
727(define-pmacro (cris-d-hwregf-a x-name x-type x-n x-attrs)
728 (define-hardware
729 (name x-name)
730 (comment (.str "Dispatcher for " x-name))
731 (.splice attrs VIRTUAL (.unsplice x-attrs))
732 (type register x-type (x-n))
733 (get (index) (reg (.sym x-name -x) index))
734 (set (index val) (set-quiet (reg (.sym x-name -x) index) val)))
735)
736(define-pmacro (cris-d-hwregf x-name x-type x-n)
737 (cris-d-hwregf-a x-name x-type x-n ())
738)
739(define-pmacro (cris-d-hwregf-p x-name x-type x-n)
740 (cris-d-hwregf-a x-name x-type x-n (PROFILE))
741)
742
743; At first glance we could use (eq-attr (current-mach) ...) for
744; everything, but that seems sometimes (always?) to yield false. For
745; ifields, it causes noncompilable C-code. For the insn semantics code,
746; it causes tests movei.ms and mulv32.ms to fail, apparently because the
747; current-mach-is-v32 usage in flags setting is miscompiled as 0 (or
748; rather, misgenerated). Instead we use different definitions of a
749; MACH-tagged virtual register yielding a constant, together with a
750; pmacro. CGEN-FIXME: If eq-attr is someday fixed, we could just remove
751; these h-v32 virtual register definitions and change the pmacro
752; definition for current-mach-is-v32.
753(define-hardware
754 (semantic-name h-v32)
755 (name h-v32-v32)
756 (attrs MACH-V32 VIRTUAL)
757 (type register BI)
758 (get () (const BI 1))
759 (set (val) (error "Can't set h-v32"))
760)
761(define-hardware
762 (semantic-name h-v32)
763 (name h-v32-non-v32)
764 (attrs MACH-PRE-V32 VIRTUAL)
765 (type register BI)
766 (get () (const BI 0))
767 (set (val) (error "Can't set h-v32"))
768)
769
770;; "Real" hardware.
771
772(define-hardware
773 (name h-pc)
774 (comment "program counter")
775 (attrs PC PROFILE)
776 (type pc)
777 ; There's no bit 0 in PC, so just ignore it when jumping etc.
778 (set (val) (set (raw-reg h-pc) (and val (inv 1))))
779)
780
781; Note that setting register 15 isn't handled here, but in each insn, so
782; the proper "jump" attributes and other special stuff for speedy
783; execution can be present.
784(cris-d-hwregf-p h-gr SI 16)
785(define-hardware
786 (semantic-name h-gr-x)
787 (name h-gr-pc)
788 (attrs MACH-PC VIRTUAL)
789 (comment "General purpose registers, aborting on PC access")
790 (type register SI (16))
791 (indices extern-keyword gr-names-pcreg)
792 (get
793 (index)
794 (if SI (eq index 15)
795 (error SI "General register read of PC is not implemented.")
796 (reg SI h-gr-real-pc index)))
797 (set
798 (index val)
799 (sequence
800 ()
801 (if (eq index 15)
802 (error "General register write to PC is not implemented."))
803 (set (reg SI h-gr-real-pc index) val)))
804)
805(define-hardware
806 (name h-gr-real-pc)
807 (attrs MACH-PC)
808 (comment "General purpose registers")
809 (type register SI (16))
810 (indices extern-keyword gr-names-pcreg)
811)
812
813; We have to use a virtual register trick to get the "raw", unaccounted
814; contents of the global register; the raw-reg RTX only works for
815; non-virtual register files.
816(define-hardware
817 (semantic-name h-raw-gr)
818 (name h-raw-gr-pc)
819 (attrs MACH-PC VIRTUAL)
820 (comment "Unaccounted version of general purpose registers")
821 (type register SI (16))
822 (get (index) (raw-reg h-gr-real-pc index))
823 (set (index val) (set-quiet (raw-reg h-gr-real-pc index) val))
824)
825(define-hardware
826 (semantic-name h-gr-x)
827 (name h-gr-acr)
828 (attrs MACH-ACR)
829 (comment "General purpose registers")
830 (type register SI (16))
831 (indices extern-keyword gr-names-acr)
832)
833(define-hardware
834 (semantic-name h-raw-gr)
835 (name h-raw-gr-acr)
836 (attrs MACH-ACR VIRTUAL)
837 (comment "Unaccounted version of general purpose registers")
838 (type register SI (16))
839 (get (index) (raw-reg h-gr-x index))
840 (set (index val) (set-quiet (raw-reg h-gr-x index) val))
841)
842
843; FIXME: get and set semantics? Unknown how to split semantics best; with
844; get/set semantics or within the insn specification. Doing the former for
845; now. Should use different names for pre-v10.
846; FIXME: No dccr for v0 and v3. Different high flag bits.
847(cris-d-hwregf-p h-sr SI 16)
848(define-pmacro
849 (cris-h-sr machver)
850 (define-hardware
851 (semantic-name h-sr-x)
852 (name (.sym h-sr-v machver))
853 (attrs (MACH (.sym crisv machver)))
854 (comment (.str "Special registers for v" machver))
855 (type register SI (16))
856 (indices extern-keyword p-names-v10)
857 (get
858 (index)
859 (cond
860 SI
861 ((orif (orif (eq index (regno p0)) (eq index (regno p4)))
862 (eq index (regno p8))) 0)
863 ((eq index (regno vr)) machver)
864 ((orif (eq index (regno ccr))
865 (eq index (regno dccr)))
866 ; Return "P U I X N Z V C" for the low 8 bits.
867 ; FIXME: More bits.
868 (or SI
869 (and SI (raw-reg SI h-sr-x (regno ccr)) #xffffff00)
870 (or
871 (zext SI (reg BI h-cbit))
872 (or
873 (sll (zext SI (reg BI h-vbit)) 1)
874 (or
875 (sll (zext SI (reg BI h-zbit)) 2)
876 (or
877 (sll (zext SI (reg BI h-nbit)) 3)
878 (or
879 (sll (zext SI (reg BI h-xbit)) 4)
880 (or
881 (sll (zext SI (reg BI h-ibit)) 5)
882 (or
883 (sll (zext SI (reg BI h-ubit)) 6)
884 (or
885 (sll (zext SI (reg BI h-pbit)) 7)
886 0))))))))))
887 (else (raw-reg SI h-sr-x index))))
888 (set
889 (index val)
890 (cond
891 ((orif (orif (eq index (regno p0)) (eq index (regno p4)))
892 (orif (eq index (regno p8)) (eq index (regno vr))))
893 (nop))
894 ((orif (eq index (regno ccr)) (eq index (regno dccr)))
895 (sequence
896 ()
897 (set (reg BI h-cbit) (if BI (ne SI (and val (sll 1 0)) 0) 1 0))
898 (set (reg BI h-vbit) (if BI (ne SI (and val (sll 1 1)) 0) 1 0))
899 (set (reg BI h-zbit) (if BI (ne SI (and val (sll 1 2)) 0) 1 0))
900 (set (reg BI h-nbit) (if BI (ne SI (and val (sll 1 3)) 0) 1 0))
901 (set (reg BI h-xbit) (if BI (ne SI (and val (sll 1 4)) 0) 1 0))
902 (set (reg BI h-ibit) (if BI (ne SI (and val (sll 1 5)) 0) 1 0))
903 (set (reg BI h-ubit) (if BI (ne SI (and val (sll 1 6)) 0) 1 0))
904 (set (reg BI h-pbit) (if BI (ne SI (and val (sll 1 7)) 0) 1 0))
905 (set-quiet (raw-reg SI h-sr-x (regno ccr)) val)
906 (set-quiet (raw-reg SI h-sr-x (regno dccr)) val)))
907 (else (set-quiet (raw-reg SI h-sr-x index) val)))))
908)
909
910(cris-h-sr 0)
911(cris-h-sr 3)
912(cris-h-sr 8)
913(cris-h-sr 10)
914
915(define-hardware
916 (semantic-name h-sr-x)
917 (name h-sr-v32)
918 (attrs MACH-V32)
919 (comment "Special registers for v32")
920 (type register SI (16))
921 (indices extern-keyword p-names-v32)
922
923 (get
924 (index)
925 (cond
926 SI
927 ((orif (orif (eq index (regno p0)) (eq index (regno p4)))
928 (eq index (regno p8))) 0)
929 ((eq index (regno vr)) 32)
930 ((eq index (regno ccs))
931 ; Return "S R P U I X N Z V C" for the low 10 bits.
932 (or SI
933 (and SI (raw-reg SI h-sr-x (regno ccs)) #x3ffffc00)
934 (or
935 (zext SI (reg BI h-cbit))
936 (or
937 (sll (zext SI (reg BI h-vbit)) 1)
938 (or
939 (sll (zext SI (reg BI h-zbit)) 2)
940 (or
941 (sll (zext SI (reg BI h-nbit)) 3)
942 (or
943 (sll (zext SI (reg BI h-xbit)) 4)
944 (or
945 (sll (zext SI (reg BI h-ibit)) 5)
946 (or
947 (sll (zext SI (reg BI h-ubit)) 6)
948 (or
949 (sll (zext SI (reg BI h-pbit)) 7)
950 (or
951 (sll (zext SI (reg BI h-rbit)) 8)
952 (or
953 (sll (zext SI (reg BI h-sbit)) 9)
954 (or
955 (sll (zext SI (reg BI h-mbit)) 30)
956 (or
957 (sll (zext SI (reg BI h-qbit)) 31)
958 0))))))))))))))
959 ((eq index (regno usp))
960 ; In user mode, return general stack pointer.
961 (if BI (reg BI h-ubit)
962 (raw-reg SI h-gr-x (regno sp))
963 (raw-reg SI h-sr-x (regno usp))))
964 (else (raw-reg SI h-sr-x index))))
965
966 (set
967 (index val)
968 (cond
969 ((orif (orif (eq index (regno p0)) (eq index (regno p4)))
970 (orif (eq index (regno p8)) (eq index (regno vr))))
971 (nop))
972 ((eq index (regno ccs))
973 (sequence
974 ()
975 ; Protected bits are handled as such in the respective setter function.
976 (set (reg BI h-cbit) (if BI (ne SI (and val (sll 1 0)) 0) 1 0))
977 (set (reg BI h-vbit) (if BI (ne SI (and val (sll 1 1)) 0) 1 0))
978 (set (reg BI h-zbit) (if BI (ne SI (and val (sll 1 2)) 0) 1 0))
979 (set (reg BI h-nbit) (if BI (ne SI (and val (sll 1 3)) 0) 1 0))
980 (set (reg BI h-xbit) (if BI (ne SI (and val (sll 1 4)) 0) 1 0))
981 (set (reg BI h-ibit) (if BI (ne SI (and val (sll 1 5)) 0) 1 0))
982 (set (reg BI h-sbit) (if BI (ne SI (and val (sll 1 9)) 0) 1 0))
983 (set (reg BI h-mbit) (if BI (ne SI (and val (sll 1 30)) 0) 1 0))
984 (set (reg BI h-pbit) (if BI (ne SI (and val (sll 1 7)) 0) 1 0))
985 (set (reg BI h-rbit) (if BI (ne SI (and val (sll 1 8)) 0) 1 0))
986 (set (reg BI h-qbit) (if BI (ne SI (and val (sll 1 31)) 0) 1 0))
987 ; Set the U bit last, so the setter functions for the other bits
988 ; don't see it as set from this operation. It is not cleared from
989 ; this operation, so we don't have to handle that; it's only
990 ; cleared "manually" from within simulator-specific context-switch
991 ; machinery.
992 (set (reg BI h-ubit) (if BI (ne SI (and val (sll 1 6)) 0) 1 0))
993 (set-quiet (raw-reg SI h-sr-x index) val)))
994 ((eq index (regno usp))
995 ; In user mode, set general register 14 too, whenever setting USP.
996 (sequence
997 ()
998 (if (reg BI h-ubit) (set (raw-reg SI h-gr-x (regno sp)) val))
999 (set (raw-reg SI h-sr-x (regno usp)) val)))
1000 ((eq index (regno srs))
1001 (if (not (reg BI h-ubit)) (set (raw-reg h-sr-x (regno srs)) val)))
1002 ((eq index (regno ebp))
1003 (if (not (reg BI h-ubit)) (set (raw-reg h-sr-x (regno ebp)) val)))
1004 ((eq index (regno pid))
1005 (if (not (reg BI h-ubit))
1006 (sequence
1007 ()
1008 (c-call VOID "@cpu@_write_pid_handler" val)
1009 (set (raw-reg h-sr-x (regno pid)) val))))
1010 ((eq index (regno spc))
1011 (if (not (reg BI h-ubit)) (set (raw-reg h-sr-x (regno spc)) val)))
1012 (else (set-quiet (raw-reg SI h-sr-x index) val))))
1013)
1014
1015(define-hardware
1016 (name h-supr)
1017 (attrs MACH-V32 VIRTUAL)
1018 (comment "Support registers")
1019 (type register SI (16))
1020 (values keyword "" (.map (.pmacro (y) ((.str S y) y)) (.iota 16)))
1021 (get (index) (c-call SI "@cpu@_read_supr" index))
1022 (set (index val) (c-call VOID "@cpu@_write_supr" index val))
1023)
1024
1025(define-pmacro (cris-dsh semantic-name name comment attrs type)
1026 "Like dsh, but the semantic-name is separate"
1027 (define-full-hardware
1028 name comment attrs semantic-name type () () () () () ())
1029)
1030
1031; We define the condition codes that hold arithmetic flags separately
1032; and "or" them in, in the get and set methods of the special
1033; registers. We define arithmetic flags as any of C V Z N X. They
1034; thankfully have that order (zero-based) in all processor versions.
1035
1036; To avoid having two variants of most move-type instructions because V32
1037; doesn't set C and V (and N and Z), we fake the setting to virtual
1038; registers which have two different implementations.
1039(define-pmacro (cris-move-flag f f-name f-whence)
1040 "Flag set differently in pre-v32 and v32 in some cases"
1041 (begin
1042 (dsh (.sym h- f bit) (.str f-name " bit") () (register BI))
1043 (cris-d-hwreg (.sym h- f bit-move) BI)
1044 (define-hardware
1045 (semantic-name (.sym h- f bit-move-x))
1046 (name (.sym h- f bit-move-v32))
1047 (comment (.str f-name " bit set in " f-whence " instructions, ignored"))
1048 (attrs MACH-V32 VIRTUAL)
1049 (type register BI)
1050 (get
1051 ()
1052 (sequence BI ()
1053 (error (.str "Can't get h-" f "bit-move on CRISv32")) 0))
1054 (set (val) (nop)))
1055 (define-hardware
1056 (semantic-name (.sym h- f bit-move-x))
1057 (name (.sym h- f bit-move-pre-v32))
1058 (comment
1059 (.str
1060 f-name " bit set in " f-whence " instructions, same as " f "bit"))
1061 (attrs MACH-PRE-V32 VIRTUAL)
1062 (type register BI)
1063 (get () (reg (.sym h- f bit)))
1064 (set (val) (set (reg (.sym h- f bit)) val))))
1065)
1066
1067(cris-move-flag c "carry" "move-type")
1068(cris-move-flag v "overflow" "move-type")
1069(cris-move-flag z "zero" "moveq")
1070(cris-move-flag n "sign" "moveq")
1071
1072(dsh h-xbit "extended-arithmetic bit" () (register BI))
1073(cris-d-hwreg h-ibit BI)
1074(cris-dsh h-ibit-x h-ibit-pre-v32
1075 "interrupt-enable bit" (MACH-PRE-V32) (register BI))
1076(dsh h-pbit "sequence-broken bit" ((MACH crisv10,crisv32)) (register BI))
1077(dsh h-rbit "carry bit for MCP+restore-p bit" (MACH-V32) (register BI))
1078(cris-d-hwreg h-ubit BI)
1079(cris-dsh h-ubit-x h-ubit-pre-v32
1080 "user mode bit" ((MACH crisv10)) (register BI))
1081(dsh h-gbit "guru mode bit" (MACH-V32) (register BI))
1082
1083; When doing a transition from kernel to user mode on V32, we save the
1084; stack pointer in an internal register and copy USP to R14, so we don't
1085; need non-trivial handlers for general registers.
1086(dsh
1087 h-kernel-sp
1088 "Kernel stack pointer during user mode"
1089 (MACH-V32)
1090 (register SI)
1091)
1092
1093(define-hardware
1094 (semantic-name h-ubit-x)
1095 (name h-ubit-v32)
1096 (comment "User mode bit")
1097 (attrs MACH-V32)
1098 (type register BI)
1099 (set
1100 (val)
1101 (sequence
1102 ()
1103 (if (andif val (not (raw-reg BI h-ubit-x)))
1104 (sequence
1105 ()
1106 (set (reg SI h-kernel-sp) (raw-reg h-gr-x (regno sp)))
1107 (set (raw-reg h-gr-x (regno sp)) (raw-reg h-sr-x (regno usp)))
1108 (set (raw-reg BI h-ubit-x) val)
1109 (c-call VOID "@cpu@_usermode_enabled")))))
1110)
1111
1112(define-hardware
1113 (semantic-name h-ibit-x)
1114 (name h-ibit-v32)
1115 (comment "Interrupt-enable bit")
1116 (attrs MACH-V32)
1117 (type register BI)
1118 (set
1119 (val)
1120 (sequence
1121 ()
1122 (if (not (reg BI h-ubit))
1123 (sequence
1124 ((BI enabled))
1125 (set enabled (andif val (not (raw-reg BI h-ibit-x))))
1126 (set (raw-reg BI h-ibit-x) val)
1127 ; Call handler when enabling.
1128 (if enabled (c-call VOID "@cpu@_interrupts_enabled"))))))
1129)
1130
1131(define-hardware
1132 (name h-mbit)
1133 (comment "NMI enable bit")
1134 (attrs MACH-V32)
1135 (type register BI)
1136 (set
1137 (val)
1138 (sequence
1139 ()
1140 ; Don't allow clearing (through this handler) when once set.
1141 (if (andif val (andif (not (raw-reg BI h-mbit)) (not (reg BI h-ubit))))
1142 (sequence
1143 ()
1144 (set (raw-reg BI h-mbit) 1)
1145 ; Call handler when enabling.
1146 (c-call VOID "@cpu@_nmi_enabled")))))
1147)
1148
1149(define-pmacro
1150 (dsh-cond-bit-v32 x-name x-comment x-cond)
1151 "dsh bit for MACH-V32, with bit only changeable when X-COND"
1152 (define-hardware
1153 (name x-name)
1154 (comment x-comment)
1155 (attrs MACH-V32)
1156 (type register BI)
1157 (set (val) (sequence () (if x-cond (set (raw-reg BI x-name) val)))))
1158)
1159(define-pmacro
1160 (dsh-protected-bit-v32 x-name x-comment)
1161 "dsh bit for MACH-V32, with bit only changeable in kernel mode"
1162 (dsh-cond-bit-v32 x-name x-comment (not (reg BI h-ubit)))
1163)
1164(dsh-protected-bit-v32 h-qbit "Pending single-step bit")
1165
1166(define-hardware
1167 (name h-sbit)
1168 (comment "Cause single step exception on ... [see CRISv32 ref] bit")
1169 (attrs MACH-V32)
1170 (type register BI)
1171 (set
1172 (val)
1173 (sequence
1174 ()
1175 (if (not (reg BI h-ubit))
1176 (sequence
1177 ((BI enabled))
1178 (set enabled (andif val (not (raw-reg BI h-sbit))))
1179 (set (raw-reg BI h-sbit) val)
1180 ; Call handler when enabling.
1181 (if enabled (c-call VOID "@cpu@_single_step_enabled"))))))
1182)
1183
1184(dnop cbit "" (SEM-ONLY) h-cbit f-nil)
1185(dnop cbit-move
1186 "cbit for pre-V32, nothing for newer" (SEM-ONLY) h-cbit-move f-nil)
1187(dnop vbit "" (SEM-ONLY) h-vbit f-nil)
1188(dnop vbit-move
1189 "vbit for pre-V32, nothing for newer" (SEM-ONLY) h-vbit-move f-nil)
1190(dnop zbit "" (SEM-ONLY) h-zbit f-nil)
1191(dnop zbit-move
1192 "zbit for pre-V32, nothing for newer" (SEM-ONLY) h-zbit-move f-nil)
1193(dnop nbit "" (SEM-ONLY) h-nbit f-nil)
1194(dnop nbit-move
1195 "nbit for pre-V32, nothing for newer" (SEM-ONLY) h-nbit-move f-nil)
1196(dnop xbit "" (SEM-ONLY) h-xbit f-nil)
1197(dnop ibit "" (SEM-ONLY) h-ibit f-nil)
1198(dnop ubit "" (SEM-ONLY (MACH crisv10,crisv32)) h-ubit f-nil)
1199(dnop pbit "" (SEM-ONLY (MACH crisv10,crisv32)) h-pbit f-nil)
1200(dnop
1201 rbit "carry bit for MCP+restore-P flag bit" (SEM-ONLY MACH-V32) h-rbit f-nil)
1202(dnop sbit "" (SEM-ONLY MACH-V32) h-sbit f-nil)
1203(dnop mbit "" (SEM-ONLY MACH-V32) h-mbit f-nil)
1204(dnop qbit "" (SEM-ONLY MACH-V32) h-qbit f-nil)
1205
1206(cris-d-hwreg h-insn-prefixed-p BI)
1207(cris-dsh
1208 h-insn-prefixed-p-x
1209 h-insn-prefixed-p-pre-v32
1210 "instruction-is-prefixed bit"
1211 (MACH-PRE-V32)
1212 (register BI)
1213)
1214
1215; CRISv32 has no prefixing on memory accesses. CGEN-FIXME: [Once (eq-attr
1216; (current-mach) ...) works]: can we change andif and/or orif so it
1217; doesn't look too close at short-circuited operands and avoid defining an
1218; operand that doesn't apply to a certain mach?
1219(define-hardware
1220 (semantic-name h-insn-prefixed-p-x)
1221 (name h-insn-prefixed-p-v32)
1222 (attrs MACH-V32 VIRTUAL)
1223 (comment "instruction-is-prefixed bit")
1224 (type register BI)
1225 (get () (const BI 0))
1226 (set (val) (nop))
1227)
1228(dnop
1229 prefix-set
1230 "Instruction-prefixed flag"
1231 (SEM-ONLY)
1232 h-insn-prefixed-p
1233 f-nil
1234)
1235
1236(cris-dsh
1237 h-prefixreg h-prefixreg-pre-v32
1238 "Prefix-address register" (MACH-PRE-V32) (register SI))
1239(define-hardware
1240 (semantic-name h-prefixreg)
1241 (name h-prefixreg-v32)
1242 (comment "Prefix-address register, redirecting to ACR")
1243 (attrs MACH-V32 VIRTUAL)
1244 (type register SI)
1245 ; Why can't we have just a "acr" a.k.a "(reg h-gr 15)" here?
1246 (get () acr)
1247 (set (value) (set acr value))
1248)
1249
1250(dnop
1251 prefixreg
1252 "Prefix address"
1253 (SEM-ONLY)
1254 h-prefixreg
1255 f-nil
1256)
1257
1258;;;;;;;;;;;;;;;;;; -ifield
1259
1260; 15 0
1261; +-----------+-----+-----------+-----+-----------+
1262; | Operand2 | Mode| Opcode | Size| Operand1 |
1263; +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1264;
1265; Figure 5. General instruction format.
1266;
1267; Some deviations from this format exist, [see below].
1268
1269; Field specifiers in CGEN specify the highest numbered bit followed by
1270; the number of bits.
1271
1272(dnf f-operand1 "Operand1" () 3 4)
1273(dnf f-size "Size" () 5 2)
1274(dnf f-opcode "Opcode" () 9 4)
1275(dnf f-mode "Mode" () 11 2)
1276(dnf f-operand2 "Operand2" () 15 4)
1277
1278; Subfields. FIXME: unfortunately there's some limitation in CGEN so we
1279; can't (as would be somewhat intuitive) make f-mode a multi-ifield
1280; consisting of these two, concatenated.
1281(dnf f-memmode "Indirect of autoincrement" () 10 1)
1282(dnf f-membit "Memory specifier" () 11 1)
1283
1284(dnf f-b5 "Bit 5 (zero for some quick operands)" () 5 1)
1285
1286; When the addressing mode is quick immediate, the low bits are
1287; part of the operand.
1288(dnf f-opcode-hi "Opcode field, high bits" () 9 2)
1289
1290; Common synonyms for those fields.
1291(define-pmacro f-source f-operand1)
1292(define-pmacro f-dest f-operand2)
1293
1294(dnmf
1295 f-dstsrc "Dest and source fields concatenated" () UINT
1296 (f-dest f-source)
1297 ; Insert-code.
1298 (sequence
1299 ((SI tmpval))
1300 (set tmpval (ifield f-dstsrc))
1301 (set (ifield f-dest) (and (srl tmpval 4) #xf))
1302 (set (ifield f-source) (and tmpval #xf)))
1303 ; Extract-code.
1304 (set
1305 (ifield f-dstsrc)
1306 (and (or (ifield f-source) (sll (ifield f-dest) 4)) #xff))
1307)
1308
1309;The 6-bit value may be sign or zero extended depending on the instruction.
1310;
1311; 15 0
1312; +-----------+-----+-----------+-----+-----------+
1313; | Operand2 | Mode| Opcode | Immediate value |
1314; +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1315;
1316; Figure 6. Quick immediate addressing mode instruction format.
1317
1318(dnf f-u6 "Quick immediate unsigned 6-bit" () 5 6)
1319(df f-s6 "Quick signed 6-bit" () 5 6 INT #f #f)
1320
1321; There's also a variant used with shift insns, with one bit larger opcode
1322; and one bit smaller immediate value, though it doesn't have a general
1323; graphic description.
1324(dnf f-u5 "Quick unsigned 5-bit" () 4 5)
1325
1326; Similarly, a four-bit immediate field.
1327(dnf f-u4 "Quick unsigned 4-bit" () 3 4)
1328
1329; An 8-bit signed value, which doesn't have a general graphic description.
1330(df f-s8 "Source signed byte" () 7 8 INT #f #f)
1331
1332; The 9-bit branch offset, with bit 0 in the field being bit 8 in the
1333; offset, and bit 0 in the offset always 0.
1334(df f-disp9-hi "PC-relative 9-bit offset, sign bit" () 0 1 INT #f #f)
1335(dnf f-disp9-lo "PC-relative 9-bit offset, low bits" () 7 7)
1336
1337; It would work to have this in two mach-specific variants, but
1338; considering that current-mach-is-v32 is a compile-time constant, we
1339; don't win any simulator performance.
1340(dnmf
1341 f-disp9 "PC-relative 9-bit offset"
1342 (PCREL-ADDR)
1343 INT
1344 (f-disp9-hi f-disp9-lo)
1345 ; Insert-code.
1346 (sequence
1347 ((SI absval))
1348 (set absval (srl (sub (sub SI (ifield f-disp9) pc)
1349 (if SI current-mach-is-v32 0 2)) 1))
1350 (set (ifield f-disp9-hi) (if (lt absval 0) 1 0))
1351 (set (ifield f-disp9-lo) (and absval) #x7f))
1352 ; Extract-code.
1353 (sequence
1354 ((SI abslo) (SI absval))
1355 (set abslo (sll (ifield f-disp9-lo) 1))
1356 (set absval
1357 (or (if SI (ne (ifield f-disp9-hi) 0)
1358 (inv SI #xff)
1359 0)
1360 abslo))
1361 (set (ifield f-disp9)
1362 (add SI (add SI pc absval) (if SI current-mach-is-v32 0 2))))
1363)
1364
1365; The operand of LAPCQ is PC-relative, similar to f-disp9 but unsigned,
1366; and only four bits.
1367(df
1368 f-qo
1369 "PC-relative 4-bit unsigned offset, counted from start of insn"
1370 (MACH-V32 PCREL-ADDR)
1371 3 4
1372 UINT
1373 ; Insert-code.
1374 ((value pc) (srl SI (sub SI value pc) 1))
1375 ; Extract-code.
1376 ((value pc) (add SI pc (sll SI value 1)))
1377)
1378
1379; 8-bit, 16-bit and 32-bit immediates. The 8-bit values are constructed
1380; through encoding/decoding functions, since the PC increment is by a
1381; word.
1382(define-pmacro (dcrisf x-name x-comment x-attrs x-word-offset x-word-length
1383 x-start x-length x-mode x-encode x-decode)
1384 (define-ifield
1385 (name x-name)
1386 (comment x-comment)
1387 (.splice attrs (.unsplice x-attrs))
1388 (word-offset x-word-offset)
1389 (word-length x-word-length)
1390 (start x-start)
1391 (length x-length)
1392 (mode x-mode)
1393 (.splice encode (.unsplice x-encode))
1394 (.splice decode (.unsplice x-decode))
1395 )
1396)
1397
1398(dcrisf
1399 f-indir-pc+-byte "[PC+] 8-bit field" (SIGN-OPT)
1400 16 16
1401 15 16 ; CGEN-FIXME: Should be 7 8
1402 INT (#f) (#f)
1403)
1404
1405(dcrisf
1406 f-indir-pc+-word "[PC+] 16-bit field" (SIGN-OPT)
1407 16 16 15 16 INT (#f) (#f)
1408)
1409
1410; CGEN-FIXME: I shouldn't have to use trunc here, should I?
1411; Sign-extension should be implicit through use of SI (as opposed to USI)
1412; and additionally through SIGN-OPT. The ext isn't actually needed, but
1413; having it there rather than implicit makes more sense than to just have
1414; the trunc.
1415(dcrisf
1416 f-indir-pc+-word-pcrel "[PC+] PC-relative 16-bit field"
1417 (PCREL-ADDR SIGN-OPT)
1418 16 16 15 16 SI
1419 ((value pc) (sub SI value (add SI pc (if SI current-mach-is-v32 0 4))))
1420 ((value pc) (add SI (ext SI (trunc HI value)) (add SI pc (if SI current-mach-is-v32 0 4))))
1421)
1422
1423(dcrisf
1424 f-indir-pc+-dword "PC autoincrement - 32-bit field" (SIGN-OPT)
1425 16 32 31 32 INT (#f) (#f)
1426)
1427
1428(dcrisf
1429 f-indir-pc+-dword-pcrel
1430 "[PC+] PC-relative 32-bit field, counted from start of insn"
1431 (SIGN-OPT MACH-V32 PCREL-ADDR)
1432 16 32 31 32 INT
1433 ((value pc) (sub SI value pc))
1434 ((value pc) (add SI pc value))
1435)
1436
1437;;;;;;;;;;;;;;;;;; -insn-enum -normal-operand -normal-derived-operand
1438
1439;; How different fields are transformed into something we put in insns.
1440
1441; m := size modifier, byte (00), word (01) or dword (10)
1442; z := size modifier, byte (0) or word (1)
1443; (For the latter, the "higher" bit is always 0, mapping trivially on m.)
1444
1445(define-normal-insn-enum
1446 insn-size
1447 "Standard instruction operand size"
1448 ()
1449 SIZE_
1450 f-size
1451 ("BYTE" "WORD" "DWORD" "FIXED")
1452)
1453
1454; The mode field for insns with "s" operand (perhaps with a partial set of
1455; operand types).
1456(define-normal-insn-enum
1457 insn-mode
1458 "Standard instruction addressing modes"
1459 ()
1460 MODE_
1461 f-mode
1462 ("QUICK_IMMEDIATE" "REGISTER" "INDIRECT" "AUTOINCREMENT")
1463)
1464
1465(define-normal-insn-enum
1466 insn-memoryness-mode
1467 "Whether the operand is indirect"
1468 ()
1469 MODEMEMP_
1470 f-membit
1471 ("NO" "YES")
1472)
1473
1474; FIXME: Needed?
1475(define-normal-insn-enum
1476 insn-memincness-mode
1477 "Whether the indirect operand is autoincrement"
1478 ()
1479 MODEINCP_
1480 f-memmode
1481 ("NO" "YES")
1482)
1483
1484; Special semantics for multiply.
1485(define-pmacro MODE_MULU MODE_INDIRECT)
1486(define-pmacro MODE_MULS MODE_AUTOINCREMENT)
1487
1488(define-normal-insn-enum
1489 insn-signed-size
1490 "Signed instruction operand size"
1491 ()
1492 SIGNED_
1493 f-size
1494 ("UNDEF_SIZE_0" "UNDEF_SIZE_1" "BYTE" "WORD")
1495)
1496
1497(define-normal-insn-enum
1498 insn-unsigned-size
1499 "Unsigned instruction operand size"
1500 ()
1501 UNSIGNED_
1502 f-size
1503 ("BYTE" "WORD" "UNDEF_SIZE_2" "UNDEF_SIZE_3")
1504)
1505
1506; Rs := source operand, register addressing mode
1507(dnop Rs "Source general register" () h-gr f-source)
1508
1509; [Rs] := source operand, indirect addressing mode
1510; = MODE_INDIRECT Rs
1511
1512; [Rs+] := source operand, autoincrement addressing mode (see note!)
1513; = MODE_AUTOINCREMENT Rs
1514
1515; The union of [Rs] and [Rs(+)]
1516; = MODEMEMP_YES Rs
1517
1518; Whether an indirect operand is increment can be obtained as an operand by
1519; = inc
1520(dnop inc "Incrementness of indirect operand" () h-inc f-memmode)
1521
1522; or as an affirmative specifier
1523; = MODEINCP_YES
1524; (or MODEINCP_NO)
1525
1526; s := source operand, any of the modes Rs, [Rs] or [Rs+]
1527; No common operand; each are handled separately, using the above definitions.
1528
1529; Ps := source operand, special register
1530; It's in the field usually used for the destination.
1531(dnop Ps "Source special register" () h-sr f-dest)
1532
1533; Ss := source operand, support register
1534; It's in the field usually used for the destination.
1535(dnop Ss "Source support register" (MACH-V32) h-supr f-dest)
1536
1537; Sd := source operand, support register
1538(dnop Sd "Destination support register" (MACH-V32) h-supr f-dest)
1539
1540; i := 6-bit signed immediate operand
1541(dnop i "Quick signed 6-bit" () h-sint f-s6)
1542
1543; j := 6-bit unsigned immediate operand
1544(dnop j "Quick unsigned 6-bit" () h-uint f-u6)
1545
1546; c := 5-bit immediate shift value
1547(dnop c "Quick unsigned 5-bit" () h-uint f-u5)
1548
1549; qo := 4-bit unsigned immediate operand
1550(dnop qo "Quick unsigned 4-bit, PC-relative" (MACH-V32) h-addr f-qo)
1551
1552; Rd := destination operand, register addressing mode
1553(dnop Rd "Destination general register" () h-gr f-dest)
1554(define-pmacro Rd-sfield Rs)
1555(define-pmacro Rs-dfield Rd)
1556
1557; [Rd] := destination operand, indirect addressing mode
1558; = MODE_INDIRECT Rd
1559
1560; [Rd+] := destination operand, autoincrement addressing mode
1561; = MODE_AUTOINCREMENT Rd
1562
1563; [PC+] := destination operand PC, autoincrement addressing mode
1564; = MODE_AUTOINCREMENT (f-dest 15) X
1565; where X is one of sconst8, uconst8, sconst16, uconst16 or const32.
1566(dnop sconst8 "Signed byte [PC+]" () h-sint f-indir-pc+-byte)
1567(dnop uconst8 "Unsigned byte [PC+]" () h-uint f-indir-pc+-byte)
1568(dnop sconst16 "Signed word [PC+]" () h-sint f-indir-pc+-word)
1569(dnop uconst16 "Unsigned word [PC+]" () h-uint f-indir-pc+-word)
1570(dnop const32 "Dword [PC+]" () h-uint f-indir-pc+-dword)
1571(dnop const32-pcrel "Dword [PC+]" () h-addr f-indir-pc+-dword-pcrel)
1572
1573; d := destination operand, any of the modes Rd, [Rd] or [Rd+]
1574; No common operand; each are handled separately, using the above definitions.
1575
1576; Pd := destination operand, special register
1577(dnop Pd "Destination special register" () h-sr f-dest)
1578
1579; o := 8-bit immediate offset value
1580(dnop o "Signed 8-bit" () h-sint f-s8)
1581
1582; The division of operand semantics and insn fields in the CRIS
1583; instruction set reference doesn't permit a simple mapping to a
1584; simulator description, and the division of insn fields and
1585; semantics in CGEN is not between the define-normal-ifield
1586; vs. define-normal-operand. For example, the "o" operand is
1587; PC-relative for branch insns, as described by the CGEN f-disp9
1588; field.
1589; See comment at f-disp9; thankfully the mach
1590; attribute works here to have two different definitions by the
1591; same name.
1592(dnop o-pcrel "9-bit signed immediate PC-rel"
1593 ()
1594 h-iaddr f-disp9)
1595
1596(dnop o-word-pcrel "16-bit signed immediate PC-rel"
1597 ()
1598 h-iaddr f-indir-pc+-word-pcrel)
1599
1600; cc := condition code
1601(dnop cc "Condition codes" () h-ccode f-dest)
1602
1603; n := 4 bit breakpoint exception vector index
1604(dnop n "Quick unsigned 4-bit" () h-uint f-u4)
1605
1606; The "option" in the SWAP insn.
1607(dnop swapoption "Swap option" () h-swap f-dest)
1608
1609(dnop list-of-flags "Flag bits as operand" () h-flagbits f-dstsrc)
1610
1611; Enumerations for insn codes, for use in insn definitions
1612; instead of raw numbers. See it as operand definitions for the
1613; opcode field.
1614
1615(define-normal-insn-enum
1616 insn-qi-opc
1617 "Insns for MODE_QUICK_IMMEDIATE"
1618 ()
1619 Q_
1620 f-opcode
1621 ("BCC_0" "BCC_1" "BCC_2" "BCC_3"
1622 "BDAP_0" "BDAP_1" "BDAP_2" "BDAP_3"
1623 "ADDQ" "MOVEQ" "SUBQ" "CMPQ"
1624 "ANDQ" "ORQ" "ASHQ" "LSHQ")
1625)
1626
1627(define-normal-insn-enum
1628 insn-qihi-opc
1629 "Same as insn-qi-opc, though using only the high two bits of the opcode"
1630 ()
1631 QHI_
1632 f-opcode-hi
1633 ("BCC" "BDAP" "OTHER2" "OTHER3")
1634)
1635(define-pmacro QHI_ADDOQ QHI_BDAP)
1636
1637(define-normal-insn-enum
1638 insn-r-opc
1639 "Insns for MODE_REGISTER and either SIZE_BYTE, SIZE_WORD or SIZE_DWORD"
1640 ()
1641 R_
1642 f-opcode
1643 ("ADDX" "MOVX" "SUBX" "LSL"
1644 "ADDI" "BIAP" "NEG" "BOUND"
1645 "ADD" "MOVE" "SUB" "CMP"
1646 "AND" "OR" "ASR" "LSR")
1647)
1648(define-pmacro R_ADDI_ACR R_BIAP)
1649
1650(define-normal-insn-enum
1651 insn-rfix-opc
1652 "Insns for MODE_REGISTER and SIZE_FIXED"
1653 ()
1654 RFIX_
1655 f-opcode
1656 ("ADDX" "MOVX" "SUBX" "BTST"
1657 "SCC" "ADDC" "SETF" "CLEARF"
1658 "MOVE_R_S" "MOVE_S_R" "ABS" "DSTEP"
1659 "LZ" "SWAP" "XOR" "MSTEP")
1660)
1661(define-pmacro RFIX_MCP RFIX_MSTEP)
1662
1663(define-normal-insn-enum
1664 insn-indir-opc
1665 "Insns for (MODE_INDIRECT or MODE_AUTOINCREMENT) and either SIZE_BYTE, SIZE_WORD or SIZE_DWORD"
1666 ()
1667 INDIR_
1668 f-opcode
1669 ("ADDX" "MOVX" "SUBX" "CMPX"
1670 "MUL" "BDAP_M" "ADDC" "BOUND"
1671 "ADD" "MOVE_M_R" "SUB" "CMP"
1672 "AND" "OR" "TEST" "MOVE_R_M")
1673)
1674(define-pmacro INDIR_ADDO INDIR_BDAP_M)
1675
1676(define-normal-insn-enum
1677 insn-infix-opc
1678 "Insns for (MODE_INDIRECT or MODE_AUTOINCREMENT) and SIZE_FIXED"
1679 ()
1680 INFIX_
1681 f-opcode
1682 ("ADDX" "MOVX" "SUBX" "CMPX"
1683 "JUMP_M" "DIP" "JUMP_R" "BCC_M"
1684 "MOVE_M_S" "MOVE_S_M" "BMOD" "BSTORE"
1685 "RBF" "SBFS" "MOVEM_M_R" "MOVEM_R_M")
1686)
1687
1688(define-pmacro INFIX_MOVE_SS INFIX_SBFS)
1689(define-pmacro INFIX_LAPC INFIX_DIP)
1690(define-pmacro INFIX_RFE INFIX_JUMP_M)
1691(define-pmacro INFIX_RFN INFIX_JUMP_M)
1692(define-pmacro INFIX_HALT INFIX_JUMP_M)
1693(define-pmacro INFIX_SFE INFIX_JUMP_M)
1694(define-pmacro INFIX_RFG INFIX_JUMP_M)
1695(define-pmacro INFIX_JAS_R INFIX_JUMP_R)
1696(define-pmacro INFIX_JAS_M INFIX_JUMP_R)
1697(define-pmacro INFIX_JASC INFIX_RBF)
1698(define-pmacro INFIX_JUMP_P INFIX_BCC_M)
1699(define-pmacro INFIX_BAS INFIX_BMOD)
1700(define-pmacro INFIX_BASC INFIX_BSTORE)
1701(define-pmacro INFIX_BREAK INFIX_JUMP_M)
1702(define-pmacro INFIX_FIDXI INFIX_JUMP_M)
1703(define-pmacro INFIX_FIDXD INFIX_BAS)
1704(define-pmacro INFIX_FTAGI INFIX_JUMP_M)
1705(define-pmacro INFIX_FTAGD INFIX_BAS)
1706
1707; Classes of insns:
1708; Move-to-register, move-to-memory, move-to/from-other-register,
1709; logical, arithmetic, branch.
1710; Classes of operands:
1711; quick, register, memory-indirect, memory-postinc.
1712
1713
1714;;;;;;;;;;;;;;;;;; -normal-insn
1715
1716(define-pmacro (dni-bwd-attr name comment attr syntax fmt fsem timing)
1717 (begin
1718 (dni (.sym name .b) (.str "byte " comment) attr (.str name ".b " syntax)
1719 (.splice (.unsplice fmt) SIZE_BYTE)
1720 (fsem QI)
1721 timing)
1722 (dni (.sym name .w) (.str "word " comment) attr (.str name ".w " syntax)
1723 (.splice (.unsplice fmt) SIZE_WORD)
1724 (fsem HI)
1725 timing)
1726 (dni (.sym name .d) (.str "dword " comment) attr (.str name ".d " syntax)
1727 (.splice (.unsplice fmt) SIZE_DWORD)
1728 (fsem SI)
1729 timing))
1730)
1731
1732(define-pmacro (dni-cdt-attr name comment attr syntax fmt semantics)
1733 "dni without specifying timing"
1734 (dni name comment attr syntax fmt semantics (cris-timing))
1735)
1736
1737(define-pmacro (dni-cdt-bwd-attr name comment attr syntax fmt fsem)
1738 (begin
1739 (dni-cdt-attr (.sym name .b-r) (.str "byte " comment) attr (.str name ".b " syntax)
1740 (.splice (.unsplice fmt) SIZE_BYTE)
1741 (fsem QI))
1742 (dni-cdt-attr (.sym name .w-r) (.str "word " comment) attr (.str name ".w " syntax)
1743 (.splice (.unsplice fmt) SIZE_WORD)
1744 (fsem HI))
1745 (dni-cdt-attr (.sym name .d-r) (.str "dword " comment) attr (.str name ".d " syntax)
1746 (.splice (.unsplice fmt) SIZE_DWORD)
1747 (fsem SI)))
1748)
1749
1750; Some convenience macros based on the above ones.
1751(define-pmacro (dni-cdt-bwd name comment syntax fmt fsem)
1752 (dni-cdt-bwd-attr name comment () syntax fmt fsem)
1753)
1754
1755(define-pmacro (dni-bwd name comment syntax fmt fsem timing)
1756 (dni-bwd-attr comment () syntax fmt fsem timing)
1757)
1758
1759(define-pmacro-map
1760 (((dni-cdt name comment syntax fmt semantics)
1761 (dni-cdt-attr name comment () syntax fmt semantics))
1762 ((dni-c-QI-attr name comment attr syntax fmt fsem)
1763 (dni name comment attr syntax fmt fsem (cris-timing-const-QI)))
1764 ((dni-c-HI-attr name comment attr syntax fmt fsem)
1765 (dni name comment attr syntax fmt fsem (cris-timing-const-HI)))
1766 ((dni-c-SI-attr name comment attr syntax fmt fsem)
1767 (dni name comment attr syntax fmt fsem (cris-timing-const-SI))))
1768)
1769
1770(define-pmacro-map
1771 (((dni-c-QI name comment syntax fmt fsem)
1772 (dni-c-QI-attr name comment () syntax fmt fsem))
1773 ((dni-c-HI name comment syntax fmt fsem)
1774 (dni-c-HI-attr name comment () syntax fmt fsem))
1775 ((dni-c-SI name comment syntax fmt fsem)
1776 (dni-c-SI-attr name comment () syntax fmt fsem)))
1777)
1778
1779; These flags are both cleared by all insns except prefixes (before
1780; CRISv32) and "setf x", so we put them in a handy macro.
1781(define-pmacro
1782 (reset-x-p)
1783 (sequence
1784 ()
1785 (set xbit 0)
1786 (set prefix-set 0))
1787)
1788
1789; NOP | 0 0 0 0| 0 1| 0 1 0 0| 0 0| 1 1 1 1|
1790; (For V32, "SETF" (no flags) is used.)
1791(dni-cdt-attr
1792 nop "nop" (MACH-PC) "nop"
1793 (+ (f-operand2 0) R_ADDI MODE_REGISTER SIZE_BYTE (f-operand1 15))
1794 (reset-x-p)
1795)
1796
1797; Pre- and v32+ variants MOVE insns set flags differently. These two
1798; macros for flag settings are meant to be used in all MOVE insns.
1799(define-pmacro (setf-moveq value)
1800 (sequence
1801 ()
1802 (set-quiet nbit-move (lt SI value 0))
1803 (set-quiet zbit-move (andif BI (eq SI value 0) (if BI xbit zbit 1)))
1804 (set-quiet cbit-move 0)
1805 (set-quiet vbit-move 0)
1806 (reset-x-p))
1807)
1808
1809(define-pmacro (setf-move size value)
1810 (sequence
1811 ()
1812 (set nbit (lt size value 0))
1813 (set zbit (andif BI (eq size value 0) (if BI xbit zbit 1)))
1814 (set-quiet cbit-move 0)
1815 (set-quiet vbit-move 0)
1816 (reset-x-p))
1817)
1818; The CGEN binop-with-bit operations are not documented well enough that I
1819; trust their semantics to remain stable. Better define local ones: the
1820; semantics become explicit.
1821(define-pmacro-map
1822 (((add-overflow size R D S carry)
1823 (orif BI (andif BI (andif BI (lt size S 0) (lt size D 0)) (ge size R 0))
1824 (andif BI (andif BI (ge size S 0) (ge size D 0)) (lt size R 0))))
1825 ((add-carry size R D S carry)
1826 (orif BI (andif BI (lt size S 0) (lt size D 0))
1827 (orif BI (andif BI (lt size D 0) (ge size R 0))
1828 (andif BI (lt size S 0) (ge size R 0)))))
1829 ((sub-overflow size R D S carry)
1830 (orif BI (andif BI (andif BI (ge size S 0) (lt size D 0)) (ge size R 0))
1831 (andif BI (andif BI (lt size S 0) (ge size D 0)) (lt size R 0))))
1832 ((sub-carry size R D S carry)
1833 (orif BI (andif BI (lt size S 0) (ge size D 0))
1834 (orif BI (andif BI (ge size D 0) (lt size R 0))
1835 (andif BI (lt size S 0) (lt size R 0)))))
1836 ; Only valid for size := DI
1837 ((mulu-overflow size R D S carry)
1838 (ne DI R (zext DI (trunc SI R))))
1839 ((mulu-carry size R D S carry)
1840 (andif current-mach-is-v32 carry))
1841 ((muls-overflow size R D S carry)
1842 (ne DI R (ext DI (trunc SI R))))
1843 ((muls-carry size R D S carry)
1844 (andif current-mach-is-v32 carry)))
1845)
1846
1847(define-pmacro (setf-arit2 size op source1 source2 result carryin carryout)
1848 "Set no-prefix, x=0, carryout, v, z and n according to operation OP in size SIZE"
1849 (sequence
1850 ()
1851 (set carryout ((.sym op -carry) size result source1 source2 carryin))
1852 (set nbit (lt size result 0))
1853 (set zbit (andif BI (eq size result 0) (orif BI zbit (not BI xbit))))
1854 (set vbit ((.sym op -overflow) size result source1 source2 carryin))
1855 (reset-x-p))
1856)
1857(define-pmacro (setf-arit size op source1 source2 result carry)
1858 "Set no-prefix, x=0, c, v, z and n according to operation OP in size SIZE"
1859 (setf-arit2 size op source1 source2 result carry cbit)
1860)
1861
1862; Let's have convienence macros for arithmetic, including evaluation of the
1863; operation, destination modification, flag setting and carry propagation.
1864(define-pmacro
1865 (cris-arit6-int arit size fdest fdest_op srcop1 srcop2 carryout carryin)
1866 "Core for performing some three-operand arithmetic with carry as parameter"
1867 (sequence
1868 ((size tmpopd) (size tmpops) (BI carry) (size newval))
1869 (set tmpops srcop2)
1870 (set tmpopd srcop1)
1871 (set carry carryin)
1872 (set newval ((.sym arit c) tmpopd tmpops (if BI (eq xbit 0) 0 carry)))
1873 (fdest size fdest_op newval)
1874 (setf-arit2 size arit tmpopd tmpops newval carry carryout))
1875)
1876
1877(define-pmacro
1878 (cris-arit5-int arit size destregno srcop1 srcop2 carryout carryin)
1879 "As cris-arit6-int, but to set a part of a general register"
1880 (cris-arit6-int
1881 arit
1882 size
1883 (.pmacro (sz regno val) (set-subreg-gr sz regno val))
1884 destregno
1885 srcop1
1886 srcop2
1887 carryout
1888 carryin)
1889)
1890
1891(define-pmacro (cris-arit5 arit size destreg srcop1 srcop2 carryout carryin)
1892 "As cris-arit5-int, but takes a register as parameter, not register number"
1893 (cris-arit5-int arit size (regno destreg) srcop1 srcop2 carryout carryin)
1894)
1895(define-pmacro (cris-arit3-int arit size destregno srcop1 srcop2)
1896 "As cris-arit5-int, but with carry-in same as carry-out"
1897 (cris-arit5-int arit size destregno srcop1 srcop2 cbit cbit)
1898)
1899(define-pmacro (cris-arit3 arit size destreg srcop1 srcop2)
1900 "As cris-arit3-int, but takes a register as parameter, not register number"
1901 (cris-arit3-int arit size (regno destreg) srcop1 srcop2)
1902)
1903(define-pmacro (cris-arit arit size destreg srcop)
1904 "As cris-arit3, but with destination same as srcop1"
1905 (cris-arit3 arit size destreg destreg srcop)
1906)
1907(define-pmacro (cris-arit-3op arit size destsrcop2 srcop1 dest-3op)
1908 "Similar to cris-arit3-int, but for prefixed operand only"
1909 (cris-arit3-int arit size
1910 (if SI (andif prefix-set (not inc))
1911 (regno dest-3op)
1912 (regno destsrcop2))
1913 destsrcop2 srcop1)
1914)
1915
1916; Convenience macros to select a part of a value and its complement, for
1917; the <op>.b, <op>.w and <op>.d operations.
1918(define-pmacro (QI-part val) (and SI val #xff))
1919(define-pmacro (non-QI-part val) (and SI val #xffffff00))
1920(define-pmacro (HI-part val) (and SI val #xffff))
1921(define-pmacro (non-HI-part val) (and SI val #xffff0000))
1922(define-pmacro (SI-part val) val)
1923(define-pmacro (non-SI-part val) 0)
1924(define-pmacro
1925 (set-subreg-gr-bw BWD gregno newval)
1926 "Set a byte or word part or full dword of a general register"
1927 (sequence
1928 ((SI oldregval))
1929 (set oldregval (reg h-raw-gr gregno))
1930 (set (reg h-gr gregno)
1931 (or SI ((.sym BWD -part) newval) ((.sym non- BWD -part) oldregval))))
1932)
1933(define-pmacro (set-subreg-gr BWD gregno newval)
1934 ((.sym set-subreg-gr- BWD) BWD gregno newval)
1935)
1936(define-pmacro (set-subreg-gr-SI SI gregno newval)
1937 (set (reg h-gr gregno) newval)
1938)
1939(define-pmacro set-subreg-gr-HI set-subreg-gr-bw)
1940(define-pmacro set-subreg-gr-QI set-subreg-gr-bw)
1941
1942; MOVE.m Rs,Rd [ Rd | 011001mm | Rs ]
1943(dni-cdt-bwd
1944 move "move.m r,R"
1945 "move.m ${Rs},${Rd}"
1946 (+ Rd MODE_REGISTER R_MOVE Rs)
1947 (.pmacro
1948 (BWD)
1949 (sequence
1950 ((BWD newval))
1951 (set newval Rs)
1952 (set-subreg-gr BWD (regno Rd) newval)
1953 (setf-move BWD newval)))
1954)
1955
1956; MOVE.D PC,Rd [ Rd | 01100110 | 1111 ]
1957; This insn is used in PIC code to find out the code address. It's an
1958; exception to the (guarded) non-implementation of PC operands in this
1959; file.
1960(dni-cdt-attr
1961 movepcr "move.d PC,R"
1962 (MACH-PC UNCOND-CTI)
1963 "move.d PC,${Rd}"
1964 (+ Rd MODE_REGISTER R_MOVE SIZE_DWORD (f-source 15))
1965 (sequence
1966 ((SI pcval))
1967 (set pcval (add SI pc 2))
1968 (set Rd pcval)
1969 (setf-move SI pcval))
1970)
1971
1972; MOVEQ i,Rd [ Rd | 001001 | i ]
1973(dni-cdt
1974 moveq "moveq"
1975 "moveq $i,$Rd"
1976 (+ Rd MODE_QUICK_IMMEDIATE Q_MOVEQ i)
1977 (sequence
1978 ((SI newval))
1979 (set newval i)
1980 (set Rd newval)
1981 (setf-moveq newval))
1982)
1983
1984(define-pmacro (dni-cdt-sbw name comment syntax fmt fsem)
1985 "Insn generator for insns with signed <op>.b and <op>.w variants"
1986 (begin
1987 (dni-cdt
1988 (.sym name .b-r) (.str "byte " comment) (.str name ".b " syntax)
1989 (.splice (.unsplice fmt) SIGNED_BYTE)
1990 (fsem QI))
1991 (dni-cdt
1992 (.sym name .w-r) (.str "word " comment) (.str name ".w " syntax)
1993 (.splice (.unsplice fmt) SIGNED_WORD)
1994 (fsem HI)))
1995)
1996
1997; MOVS.z Rs,Rd [ Rd | 0100011z | Rs ]
1998(dni-cdt-sbw
1999 movs "movs.m r,R"
2000 "movs.m ${Rs},${Rd}"
2001 (+ Rd MODE_REGISTER R_MOVX Rs)
2002 (.pmacro
2003 (BW)
2004 (sequence
2005 ((BW newval))
2006 (set newval Rs)
2007 (set Rd (ext SI newval))
2008 (setf-move SI newval)))
2009)
2010
2011(define-pmacro (dni-cdt-ubw name comment syntax fmt fsem)
2012 "Similar to dni-cdt-sbw but for unsigned operations"
2013 (begin
2014 (dni-cdt
2015 (.sym name .b-r) (.str "byte " comment) (.str name ".b " syntax)
2016 (.splice (.unsplice fmt) UNSIGNED_BYTE)
2017 (fsem QI))
2018 (dni-cdt
2019 (.sym name .w-r) (.str "word " comment) (.str name ".w " syntax)
2020 (.splice (.unsplice fmt) UNSIGNED_WORD)
2021 (fsem HI)))
2022)
2023
2024; MOVU.z Rs,Rd [ Rd | 0100010z | Rs ]
2025(dni-cdt-ubw
2026 movu "movu.m r,R"
2027 "movu.m ${Rs},${Rd}"
2028 (+ Rd MODE_REGISTER R_MOVX Rs)
2029 (.pmacro
2030 (BW)
2031 (sequence
2032 ((BW newval))
2033 (set newval Rs)
2034 (set Rd (zext SI newval))
2035 (setf-move SI newval)))
2036)
2037
2038; (MOVE.m [PC+],Rd [ Rd | 111001mm | 1111 ])
2039; For the moment, it doesn't seem worthwhile to make a dni-c-bwd macro;
2040; too many places to parametrize.
2041(dni-c-QI
2042 movecbr "move.b [PC+],R"
2043 "move.b ${sconst8},${Rd}"
2044 (+ Rd MODE_AUTOINCREMENT INDIR_MOVE_M_R SIZE_BYTE (f-source 15) sconst8)
2045 (sequence
2046 ((QI newval))
2047 (set newval sconst8)
2048 (set-subreg-gr QI (regno Rd) newval)
2049 (setf-move QI newval))
2050)
2051
2052(dni-c-HI
2053 movecwr "move.w [PC+],R"
2054 "move.w ${sconst16},${Rd}"
2055 (+ Rd MODE_AUTOINCREMENT INDIR_MOVE_M_R SIZE_WORD (f-source 15) sconst16)
2056 (sequence
2057 ((HI newval))
2058 (set newval sconst16)
2059 (set-subreg-gr HI (regno Rd) newval)
2060 (setf-move HI newval))
2061)
2062
2063(dni-c-SI
2064 movecdr "move.d [PC+],R"
2065 "move.d ${const32},${Rd}"
2066 (+ Rd MODE_AUTOINCREMENT INDIR_MOVE_M_R SIZE_DWORD (f-source 15) const32)
2067 (sequence
2068 ((SI newval))
2069 (set newval const32)
2070 (set Rd newval)
2071 (setf-move SI newval))
2072)
2073
2074; (MOVS.z [PC+],Rd [ Rd | 1100011z | 1111 ])
2075; Similarly, no likely net improvement for a dni-c-bw.
2076(dni-c-QI
2077 movscbr "movs.b [PC+],R"
2078 "movs.b ${sconst8},${Rd}"
2079 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX SIGNED_BYTE (f-source 15) sconst8)
2080 (sequence
2081 ((SI newval))
2082 ; FIXME: Make trunc unnecessary.
2083 (set newval (ext SI (trunc QI sconst8)))
2084 (set Rd newval)
2085 (setf-move SI newval))
2086)
2087
2088(dni-c-HI
2089 movscwr "movs.w [PC+],R"
2090 "movs.w ${sconst16},${Rd}"
2091 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX SIGNED_WORD (f-source 15) sconst16)
2092 (sequence
2093 ((SI newval))
2094 ; FIXME: Make trunc unnecessary.
2095 (set newval (ext SI (trunc HI sconst16)))
2096 (set Rd newval)
2097 (setf-move SI newval))
2098)
2099
2100; (MOVU.z [PC+],Rd [ Rd | 1100010z | 1111 ])
2101(dni-c-QI
2102 movucbr "movu.b [PC+],R"
2103 "movu.b ${uconst8},${Rd}"
2104 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX UNSIGNED_BYTE (f-source 15) uconst8)
2105 (sequence
2106 ((SI newval))
2107 ; FIXME: Make trunc unnecessary.
2108 (set newval (zext SI (trunc QI uconst8)))
2109 (set Rd newval)
2110 (setf-move SI newval))
2111)
2112
2113(dni-c-HI
2114 movucwr "movu.w [PC+],R"
2115 "movu.w ${uconst16},${Rd}"
2116 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX UNSIGNED_WORD (f-source 15) uconst16)
2117 (sequence
2118 ((SI newval))
2119 ; FIXME: Make trunc unnecessary.
2120 (set newval (zext SI (trunc HI uconst16)))
2121 (set Rd newval)
2122 (setf-move SI newval))
2123)
2124
2125; ADDQ j,Rd [ Rd | 001000 | j ]
2126(dni-cdt
2127 addq "addq j,Rd"
2128 "addq $j,$Rd"
2129 (+ Rd MODE_QUICK_IMMEDIATE Q_ADDQ j)
2130 (cris-arit add SI Rd j)
2131)
2132
2133; SUBQ j,Rd [ Rd | 001010| j ]
2134(dni-cdt
2135 subq "subq j,Rd"
2136 "subq $j,$Rd"
2137 (+ Rd MODE_QUICK_IMMEDIATE Q_SUBQ j)
2138 (cris-arit sub SI Rd j)
2139)
2140
2141; Convenience macros for insns with a memory operand.
2142(define-pmacro
2143 (dni-cmt-attr-tim name comment attr syntax fmt semantics timing)
2144 "dni with memory-access"
2145 (dni name comment attr syntax
2146 ; Specifying MODE_INDIRECT and MODE_AUTOINCREMENT in this
2147 ; manner makes the autoincrementness handily available.
2148 ; It also effectively excludes non-memory use of dni-cmt.
2149 (.splice (.unsplice fmt) MODEMEMP_YES inc)
2150 semantics
2151 timing)
2152)
2153
2154(define-pmacro (dni-cmt-attr name comment attr syntax fmt semantics)
2155 "dni with read memory-access timing"
2156 (dni-cmt-attr-tim name comment attr syntax fmt semantics
2157 (cris-mem-timing))
2158)
2159
2160(define-pmacro (dni-cmwt-attr name comment attr syntax fmt semantics)
2161 "dni with write memory-access timing"
2162 (dni-cmt-attr-tim name comment attr syntax fmt semantics
2163 (cris-mem-write-timing))
2164)
2165
2166(define-pmacro QI-size 1)
2167(define-pmacro HI-size 2)
2168(define-pmacro SI-size 4)
2169
2170(define-pmacro (cris-get-mem size regop)
2171 "Handle reading memory in <size>, with source address register\
2172 (read once, maybe set once) in <regop> or prefixed"
2173 (sequence
2174 size
2175 ((SI addr) (size tmp-mem) (BI postinc))
2176
2177 ; Cache the incrementness of the operand.
2178 (set postinc inc)
2179
2180 ; Get the address from somewhere.
2181 (set addr
2182 (if SI (eq prefix-set 0)
2183 ; If the insn was prefixed, it's in the prefix-register.
2184 regop
2185 prefixreg))
2186
2187 ; Get the memory contents.
2188 (set tmp-mem (mem size addr))
2189
2190 ; For non-prefixed post-increment, we increment the address by the
2191 ; size of the memory access.
2192 (if (ne postinc 0)
2193 (sequence
2194 ()
2195 (if (eq prefix-set 0)
2196 (set addr (add addr (.sym size -size))))
2197 ; Update the source-register for post-increments.
2198 (set regop addr)))
2199
2200 ; Don't forget the return-value.
2201 tmp-mem)
2202)
2203
2204(define-pmacro (cris-set-mem size regop value)
2205 "Handle writing <value> of <size> to memory, with memory address register\
2206 (read once, maybe set once) in <regop> or prefixed."
2207 (sequence
2208 ((SI addr) (BI postinc))
2209
2210 ; Cache the incrementness of the operand.
2211 (set postinc inc)
2212
2213 ; Get the address from somewhere.
2214 (set addr
2215 (if SI (eq prefix-set 0)
2216 ; If the insn was prefixed, it's in the prefix-register.
2217 regop
2218 prefixreg))
2219
2220 ; Set the memory contents. Integral-write semantics apply.
2221 ; FIXME: currently v32 only; when proper semantics needed, fix v10.
2222 (if (andif current-mach-is-v32 (ne xbit 0))
2223 (if (eq pbit 0)
2224 (sequence
2225 ()
2226 (set (mem size addr) value)
2227 (set cbit 0))
2228 (set cbit 1))
2229 (set (mem size addr) value))
2230
2231 ; For non-prefixed post-increment, we increment the address by the
2232 ; size of the memory access. As for the integral-write, this needs to
2233 ; be tweaked for pre-v32: increment should have been performed if
2234 ; there's a fault at the memory access above.
2235 (if (ne postinc 0)
2236 (sequence
2237 ()
2238 (if (eq prefix-set 0)
2239 (set addr (add addr (.sym size -size))))
2240 ; Update the source-register for post-increments.
2241 (set regop addr))))
2242)
2243
2244(define-pmacro
2245 (dni-cmt-bwd-attr-tim name comment attr syntax fmt fsem timing)
2246 "Core generator macro for insns with <op>.b, <op>.w and <op>.d variants\
2247 and a memory operand."
2248 (begin
2249 (dni-cmt-attr-tim
2250 (.sym name .b-m)
2251 (.str "byte mem " comment)
2252 attr
2253 (.str name ".b " syntax)
2254 (.splice (.unsplice fmt) SIZE_BYTE)
2255 (fsem QI)
2256 timing)
2257 (dni-cmt-attr-tim
2258 (.sym name .w-m)
2259 (.str "word mem " comment)
2260 attr
2261 (.str name ".w " syntax)
2262 (.splice (.unsplice fmt) SIZE_WORD)
2263 (fsem HI)
2264 timing)
2265 (dni-cmt-attr-tim
2266 (.sym name .d-m)
2267 (.str "dword mem " comment)
2268 attr
2269 (.str name ".d " syntax)
2270 (.splice (.unsplice fmt) SIZE_DWORD)
2271 (fsem SI)
2272 timing))
2273)
2274
2275; Further refinement macros.
2276(define-pmacro (dni-cmt-bwd-attr name comment attr syntax fmt fsem)
2277 (dni-cmt-bwd-attr-tim name comment attr syntax fmt fsem
2278 (cris-mem-timing))
2279)
2280
2281(define-pmacro (dni-cmwt-bwd name comment syntax fmt fsem)
2282 (dni-cmt-bwd-attr-tim name comment () syntax fmt fsem
2283 (cris-mem-write-timing))
2284)
2285
2286(define-pmacro (dni-cmt-bwd name comment syntax fmt fsem)
2287 (dni-cmt-bwd-attr name comment () syntax fmt fsem)
2288)
2289
2290(define-pmacro (dni-cmt-sbw name comment syntax fmt fsem)
2291 "Core generator macro for insns with <op>.b and <op>.w variants\
2292 and a signed memory operand."
2293 (begin
2294 (dni-cmt-attr
2295 (.sym name .b-m) (.str "byte mem " comment)
2296 ()
2297 (.str name ".b " syntax)
2298 (.splice (.unsplice fmt) SIGNED_BYTE)
2299 (fsem QI))
2300 (dni-cmt-attr
2301 (.sym name .w-m) (.str "word mem " comment)
2302 ()
2303 (.str name ".w " syntax)
2304 (.splice (.unsplice fmt) SIGNED_WORD)
2305 (fsem HI)))
2306)
2307
2308(define-pmacro (dni-cmt-ubw name comment syntax fmt fsem)
2309 "Core generator macro for insns with <op>.b and <op>.w variants\
2310 and an unsigned memory operand."
2311 (begin
2312 (dni-cmt-attr
2313 (.sym name .b-m) (.str "byte mem " comment)
2314 ()
2315 (.str name ".b " syntax)
2316 (.splice (.unsplice fmt) UNSIGNED_BYTE)
2317 (fsem QI))
2318 (dni-cmt-attr
2319 (.sym name .w-m) (.str "word mem " comment)
2320 ()
2321 (.str name ".w " syntax)
2322 (.splice (.unsplice fmt) UNSIGNED_WORD)
2323 (fsem HI)))
2324)
2325
2326; CMP.m Rs,Rd [ Rd | 011011mm | Rs ]
2327(dni-cdt-bwd
2328 cmp-r "compare register to register"
2329 "$Rs,$Rd"
2330 (+ Rd MODE_REGISTER R_CMP Rs)
2331 (.pmacro
2332 (BWD)
2333 (cris-arit6-int
2334 sub BWD (.pmacro (sz regno val) (nop)) 0
2335 Rd Rs cbit cbit))
2336)
2337
2338; CMP.m [Rs],Rd [ Rd | 101011mm | Rs ]
2339; CMP.m [Rs+],Rd [ Rd | 111011mm | Rs ]
2340(dni-cmt-bwd
2341 cmp-m "compare memory to register"
2342 "[${Rs}${inc}],${Rd}"
2343 (+ INDIR_CMP Rs Rd)
2344 (.pmacro
2345 (BWD)
2346 (cris-arit6-int
2347 sub BWD (.pmacro (sz regno val) (nop)) 0
2348 Rd (cris-get-mem BWD Rs) cbit cbit))
2349)
2350
2351; (CMP.m [PC+],Rd [ Rd | 111011mm | 1111 ])
2352(dni-c-QI
2353 cmpcbr "cmp constant byte to register"
2354 "cmp.b $sconst8,$Rd"
2355 (+ Rd MODE_AUTOINCREMENT INDIR_CMP SIZE_BYTE (f-source 15) sconst8)
2356 (cris-arit6-int
2357 sub QI (.pmacro (sz regno val) (nop)) 0
2358 Rd (trunc QI sconst8) cbit cbit)
2359)
2360
2361(dni-c-HI
2362 cmpcwr "cmp constant word to register"
2363 "cmp.w $sconst16,$Rd"
2364 (+ Rd MODE_AUTOINCREMENT INDIR_CMP SIZE_WORD (f-source 15) sconst16)
2365 (cris-arit6-int
2366 sub HI (.pmacro (sz regno val) (nop)) 0
2367 Rd (trunc HI sconst16) cbit cbit)
2368)
2369
2370(dni-c-SI
2371 cmpcdr "cmp constant dword to register"
2372 "cmp.d $const32,$Rd"
2373 (+ Rd MODE_AUTOINCREMENT INDIR_CMP SIZE_DWORD (f-source 15) const32)
2374 (cris-arit6-int
2375 sub SI (.pmacro (sz regno val) (nop)) 0
2376 Rd const32 cbit cbit)
2377)
2378
2379; CMPQ i,Rd [ Rd | 001011 | i ]
2380(dni-cdt
2381 cmpq "cmpq i,Rd"
2382 "cmpq $i,$Rd"
2383 (+ Rd MODE_QUICK_IMMEDIATE Q_CMPQ i)
2384 (cris-arit6-int
2385 sub SI (.pmacro (sz regno val) (nop)) 0
2386 Rd i cbit cbit)
2387)
2388
2389; CMPS.z [Rs],Rd [ Rd | 1000111z | Rs ]
2390; CMPS.z [Rs+],Rd [ Rd | 1100111z | Rs ]
2391(dni-cmt-sbw
2392 cmps-m "cmp sign-extended from memory to register"
2393 "[${Rs}${inc}],$Rd"
2394 (+ Rd INDIR_CMPX Rs)
2395 (.pmacro
2396 (BW)
2397 (cris-arit6-int
2398 sub SI (.pmacro (sz regno val) (nop)) 0
2399 Rd ((.sym BW -ext) (cris-get-mem BW Rs)) cbit cbit))
2400)
2401
2402; (CMPS.z [PC+],Rd [ Rd | 1100111z | 1111 ])
2403(dni-c-QI
2404 cmpscbr "cmp sign-extended constant byte to register"
2405 "[${Rs}${inc}],$Rd"
2406 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX SIGNED_BYTE (f-source 15) sconst8)
2407 (cris-arit6-int
2408 sub SI (.pmacro (sz regno val) (nop)) 0
2409 Rd (ext SI (trunc QI sconst8)) cbit cbit)
2410)
2411(dni-c-HI
2412 cmpscwr "cmp sign-extended constant word to register"
2413 "[${Rs}${inc}],$Rd"
2414 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX SIGNED_WORD (f-source 15) sconst16)
2415 (cris-arit6-int
2416 sub SI (.pmacro (sz regno val) (nop)) 0
2417 Rd (ext SI (trunc HI sconst16)) cbit cbit)
2418)
2419
2420; CMPU.z [Rs],Rd [ Rd | 1000110z | Rs ]
2421; CMPU.z [Rs+],Rd [ Rd | 1100110z | Rs ]
2422(dni-cmt-ubw
2423 cmpu-m "cmp zero-extended from memory to register"
2424 "[${Rs}${inc}],$Rd"
2425 (+ Rd INDIR_CMPX Rs)
2426 (.pmacro
2427 (BW)
2428 (cris-arit6-int
2429 sub SI (.pmacro (sz regno val) (nop)) 0
2430 Rd ((.sym BW -zext) (cris-get-mem BW Rs)) cbit cbit))
2431)
2432
2433; (CMPU.z [PC+],Rd [ Rd | 1100110z | 1111 ])
2434(dni-c-QI
2435 cmpucbr "cmp zero-extended constant byte to register"
2436 "[${Rs}${inc}],$Rd"
2437 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX UNSIGNED_BYTE (f-source 15) uconst8)
2438 (cris-arit6-int
2439 sub SI (.pmacro (sz regno val) (nop)) 0
2440 Rd (zext SI (trunc QI uconst8)) cbit cbit)
2441)
2442(dni-c-HI
2443 cmpucwr "cmp zero-extended constant word to register"
2444 "[${Rs}${inc}],$Rd"
2445 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX UNSIGNED_WORD (f-source 15) uconst16)
2446 (cris-arit6-int
2447 sub SI (.pmacro (sz regno val) (nop)) 0
2448 Rd (zext SI (trunc HI uconst16)) cbit cbit)
2449)
2450
2451; MOVE.m [Rs],Rd [ Rd | 101001mm | Rs ]
2452; MOVE.m [Rs+],Rd [ Rd | 111001mm | Rs ]
2453(dni-cmt-bwd
2454 move-m "move from memory to register"
2455 "[${Rs}${inc}],${Rd}"
2456 (+ INDIR_MOVE_M_R Rs Rd)
2457 (.pmacro
2458 (BWD)
2459 (sequence
2460 ((SI tmp))
2461 (set tmp (cris-get-mem BWD Rs))
2462 (set-subreg-gr
2463 BWD
2464 (if SI (andif prefix-set (not inc)) (regno Rs) (regno Rd))
2465 tmp)
2466 (setf-move BWD tmp)))
2467)
2468
2469; MOVS.z [Rs],Rd [ Rd | 1000011z | Rs ]
2470; MOVS.z [Rs+],Rd [ Rd | 1100011z | Rs ]
2471(dni-cmt-sbw
2472 movs-m "movs from memory to register"
2473 "[${Rs}${inc}],${Rd}"
2474 (+ INDIR_MOVX Rs Rd)
2475 (.pmacro
2476 (BW)
2477 (sequence
2478 ((SI tmp))
2479 (set tmp (ext SI (cris-get-mem BW Rs)))
2480 (if (andif prefix-set (not inc))
2481 (set Rs tmp)
2482 (set Rd tmp))
2483 (setf-move SI tmp)))
2484)
2485
2486; MOVU.z [Rs],Rd [ Rd | 1000010z | Rs ]
2487; MOVU.z [Rs+],Rd [ Rd | 1100010z | Rs ]
2488(dni-cmt-ubw
2489 movu-m "movu from memory to register"
2490 "[${Rs}${inc}],${Rd}"
2491 (+ INDIR_MOVX Rs Rd)
2492 (.pmacro
2493 (BW)
2494 (sequence
2495 ((SI tmp))
2496 (set tmp (zext SI (cris-get-mem BW Rs)))
2497 (if (andif prefix-set (not inc))
2498 (set Rs tmp)
2499 (set Rd tmp))
2500 (setf-move SI tmp)))
2501)
2502
2503; MOVE Rs,Pd [ Pd | 01100011 | Rs ]
2504(.splice
2505 begin
2506 (.unsplice
2507 (.map
2508 (.pmacro
2509 (VER)
2510 (dni
2511 (.sym move-r-spr VER)
2512 "Move from general register to special register"
2513 ((MACH (.sym cris VER)))
2514 "move ${Rs},${Pd}"
2515 (+ RFIX_MOVE_R_S MODE_REGISTER SIZE_FIXED Rs Pd)
2516 (sequence
2517 ((SI tmp) (SI rno))
2518 (set tmp Rs)
2519 (set rno (regno Pd))
2520 (cond
2521 ; See reg-sr setter for most of the special-register semantics.
2522 ; The sanity check for known read-only registers is for program
2523 ; debug help; the real insn would be harmless and have no effect.
2524 ; CGEN-FIXME: regno of symbolic h-sr names doesn't work here.
2525 ((orif (orif (eq rno 0) (eq rno 1)) (orif (eq rno 4) (eq rno 8)))
2526 (error "move-r-spr: trying to set a read-only special register"))
2527 (else (set Pd tmp)))
2528 (reset-x-p))
2529 (cris-reg-sr-timing)))
2530 (cris-cpu-models)))
2531)
2532
2533(define-pmacro (dni-cdt-ver-attr name comment fattr syntax fmt fsem)
2534 "Generator for each MACH, using default timing."
2535 (.splice
2536 begin
2537 (.unsplice
2538 (.map
2539 (.pmacro (v) (dni-cdt-attr name comment (fattr v) syntax fmt (fsem v)))
2540 (cris-cpu-models))))
2541)
2542
2543; MOVE Ps,Rd [ Ps | 01100111 | Rd ]
2544; Note that in the insn format, the Rd operand is in the Rs field (the
2545; Rd field by the definition used everywhere else is the Ps position in
2546; this insn).
2547; It gets a little weird here because we can't get this insn into a
2548; define-pmacro unless we make named pmacros for e.g. a separate attr
2549; function and a semantics function: a .pmacro can't refer to the
2550; parameters of the outer define-pmacro. (The manual refers to this as
2551; not implementing "lexical scoping").
2552(.splice
2553 begin
2554 (.unsplice
2555 (.map
2556 (.pmacro
2557 (VER)
2558 (dni-cdt-attr
2559 (.sym move-spr-r VER)
2560 "Move from special register to general register"
2561 ((MACH (.sym cris VER)))
2562 "move ${Ps},${Rd-sfield}"
2563 (+ Ps RFIX_MOVE_S_R MODE_REGISTER SIZE_FIXED Rd-sfield)
2564 (sequence
2565 ((SI grno) (SI prno) (SI newval))
2566 (set prno (regno Ps))
2567 ; CGEN-FIXME: Can't use the following and then "grno" below because
2568 ; CGEN will emit a "tmp_grno" *also* in decodev32.c:crisv32f_decode
2569 ; (set grno (regno Rd-sfield))
2570 (set newval Ps)
2571 (.splice
2572 cond
2573 (.unsplice
2574 (.map
2575 (.pmacro
2576 (r)
2577 ((eq prno (.cadr2 r))
2578 (set-subreg-gr (.car2 r) (regno Rd-sfield) newval)))
2579 ((.sym cris-implemented-specregs- VER))))
2580 (else (error "move-spr-r from unimplemented register")))
2581 (reset-x-p))))
2582 (cris-cpu-models)))
2583)
2584
2585; MOVE Ps,PC [ Ps | 01100111 | 1111 ]
2586; The move-special-register-to-pc insns are return-type instructions and
2587; have to be special-cased to get the delay-slot and avoid being indicated
2588; as invalid.
2589(dni-cdt-attr
2590 ret-type
2591 "ret-type"
2592 (MACH-PC)
2593 "ret/reti/retb"
2594 (+ Ps MODE_REGISTER RFIX_MOVE_S_R SIZE_FIXED (f-source 15))
2595 (sequence
2596 ((SI retaddr))
2597 (set retaddr Ps)
2598 (reset-x-p)
2599 (delay 1 (set pc retaddr)))
2600)
2601
2602; MOVE [Rs],Pd [ Pd | 10100011 | Rs ]
2603; MOVE [Rs+],Pd [ Pd | 11100011 | Rs ]
2604; We make variants that loads constants or memory for each MACH version,
2605; since each consider some subset of the "special registers" to have
2606; different sizes. FIXME: Should be able to simplify this.
2607(.splice
2608 begin
2609 (.unsplice
2610 (.map
2611 (.pmacro
2612 (VER)
2613 (dni
2614 (.sym move-m-spr VER)
2615 "Move from memory to special register"
2616 ((MACH (.sym cris VER)))
2617 "move [${Rs}${inc}],${Pd}"
2618 (+ Pd INFIX_MOVE_M_S MODEMEMP_YES inc SIZE_FIXED Rs)
2619 (sequence
2620 ((SI rno) (SI newval))
2621 (set rno (regno Pd))
2622 (.splice
2623 cond
2624 ; No sanity check for constant special register here, since the
2625 ; memory read side-effect or post-increment may be the goal, or
2626 ; for pre-v32 a prefix assignment side-effect.
2627 (.unsplice
2628 (.map
2629 (.pmacro
2630 (r)
2631 ((eq rno (.cadr2 r))
2632 (set newval ((.sym (.car2 r) -ext) (cris-get-mem (.car2 r) Rs)))))
2633 ((.sym cris-implemented-specregs- VER))))
2634 (else (error "Trying to set unimplemented special register")))
2635 (set Pd newval)
2636 (reset-x-p))
2637 (cris-mem-sr-timing)))
2638 (cris-cpu-models)))
2639)
2640
2641(define-pmacro QI-operand sconst8)
2642(define-pmacro HI-operand sconst16)
2643(define-pmacro SI-operand const32)
2644
2645(define-pmacro
2646 (cris-move-c-spr VER VERFN)
2647 "Generator for loading constant into special register"
2648 (.splice
2649 begin
2650 (.unsplice
2651 (.map
2652 (.pmacro
2653 (srdef v)
2654 (dni
2655 (.sym move-c-spr v -p (.cadr2 srdef))
2656 (.str "Move constant to special register p" (.cadr2 srdef))
2657 ((MACH (.sym cris v)))
2658 (.str "move ${" (.sym (.car2 srdef) -operand) "},${Pd}")
2659 ; We use Pd in semantics without naming it in the format (which
2660 ; would CGEN-FIXME: cause a CGEN error for some reason, likely
2661 ; related to specifying an insn field multiple times). This
2662 ; currently works and is guarded with test-cases (specifically
2663 ; wrt. the timing model) but may need to be tweaked in the future.
2664 ; Note that using instead (ifield f-dest) causes incorrect timing
2665 ; model to be generated; the timing model requires that Pd is set.
2666 (+ (f-dest (.cadr2 srdef)) MODE_AUTOINCREMENT INFIX_MOVE_M_S SIZE_FIXED
2667 (f-source 15) (.sym (.car2 srdef) -operand))
2668 (sequence
2669 ()
2670 (set Pd (.sym (.car2 srdef) -operand)) ; (reg h-sr (.cadr2 srdef))
2671 (reset-x-p))
2672 ((.sym cris-timing-const-sr- (.car2 srdef)))))
2673 ((.sym cris-implemented-specregs-const- VER))
2674 (.map VERFN ((.sym cris-implemented-specregs-const- VER))))))
2675)
2676
2677; CGEN-FIXME:
2678; Unfortunately we can't iterate over the list of models due to the
2679; problem with referring to the parameters of a surrounding pmacro from
2680; within an enclosed .pmacro (perhaps related to "lexical scoping").
2681; We get e.g. 'insn already defined:: (move-c-sprvn-p0)' with this:
2682;(.splice
2683; begin (.unsplice (.map (.pmacro (vn) (cris-move-c-spr vn (.pmacro (x) vn)))
2684; (cris-cpu-models)))
2685;)
2686(cris-move-c-spr v0 (.pmacro (x) v0))
2687(cris-move-c-spr v3 (.pmacro (x) v3))
2688(cris-move-c-spr v8 (.pmacro (x) v8))
2689(cris-move-c-spr v10 (.pmacro (x) v10))
2690(cris-move-c-spr v32 (.pmacro (x) v32))
2691
2692; MOVE Ps,[Rd] [ Ps | 10100111 | Rd ]
2693; MOVE Ps,[Rd+] [ Ps | 11100111 | Rd ]
2694(.splice
2695 begin
2696 (.unsplice
2697 (.map
2698 (.pmacro
2699 (VER)
2700 (dni-cmwt-attr
2701 (.sym move-spr-m VER)
2702 "Move from special register to memory"
2703 ((MACH (.sym cris VER)))
2704 "move ${Ps},[${Rd-sfield}${inc}]"
2705 (+ INFIX_MOVE_S_M SIZE_FIXED Rd-sfield Ps)
2706 (sequence
2707 ((SI rno))
2708 (set rno (regno Ps))
2709 (.splice
2710 cond
2711 (.unsplice
2712 (.map
2713 (.pmacro
2714 (r)
2715 ((eq rno (.cadr2 r))
2716 (cris-set-mem (.car2 r) Rd-sfield Ps)))
2717 ((.sym cris-implemented-specregs- VER))))
2718 (else (error "write from unimplemented special register")))
2719 (reset-x-p))))
2720 (cris-cpu-models)))
2721)
2722
2723; SBFS [Rs(+)]
2724; Instruction format: |0 0 1 1 1 m 1 1 0 1 1 1| Dest. |
2725(dni-cdt-attr
2726 sbfs
2727 "sbfs"
2728 ((MACH crisv10))
2729 "sbfs [${Rd-sfield}${inc}]"
2730 (+ (f-dest 3) INFIX_SBFS SIZE_FIXED MODEMEMP_YES inc Rd-sfield)
2731 (error "SBFS isn't implemented")
2732)
2733
2734; MOVE Ss,Rd [ Ss | 11110111 | Rd ]
2735(dni-cdt-attr
2736 move-ss-r
2737 "move from support register to general register"
2738 (MACH-V32)
2739 "move ${Ss},${Rd-sfield}"
2740 (+ Ss INFIX_MOVE_SS SIZE_FIXED (f-mode 3) Rd-sfield)
2741 (sequence
2742 ()
2743 (set Rd-sfield Ss)
2744 (reset-x-p))
2745)
2746
2747; MOVE Rs,Sd [ Sd | 10110111 | Rs ]
2748(dni-cdt-attr
2749 move-r-ss
2750 "move from general register to support register"
2751 (MACH-V32)
2752 "move ${Rs},${Sd}"
2753 (+ Sd INFIX_MOVE_SS SIZE_FIXED (f-mode 2) Rs)
2754 (sequence
2755 ()
2756 (set Sd Rs)
2757 (reset-x-p))
2758)
2759
2760; MOVEM Rs,[Rd] [ Rs | 10111111 | Rd ]
2761; MOVEM Rs,[Rd+] [ Rs | 11111111 | Rd ]
2762
2763(define-pmacro (movem-to-mem-step regn)
2764 ; Without the SI attribute, UINT is generated, which isn't supported by
2765 ; the sim framework.
2766 (if (ge SI (regno Rs-dfield) regn)
2767 (sequence
2768 ((SI tmp))
2769 (set tmp (reg h-gr regn))
2770 (set (mem SI addr) tmp)
2771 (set addr (add addr 4))))
2772)
2773
2774(dni
2775 movem-r-m
2776 "movem to memory"
2777 (MACH-PRE-V32)
2778 "movem ${Rs-dfield},[${Rd-sfield}${inc}]"
2779 (+ INFIX_MOVEM_R_M MODEMEMP_YES inc SIZE_FIXED Rs-dfield Rd-sfield)
2780 (sequence
2781 ((SI addr) (BI postinc))
2782 ; FIXME: A copy of what's in cris-get-mem.
2783
2784 ; Cache the incrementness of the operand.
2785 (set postinc inc)
2786
2787 ; CGEN-FIXME: Kludge to work around a CGEN bug: it doesn't see that
2788 ; Rs-dfield is used as an input, causing the timing model to be wrong.
2789 (sequence ((SI dummy)) (set dummy Rs-dfield))
2790
2791 ; Get the address from somewhere. If the insn was prefixed, it's in
2792 ; the prefix-register.
2793 (set addr
2794 (if SI (eq prefix-set 0)
2795 Rd-sfield
2796 prefixreg))
2797
2798 (.splice
2799 sequence ()
2800 (.unsplice (.map movem-to-mem-step (.iota 16 15 -1))))
2801
2802 ; Update the source-register for post-increments.
2803 (if (ne postinc 0)
2804 (set Rd-sfield
2805 (if SI (eq prefix-set 0) addr prefixreg)))
2806 (reset-x-p))
2807 (simplecris-movem-timing)
2808)
2809
2810(dni
2811 movem-r-m-v32
2812 "movem to memory"
2813 (MACH-V32)
2814 "movem ${Rs-dfield},[${Rd-sfield}${inc}]"
2815 (+ INFIX_MOVEM_R_M MODEMEMP_YES inc SIZE_FIXED Rs-dfield Rd-sfield)
2816 (sequence
2817 ((SI addr) (BI postinc))
2818 ; FIXME: Mostly a copy of what's in cris-get-mem.
2819
2820 ; Cache the incrementness of the operand.
2821 (set postinc inc)
2822
2823 ; CGEN-FIXME: See movem-r-m.
2824 (sequence ((SI dummy)) (set dummy Rs-dfield))
2825
2826 (set addr Rd-sfield)
2827
2828 (.splice
2829 sequence ()
2830 (.unsplice (.map movem-to-mem-step (.iota 16))))
2831
2832 ; Update the source-register for post-increments.
2833 (if (ne postinc 0)
2834 (set Rd-sfield addr))
2835 (reset-x-p))
2836 ; Unit u-mem must be specified before the u-movem-* for memory address
2837 ; register stall count to be right.
2838 ((crisv32 (unit u-mem) (unit u-movem-rtom) (unit u-exec-movem)
2839 (unit u-mem-w)))
2840)
2841
2842; MOVEM [Rs],Rd [ Rd | 10111011 | Rs ]
2843; MOVEM [Rs+],Rd [ Rd | 11111011 | Rs ]
2844
2845(define-pmacro
2846 (movem-to-reg-step regn)
2847 ; Without the SI attribute, UINT is generated, which isn't supported by
2848 ; the sim framework.
2849 (if (ge SI (regno Rd) regn)
2850 (sequence
2851 ((SI tmp))
2852 (set tmp (mem SI addr))
2853 (set (reg h-gr regn) tmp)
2854 (set addr (add addr 4))))
2855)
2856
2857(dni
2858 movem-m-r
2859 "movem to register"
2860 (MACH-PRE-V32)
2861 "movem [${Rs}${inc}],${Rd}"
2862 (+ Rd INFIX_MOVEM_M_R MODEMEMP_YES inc SIZE_FIXED Rs)
2863 (sequence
2864 ((SI addr) (BI postinc))
2865 ; FIXME: Mostly a copy of what's in cris-get-mem.
2866
2867 ; Cache the incrementness of the operand.
2868 (set postinc inc)
2869
2870 ; Get the address from somewhere. If the insn was prefixed, it's in
2871 ; the prefix-register.
2872 (set addr
2873 (if SI (eq prefix-set 0)
2874 Rs
2875 prefixreg))
2876
2877 ; CGEN-FIXME: See movem-r-m.
2878 (sequence ((SI dummy)) (set dummy Rd))
2879
2880 (.splice
2881 sequence ()
2882 ; The first movem step is left out because it can't happen; it's for
2883 ; PC destination. See the pattern below.
2884 (.unsplice (.map movem-to-reg-step (.iota 15 14 -1))))
2885
2886 ; Update the source-register for post-increments.
2887 ; FIXME: No postinc-prefixed for v0 IIRC.
2888 (if (ne postinc 0)
2889 (set Rs (if SI (eq prefix-set 0) addr prefixreg)))
2890 (reset-x-p))
2891 (simplecris-movem-timing)
2892)
2893
2894; (MOVEM [Rs],PC [ 1111 | 10111011 | Rs ])
2895; (MOVEM [Rs+],PC [ 1111 | 11111011 | Rs ])
2896; We have to special-case it for PC destination; used in longjump.
2897; We shouldn't *have* to special-case it; the main reason is (FIXME:)
2898; misgeneration of the simulator when the PC case is folded into the
2899; generic PRE-V32 movem; possibly related to then being a COND-CTI rather
2900; than an UNCOND-CTI.
2901(dni-cmt-attr
2902 movem-m-pc
2903 "movem to register, ending with PC"
2904 (MACH-PRE-V32)
2905 "movem [${Rs}${inc}],${Rd}"
2906 (+ (f-dest 15) INFIX_MOVEM_M_R SIZE_FIXED Rs)
2907 (sequence
2908 ((SI addr) (BI postinc))
2909 ; FIXME: Mostly a copy of what's in cris-get-mem.
2910
2911 ; Cache the incrementness of the operand.
2912 (set postinc inc)
2913
2914 ; Get the address from somewhere. If the insn was prefixed, it's in
2915 ; the prefix-register.
2916 (set addr
2917 (if SI (eq prefix-set 0)
2918 Rs
2919 prefixreg))
2920
2921 ; FIXME: Add kludge here too *and* a test-case.
2922
2923 (.splice
2924 sequence ()
2925 ; The first movem step is for PC destination, used in longjmp.
2926 (set pc (mem SI addr))
2927 (set addr (add addr 4))
2928 (.unsplice
2929 (.map
2930 (.pmacro
2931 (regn)
2932 (sequence
2933 ((SI tmp))
2934 (set tmp (mem SI addr))
2935 (set (reg h-gr regn) tmp)
2936 (set addr (add addr 4))))
2937 (.iota 15 14 -1))))
2938
2939 ; Update the source-register for post-increments.
2940 ; FIXME: No postinc-prefixed for v0.
2941 (if (ne postinc 0)
2942 (set Rs (if SI (eq prefix-set 0) addr prefixreg)))
2943 (reset-x-p))
2944)
2945
2946(dni
2947 movem-m-r-v32
2948 "movem to register"
2949 (MACH-V32)
2950 "movem [${Rs}${inc}],${Rd}"
2951 (+ INFIX_MOVEM_M_R MODEMEMP_YES inc SIZE_FIXED Rs Rd)
2952 (sequence
2953 ((SI addr) (BI postinc))
2954 ; FIXME: A copy of what's in cris-get-mem
2955
2956 ; Cache the incrementness of the operand.
2957 (set postinc inc)
2958
2959 ; Get the address from somewhere.
2960 (set addr Rs)
2961
2962 ; CGEN-FIXME: See movem-r-m.
2963 (sequence ((SI dummy)) (set dummy Rd))
2964
2965 (.splice
2966 sequence ()
2967 (.unsplice (.map movem-to-reg-step (.iota 16))))
2968
2969 ; Update the source-register for post-increments.
2970 ; FIXME: No postinc-prefixed for v0 IIRC.
2971 (if (ne postinc 0)
2972 (set Rs addr))
2973 (reset-x-p))
2974 ; u-mem must be specified before the u-movem-* for memory source
2975 ; register stall count to be right.
2976 ((crisv32 (unit u-mem) (unit u-mem-r) (unit u-movem-mtor)
2977 (unit u-exec-movem)))
2978)
2979
2980; ADD.m Rs,Rd [ Rd | 011000mm | Rs ]
2981(dni-cdt-bwd
2982 add "add from register to register"
2983 "$Rs,$Rd"
2984 (+ Rd MODE_REGISTER R_ADD Rs)
2985 (.pmacro (BWD) (cris-arit add BWD Rd Rs))
2986)
2987
2988; ADD.m [Rs],Rd [ Rd | 101000mm | Rs ]
2989; ADD.m [Rs+],Rd [ Rd | 111000mm | Rs ]
2990(dni-cmt-bwd
2991 add-m "add from memory to register"
2992 "[${Rs}${inc}],${Rd}"
2993 (+ INDIR_ADD Rs Rd)
2994 (.pmacro (BWD) (cris-arit-3op add BWD Rd (cris-get-mem BWD Rs) Rs))
2995)
2996; (ADD.m [PC+],Rd [ Rd | 111000mm | 1111 ])
2997(dni-c-QI
2998 addcbr "add constant byte to register"
2999 "add.b ${sconst8}],${Rd}"
3000 (+ Rd MODE_AUTOINCREMENT INDIR_ADD SIZE_BYTE (f-source 15) sconst8)
3001 (cris-arit add QI Rd sconst8)
3002)
3003
3004(dni-c-HI
3005 addcwr "add constant word to register"
3006 "add.w ${sconst16}],${Rd}"
3007 (+ Rd MODE_AUTOINCREMENT INDIR_ADD SIZE_WORD (f-source 15) sconst16)
3008 (cris-arit add HI Rd sconst16)
3009)
3010
3011(dni-c-SI
3012 addcdr "add constant dword to register"
3013 "add.d ${const32}],${Rd}"
3014 (+ Rd MODE_AUTOINCREMENT INDIR_ADD SIZE_DWORD (f-source 15) const32)
3015 (cris-arit add SI Rd const32)
3016)
3017
3018; (ADD.D [PC+],PC [ 1111 | 11100010 | 1111 ])
3019; This insn is used for DSO-local jumps in PIC code.
3020(dni
3021 addcpc "Relative jump by adding constant to PC"
3022 (MACH-PC)
3023 "add.d ${sconst32},PC"
3024 (+ (f-dest 15) MODE_AUTOINCREMENT INDIR_ADD SIZE_DWORD (f-source 15) const32)
3025 (sequence
3026 ((SI newpc) (SI oldpc) (SI offs))
3027 (set offs const32)
3028 (set oldpc (add SI pc 6))
3029 (set newpc (add SI oldpc offs))
3030 (set pc newpc)
3031 (setf-arit SI add oldpc offs newpc cbit))
3032 (simplecris-common-timing ((unit u-const32) (unit u-stall) (unit u-exec)))
3033)
3034
3035; ADDS.z Rs,Rd [ Rd | 0100001z | Rs ]
3036(dni-cdt-sbw
3037 adds "add sign-extended from register to register"
3038 "$Rs,$Rd"
3039 (+ Rd MODE_REGISTER R_ADDX Rs)
3040 (.pmacro (BW) (cris-arit add SI Rd ((.sym BW -ext) (trunc BW Rs))))
3041)
3042
3043; ADDS.z [Rs],Rd [ Rd | 1000001z | Rs ]
3044; ADDS.z [Rs+],Rd [ Rd | 1100001z | Rs ]
3045(dni-cmt-sbw
3046 adds-m "add sign-extended from memory to register"
3047 "[${Rs}${inc}],$Rd"
3048 (+ Rd INDIR_ADDX Rs)
3049 (.pmacro (BW) (cris-arit-3op add SI Rd ((.sym BW -ext) (cris-get-mem BW Rs)) Rs))
3050)
3051
3052; (ADDS.z [PC+],Rd [ Rd | 1100001z | 1111 ])
3053(dni-c-QI
3054 addscbr "add sign-extended constant byte to register"
3055 "[${Rs}${inc}],$Rd"
3056 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX SIGNED_BYTE (f-source 15) sconst8)
3057 (cris-arit add SI Rd (ext SI (trunc QI sconst8)))
3058)
3059(dni-c-HI
3060 addscwr "add sign-extended constant word to register"
3061 "[${Rs}${inc}],$Rd"
3062 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX SIGNED_WORD (f-source 15) sconst16)
3063 (cris-arit add SI Rd (ext SI (trunc HI sconst16)))
3064)
3065
3066; (ADDS.w [],PC [ 1111 | 10000011 | 1111 ])
3067; For a PC destination, we support only the two-operand case
3068; (dest == src), which is used in switch/case statements.
3069; FIXME: Should implement ADD.D [PC],PC and ADDS.B [PC],PC for use if/when
3070; implementing CASE_VECTOR_SHORTEN_MODE.
3071(dni
3072 addspcpc "add sign-extended prefixed arg to PC"
3073 (MACH-PC)
3074 "adds.w [PC],PC"
3075 (+ (f-dest 15) MODE_INDIRECT INDIR_ADDX SIGNED_WORD (f-source 15))
3076 (sequence
3077 ((SI newpc) (SI oldpc) (HI offs))
3078 (if (not prefix-set)
3079 (error "Unexpected adds.w [PC],PC without prefix"))
3080 ; We don't use cris-get-mem but instead special-case this one, since we
3081 ; have most instruction fields fixed where cris-get-mem expects
3082 ; field-parametrization by certain names.
3083 (set offs (mem HI prefixreg))
3084 (set oldpc (add SI pc 2))
3085 (set newpc (add SI oldpc offs))
3086 (set pc newpc)
3087 (setf-arit SI add oldpc (ext SI offs) newpc cbit))
3088 (simplecris-common-timing ((unit u-mem) (unit u-stall) (unit u-exec)))
3089)
3090
3091; ADDU.z Rs,Rd [ Rd | 0100000z | Rs ]
3092(dni-cdt-ubw
3093 addu "add zero-extended from register to register"
3094 "$Rs,$Rd"
3095 (+ Rd MODE_REGISTER R_ADDX Rs)
3096 (.pmacro (BW) (cris-arit add SI Rd ((.sym BW -zext) (trunc BW Rs))))
3097)
3098
3099; ADDU.z [Rs],Rd [ Rd | 1000000z | Rs ]
3100; ADDU.z [Rs+],Rd [ Rd | 1100000z | Rs ]
3101(dni-cmt-ubw
3102 addu-m "add zero-extended from memory to register"
3103 "[${Rs}${inc}],$Rd"
3104 (+ Rd INDIR_ADDX Rs)
3105 (.pmacro (BW)
3106 (cris-arit-3op add SI Rd ((.sym BW -zext) (cris-get-mem BW Rs)) Rs))
3107)
3108
3109; (ADDU.z [PC+],Rd [ Rd | 1100000z | 1111 ])
3110(dni-c-QI
3111 adducbr "add zero-extended constant byte to register"
3112 "[${Rs}${inc}],$Rd"
3113 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX UNSIGNED_BYTE (f-source 15) sconst8)
3114 (cris-arit add SI Rd (zext SI (trunc QI sconst8)))
3115)
3116(dni-c-HI
3117 adducwr "add zero-extended constant word to register"
3118 "[${Rs}${inc}],$Rd"
3119 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX UNSIGNED_WORD (f-source 15) sconst16)
3120 (cris-arit add SI Rd (zext SI (trunc HI sconst16)))
3121)
3122
3123; SUB.m Rs,Rd [ Rd | 011010mm | Rs ]
3124(dni-cdt-bwd
3125 sub "subtract from register to register"
3126 "$Rs,$Rd"
3127 (+ Rd MODE_REGISTER R_SUB Rs)
3128 (.pmacro (BWD) (cris-arit sub BWD Rd Rs))
3129)
3130
3131; SUB.m [Rs],Rd [ Rd | 101010mm | Rs ]
3132; SUB.m [Rs+],Rd [ Rd | 111010mm | Rs ]
3133(dni-cmt-bwd
3134 sub-m "subtract from memory to register"
3135 "[${Rs}${inc}],${Rd}"
3136 (+ INDIR_SUB Rs Rd)
3137 (.pmacro (BWD) (cris-arit-3op sub BWD Rd (cris-get-mem BWD Rs) Rs))
3138)
3139
3140; (SUB.m [PC+],Rd [ Rd | 111010mm | 1111 ]
3141(dni-c-QI
3142 subcbr "subtract constant byte from register"
3143 "sub.b ${sconst8}],${Rd}"
3144 (+ Rd MODE_AUTOINCREMENT INDIR_SUB SIZE_BYTE (f-source 15) sconst8)
3145 (cris-arit sub QI Rd sconst8)
3146)
3147
3148(dni-c-HI
3149 subcwr "subtract constant word from register"
3150 "sub.w ${sconst16}],${Rd}"
3151 (+ Rd MODE_AUTOINCREMENT INDIR_SUB SIZE_WORD (f-source 15) sconst16)
3152 (cris-arit sub HI Rd sconst16)
3153)
3154
3155(dni-c-SI
3156 subcdr "subtract constant dword from register"
3157 "sub.d ${const32}],${Rd}"
3158 (+ Rd MODE_AUTOINCREMENT INDIR_SUB SIZE_DWORD (f-source 15) const32)
3159 (cris-arit sub SI Rd const32)
3160)
3161
3162; SUBS.z Rs,Rd [ Rd | 0100101z | Rs ]
3163(dni-cdt-sbw
3164 subs "sub sign-extended from register to register"
3165 "$Rs,$Rd"
3166 (+ Rd MODE_REGISTER R_SUBX Rs)
3167 (.pmacro (BW) (cris-arit sub SI Rd ((.sym BW -ext) (trunc BW Rs))))
3168)
3169
3170; SUBS.z [Rs],Rd [ Rd | 1000101z | Rs ]
3171; SUBS.z [Rs+],Rd [ Rd | 1100101z | Rs ]
3172(dni-cmt-sbw
3173 subs-m "sub sign-extended from memory to register"
3174 "[${Rs}${inc}],$Rd"
3175 (+ Rd INDIR_SUBX Rs)
3176 (.pmacro (BW)
3177 (cris-arit-3op sub SI Rd ((.sym BW -ext) (cris-get-mem BW Rs)) Rs))
3178)
3179
3180; (SUBS.z [PC+],Rd [ Rd | 1100101z | 1111 ])
3181(dni-c-QI
3182 subscbr "sub sign-extended constant byte to register"
3183 "[${Rs}${inc}],$Rd"
3184 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX SIGNED_BYTE (f-source 15) sconst8)
3185 (cris-arit sub SI Rd (ext SI (trunc QI sconst8)))
3186)
3187(dni-c-HI
3188 subscwr "sub sign-extended constant word to register"
3189 "[${Rs}${inc}],$Rd"
3190 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX SIGNED_WORD (f-source 15) sconst16)
3191 (cris-arit sub SI Rd (ext SI (trunc HI sconst16)))
3192)
3193
3194; SUBU.z Rs,Rd [ Rd | 0100100z | Rs ]
3195(dni-cdt-ubw
3196 subu "sub zero-extended from register to register"
3197 "$Rs,$Rd"
3198 (+ Rd MODE_REGISTER R_SUBX Rs)
3199 (.pmacro (BW) (cris-arit sub SI Rd ((.sym BW -zext) (trunc BW Rs))))
3200)
3201
3202; SUBU.z [Rs],Rd [ Rd | 1000100z | Rs ]
3203; SUBU.z [Rs+],Rd [ Rd | 1100100z | Rs ]
3204(dni-cmt-ubw
3205 subu-m "sub zero-extended from memory to register"
3206 "[${Rs}${inc}],$Rd"
3207 (+ Rd INDIR_SUBX Rs)
3208 (.pmacro (BW)
3209 (cris-arit-3op sub SI Rd ((.sym BW -zext) (cris-get-mem BW Rs)) Rs))
3210)
3211
3212; (SUBU.z [PC+],Rd [ Rd | 1100100z | 1111 ])
3213(dni-c-QI
3214 subucbr "sub zero-extended constant byte to register"
3215 "[${Rs}${inc}],$Rd"
3216 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX UNSIGNED_BYTE (f-source 15) sconst8)
3217 (cris-arit sub SI Rd (zext SI (trunc QI sconst8)))
3218)
3219(dni-c-HI
3220 subucwr "sub zero-extended constant word to register"
3221 "[${Rs}${inc}],$Rd"
3222 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX UNSIGNED_WORD (f-source 15) sconst16)
3223 (cris-arit sub SI Rd (zext SI (trunc HI sconst16)))
3224)
3225
3226; ADDC Rs,Rd [ Rd | 01010111 | Rs ]
3227(dni-cdt-attr
3228 addc-r "addc from register to register"
3229 (MACH-V32)
3230 "addc $Rs,$Rd"
3231 (+ Rd MODE_REGISTER RFIX_ADDC SIZE_FIXED Rs)
3232 ; Since this is equivalent to "ax" plus "add.d Rs,Rd", we'll just do
3233 ; that, semantically.
3234 (sequence
3235 ()
3236 (set-quiet xbit 1)
3237 (cris-arit add SI Rd Rs))
3238)
3239
3240; ADDC [Rs],Rd [ Rd | 10011010 | Rs ]
3241; ADDC [Rs+],Rd [ Rd | 11011010 | Rs ]
3242(dni-cmt-attr
3243 addc-m "addc from memory to register"
3244 (MACH-V32)
3245 "addc [${Rs}${inc}],${Rd}"
3246 (+ Rd INDIR_ADDC SIZE_DWORD Rs)
3247 (sequence
3248 ()
3249 (set-quiet xbit 1)
3250 (cris-arit add SI Rd (cris-get-mem SI Rs)))
3251)
3252
3253; (ADDC [Rs+],Rd [ Rd | 11011010 | 1111 ])
3254(dni-c-SI-attr
3255 addc-c "addc constant to register"
3256 (MACH-V32)
3257 "addc ${const32},${Rd}"
3258 (+ Rd MODE_AUTOINCREMENT INDIR_ADDC SIZE_DWORD (f-source 15) const32)
3259 (sequence
3260 ()
3261 (set-quiet xbit 1)
3262 (cris-arit add SI Rd const32))
3263)
3264
3265; LAPC [PC+],Rd [ Rd | 11010111 1111 ]
3266(dni-c-SI-attr
3267 lapc-d "lapc.d"
3268 (MACH-V32)
3269 "lapc.d ${const32-pcrel},${Rd}"
3270 (+ Rd MODE_AUTOINCREMENT INFIX_LAPC SIZE_FIXED (f-source 15) const32-pcrel)
3271 (sequence
3272 ()
3273 (set Rd const32-pcrel)
3274 (reset-x-p))
3275)
3276
3277; LAPCQ qo,Rd [ Rd | 10010111 | qo ]
3278(dni-cdt-attr
3279 lapcq "lapcq"
3280 (MACH-V32)
3281 "lapcq ${qo},${Rd}"
3282 (+ Rd MODE_INDIRECT INFIX_LAPC SIZE_FIXED qo)
3283 (sequence
3284 ()
3285 (set Rd qo)
3286 (reset-x-p))
3287)
3288
3289; ADDI Rs.m,Rd [ Rs | 010100mm | Rd ]
3290(dni-cdt-bwd
3291 addi "addi"
3292 "${Rs-dfield}.m,${Rd-sfield}"
3293 (+ Rd-sfield MODE_REGISTER R_ADDI Rs-dfield)
3294 (.pmacro
3295 (BWD)
3296 (sequence
3297 ()
3298 (set Rd-sfield (add SI Rd-sfield (mul Rs-dfield (.sym BWD -size))))
3299 (reset-x-p)))
3300)
3301
3302; NEG.m Rs,Rd [ Rd | 010110mm | Rs ]
3303(dni-cdt-bwd
3304 neg "neg.m Rs,Rd"
3305 "$Rs,$Rd"
3306 (+ Rd MODE_REGISTER R_NEG Rs)
3307 (.pmacro (BWD) (cris-arit3 sub BWD Rd 0 Rs))
3308)
3309
3310; TEST.m [Rs] [ 0000101110mm | Rs ]
3311; TEST.m [Rs+] [ 0000111110mm | Rs ]
3312(dni-cmt-bwd
3313 test-m "test.m [Rs(+)]"
3314 "[${Rs}${inc}]"
3315 (+ (f-dest 0) INDIR_TEST Rs)
3316 (.pmacro
3317 (BWD)
3318 (sequence
3319 ((BWD tmpd))
3320 (set tmpd (cris-get-mem BWD Rs))
3321 ; This is supposed to be the same result as for cmpq 0,X, hence same code.
3322 (cris-arit6-int
3323 sub BWD (.pmacro (sz regno val) (nop)) 0 tmpd 0 cbit cbit)))
3324)
3325
3326; MOVE.m Rs,[Rd] [ Rs | 101111mm | Rd ]
3327; MOVE.m Rs,[Rd+] [ Rs | 111111mm | Rd ]
3328
3329(dni-cmwt-bwd
3330 move-r-m "move.m R,[]"
3331 "${Rs-dfield},[${Rd-sfield}${inc}]"
3332 (+ Rs-dfield INDIR_MOVE_R_M Rd-sfield)
3333 (.pmacro
3334 (BWD)
3335 (sequence
3336 ((BWD tmpd))
3337 (set tmpd Rs-dfield)
3338 (cris-set-mem BWD Rd-sfield tmpd)
3339 (reset-x-p)))
3340)
3341
3342; MULS.m Rs,Rd [ Rd | 110100mm | Rs ]
3343(dni-bwd-attr
3344 muls "muls.m Rs,Rd"
3345 ((MACH crisv10,crisv32))
3346 "$Rs,$Rd"
3347 (+ Rd MODE_MULS INDIR_MUL Rs)
3348 (.pmacro
3349 (BWD)
3350 (sequence
3351 ((DI src1) (DI src2) (DI tmpr))
3352 (set src1 (ext DI (trunc BWD Rs)))
3353 (set src2 (ext DI (trunc BWD Rd)))
3354 (set tmpr (mul src1 src2))
3355 (set Rd (trunc SI tmpr))
3356 (set mof (trunc SI (srl tmpr 32)))
3357 (setf-arit DI muls src1 src2 tmpr cbit)))
3358 ((crisv10 (unit u-multiply) (unit u-exec))
3359 (crisv32 (unit u-multiply) (unit u-exec)))
3360)
3361
3362; MULU.m Rs,Rd [ Rd | 100100mm | Rs ]
3363(dni-bwd-attr
3364 mulu "mulu.m Rs,Rd"
3365 ((MACH crisv10,crisv32))
3366 "$Rs,$Rd"
3367 (+ Rd MODE_MULU INDIR_MUL Rs)
3368 (.pmacro
3369 (BWD)
3370 (sequence
3371 ((DI src1) (DI src2) (DI tmpr))
3372 (set src1 (zext DI (trunc BWD Rs)))
3373 (set src2 (zext DI (trunc BWD Rd)))
3374 (set tmpr (mul src1 src2))
3375 (set Rd (trunc SI tmpr))
3376 (set mof (trunc SI (srl tmpr 32)))
3377 (setf-arit DI mulu src1 src2 tmpr cbit)))
3378 ((crisv10 (unit u-multiply) (unit u-exec))
3379 (crisv32 (unit u-multiply) (unit u-exec)))
3380)
3381
3382; MCP Ps,Rd [ Ps | 01111111 | Rd ]
3383(dni-cdt-attr
3384 mcp "Multiply Carry Propagation"
3385 (MACH-V32)
3386 "mcp $Ps,$Rd"
3387 (+ Ps MODE_REGISTER RFIX_MCP SIZE_FIXED Rd-sfield)
3388 (sequence
3389 ()
3390 (set-quiet xbit 1)
3391 (set-quiet zbit 1)
3392 (cris-arit5 add SI Rd-sfield Rd-sfield Ps rbit rbit))
3393)
3394
3395; DSTEP Rs,Rd [ Rd | 01101111 | Rs ]
3396(dni-cdt
3397 dstep "Division step"
3398 "dstep $Rs,$Rd"
3399 (+ Rd MODE_REGISTER RFIX_DSTEP SIZE_FIXED Rs)
3400 (sequence
3401 ((SI tmp) (SI tmps) (SI tmpd))
3402 (set tmps Rs)
3403 (set tmp (sll Rd 1))
3404 (set tmpd (if SI (geu tmp tmps) (sub tmp tmps) tmp))
3405 (set Rd tmpd)
3406 (setf-move SI tmpd))
3407)
3408
3409; ABS Rs,Rd [ Rd | 01101011 | Rs ]
3410(dni-cdt
3411 abs "Absolut Instruction"
3412 "abs $Rs,$Rd"
3413 (+ Rd MODE_REGISTER RFIX_ABS SIZE_FIXED Rs)
3414 (sequence
3415 ((SI tmpd))
3416 (set tmpd (abs Rs))
3417 (set Rd tmpd)
3418 (setf-move SI tmpd))
3419)
3420
3421; AND.m Rs,Rd [ Rd | 011100mm | Rs ]
3422(dni-cdt-bwd
3423 and "And from register to register"
3424 "$Rs,$Rd"
3425 (+ Rd MODE_REGISTER R_AND Rs)
3426 (.pmacro
3427 (BWD)
3428 (sequence
3429 ((BWD tmpd))
3430 (set tmpd (and BWD Rd Rs))
3431 (set-subreg-gr BWD (regno Rd) tmpd)
3432 (setf-move BWD tmpd)))
3433)
3434
3435; AND.m [Rs],Rd [ Rd | 101100mm | Rs ]
3436; AND.m [Rs+],Rd [ Rd | 111100mm | Rs ]
3437(dni-cmt-bwd
3438 and-m "And from memory to register"
3439 "[${Rs}${inc}],${Rd}"
3440 (+ INDIR_AND Rs Rd)
3441 (.pmacro
3442 (BWD)
3443 (sequence
3444 ((BWD tmpd))
3445 (set tmpd (and BWD Rd (cris-get-mem BWD Rs)))
3446 (set-subreg-gr
3447 BWD
3448 (if SI (andif prefix-set (not inc)) (regno Rs) (regno Rd))
3449 tmpd)
3450 (setf-move BWD tmpd)))
3451)
3452
3453; (AND.m [PC+],Rd [ Rd | 111100mm | 1111 ])
3454(dni-c-QI
3455 andcbr "And constant byte to register"
3456 "and.b ${sconst8}],${Rd}"
3457 (+ Rd MODE_AUTOINCREMENT INDIR_AND SIZE_BYTE (f-source 15) sconst8)
3458 (sequence
3459 ((QI tmpd))
3460 (set tmpd (and QI Rd sconst8))
3461 (set-subreg-gr QI (regno Rd) tmpd)
3462 (setf-move QI tmpd))
3463)
3464
3465(dni-c-HI
3466 andcwr "And constant word to register"
3467 "and.w ${sconst16}],${Rd}"
3468 (+ Rd MODE_AUTOINCREMENT INDIR_AND SIZE_WORD (f-source 15) sconst16)
3469 (sequence
3470 ((HI tmpd))
3471 (set tmpd (and HI Rd sconst16))
3472 (set-subreg-gr HI (regno Rd) tmpd)
3473 (setf-move HI tmpd))
3474)
3475
3476(dni-c-SI
3477 andcdr "And constant dword to register"
3478 "and.d ${const32}],${Rd}"
3479 (+ Rd MODE_AUTOINCREMENT INDIR_AND SIZE_DWORD (f-source 15) const32)
3480 (sequence
3481 ((SI tmpd))
3482 (set tmpd (and SI Rd const32))
3483 (set-subreg-gr SI (regno Rd) tmpd)
3484 (setf-move SI tmpd))
3485)
3486
3487; ANDQ i,Rd [ Rd | 001100 | i ]
3488(dni-cdt
3489 andq "And quick-immediate to register"
3490 "andq $i,$Rd"
3491 (+ Rd MODE_QUICK_IMMEDIATE Q_ANDQ i)
3492 (sequence
3493 ((SI tmpd))
3494 (set tmpd (and SI Rd i))
3495 (set-subreg-gr SI (regno Rd) tmpd)
3496 (setf-move SI tmpd))
3497)
3498
3499; OR.m Rs,Rd [ Rd | 011101mm | Rs ]
3500(dni-cdt-bwd
3501 orr "Or from register to register"
3502 "$Rs,$Rd"
3503 (+ Rd MODE_REGISTER R_OR Rs)
3504 (.pmacro
3505 (BWD)
3506 (sequence
3507 ((BWD tmpd))
3508 (set tmpd (or BWD Rd Rs))
3509 (set-subreg-gr BWD (regno Rd) tmpd)
3510 (setf-move BWD tmpd)))
3511)
3512
3513; OR.m [Rs],Rd [ Rd | 101101mm | Rs ]
3514; OR.m [Rs+],Rd [ Rd | 111101mm | Rs ]
3515(dni-cmt-bwd
3516 or-m "Or from memory to register"
3517 "[${Rs}${inc}],${Rd}"
3518 (+ INDIR_OR Rs Rd)
3519 (.pmacro
3520 (BWD)
3521 (sequence
3522 ((BWD tmpd))
3523 (set tmpd (or BWD Rd (cris-get-mem BWD Rs)))
3524 (set-subreg-gr
3525 BWD
3526 (if SI (andif prefix-set (not inc)) (regno Rs) (regno Rd))
3527 tmpd)
3528 (setf-move BWD tmpd)))
3529)
3530
3531; (OR.m [PC+],Rd [ Rd | 111101mm | 1111 ])
3532(dni-c-QI
3533 orcbr "Or constant byte to register"
3534 "or.b ${sconst8}],${Rd}"
3535 (+ Rd MODE_AUTOINCREMENT INDIR_OR SIZE_BYTE (f-source 15) sconst8)
3536 (sequence
3537 ((QI tmpd))
3538 (set tmpd (or QI Rd sconst8))
3539 (set-subreg-gr QI (regno Rd) tmpd)
3540 (setf-move QI tmpd))
3541)
3542
3543(dni-c-HI
3544 orcwr "Or constant word to register"
3545 "or.w ${sconst16}],${Rd}"
3546 (+ Rd MODE_AUTOINCREMENT INDIR_OR SIZE_WORD (f-source 15) sconst16)
3547 (sequence
3548 ((HI tmpd))
3549 (set tmpd (or HI Rd sconst16))
3550 (set-subreg-gr HI (regno Rd) tmpd)
3551 (setf-move HI tmpd))
3552)
3553
3554(dni-c-SI
3555 orcdr "Or constant dword to register"
3556 "or.d ${const32}],${Rd}"
3557 (+ Rd MODE_AUTOINCREMENT INDIR_OR SIZE_DWORD (f-source 15) const32)
3558 (sequence
3559 ((SI tmpd))
3560 (set tmpd (or SI Rd const32))
3561 (set-subreg-gr SI (regno Rd) tmpd)
3562 (setf-move SI tmpd))
3563)
3564
3565; ORQ i,Rd [ Rd | 001101 | i ]
3566(dni-cdt
3567 orq "Or quick-immediate to register"
3568 "orq $i,$Rd"
3569 (+ Rd MODE_QUICK_IMMEDIATE Q_ORQ i)
3570 (sequence
3571 ((SI tmpd))
3572 (set tmpd (or SI Rd i))
3573 (set-subreg-gr SI (regno Rd) tmpd)
3574 (setf-move SI tmpd))
3575)
3576
3577; XOR Rs,Rd [ Rd | 01111011 | Rs ]
3578(dni-cdt
3579 xor "Xor from register to register"
3580 "xor $Rs,$Rd"
3581 (+ Rd MODE_REGISTER RFIX_XOR SIZE_FIXED Rs)
3582 (sequence
3583 ((SI tmpd))
3584 (set tmpd (xor SI Rd Rs))
3585 (set Rd tmpd)
3586 (setf-move SI tmpd))
3587)
3588
3589(define-pmacro (swap-r x)
3590 "Perform bit-wise swap within each byte"
3591 (sequence
3592 SI
3593 ((SI tmpr))
3594 (set tmpr x)
3595 (or (sll (and tmpr #x1010101) 7)
3596 (or (sll (and tmpr #x2020202) 5)
3597 (or (sll (and tmpr #x4040404) 3)
3598 (or (sll (and tmpr #x8080808) 1)
3599 (or (srl (and tmpr #x10101010) 1)
3600 (or (srl (and tmpr #x20202020) 3)
3601 (or (srl (and tmpr #x40404040) 5)
3602 (srl (and tmpr #x80808080) 7)))))))))
3603)
3604
3605(define-pmacro (swap-b x)
3606 "Perform byte-wise swap within each word"
3607 (sequence
3608 SI
3609 ((SI tmpb))
3610 (set tmpb x)
3611 (or (and (sll tmpb 8) #xff00ff00)
3612 (and (srl tmpb 8) #xff00ff)))
3613)
3614
3615(define-pmacro (swap-w x)
3616 "Perform word-wise swap within each dword"
3617 (sequence
3618 SI
3619 ((SI tmpb))
3620 (set tmpb x)
3621 (or (and (sll tmpb 16) #xffff0000)
3622 (and (srl tmpb 16) #xffff)))
3623)
3624
3625(define-pmacro (swap-_ x)
3626 "Do nothing swap-wise"
3627 (error SI "SWAP without swap modifier isn't implemented")
3628)
3629
3630(define-pmacro (swap-n x)
3631 "Perform bitwise not (that is, perform a not, not not perform)"
3632 (inv x)
3633)
3634
3635(define-pmacro (swap-br x) "Combine swap-r and swap-b" (swap-r (swap-b x)))
3636(define-pmacro (swap-wr x) "Combine swap-r and swap-w" (swap-r (swap-w x)))
3637(define-pmacro (swap-wb x) "Combine swap-b and swap-w" (swap-b (swap-w x)))
3638(define-pmacro (swap-wbr x) "Combine swap-r and swap-wb" (swap-r (swap-wb x)))
3639(define-pmacro (swap-nr x) "Combine swap-r and swap-n" (swap-r (swap-n x)))
3640(define-pmacro (swap-nb x) "Combine swap-n and swap-b" (swap-b (swap-n x)))
3641(define-pmacro (swap-nbr x) "Combine swap-r and swap-nb" (swap-r (swap-nb x)))
3642(define-pmacro (swap-nw x) "Combine swap-n and swap-w" (swap-w (swap-n x)))
3643(define-pmacro (swap-nwr x) "Combine swap-r and swap-nw" (swap-r (swap-nw x)))
3644(define-pmacro (swap-nwb x) "Combine swap-b and swap-nw" (swap-b (swap-nw x)))
3645(define-pmacro (swap-nwbr x) "Combine swap-r and swap-nwb" (swap-r (swap-nwb x)))
3646
3647(define-pmacro (cris-swap swapcode val)
3648 (sequence
3649 SI
3650 ((SI tmpcode) (SI tmpval) (SI tmpres))
3651 (set tmpcode swapcode)
3652 (set tmpval val)
3653 (.splice
3654 cond
3655 (.unsplice
3656 (.map
3657 (.pmacro
3658 (x-swapcode x-swap)
3659 ((eq tmpcode x-swapcode)
3660 (set tmpres ((.sym swap- x-swap) tmpval))))
3661 (.iota 16)
3662 (.splice _ (.unsplice cris-swap-codes)))))
3663 tmpres)
3664)
3665
3666; NOT Rd alias for SWAPN Rd
3667(dni-cdt-attr
3668 not "Not"
3669 ((MACH crisv0,crisv3))
3670 "not ${Rs}"
3671 (+ (f-dest 8) RFIX_SWAP MODE_REGISTER SIZE_FIXED Rd-sfield)
3672 (sequence
3673 ((SI tmp) (SI tmpd))
3674 (set tmp Rd-sfield)
3675 (set tmpd (cris-swap 8 tmp))
3676 (set Rd-sfield tmpd)
3677 (setf-move SI tmpd))
3678)
3679
3680; SWAP<option> Rd [ N W B R | 01110111 | Rd ]
3681(dni-cdt-attr
3682 swap "Swap"
3683 ((MACH crisv8,crisv10,crisv32))
3684 "swap${swapoption} ${Rs}"
3685 (+ swapoption RFIX_SWAP MODE_REGISTER SIZE_FIXED Rd-sfield)
3686 (sequence
3687 ((SI tmps) (SI tmpd))
3688 (set tmps Rd-sfield)
3689 (set tmpd (cris-swap swapoption tmps))
3690 (set Rd-sfield tmpd)
3691 (setf-move SI tmpd))
3692)
3693
3694; ASR.m Rs,Rd [ Rd | 011110mm | Rs ]
3695(dni-cdt-bwd
3696 asrr "Arithmetic shift right register count"
3697 "$Rs,$Rd"
3698 (+ Rd MODE_REGISTER R_ASR Rs)
3699 (.pmacro
3700 (BWD)
3701 (sequence
3702 ((BWD tmpd) (SI cnt1) (SI cnt2))
3703 (set cnt1 Rs)
3704 (set cnt2 (if SI (ne (and cnt1 32) 0) 31 (and cnt1 31)))
3705 (set tmpd (sra SI (ext SI (trunc BWD Rd)) cnt2))
3706 (set-subreg-gr BWD (regno Rd) tmpd)
3707 (setf-move BWD tmpd)))
3708)
3709
3710; ASRQ c,Rd [ Rd | 0011101 | c ]
3711(dni-cdt
3712 asrq "Arithmetic shift right quick-immediate count"
3713 "asrq $c,${Rd}"
3714 (+ Rd Q_ASHQ MODE_QUICK_IMMEDIATE (f-b5 1) c)
3715 (sequence
3716 ((SI tmpd))
3717 (set tmpd (sra Rd c))
3718 (set Rd tmpd)
3719 (setf-move SI tmpd))
3720)
3721
3722; LSR.m Rs,Rd [ Rd | 011111mm | Rs ]
3723(dni-cdt-bwd
3724 lsrr "Logical shift right register count"
3725 "$Rs,$Rd"
3726 (+ Rd MODE_REGISTER R_LSR Rs)
3727 (.pmacro
3728 (BWD)
3729 (sequence
3730 ((SI tmpd) (SI cnt))
3731 (set cnt (and Rs 63))
3732 (set
3733 tmpd
3734 (if SI (ne (and cnt 32) 0)
3735 0
3736 (srl SI (zext SI (trunc BWD Rd)) (and cnt 31))))
3737 (set-subreg-gr BWD (regno Rd) tmpd)
3738 (setf-move BWD tmpd)))
3739)
3740
3741; LSRQ c,Rd [ Rd | 0011111 | c ]
3742(dni-cdt
3743 lsrq "Logical shift right quick-immediate count"
3744 "lsrq $c,${Rd}"
3745 (+ Rd Q_LSHQ MODE_QUICK_IMMEDIATE (f-b5 1) c)
3746 (sequence
3747 ((SI tmpd))
3748 (set tmpd (srl Rd c))
3749 (set Rd tmpd)
3750 (setf-move SI tmpd))
3751)
3752
3753; LSL.m Rs,Rd [ Rd | 010011mm | Rs ]
3754(dni-cdt-bwd
3755 lslr "Logical shift left register count"
3756 "$Rs,$Rd"
3757 (+ Rd MODE_REGISTER R_LSL Rs)
3758 (.pmacro
3759 (BWD)
3760 (sequence
3761 ((SI tmpd) (SI cnt))
3762 (set cnt (and Rs 63))
3763 (set
3764 tmpd
3765 (if SI (ne (and cnt 32) 0)
3766 0
3767 (sll SI (zext SI (trunc BWD Rd)) (and cnt 31))))
3768 (set-subreg-gr BWD (regno Rd) tmpd)
3769 (setf-move BWD tmpd)))
3770)
3771
3772; LSLQ c,Rd [ Rd | 0011110 | c ]
3773(dni-cdt
3774 lslq "Logical shift left quick-immediate count"
3775 "lslq $c,${Rd}"
3776 (+ Rd Q_LSHQ MODE_QUICK_IMMEDIATE (f-b5 0) c)
3777 (sequence
3778 ((SI tmpd))
3779 (set tmpd (sll Rd c))
3780 (set Rd tmpd)
3781 (setf-move SI tmpd))
3782)
3783
3784; BTST Rs,Rd [ Rd | 01001111 | Rs ]
3785(dni-cdt
3786 btst "Bit test register number"
3787 "$Rs,$Rd"
3788 (+ Rd MODE_REGISTER RFIX_BTST SIZE_FIXED Rs)
3789 (sequence
3790 ((SI tmpd) (SI cnt))
3791 (set tmpd (sll Rd (sub 31 (and Rs 31))))
3792 (setf-move SI tmpd))
3793)
3794
3795; BTSTQ c,Rd [ Rd | 0011100 | c ]
3796(dni-cdt
3797 btstq "Bit test quick-immediate number"
3798 "btstq $c,${Rd}"
3799 (+ Rd Q_ASHQ MODE_QUICK_IMMEDIATE (f-b5 0) c)
3800 (sequence
3801 ((SI tmpd))
3802 (set tmpd (sll Rd (sub 31 c)))
3803 (setf-move SI tmpd))
3804)
3805
3806; SETF <list of flags> [ P U I X | 01011011 | N Z V C ]
3807(dni-cdt
3808 setf "Set condition code flags explicitly"
3809 "setf ${list-of-flags}"
3810 ; The zero-flags case gets flag operands wrong; there's a "_"
3811 ; where there should have been nothing. Also, flags are in
3812 ; assembly code allowed to be specified in any order, which
3813 ; doesn't match the "flagbits" settings. Luckily we don't
3814 ; use this field for assembly.
3815 (+ RFIX_SETF MODE_REGISTER SIZE_FIXED list-of-flags)
3816 (.splice
3817 sequence
3818 ((SI tmp))
3819 (set tmp list-of-flags)
3820 (.unsplice
3821 (.map
3822 (.pmacro (ccbit)
3823 (if (ne (and tmp (sll 1 (.sym ccbit -bitnumber))) 0)
3824 (set (.sym ccbit bit) 1)))
3825 cris-flagnames))
3826 (set prefix-set 0)
3827 ; Unless x was specified to be set, set it to 0.
3828 (if (eq (and tmp (sll 1 x-bitnumber)) 0)
3829 (set xbit 0)))
3830)
3831
3832; CLEARF <list of flags> [ P U I X | 01011111 | N Z V C ]
3833(dni-cdt
3834 clearf "Clear condition code flags explicitly"
3835 "clearf ${list-of-flags}"
3836 ; The zero-flags case gets flag operands wrong; there's a "_"
3837 ; where there should have been nothing. Also, flags are in
3838 ; assembly code allowed to be specified in any order, which
3839 ; doesn't match the "flagbits" settings. Luckily we don't
3840 ; use this field for assembly.
3841 (+ RFIX_CLEARF MODE_REGISTER SIZE_FIXED list-of-flags)
3842 (.splice
3843 sequence
3844 ((SI tmp))
3845 (set tmp list-of-flags)
3846 (.unsplice
3847 (.map
3848 (.pmacro (ccbit)
3849 (if (ne (and tmp (sll 1 (.sym ccbit -bitnumber))) 0)
3850 (set (.sym ccbit bit) 0)))
3851 cris-flagnames))
3852 (reset-x-p))
3853)
3854
3855(define-pmacro
3856 (rfe-rfn-guts)
3857 "Common parts of RFE and RFN"
3858 (sequence
3859 ((USI oldccs) (USI samebits) (USI shiftbits) (USI keepmask) (BI p1))
3860 (set oldccs ccs)
3861 ; Keeping U, S and I in user mode is handled by the CCS setter, so we
3862 ; don't have to bother. Actually Q and M are handled too. The reason
3863 ; to mask those out is to not have them shifted down into the second
3864 ; flags level.
3865 (set keepmask #xc0000000)
3866 (set samebits (and oldccs keepmask))
3867 ; The P bit has its own equation.
3868 (set shiftbits (and (srl (and oldccs #x3ffdfc00) 10) (inv keepmask)))
3869 (set p1 (ne 0 (and oldccs #x20000)))
3870 (set ccs (or (or samebits shiftbits)
3871 (if SI (and rbit (not p1)) 0 #x80))))
3872)
3873
3874; RFE [ 0010 10010011 0000 ]
3875(dni-cdt-attr
3876 rfe
3877 "RFE"
3878 (MACH-V32)
3879 "rfe"
3880 (+ (f-dest 2) MODE_INDIRECT INFIX_RFE SIZE_FIXED (f-source 0))
3881 (rfe-rfn-guts)
3882)
3883
3884; SFE [ 0011 10010011 0000 ]
3885(dni-cdt-attr
3886 sfe
3887 "SFE"
3888 (MACH-V32)
3889 "sfe"
3890 (+ (f-dest 3) MODE_INDIRECT INFIX_SFE SIZE_FIXED (f-source 0))
3891 (sequence
3892 ((SI oldccs) (SI savemask))
3893 (set savemask #xc0000000)
3894 (set oldccs ccs)
3895 (set ccs
3896 (or (and savemask oldccs)
3897 (and (inv savemask) (sll oldccs 10)))))
3898)
3899
3900; RFG [ 0100 10010011 0000 ]
3901(dni-cdt-attr
3902 rfg
3903 "RFG"
3904 (MACH-V32)
3905 "rfg"
3906 (+ (f-dest 4) MODE_INDIRECT INFIX_RFG SIZE_FIXED (f-source 0))
3907 (c-call VOID "@cpu@_rfg_handler" pc)
3908)
3909
3910; RFN [ 0101 10010011 0000 ]
3911(dni-cdt-attr
3912 rfn
3913 "RFN"
3914 (MACH-V32)
3915 "rfn"
3916 (+ (f-dest 5) MODE_INDIRECT INFIX_RFN SIZE_FIXED (f-source 0))
3917 (sequence () (rfe-rfn-guts) (set mbit 1))
3918)
3919
3920; HALT [ 1111 10010011 0000 ]
3921(dni-cdt-attr
3922 halt
3923 "HALT"
3924 (MACH-V32)
3925 "halt"
3926 (+ (f-dest 15) MODE_INDIRECT INFIX_HALT SIZE_FIXED (f-source 0))
3927 (set pc (c-call USI "@cpu@_halt_handler" pc))
3928)
3929
3930; Bcc o [ cc | 0000 | o ]
3931(dni
3932 bcc-b "bcc byte operand"
3933 ()
3934 "b${cc} ${o-pcrel}"
3935 (+ cc QHI_BCC MODE_QUICK_IMMEDIATE o-pcrel)
3936 (sequence
3937 ((BI truthval))
3938 (set truthval (cris-condition cc))
3939
3940 ; Amazing as it may seem, there's no simpler way to find out
3941 ; whether a branch is taken or not than to mark it through a kludge
3942 ; like this.
3943 (c-call VOID "@cpu@_branch_taken" pc o-pcrel truthval)
3944
3945 (reset-x-p)
3946 (if truthval
3947 (delay 1
3948 (set pc o-pcrel))))
3949 (.splice (.unsplice (simplecris-timing))
3950 (crisv32 (unit u-branch) (unit u-exec)))
3951)
3952(dni
3953 ba-b "ba byte operand"
3954 ()
3955 "ba ${o-pcrel}"
3956 (+ (f-dest 14) QHI_BCC MODE_QUICK_IMMEDIATE o-pcrel)
3957 (sequence
3958 ()
3959 (reset-x-p)
3960 (delay 1
3961 (set pc o-pcrel)))
3962 ((crisv32 (unit u-jump) (unit u-exec)))
3963)
3964
3965; Bcc [PC+] [ cc | 11011111 1111 ]
3966; (We don't implement the generic for pre-V32 but unused variant
3967; "Bcc [Rn(+)]" where n != 15.)
3968(dni
3969 bcc-w "bcc, word operand"
3970 ()
3971 "b${cc} ${o-word-pcrel}"
3972 (+ cc MODE_AUTOINCREMENT INFIX_BCC_M SIZE_FIXED (f-source 15) o-word-pcrel)
3973 (sequence
3974 ((BI truthval))
3975 (set truthval (cris-condition cc))
3976
3977 ; Amazing as it may seem, there's no simpler way to find out
3978 ; whether a branch is taken or not than to mark it through a kludge
3979 ; like this.
3980 (c-call VOID "@cpu@_branch_taken" pc o-word-pcrel truthval)
3981
3982 (reset-x-p)
3983 (if truthval
3984 (delay 1
3985 (set pc o-word-pcrel))))
3986 (.splice
3987 (.unsplice (simplecris-common-timing ((unit u-const16) (unit u-exec))))
3988 (crisv32 (unit u-const16) (unit u-branch) (unit u-exec)))
3989)
3990(dni
3991 ba-w "ba word operand"
3992 ()
3993 "ba ${o-word-pcrel}"
3994 (+ (f-dest 14) MODE_AUTOINCREMENT INFIX_BCC_M SIZE_FIXED (f-source 15) o-word-pcrel)
3995 (sequence
3996 ()
3997 (reset-x-p)
3998 (delay 1
3999 (set pc o-word-pcrel)))
4000 (.splice
4001 (.unsplice (simplecris-common-timing ((unit u-const16) (unit u-exec))))
4002 (crisv32 (unit u-const16) (unit u-jump) (unit u-exec)))
4003)
4004
4005; JAS Rs,Pd [ Pd | 10011011 | Rs ]
4006(dni
4007 jas-r "JAS register"
4008 (MACH-V32)
4009 "jas ${Rs},${Pd}"
4010 (+ Pd MODE_INDIRECT INFIX_JAS_R SIZE_FIXED Rs)
4011 (sequence
4012 ()
4013 (reset-x-p)
4014 (if (andif (eq (regno Rs) 1) (eq (regno Pd) 11))
4015 ; We use this as a trigger; a normally reasonably rare instruction
4016 ; used in the v32 trampoline. See comment at bdapqpc.
4017 ; CGEN-FIXME: can't use (regno srp) [== (regno (reg h-sr 11))]
4018 (c-call VOID "cris_flush_simulator_decode_cache" pc))
4019 (delay 1
4020 (sequence
4021 ()
4022 (set Pd (add SI pc 4))
4023 (set pc Rs))))
4024 ((crisv32 (unit u-jump-r) (unit u-jump) (unit u-exec)))
4025)
4026; Same semantics in pre-V32, except no delay-slot.
4027; FIXME: Missing JIRC/JSRC/JBRC.
4028(dni-cdt-attr
4029 jump-r "JUMP/JSR/JIR register"
4030 (MACH-PC)
4031 "jump/jsr/jir ${Rs}"
4032 (+ Pd MODE_INDIRECT INFIX_JUMP_R SIZE_FIXED Rs)
4033 (sequence
4034 ()
4035 (set Pd (add SI pc 2))
4036 (set pc Rs)
4037 (reset-x-p))
4038)
4039
4040; JAS [PC+],Pd [ Pd | 11011011 1111 ]
4041(dni
4042 jas-c "JAS constant"
4043 (MACH-V32)
4044 "jas ${const32},${Pd}"
4045 (+ Pd MODE_AUTOINCREMENT INFIX_JAS_M SIZE_FIXED (f-source 15) const32)
4046 (sequence
4047 ()
4048 (reset-x-p)
4049 (delay 1
4050 (sequence
4051 ()
4052 (set Pd (add SI pc 8))
4053 (set pc const32))))
4054 ((crisv32 (unit u-const32) (unit u-jump) (unit u-exec)))
4055)
4056
4057; JUMP/JSR/JIR | Special r.| 1 m| 0 1 0 0| 1 1| Source |
4058(dni-cmt-attr
4059 jump-m "JUMP/JSR/JIR memory"
4060 (MACH-PC)
4061 "jump/jsr/jir [${Rs}${inc}]"
4062 (+ Pd INFIX_JUMP_M SIZE_FIXED Rs)
4063 (sequence
4064 ()
4065 (set Pd (add SI pc 2))
4066 (set pc (cris-get-mem SI Rs))
4067 (reset-x-p))
4068)
4069(dni-c-SI-attr
4070 jump-c "JUMP/JSR/JIR constant"
4071 (MACH-PC)
4072 "jump/jsr/jir ${const32}"
4073 (+ Pd MODE_AUTOINCREMENT INFIX_JUMP_M SIZE_FIXED (f-source 15) const32)
4074 (sequence
4075 ()
4076 (set Pd (add SI pc 6))
4077 (set pc const32)
4078 (reset-x-p))
4079)
4080
4081; JUMP Ps [ Ps | 10011111 0000 ]
4082(dni
4083 jump-p "JUMP special register"
4084 (MACH-V32)
4085 "jump ${Ps}"
4086 (+ Ps MODE_INDIRECT INFIX_JUMP_P SIZE_FIXED (f-source 0))
4087 (sequence
4088 ()
4089 (reset-x-p)
4090 (delay 1
4091 (set pc Ps)))
4092 ((crisv32 (unit u-jump-sr)
4093 (unit u-exec)))
4094)
4095
4096; BAS [PC+],Pd [ Pd | 11101011 1111 ]
4097(dni
4098 bas-c "BAS constant"
4099 (MACH-V32)
4100 "bas ${const32},${Pd}"
4101 (+ Pd MODE_AUTOINCREMENT INFIX_BAS SIZE_FIXED (f-source 15) const32-pcrel)
4102 (sequence
4103 ()
4104 (reset-x-p)
4105 (delay 1
4106 (sequence
4107 ()
4108 (set Pd (add SI pc 8))
4109 (set pc const32-pcrel))))
4110 ((crisv32 (unit u-const32) (unit u-jump) (unit u-exec)))
4111)
4112
4113; JASC Rs,Pd [ Pd | 10110011 | Rs ]
4114(dni
4115 jasc-r "JASC register"
4116 (MACH-V32)
4117 "jasc ${Rs},${Pd}"
4118 (+ Pd MODE_INDIRECT INFIX_JASC SIZE_FIXED Rs)
4119 (sequence
4120 ()
4121 (reset-x-p)
4122 (delay 1
4123 (sequence
4124 ()
4125 (set Pd (add SI pc 8))
4126 (set pc Rs))))
4127 ((crisv32 (unit u-jump-r) (unit u-skip4) (unit u-jump) (unit u-exec)))
4128)
4129
4130; JASC [PC+],Pd [ Pd | 11110011 1111 ]
4131(dni
4132 jasc-c "JASC constant"
4133 (MACH-V32)
4134 "jasc ${const32},${Pd}"
4135 (+ Pd MODE_AUTOINCREMENT INFIX_JASC SIZE_FIXED (f-source 15) const32)
4136 (sequence
4137 ()
4138 (reset-x-p)
4139 (delay 1
4140 (sequence
4141 ()
4142 (set Pd (add SI pc 12))
4143 (set pc const32))))
4144 ((crisv32 (unit u-const32) (unit u-skip4) (unit u-jump) (unit u-exec)))
4145)
4146
4147; BASC [PC+],Pd [ Pd | 11101111 1111 ]
4148(dni
4149 basc-c "BASC constant"
4150 (MACH-V32)
4151 "basc ${const32},${Pd}"
4152 (+ Pd MODE_AUTOINCREMENT INFIX_BASC SIZE_FIXED (f-source 15) const32-pcrel)
4153 (sequence
4154 ()
4155 (reset-x-p)
4156 (delay 1
4157 (sequence
4158 ()
4159 (set Pd (add SI pc 12))
4160 (set pc const32-pcrel))))
4161 ((crisv32 (unit u-const32) (unit u-skip4) (unit u-jump) (unit u-exec)))
4162)
4163
4164; BREAK n [ 1110 | 10010011 | n ]
4165
4166(dni-cdt
4167 break "break"
4168 "break $n"
4169 (+ (f-operand2 #xe) MODE_INDIRECT INFIX_BREAK SIZE_FIXED n)
4170 (sequence () (reset-x-p) (set pc (c-call USI "@cpu@_break_handler" n pc)))
4171)
4172
4173; BOUND.m Rs,Rd [ Rd | 010111mm | Rs ]
4174(dni-cdt-bwd
4175 bound-r "Bound register"
4176 "${Rs},${Rd}"
4177 (+ Rd R_BOUND MODE_REGISTER Rs)
4178 (.pmacro
4179 (BWD)
4180 (sequence
4181 ((SI tmpopd) (SI tmpops) (SI newval))
4182 (set tmpops ((.sym BWD -zext) (trunc BWD Rs)))
4183 (set tmpopd Rd)
4184 (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
4185 (set Rd newval)
4186 (setf-move SI newval)))
4187)
4188
4189; BOUND.m [Rs],Rd [ Rd | 100111mm | Rs ]
4190; BOUND.m [Rs+],Rd [ Rd | 110111mm | Rs ]
4191(dni-cmt-bwd-attr
4192 bound-m "Bound memory"
4193 (MACH-PRE-V32)
4194 "[${Rs}${inc}],${Rd}"
4195 (+ Rd INDIR_BOUND Rs)
4196 (.pmacro
4197 (BWD)
4198 (sequence
4199 ((SI tmpopd) (SI tmpops) (SI newval))
4200 (set tmpops ((.sym BWD -zext) (cris-get-mem BWD Rs)))
4201 (set tmpopd Rd)
4202 (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
4203 (if (andif prefix-set (not inc))
4204 (set Rs newval)
4205 (set Rd newval))
4206 (setf-move SI newval)))
4207)
4208
4209; (BOUND.m [PC+],Rd [ Rd | 110111mm | 1111 ])
4210(dni-c-QI
4211 bound-cb "Bound constant byte"
4212 "bound.b [PC+],${Rd}"
4213 (+ Rd MODE_AUTOINCREMENT INDIR_BOUND SIZE_BYTE (f-source 15) uconst8)
4214 (sequence
4215 ((SI tmpopd) (SI tmpops) (SI newval))
4216 (set tmpops (zext SI (trunc QI uconst8)))
4217 (set tmpopd Rd)
4218 (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
4219 (set Rd newval)
4220 (setf-move SI newval))
4221)
4222(dni-c-HI
4223 bound-cw "Bound constant word"
4224 "bound.w [PC+],${Rd}"
4225 (+ Rd MODE_AUTOINCREMENT INDIR_BOUND SIZE_WORD (f-source 15) uconst16)
4226 (sequence
4227 ((SI tmpopd) (SI tmpops) (SI newval))
4228 (set tmpops (zext SI uconst16))
4229 (set tmpopd Rd)
4230 (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
4231 (set Rd newval)
4232 (setf-move SI newval))
4233)
4234(dni-c-SI
4235 bound-cd "Bound constant dword"
4236 "bound.d [PC+],${Rd}"
4237 (+ Rd MODE_AUTOINCREMENT INDIR_BOUND SIZE_DWORD (f-source 15) const32)
4238 (sequence
4239 ((SI tmpopd) (SI tmpops) (SI newval))
4240 (set tmpops const32)
4241 (set tmpopd Rd)
4242 (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
4243 (set Rd newval)
4244 (setf-move SI newval))
4245)
4246
4247; Scc Rd [ cc | 01010011 | Rd ]
4248(dni-cdt
4249 scc "scc"
4250 "s${cc} ${Rd-sfield}"
4251 (+ cc MODE_REGISTER RFIX_SCC SIZE_FIXED Rd-sfield)
4252 (sequence
4253 ((BI truthval))
4254 (set truthval (cris-condition cc))
4255 (set Rd-sfield (zext SI truthval))
4256 (reset-x-p))
4257)
4258
4259; LZ Rs,Rd [ Rd | 01110011 | Rs ]
4260(dni-cdt-attr
4261 lz "lz"
4262 (MACH-V3-UP)
4263 "lz ${Rs},${Rd}"
4264 (+ Rd MODE_REGISTER RFIX_LZ SIZE_FIXED Rs)
4265 (sequence
4266 ((SI tmpd) (SI tmp))
4267 (set tmp Rs)
4268 (set tmpd 0)
4269 (.splice
4270 sequence
4271 ()
4272 (.unsplice
4273 (.map
4274 (.pmacro (n)
4275 (if (ge tmp 0)
4276 (sequence
4277 ()
4278 (set tmp (sll tmp 1))
4279 (set tmpd (add tmpd 1)))))
4280 (.iota 32))))
4281 (set Rd tmpd)
4282 (setf-move SI tmpd))
4283)
4284
4285; ADDOQ o,Rs,ACR [ Rs | 0001 | o ]
4286(dni-cdt
4287 addoq "addoq"
4288 "addoq $o,$Rs,ACR"
4289 (+ Rs-dfield MODE_QUICK_IMMEDIATE QHI_ADDOQ o)
4290 (sequence
4291 ()
4292 (set prefixreg (add SI Rs-dfield o))
4293 (set prefix-set 1))
4294)
4295
4296; (BDAPQ o,PC [ 1111 | 0001 | o ])
4297; This [PC+I] prefix is used in trampolines.
4298(dni-cdt-attr
4299 bdapqpc "bdapq pc operand"
4300 (MACH-PC UNCOND-CTI)
4301 "bdapq $o,PC"
4302 (+ (f-dest 15) MODE_QUICK_IMMEDIATE QHI_BDAP o)
4303 (sequence
4304 ()
4305 (set prefixreg (add SI (add SI pc 2) o))
4306 (set prefix-set 1)
4307 ; When this *rare* instruction is seen, we're may be about to write
4308 ; into code to be executed soon, *probably* covering addresses decoded
4309 ; and executed before. If the simulator does not implement snooping
4310 ; and automatic decoder flush, it will execute old code. This call
4311 ; is a kludge for such simulators, asking it to abandon such cached
4312 ; information. Anyway, it is hopefully enough to make CGEN-sim not
4313 ; hork on gcc trampolines.
4314 ; We mark this insn as UNCOND-CTI so this insn will end a simulator
4315 ; basic block (the atomic unit of translation).
4316 (c-call VOID "cris_flush_simulator_decode_cache" pc))
4317)
4318
4319; ADDO.m [Rs],Rd,ACR [ Rd | 100101mm | Rs ]
4320; ADDO.m [Rs+],Rd,ACR [ Rd | 110101mm | Rs ]
4321(dni-cmt-bwd
4322 addo-m "addo.m memory"
4323 "[${Rs}${inc}],$Rd,ACR"
4324 (+ Rd INDIR_ADDO Rs)
4325 (.pmacro
4326 (BWD)
4327 (sequence
4328 ((BWD tmps))
4329 (set tmps (cris-get-mem BWD Rs))
4330 (set prefixreg (add SI Rd ((.sym BWD -ext) tmps)))
4331 (set prefix-set 1)))
4332)
4333
4334; (ADDO.m [PC+],Rd,ACR [ Rd | 110101mm | 1111 ]
4335(dni-c-QI
4336 addo-cb "addo.b const"
4337 "addo.b [PC+],$Rd,ACR"
4338 (+ Rd MODE_AUTOINCREMENT INDIR_ADDO SIZE_BYTE (f-source 15) sconst8)
4339 (sequence
4340 ()
4341 (set prefixreg (add SI Rd (ext SI (trunc QI sconst8))))
4342 (set prefix-set 1))
4343)
4344(dni-c-HI
4345 addo-cw "addo.w const"
4346 "addo.w [PC+],$Rd,ACR"
4347 (+ Rd MODE_AUTOINCREMENT INDIR_ADDO SIZE_WORD (f-source 15) sconst16)
4348 (sequence
4349 ()
4350 (set prefixreg (add SI Rd (ext SI (trunc HI sconst16))))
4351 (set prefix-set 1))
4352)
4353(dni-c-SI
4354 addo-cd "addo.d const"
4355 "addo.d [PC+],$Rd,ACR"
4356 (+ Rd MODE_AUTOINCREMENT INDIR_ADDO SIZE_DWORD (f-source 15) const32)
4357 (sequence
4358 ()
4359 (set prefixreg (add SI Rd const32))
4360 (set prefix-set 1))
4361)
4362
4363; DIP [] | 0 0 0 0| 1 m| 0 1 0 1| 1 1| Source |
4364
4365(dni-cmt-attr
4366 dip-m "dip mem"
4367 (MACH-PRE-V32)
4368 "dip [${Rs}${inc}]"
4369 (+ (f-dest 0) INFIX_DIP SIZE_FIXED Rs)
4370 (sequence
4371 ((SI tmps))
4372 (set tmps (cris-get-mem SI Rs))
4373 (set prefixreg tmps)
4374 (set prefix-set 1))
4375)
4376
4377; (DIP [] | 0 0 0 0| 1 m| 0 1 0 1| 1 1| Source | )
4378(dni-c-SI-attr
4379 dip-c "dip [PC+]"
4380 (MACH-PC)
4381 "dip [PC+]"
4382 (+ (f-dest 0) MODE_AUTOINCREMENT INFIX_DIP SIZE_FIXED (f-source 15) const32)
4383 (sequence
4384 ()
4385 (set prefixreg const32)
4386 (set prefix-set 1))
4387)
4388
4389; ADDI Rs.m,Rd,ACR [ Rs | 010101mm | Rd ]
4390; a.k.a. biap
4391(dni-cdt-bwd
4392 addi-acr "addi prefix"
4393 "${Rs-dfield}.m,${Rd-sfield},ACR"
4394 (+ Rd-sfield MODE_REGISTER R_ADDI_ACR Rs-dfield)
4395 (.pmacro
4396 (BWD)
4397 (sequence
4398 ()
4399 (set prefixreg (add SI Rd-sfield (mul Rs-dfield (.sym BWD -size))))
4400 (set prefix-set 1)))
4401)
4402
4403(dni-cdt-bwd-attr
4404 biap-pc "biap.m ${Rs-dfield},PC"
4405 (MACH-PC)
4406 "${Rs-dfield}.m,PC"
4407 (+ Rs-dfield MODE_REGISTER R_ADDI_ACR (f-source 15))
4408 (.pmacro
4409 (BWD)
4410 (sequence
4411 ()
4412 (set prefixreg (add SI (add SI pc 4) (mul Rs-dfield (.sym BWD -size))))
4413 (set prefix-set 1)))
4414)
4415
4416; FIDXI [Rs] [ 0000 | 11010011 | Rs ]
4417(dni-cdt-attr
4418 fidxi "fidxi [Rs]"
4419 (MACH-V32)
4420 "fidxi [$Rs]"
4421 (+ (f-dest 0) MODE_AUTOINCREMENT INFIX_FIDXI SIZE_FIXED Rs)
4422 (set pc (c-call USI "@cpu@_fidxi_handler" pc Rs))
4423)
4424
4425; FTAGI [Rs] [ 0001 | 11010011 | Rs ]
4426(dni-cdt-attr
4427 ftagi "ftagi [Rs]"
4428 (MACH-V32)
4429 "fidxi [$Rs]"
4430 (+ (f-dest 1) MODE_AUTOINCREMENT INFIX_FTAGI SIZE_FIXED Rs)
4431 (set pc (c-call USI "@cpu@_ftagi_handler" pc Rs))
4432)
4433
4434; FIDXD [Rs] [ 0000 | 10101011 | Rs ]
4435(dni-cdt-attr
4436 fidxd "fidxd [Rs]"
4437 (MACH-V32)
4438 "fidxd [$Rs]"
4439 (+ (f-dest 0) MODE_INDIRECT INFIX_FIDXD SIZE_FIXED Rs)
4440 (set pc (c-call USI "@cpu@_fidxd_handler" pc Rs))
4441)
4442
4443; FTAGD [Rs] [ 0001 | 10101011 | Rs ]
4444(dni-cdt-attr
4445 ftagd "ftagd [Rs]"
4446 (MACH-V32)
4447 "ftagd [$Rs]"
4448 (+ (f-dest 1) MODE_INDIRECT INFIX_FTAGD SIZE_FIXED Rs)
4449 (set pc (c-call USI "@cpu@_ftagd_handler" pc Rs))
4450)
This page took 0.271307 seconds and 4 git commands to generate.