1 ; CRIS CPU description. -*- Scheme -*-
3 ; Copyright 2003, 2004, 2007 Free Software Foundation, Inc.
5 ; Contributed by Axis Communications AB.
7 ; This file is part of the GNU Binutils.
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 3 of the License, or
12 ; (at your option) any later version.
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.
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., 51 Franklin Street - Fifth Floor, Boston,
24 (include "simplify.inc")
26 ;;;;;;;;;;;;;;;;;; -pmacro (generic ones)
28 (define-pmacro (.car2 l) (.apply (.pmacro (a b) a) l))
29 (define-pmacro (.cadr2 l) (.apply (.pmacro (a b) b) l))
30 (define-pmacro (SI-ext x) "How to sign-extend a dword to dword (a nop)" x)
31 (define-pmacro (HI-ext x) "How to sign-extend a word to dword" (ext SI x))
32 (define-pmacro (QI-ext x) "How to sign-extend a byte to dword" (ext SI x))
33 (define-pmacro (SI-zext x) "How to zero-extend a dword to dword (a nop)" x)
34 (define-pmacro (HI-zext x) "How to zero-extend a word to dword" (zext SI x))
35 (define-pmacro (QI-zext x) "How to zero-extend a byte to dword" (zext SI x))
38 "On a list ((x0 y0) .. (xN yN)), 0 <= m <= N, (define-pmacro xm ym)"
43 (.pmacro (l) (.apply (.pmacro (xm ym) (define-pmacro xm ym)) l)) x)))
46 ;;;;;;;;;;;;;;;;;; -arch -isa -cpu -model
50 (comment "Axis Communications CRIS")
51 (default-alignment unaligned)
53 (machs crisv0 crisv3 crisv8 crisv10 crisv32)
59 (base-insn-bitsize 16)
65 (define-cpu-cris x-suffix x-comment)
66 "Define a CRIS CPU family"
68 (name (.sym cris x-suffix f))
71 ; CGEN-FIXME: Should be deduced from the default?
73 (file-transform (.str x-suffix))
77 ; Useful when there's a need to iterate over all models.
78 (define-pmacro (cris-cpu-model-numbers)
79 "List of CRIS CPU model numbers (version register contents)"
83 (define-pmacro (cris-cpu-models)
84 "List of CRIS CPU model names"
85 (.map (.pmacro (n) (.sym v n)) (cris-cpu-model-numbers))
88 ; Mapping from model name to number.
90 (.map (.pmacro (n) ((.sym v n -number) n))
91 (cris-cpu-model-numbers)))
93 ; FIXME: Rationalize these rules.
94 ; CPU names must be distinct from the architecture name and machine names.
95 ; The "b" suffix stands for "base" and is the convention.
96 ; The "f" suffix stands for "family" and is the convention.
97 ; We ignore the "b" convention, partly because v0 isn't really a "base", at
98 ; least not for some aspects of v32.
99 (define-cpu-cris v0 "CRIS base family")
100 (define-cpu-cris v3 "CRIS v3 family")
101 (define-cpu-cris v8 "CRIS v8 family")
102 (define-cpu-cris v10 "CRIS v10 family")
103 (define-cpu-cris v32 "CRIS v32 family")
105 (define-pmacro MACH-PRE-V32 (MACH crisv0,crisv3,crisv8,crisv10))
106 (define-pmacro MACH-V3-UP (MACH crisv3,crisv8,crisv10,crisv32))
107 (define-pmacro MACH-V32 (MACH crisv32))
108 (define-pmacro MACH-PC MACH-PRE-V32)
109 (define-pmacro MACH-ACR MACH-V32)
110 (define-pmacro MACH-BRANCH-OFFSET-AT-INSN MACH-V32)
111 (define-pmacro MACH-BRANCH-OFFSET-AFTER-INSN MACH-PRE-V32)
115 "Whether the generated code is for V32. See comment at h-v32."
119 (define-pmacro (define-mach-cris x-suffix x-comment x-name)
122 (name (.sym cris x-suffix))
123 ; They're all called "cris" in bfd. Watch out for breakages for some
127 (cpu (.sym cris x-suffix f)))
130 (define-mach-cris v0 "Generic CRIS v0 CPU, ETRAX 1 .. 3" "cris")
131 (define-mach-cris v3 "Generic CRIS v3 CPU, ETRAX 4" "cris")
132 (define-mach-cris v8 "Generic CRIS v8 CPU, ETRAX 100" "cris")
133 (define-mach-cris v10 "Generic CRIS v10 CPU, ETRAX 100 LX" "cris")
134 (define-mach-cris v32 "Generic CRIS v32 CPU, ETRAX FS" "crisv32")
136 (define-pmacro (define-model-simplecris x-name x-comment)
137 "Define a simple CRIS model"
139 (name (.sym cris x-name))
141 (mach (.sym cris x-name))
143 (unit u-exec "Execution Unit" () 1 1 () () () ())
144 (unit u-mem "Memory Unit" () 1 1 () () () ())
146 (unit u-const16 "Fetch 16-bit operand" () 1 1 () () () ())
147 (unit u-const32 "Fetch 32-bit operand" () 1 1
149 ; Used in special-case insn, for example arithmetic with PC destination.
150 (unit u-stall "Stall unit" () 1 1 () () () ())
151 (unit u-skip4 "Skip 4 bytes" () 1 1 () () () ())
152 (unit u-multiply "Multiply Unit" () 1 1 ((MACH crisv10)) () () ())
153 (unit u-movem "Movem Unit" () 1 1 ()
158 (define-model-simplecris v0 "Model of CRIS v0, ETRAX 1 .. 3")
159 (define-model-simplecris v3 "Model of CRIS v3, ETRAX 4")
160 (define-model-simplecris v8 "Model of CRIS v8, ETRAX 100")
161 (define-model-simplecris v10 "Model of CRIS v10, ETRAX 100 LX")
163 ; For some reason, we get an error:
164 ; Generating arch.h ...
165 ; ERROR: In procedure vector-ref:
166 ; ERROR: Wrong type argument in position 1: ()
167 ; if we include timings for machs that we don't generate sims for.
168 ; Last checked: CVS as of 2004-11-18.
169 ; CGEN-FIXME: Looks like another CGEN bug. When it's fixed (or when
170 ; generating sims for v0, v3 or v8), add 0, 3 and 8 to
171 ; simplecris-timing-models. But before that, simplecris-timing-x has to
172 ; be rewritten to work on a multiple-element-list, not assume a single
173 ; element. (A change which seems likely to depend on lexical scoping for
174 ; macros to be introduced: try the obvious implementation.)
175 (define-pmacro simplecris-timing-models (10))
176 (define-pmacro (simplecris-common-timing x-units)
177 "Make timing models, using x-units for all simplecris-timing-models"
178 ; CGEN-FIXME: Another CGEN bug: the part (.unsplice (10)) will remain
179 ; unexpanded in (.sym crisv (.unsplice (10)) if we write this as
180 ; ((.splice (.sym crisv (.unsplice simplecris-timing-models))
181 ; (.unsplice x-units)))
182 ((.splice (.sym crisv (.apply (.pmacro (x) x) simplecris-timing-models))
183 (.unsplice x-units)))
188 ; Timing for memory instructions running on a simple cris model.
189 ((simplecris-mem-timing) (simplecris-common-timing
190 ((unit u-mem) (unit u-exec))))
191 ; Timing for movem instructions running on a simple cris model.
192 ((simplecris-movem-timing) (simplecris-common-timing
193 ((unit u-movem) (unit u-exec))))
194 ; Similar, for an 8- or 16-bit constant ([PC+]) operand.
195 ((simplecris-const-timing-HI)
196 (simplecris-common-timing
197 ((unit u-const16) (unit u-exec))))
198 ; Similar, for a 32-bit constant ([PC+]) operand.
199 ((simplecris-const-timing-SI)
200 (simplecris-common-timing
201 ((unit u-const32) (unit u-exec))))
202 ; Similar, no particular operand.
203 ((simplecris-timing) (simplecris-common-timing
209 (comment "Model of CRISv32")
213 ; Bitmask of h-gr register (0..15) and h-sr register (17..31)
214 ; modified by 3rd previous insn, updated by the u-exec unit.
215 ; Because there's no need to mark writes to special registers BZ and
216 ; WZ, bit 16 is for jump mark and bit 20 for memory-write mark.
217 (prev-prev-prev-modf-regs UINT)
219 ; Ditto for the 2nd previous insn.
220 (prev-prev-modf-regs UINT)
222 ; Ditto for the previous insn.
223 (prev-modf-regs UINT)
225 ; Bit-mask for regs modified by the current insn, propagated to
229 ; Registers loaded by movem are not forwarded to the execution
230 ; stage, so we need to insert stall-cycles for ordinary insns
231 ; accessing such registers. In addition to the *modf-regs
232 ; above, these are set to tell *ordinary* insns which registers
235 (prev-prev-prev-movem-dest-regs UINT)
237 ; Ditto for the 2nd previous insn.
238 (prev-prev-movem-dest-regs UINT)
240 ; Ditto for the previous insn.
241 (prev-movem-dest-regs UINT)
243 ; Bit-mask for regs modified by the current insn, propagated to
244 ; prev-movem-dest-regs.
245 (movem-dest-regs UINT))
247 ; It seems this pipeline description isn't used at all; this is just
249 ; Noteworthy is the placement of the memory stage before the execute stage.
250 (pipeline all "" () ((fetch) (decode) (memory) (execute) (writeback)))
252 ; Units that contribute only a constant pipeline delay are not included.
253 (unit u-mem "Memory Unit" () 1 1 ()
257 ; Artificial units for read/write-related hazard accounting.
258 (unit u-mem-r "Memory Unit Read" () 1 1 () () () ())
259 (unit u-mem-w "Memory Unit Write" () 1 1 () () () ())
261 (unit u-movem-rtom "Movem-to-memory Unit" () 1 1 ()
262 ((Rs INT -1) (Rd INT -1))
264 (unit u-movem-mtor "Movem-to-register Unit" () 1 1 ()
265 ((Rs INT -1) (Rd INT -1))
267 (unit u-multiply "Multiply Unit" () 1 1 ()
268 ((Rs INT -1) (Rd INT -1))
270 (unit u-branch "Branch Unit" () 1 1 ()
273 (unit u-jump-r "Jump-to-register Unit" () 1 1 ()
276 (unit u-jump-sr "Jump-to-special-register Unit" () 1 1 ()
279 (unit u-jump "JAS/BAS Unit, saving PC" () 1 1 ()
283 ; To keep track of PC; not really functional units.
284 (unit u-const16 "Fetch 16-bit operand" () 1 1 () () () ())
285 (unit u-const32 "Fetch 32-bit operand" () 1 1 () () () ())
286 (unit u-skip4 "Skip 4 bytes" () 1 1 () () () ())
288 ; For v32, we need to keep track of inputs (for movem destination
289 ; cycle penalties) and output (for e.g. memory source and jump
290 ; source cycle penalties).
291 (unit u-exec "Execution Unit" () 1 1 ()
292 ((Rd INT -1) (Rs INT -1))
296 ; Special case of u-exec for movem: don't treat Rd as an incoming
298 (unit u-exec-movem "Execution Unit" () 1 1 ()
303 ; Special case of u-exec when the destination is a special
305 (unit u-exec-to-sr "Execution Unit" () 1 1 ()
310 (define-pmacro (crisv32-timing-destreg d)
311 "Timing for instructions running on a crisv32 model"
313 (.splice unit u-exec (.unsplice d))))
315 (define-pmacro (crisv32-timing) (crisv32-timing-destreg ()))
317 (define-pmacro (cris-timing-Rd-sfield)
318 (crisv32-timing-destreg ((out Rd Rd-sfield)))
321 (define-pmacro (crisv32-timing-c-HI)
322 ((crisv32 (unit u-const16) (unit u-exec)))
326 ((crisv32-timing-c-QI crisv32-timing-c-HI)
327 ((crisv32-timing-c-SI) ((crisv32 (unit u-const32) (unit u-exec))))
328 ((crisv32-timing-c-sr-SI) ((crisv32 (unit u-const32) (unit u-exec-to-sr))))
329 ((crisv32-reg-sr-timing) ((crisv32 (unit u-exec-to-sr))))
330 ((crisv32-mem-sr-timing)
331 ((crisv32 (unit u-mem) (unit u-mem-r) (unit u-exec-to-sr))))
332 ((crisv32-mem-timing) ((crisv32 (unit u-mem) (unit u-mem-r) (unit u-exec))))
333 ((crisv32-mem-write-timing) ((crisv32 (unit u-mem) (unit u-exec) (unit u-mem-w)))))
338 ; Timing for instructions using memory operands.
339 ((cris-mem-timing) (.splice (.unsplice (simplecris-mem-timing))
340 (.unsplice (crisv32-mem-timing))))
341 ; Timing for instructions using memory operands.
342 ((cris-mem-write-timing) (.splice
343 (.unsplice (simplecris-mem-timing))
344 (.unsplice (crisv32-mem-write-timing))))
345 ; Timing for moves from general register to special register.
346 ((cris-reg-sr-timing) (.splice (.unsplice (simplecris-timing))
347 (.unsplice (crisv32-reg-sr-timing))))
348 ; Timing for moves from memory to special register.
349 ((cris-mem-sr-timing) (.splice (.unsplice (simplecris-mem-timing))
350 (.unsplice (crisv32-mem-sr-timing))))
351 ; Timing for non-mul, non-memory, non-special-register, 16-bit instructions.
352 ((cris-timing) (.splice (.unsplice (simplecris-timing))
353 (.unsplice (crisv32-timing))))
354 ; Timing for instructions with 8- or 16-bit constant operand ([PC+]).
355 ((cris-timing-const-HI) (.splice
356 (.unsplice (simplecris-const-timing-HI))
357 (.unsplice (crisv32-timing-c-HI))))
358 ; Timing for instructions with a 32-bit constant operand ([PC+]).
359 ((cris-timing-const-SI) (.splice
360 (.unsplice (simplecris-const-timing-SI))
361 (.unsplice (crisv32-timing-c-SI))))
362 ; Like cris-timing-const-SI, but destination special register.
363 ((cris-timing-const-sr-SI) (.splice
364 (.unsplice (simplecris-const-timing-SI))
365 (.unsplice (crisv32-timing-c-sr-SI))))
366 ; Like cris-timing-const-HI, but destination special register.
367 ((cris-timing-const-sr-HI) (.splice
368 (.unsplice (simplecris-const-timing-HI))
369 (.unsplice (crisv32-timing-c-sr-SI)))))
372 (define-pmacro cris-timing-const-QI cris-timing-const-HI)
373 (define-pmacro cris-timing-const-sr-QI cris-timing-const-sr-HI)
375 (define-pmacro (simplecris-common-writable-specregs)
376 "The common writable special registers in pre-v32 models."
377 ((HI 5) (SI 9) (SI 10) (SI 11) (SI 12) (SI 13))
380 (define-pmacro (simplecris-common-readable-specregs)
381 "The common readable special registers in pre-v32 models."
382 (.splice (.unsplice (simplecris-common-writable-specregs))
383 (QI 0) (QI 1) (HI 4) (SI 8))
386 (define-pmacro (cris-implemented-writable-specregs-v0)
387 "Special writable registers in v0 and their sizes"
388 (.splice (.unsplice (simplecris-common-writable-specregs)) (HI 6) (HI 7))
391 cris-implemented-specregs-const-v0
392 cris-implemented-writable-specregs-v0
394 (define-pmacro (cris-implemented-readable-specregs-v0)
395 "Special readable registers in v0 and their sizes"
396 (.splice (.unsplice (simplecris-common-readable-specregs)) (HI 6) (HI 7))
399 (define-pmacro (cris-implemented-writable-specregs-v3)
400 "Special writable registers in v3 and their sizes"
401 (.splice (.unsplice (cris-implemented-writable-specregs-v0)) (SI 14))
404 cris-implemented-specregs-const-v3
405 cris-implemented-writable-specregs-v3
407 (define-pmacro (cris-implemented-readable-specregs-v3)
408 "Special readable registers in v3 and their sizes"
409 (.splice (.unsplice (cris-implemented-readable-specregs-v0)) (SI 14))
412 (define-pmacro (cris-implemented-writable-specregs-v8)
413 "Special writable registers in v8 and their sizes"
414 (.splice (.unsplice (simplecris-common-writable-specregs)) (SI 14))
417 cris-implemented-specregs-const-v8
418 cris-implemented-writable-specregs-v8
420 (define-pmacro (cris-implemented-readable-specregs-v8)
421 "Special readable registers in v8 and their sizes"
422 (.splice (.unsplice (simplecris-common-readable-specregs)) (SI 14))
425 (define-pmacro (cris-implemented-writable-specregs-v10)
426 "Special writable registers in v10 and their sizes"
427 (.splice (.unsplice (simplecris-common-writable-specregs))
428 (SI 7) (SI 14) (SI 15))
431 cris-implemented-specregs-const-v10
432 cris-implemented-writable-specregs-v10
434 (define-pmacro (cris-implemented-readable-specregs-v10)
435 "Special registers in v10 and their sizes"
436 (.splice (.unsplice (simplecris-common-readable-specregs))
437 (SI 7) (SI 14) (SI 15))
440 (define-pmacro (cris-implemented-writable-specregs-v32)
441 "Special writable registers in v32 and their sizes"
443 (SI 5) (SI 6) (SI 7) (SI 9)
444 (SI 10) (SI 11) (SI 12) (SI 13) (SI 14) (SI 15))
446 (define-pmacro (cris-implemented-readable-specregs-v32)
447 "Special readable registers in v32 and their sizes"
448 (.splice (.unsplice (cris-implemented-writable-specregs-v32))
449 (QI 0) (QI 1) (HI 4) (SI 8))
452 ; For v32, all special register operations on constants (that is,
453 ; move) take 32-bit operands, not the real size of the register, as in
454 ; other move operations.
455 (define-pmacro (cris-implemented-specregs-const-v32)
456 (.map (.pmacro (x) (SI (.cadr2 x)))
457 (cris-implemented-writable-specregs-v32))
460 (define-pmacro cris-swap-codes
461 "CRIS Swap codes in numeric order (no zero)"
463 n nr nb nbr nw nwr nwb nwbr)
466 (define-pmacro cris-flagnames
467 "CRIS flag field values, dest and src fields concatenated"
468 (c v z n x i u p) ; ... b m for pre-v32
472 ; Bitnumber for each respective flag.
473 (.map (.pmacro (x num) ((.sym x -bitnumber) num))
474 cris-flagnames (.iota 8))
477 ; I give up. Here's a perl-script to get the values I want for this macro
478 ; (not working along list principles, though). You can run this region.
479 ; perl -e '$x = "cvznxiup"; for ($i = 0; $i < 256; $i++) { $s = "";
480 ; for ($j = 0; $j < 8; $j++) { if ($i & (1 << $j)) {
481 ; $s .= substr ($x, $j, 1);}}
482 ; printf ("%s%s", $s eq "" ? "_" : $s, (($i + 1) % 8) == 0 ? "\n " : " "); }'
483 (define-pmacro cris-flag-combinations
484 "Combinations of flags in numeric order"
485 (_ c v cv z cz vz cvz
486 n cn vn cvn zn czn vzn cvzn
487 x cx vx cvx zx czx vzx cvzx
488 nx cnx vnx cvnx znx cznx vznx cvznx
489 i ci vi cvi zi czi vzi cvzi
490 ni cni vni cvni zni czni vzni cvzni
491 xi cxi vxi cvxi zxi czxi vzxi cvzxi
492 nxi cnxi vnxi cvnxi znxi cznxi vznxi cvznxi
493 u cu vu cvu zu czu vzu cvzu
494 nu cnu vnu cvnu znu cznu vznu cvznu
495 xu cxu vxu cvxu zxu czxu vzxu cvzxu
496 nxu cnxu vnxu cvnxu znxu cznxu vznxu cvznxu
497 iu ciu viu cviu ziu cziu vziu cvziu
498 niu cniu vniu cvniu zniu czniu vzniu cvzniu
499 xiu cxiu vxiu cvxiu zxiu czxiu vzxiu cvzxiu
500 nxiu cnxiu vnxiu cvnxiu znxiu cznxiu vznxiu cvznxiu
501 p cp vp cvp zp czp vzp cvzp
502 np cnp vnp cvnp znp cznp vznp cvznp
503 xp cxp vxp cvxp zxp czxp vzxp cvzxp
504 nxp cnxp vnxp cvnxp znxp cznxp vznxp cvznxp
505 ip cip vip cvip zip czip vzip cvzip
506 nip cnip vnip cvnip znip cznip vznip cvznip
507 xip cxip vxip cvxip zxip czxip vzxip cvzxip
508 nxip cnxip vnxip cvnxip znxip cznxip vznxip cvznxip
509 up cup vup cvup zup czup vzup cvzup
510 nup cnup vnup cvnup znup cznup vznup cvznup
511 xup cxup vxup cvxup zxup czxup vzxup cvzxup
512 nxup cnxup vnxup cvnxup znxup cznxup vznxup cvznxup
513 iup ciup viup cviup ziup cziup vziup cvziup
514 niup cniup vniup cvniup zniup czniup vzniup cvzniup
515 xiup cxiup vxiup cvxiup zxiup czxiup vzxiup cvzxiup
516 nxiup cnxiup vnxiup cvnxiup znxiup cznxiup vznxiup cvznxiup
520 (define-pmacro cc-condition (not cbit))
521 (define-pmacro cs-condition cbit)
522 (define-pmacro ne-condition (not zbit))
523 (define-pmacro eq-condition zbit)
524 (define-pmacro vc-condition (not vbit))
525 (define-pmacro vs-condition vbit)
526 (define-pmacro pl-condition (not nbit))
527 (define-pmacro mi-condition nbit)
528 (define-pmacro ls-condition (or cbit zbit))
529 (define-pmacro hi-condition (not (or cbit zbit)))
530 (define-pmacro ge-condition (not (xor vbit nbit)))
531 (define-pmacro lt-condition (xor vbit nbit))
532 (define-pmacro gt-condition (not (or (xor vbit nbit) zbit)))
533 (define-pmacro le-condition (or (xor vbit nbit) zbit))
534 (define-pmacro a-condition 1)
536 ; FIXME: define this properly for v10 and pre-v10.
537 (define-pmacro wf-condition pbit)
539 (define-pmacro (cris-condition condno)
540 "Return condition state for condition number CONDNO"
543 ((SI tmpcond) (BI condres))
551 ((eq tmpcond condn) (set condres (.sym condc -condition))))
553 cris-condition-codes)))
557 ;;;;;;;;;;;;;;;;;; -keyword
560 (define-pmacro (cris-general-gregs)
561 (.splice (SP 14) (.unsplice (.map (.pmacro (n) ((.sym R n) n)) (.iota 15))))
564 ; Can't keep more than one gr-names definition at the same time;
565 ; generated enum declarations in sim/cris/cris-desc.h will collide.
566 ; FIXME: (include "different-mach-parts")
569 (name gr-names-pcreg)
571 (print-name h-gr-real-pc)
572 ; Put PC first so it is preferred over r15.
573 (.splice values (PC 15) (.unsplice (cris-general-gregs)))
579 ; The print-name directive will control the enum prefix. With the
580 ; arguably more appropriate h-gr-v32 or h-gr-acr, we'd get names like
581 ; H_GR_ACR_R0 instead of H_GR_R0. Since we have to choose something for
582 ; unprefixed names, we use the CRISv32 names. FIXME: All users should
583 ; change to use H_GR_V32_R0 (etc.), then change this to h-gr-v32.
585 ; Put ACR first so it is preferred over r15.
586 (.splice values (ACR 15) (.unsplice (cris-general-gregs)))
592 ; In preparation for implementing the FIXME above.
593 (print-name h-gr-v32)
594 ; Put ACR first so it is preferred over r15.
595 (.splice values (ACR 15) (.unsplice (cris-general-gregs)))
598 ; Special registers with names common to all.
599 (define-pmacro (cris-general-pregs)
603 (.unsplice (.map (.pmacro (n) ((.sym P n) n)) (.iota 15))))
609 (print-name h-sr-pre-v32)
620 (.unsplice (cris-general-pregs)))
626 ; See comment for gr-names-acr.
644 (.unsplice (cris-general-pregs)))
647 ; Similarly as for h-gr-v32, in preparation.
651 ; See comment for gr-names-acr.
652 (print-name h-sr-v32)
669 (.unsplice (cris-general-pregs)))
672 (define-pmacro p0 (reg h-sr 0))
673 (define-pmacro vr (reg h-sr 1))
674 (define-pmacro pid (reg h-sr 2))
675 (define-pmacro srs (reg h-sr 3))
676 (define-pmacro p4 (reg h-sr 4))
677 (define-pmacro ccr (reg h-sr 5))
678 (define-pmacro mof (reg h-sr 7))
679 (define-pmacro p8 (reg h-sr 8))
680 (define-pmacro ibr (reg h-sr 9))
681 (define-pmacro ebp (reg h-sr 9))
682 (define-pmacro erp (reg h-sr 10))
683 (define-pmacro srp (reg h-sr 11))
684 (define-pmacro ccs (reg h-sr 13))
685 (define-pmacro dccr (reg h-sr 13))
686 (define-pmacro usp (reg h-sr 14))
687 (define-pmacro spc (reg h-sr 15))
689 (define-pmacro sp (reg h-gr 14))
690 (define-pmacro acr (reg h-gr 15))
692 (define-pmacro cris-condition-codes
693 "CRIS condition codes in numeric order"
694 (cc cs ne eq vc vs pl mi ls hi ge lt gt le a wf)
697 ; No use having different lists; this is the only CC that
698 ; differs between v10 and v32, and mostly in the name.
699 (define-pmacro sb wf)
702 ;;;;;;;;;;;;;;;;;; -hardware
704 ;; Various constant generators.
708 (comment "autoincrement-bit syntax specifier")
709 (type immediate (UINT 1))
710 (values keyword "" (("" 0) ("+" 1)))
715 (comment "Condition code specifier")
716 (type immediate (UINT 4))
718 (.map (.pmacro (x y) ((.str x) y))
719 cris-condition-codes (.iota 16)))
724 (comment "Swap option specifier")
725 (type immediate (UINT 4))
732 (.pmacro (x y) ((.str x) y)) cris-swap-codes (.iota 15 1)))))
737 (comment "Flag bits specifier")
738 (type immediate (UINT 8))
741 (.map (.pmacro (x y) ((.str x) y)) cris-flag-combinations (.iota 256)))
744 ; Apparently, the semantic-name isn't used for accessors, so external
745 ; users like the sim glue and SID sees the -v32 and -pre-v32 munged names.
746 ; Defining "dispatchers"; virtual registers whose getter and setter works
747 ; on the "real" mach variants, seems to help. CGEN-FIXME: Make
748 ; semantic-name set the generated names.
749 (define-pmacro (cris-d-hwreg x-name x-type)
752 (comment (.str "Dispatcher for " x-name))
754 (type register x-type)
755 (get () (reg (.sym x-name -x)))
756 (set (val) (set (reg (.sym x-name -x)) val)))
758 (define-pmacro (cris-d-hwregf-a x-name x-type x-n x-attrs)
761 (comment (.str "Dispatcher for " x-name))
762 (.splice attrs VIRTUAL (.unsplice x-attrs))
763 (type register x-type (x-n))
764 (get (index) (reg (.sym x-name -x) index))
765 (set (index val) (set-quiet (reg (.sym x-name -x) index) val)))
767 (define-pmacro (cris-d-hwregf x-name x-type x-n)
768 (cris-d-hwregf-a x-name x-type x-n ())
770 (define-pmacro (cris-d-hwregf-p x-name x-type x-n)
771 (cris-d-hwregf-a x-name x-type x-n (PROFILE))
774 ; At first glance we could use (eq-attr (current-mach) ...) for
775 ; everything, but that seems sometimes (always?) to yield false. For
776 ; ifields, it causes noncompilable C-code. For the insn semantics code,
777 ; it causes tests movei.ms and mulv32.ms to fail, apparently because the
778 ; current-mach-is-v32 usage in flags setting is miscompiled as 0 (or
779 ; rather, misgenerated). Instead we use different definitions of a
780 ; MACH-tagged virtual register yielding a constant, together with a
781 ; pmacro. CGEN-FIXME: If eq-attr is someday fixed, we could just remove
782 ; these h-v32 virtual register definitions and change the pmacro
783 ; definition for current-mach-is-v32.
785 (semantic-name h-v32)
787 (attrs MACH-V32 VIRTUAL)
789 (get () (const BI 1))
790 (set (val) (error "Can't set h-v32"))
793 (semantic-name h-v32)
795 (attrs MACH-PRE-V32 VIRTUAL)
797 (get () (const BI 0))
798 (set (val) (error "Can't set h-v32"))
805 (comment "program counter")
808 ; There's no bit 0 in PC, so just ignore it when jumping etc.
809 (set (val) (set (raw-reg h-pc) (and val (inv 1))))
812 ; Note that setting register 15 isn't handled here, but in each insn, so
813 ; the proper "jump" attributes and other special stuff for speedy
814 ; execution can be present.
815 (cris-d-hwregf-p h-gr SI 16)
817 (semantic-name h-gr-x)
819 (attrs MACH-PC VIRTUAL)
820 (comment "General purpose registers, aborting on PC access")
821 (type register SI (16))
822 (indices extern-keyword gr-names-pcreg)
826 (error SI "General register read of PC is not implemented.")
827 (reg SI h-gr-real-pc index)))
833 (error "General register write to PC is not implemented."))
834 (set (reg SI h-gr-real-pc index) val)))
839 (comment "General purpose registers")
840 (type register SI (16))
841 (indices extern-keyword gr-names-pcreg)
844 ; We have to use a virtual register trick to get the "raw", unaccounted
845 ; contents of the global register; the raw-reg RTX only works for
846 ; non-virtual register files.
848 (semantic-name h-raw-gr)
850 (attrs MACH-PC VIRTUAL)
851 (comment "Unaccounted version of general purpose registers")
852 (type register SI (16))
853 (get (index) (raw-reg h-gr-real-pc index))
854 (set (index val) (set-quiet (raw-reg h-gr-real-pc index) val))
857 (semantic-name h-gr-x)
860 (comment "General purpose registers")
861 (type register SI (16))
862 (indices extern-keyword gr-names-acr)
865 (semantic-name h-raw-gr)
867 (attrs MACH-ACR VIRTUAL)
868 (comment "Unaccounted version of general purpose registers")
869 (type register SI (16))
870 (get (index) (raw-reg h-gr-x index))
871 (set (index val) (set-quiet (raw-reg h-gr-x index) val))
874 ; FIXME: get and set semantics? Unknown how to split semantics best; with
875 ; get/set semantics or within the insn specification. Doing the former for
876 ; now. Should use different names for pre-v10.
877 ; FIXME: No dccr for v0 and v3. Different high flag bits.
878 (cris-d-hwregf-p h-sr SI 16)
882 (semantic-name h-sr-x)
883 (name (.sym h-sr-v machver))
884 (attrs (MACH (.sym crisv machver)))
885 (comment (.str "Special registers for v" machver))
886 (type register SI (16))
887 (indices extern-keyword p-names-v10)
892 ((orif (orif (eq index (regno p0)) (eq index (regno p4)))
893 (eq index (regno p8))) 0)
894 ((eq index (regno vr)) machver)
895 ((orif (eq index (regno ccr))
896 (eq index (regno dccr)))
897 ; Return "P U I X N Z V C" for the low 8 bits.
900 (and SI (raw-reg SI h-sr-x (regno ccr)) #xffffff00)
902 (zext SI (reg BI h-cbit))
904 (sll (zext SI (reg BI h-vbit)) 1)
906 (sll (zext SI (reg BI h-zbit)) 2)
908 (sll (zext SI (reg BI h-nbit)) 3)
910 (sll (zext SI (reg BI h-xbit)) 4)
912 (sll (zext SI (reg BI h-ibit)) 5)
914 (sll (zext SI (reg BI h-ubit)) 6)
916 (sll (zext SI (reg BI h-pbit)) 7)
918 (else (raw-reg SI h-sr-x index))))
922 ((orif (orif (eq index (regno p0)) (eq index (regno p4)))
923 (orif (eq index (regno p8)) (eq index (regno vr))))
925 ((orif (eq index (regno ccr)) (eq index (regno dccr)))
928 (set (reg BI h-cbit) (if BI (ne SI (and val (sll 1 0)) 0) 1 0))
929 (set (reg BI h-vbit) (if BI (ne SI (and val (sll 1 1)) 0) 1 0))
930 (set (reg BI h-zbit) (if BI (ne SI (and val (sll 1 2)) 0) 1 0))
931 (set (reg BI h-nbit) (if BI (ne SI (and val (sll 1 3)) 0) 1 0))
932 (set (reg BI h-xbit) (if BI (ne SI (and val (sll 1 4)) 0) 1 0))
933 (set (reg BI h-ibit) (if BI (ne SI (and val (sll 1 5)) 0) 1 0))
934 (set (reg BI h-ubit) (if BI (ne SI (and val (sll 1 6)) 0) 1 0))
935 (set (reg BI h-pbit) (if BI (ne SI (and val (sll 1 7)) 0) 1 0))
936 (set-quiet (raw-reg SI h-sr-x (regno ccr)) val)
937 (set-quiet (raw-reg SI h-sr-x (regno dccr)) val)))
938 (else (set-quiet (raw-reg SI h-sr-x index) val)))))
947 (semantic-name h-sr-x)
950 (comment "Special registers for v32")
951 (type register SI (16))
952 (indices extern-keyword p-names-v32)
958 ((orif (orif (eq index (regno p0)) (eq index (regno p4)))
959 (eq index (regno p8))) 0)
960 ((eq index (regno vr)) 32)
961 ((eq index (regno ccs))
962 ; Return "S R P U I X N Z V C" for the low 10 bits.
964 (and SI (raw-reg SI h-sr-x (regno ccs)) #x3ffffc00)
966 (zext SI (reg BI h-cbit))
968 (sll (zext SI (reg BI h-vbit)) 1)
970 (sll (zext SI (reg BI h-zbit)) 2)
972 (sll (zext SI (reg BI h-nbit)) 3)
974 (sll (zext SI (reg BI h-xbit)) 4)
976 (sll (zext SI (reg BI h-ibit)) 5)
978 (sll (zext SI (reg BI h-ubit)) 6)
980 (sll (zext SI (reg BI h-pbit)) 7)
982 (sll (zext SI (reg BI h-rbit)) 8)
984 (sll (zext SI (reg BI h-sbit)) 9)
986 (sll (zext SI (reg BI h-mbit)) 30)
988 (sll (zext SI (reg BI h-qbit)) 31)
990 ((eq index (regno usp))
991 ; In user mode, return general stack pointer.
992 (if BI (reg BI h-ubit)
993 (raw-reg SI h-gr-x (regno sp))
994 (raw-reg SI h-sr-x (regno usp))))
995 (else (raw-reg SI h-sr-x index))))
1000 ((orif (orif (eq index (regno p0)) (eq index (regno p4)))
1001 (orif (eq index (regno p8)) (eq index (regno vr))))
1003 ((eq index (regno ccs))
1006 ; Protected bits are handled as such in the respective setter function.
1007 (set (reg BI h-cbit) (if BI (ne SI (and val (sll 1 0)) 0) 1 0))
1008 (set (reg BI h-vbit) (if BI (ne SI (and val (sll 1 1)) 0) 1 0))
1009 (set (reg BI h-zbit) (if BI (ne SI (and val (sll 1 2)) 0) 1 0))
1010 (set (reg BI h-nbit) (if BI (ne SI (and val (sll 1 3)) 0) 1 0))
1011 (set (reg BI h-xbit) (if BI (ne SI (and val (sll 1 4)) 0) 1 0))
1012 (set (reg BI h-ibit) (if BI (ne SI (and val (sll 1 5)) 0) 1 0))
1013 (set (reg BI h-sbit) (if BI (ne SI (and val (sll 1 9)) 0) 1 0))
1014 (set (reg BI h-mbit) (if BI (ne SI (and val (sll 1 30)) 0) 1 0))
1015 (set (reg BI h-pbit) (if BI (ne SI (and val (sll 1 7)) 0) 1 0))
1016 (set (reg BI h-rbit) (if BI (ne SI (and val (sll 1 8)) 0) 1 0))
1017 (set (reg BI h-qbit) (if BI (ne SI (and val (sll 1 31)) 0) 1 0))
1018 ; Set the U bit last, so the setter functions for the other bits
1019 ; don't see it as set from this operation. It is not cleared from
1020 ; this operation, so we don't have to handle that; it's only
1021 ; cleared "manually" from within simulator-specific context-switch
1023 (set (reg BI h-ubit) (if BI (ne SI (and val (sll 1 6)) 0) 1 0))
1024 (set-quiet (raw-reg SI h-sr-x index) val)))
1025 ((eq index (regno usp))
1026 ; In user mode, set general register 14 too, whenever setting USP.
1029 (if (reg BI h-ubit) (set (raw-reg SI h-gr-x (regno sp)) val))
1030 (set (raw-reg SI h-sr-x (regno usp)) val)))
1031 ((eq index (regno srs))
1032 (if (not (reg BI h-ubit)) (set (raw-reg h-sr-x (regno srs)) val)))
1033 ((eq index (regno ebp))
1034 (if (not (reg BI h-ubit)) (set (raw-reg h-sr-x (regno ebp)) val)))
1035 ((eq index (regno pid))
1036 (if (not (reg BI h-ubit))
1039 (c-call VOID "@cpu@_write_pid_handler" val)
1040 (set (raw-reg h-sr-x (regno pid)) val))))
1041 ((eq index (regno spc))
1042 (if (not (reg BI h-ubit)) (set (raw-reg h-sr-x (regno spc)) val)))
1043 (else (set-quiet (raw-reg SI h-sr-x index) val))))
1048 (attrs MACH-V32 VIRTUAL)
1049 (comment "Support registers")
1050 (type register SI (16))
1051 (values keyword "" (.map (.pmacro (y) ((.str S y) y)) (.iota 16)))
1052 (get (index) (c-call SI "@cpu@_read_supr" index))
1053 (set (index val) (c-call VOID "@cpu@_write_supr" index val))
1056 (define-pmacro (cris-dsh semantic-name name comment attrs type)
1057 "Like dsh, but the semantic-name is separate"
1058 (define-full-hardware
1059 name comment attrs semantic-name type () () () () () ())
1062 ; We define the condition codes that hold arithmetic flags separately
1063 ; and "or" them in, in the get and set methods of the special
1064 ; registers. We define arithmetic flags as any of C V Z N X. They
1065 ; thankfully have that order (zero-based) in all processor versions.
1067 ; To avoid having two variants of most move-type instructions because V32
1068 ; doesn't set C and V (and N and Z), we fake the setting to virtual
1069 ; registers which have two different implementations.
1070 (define-pmacro (cris-move-flag f f-name f-whence)
1071 "Flag set differently in pre-v32 and v32 in some cases"
1073 (dsh (.sym h- f bit) (.str f-name " bit") () (register BI))
1074 (cris-d-hwreg (.sym h- f bit-move) BI)
1076 (semantic-name (.sym h- f bit-move-x))
1077 (name (.sym h- f bit-move-v32))
1078 (comment (.str f-name " bit set in " f-whence " instructions, ignored"))
1079 (attrs MACH-V32 VIRTUAL)
1084 (error (.str "Can't get h-" f "bit-move on CRISv32")) 0))
1087 (semantic-name (.sym h- f bit-move-x))
1088 (name (.sym h- f bit-move-pre-v32))
1091 f-name " bit set in " f-whence " instructions, same as " f "bit"))
1092 (attrs MACH-PRE-V32 VIRTUAL)
1094 (get () (reg (.sym h- f bit)))
1095 (set (val) (set (reg (.sym h- f bit)) val))))
1098 (cris-move-flag c "carry" "move-type")
1099 (cris-move-flag v "overflow" "move-type")
1100 (cris-move-flag z "zero" "moveq")
1101 (cris-move-flag n "sign" "moveq")
1103 (dsh h-xbit "extended-arithmetic bit" () (register BI))
1104 (cris-d-hwreg h-ibit BI)
1105 (cris-dsh h-ibit-x h-ibit-pre-v32
1106 "interrupt-enable bit" (MACH-PRE-V32) (register BI))
1107 (dsh h-pbit "sequence-broken bit" ((MACH crisv10,crisv32)) (register BI))
1108 (dsh h-rbit "carry bit for MCP+restore-p bit" (MACH-V32) (register BI))
1109 (cris-d-hwreg h-ubit BI)
1110 (cris-dsh h-ubit-x h-ubit-pre-v32
1111 "user mode bit" ((MACH crisv10)) (register BI))
1112 (dsh h-gbit "guru mode bit" (MACH-V32) (register BI))
1114 ; When doing a transition from kernel to user mode on V32, we save the
1115 ; stack pointer in an internal register and copy USP to R14, so we don't
1116 ; need non-trivial handlers for general registers.
1119 "Kernel stack pointer during user mode"
1125 (semantic-name h-ubit-x)
1127 (comment "User mode bit")
1134 (if (andif val (not (raw-reg BI h-ubit-x)))
1137 (set (reg SI h-kernel-sp) (raw-reg h-gr-x (regno sp)))
1138 (set (raw-reg h-gr-x (regno sp)) (raw-reg h-sr-x (regno usp)))
1139 (set (raw-reg BI h-ubit-x) val)
1140 (c-call VOID "@cpu@_usermode_enabled")))))
1144 (semantic-name h-ibit-x)
1146 (comment "Interrupt-enable bit")
1153 (if (not (reg BI h-ubit))
1156 (set enabled (andif val (not (raw-reg BI h-ibit-x))))
1157 (set (raw-reg BI h-ibit-x) val)
1158 ; Call handler when enabling.
1159 (if enabled (c-call VOID "@cpu@_interrupts_enabled"))))))
1164 (comment "NMI enable bit")
1171 ; Don't allow clearing (through this handler) when once set.
1172 (if (andif val (andif (not (raw-reg BI h-mbit)) (not (reg BI h-ubit))))
1175 (set (raw-reg BI h-mbit) 1)
1176 ; Call handler when enabling.
1177 (c-call VOID "@cpu@_nmi_enabled")))))
1181 (dsh-cond-bit-v32 x-name x-comment x-cond)
1182 "dsh bit for MACH-V32, with bit only changeable when X-COND"
1188 (set (val) (sequence () (if x-cond (set (raw-reg BI x-name) val)))))
1191 (dsh-protected-bit-v32 x-name x-comment)
1192 "dsh bit for MACH-V32, with bit only changeable in kernel mode"
1193 (dsh-cond-bit-v32 x-name x-comment (not (reg BI h-ubit)))
1195 (dsh-protected-bit-v32 h-qbit "Pending single-step bit")
1199 (comment "Cause single step exception on ... [see CRISv32 ref] bit")
1206 (if (not (reg BI h-ubit))
1209 (set enabled (andif val (not (raw-reg BI h-sbit))))
1210 (set (raw-reg BI h-sbit) val)
1211 ; Call handler when enabling.
1212 (if enabled (c-call VOID "@cpu@_single_step_enabled"))))))
1215 (dnop cbit "" (SEM-ONLY) h-cbit f-nil)
1217 "cbit for pre-V32, nothing for newer" (SEM-ONLY) h-cbit-move f-nil)
1218 (dnop vbit "" (SEM-ONLY) h-vbit f-nil)
1220 "vbit for pre-V32, nothing for newer" (SEM-ONLY) h-vbit-move f-nil)
1221 (dnop zbit "" (SEM-ONLY) h-zbit f-nil)
1223 "zbit for pre-V32, nothing for newer" (SEM-ONLY) h-zbit-move f-nil)
1224 (dnop nbit "" (SEM-ONLY) h-nbit f-nil)
1226 "nbit for pre-V32, nothing for newer" (SEM-ONLY) h-nbit-move f-nil)
1227 (dnop xbit "" (SEM-ONLY) h-xbit f-nil)
1228 (dnop ibit "" (SEM-ONLY) h-ibit f-nil)
1229 (dnop ubit "" (SEM-ONLY (MACH crisv10,crisv32)) h-ubit f-nil)
1230 (dnop pbit "" (SEM-ONLY (MACH crisv10,crisv32)) h-pbit f-nil)
1232 rbit "carry bit for MCP+restore-P flag bit" (SEM-ONLY MACH-V32) h-rbit f-nil)
1233 (dnop sbit "" (SEM-ONLY MACH-V32) h-sbit f-nil)
1234 (dnop mbit "" (SEM-ONLY MACH-V32) h-mbit f-nil)
1235 (dnop qbit "" (SEM-ONLY MACH-V32) h-qbit f-nil)
1237 (cris-d-hwreg h-insn-prefixed-p BI)
1240 h-insn-prefixed-p-pre-v32
1241 "instruction-is-prefixed bit"
1246 ; CRISv32 has no prefixing on memory accesses. CGEN-FIXME: [Once (eq-attr
1247 ; (current-mach) ...) works]: can we change andif and/or orif so it
1248 ; doesn't look too close at short-circuited operands and avoid defining an
1249 ; operand that doesn't apply to a certain mach?
1251 (semantic-name h-insn-prefixed-p-x)
1252 (name h-insn-prefixed-p-v32)
1253 (attrs MACH-V32 VIRTUAL)
1254 (comment "instruction-is-prefixed bit")
1256 (get () (const BI 0))
1261 "Instruction-prefixed flag"
1268 h-prefixreg h-prefixreg-pre-v32
1269 "Prefix-address register" (MACH-PRE-V32) (register SI))
1271 (semantic-name h-prefixreg)
1272 (name h-prefixreg-v32)
1273 (comment "Prefix-address register, redirecting to ACR")
1274 (attrs MACH-V32 VIRTUAL)
1276 ; Why can't we have just a "acr" a.k.a "(reg h-gr 15)" here?
1278 (set (value) (set acr value))
1289 ;;;;;;;;;;;;;;;;;; -ifield
1292 ; +-----------+-----+-----------+-----+-----------+
1293 ; | Operand2 | Mode| Opcode | Size| Operand1 |
1294 ; +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1296 ; Figure 5. General instruction format.
1298 ; Some deviations from this format exist, [see below].
1300 ; Field specifiers in CGEN specify the highest numbered bit followed by
1301 ; the number of bits.
1303 (dnf f-operand1 "Operand1" () 3 4)
1304 (dnf f-size "Size" () 5 2)
1305 (dnf f-opcode "Opcode" () 9 4)
1306 (dnf f-mode "Mode" () 11 2)
1307 (dnf f-operand2 "Operand2" () 15 4)
1309 ; Subfields. FIXME: unfortunately there's some limitation in CGEN so we
1310 ; can't (as would be somewhat intuitive) make f-mode a multi-ifield
1311 ; consisting of these two, concatenated.
1312 (dnf f-memmode "Indirect of autoincrement" () 10 1)
1313 (dnf f-membit "Memory specifier" () 11 1)
1315 (dnf f-b5 "Bit 5 (zero for some quick operands)" () 5 1)
1317 ; When the addressing mode is quick immediate, the low bits are
1318 ; part of the operand.
1319 (dnf f-opcode-hi "Opcode field, high bits" () 9 2)
1321 ; Common synonyms for those fields.
1322 (define-pmacro f-source f-operand1)
1323 (define-pmacro f-dest f-operand2)
1326 f-dstsrc "Dest and source fields concatenated" () UINT
1331 (set tmpval (ifield f-dstsrc))
1332 (set (ifield f-dest) (and (srl tmpval 4) #xf))
1333 (set (ifield f-source) (and tmpval #xf)))
1337 (and (or (ifield f-source) (sll (ifield f-dest) 4)) #xff))
1340 ;The 6-bit value may be sign or zero extended depending on the instruction.
1343 ; +-----------+-----+-----------+-----+-----------+
1344 ; | Operand2 | Mode| Opcode | Immediate value |
1345 ; +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1347 ; Figure 6. Quick immediate addressing mode instruction format.
1349 (dnf f-u6 "Quick immediate unsigned 6-bit" () 5 6)
1350 (df f-s6 "Quick signed 6-bit" () 5 6 INT #f #f)
1352 ; There's also a variant used with shift insns, with one bit larger opcode
1353 ; and one bit smaller immediate value, though it doesn't have a general
1354 ; graphic description.
1355 (dnf f-u5 "Quick unsigned 5-bit" () 4 5)
1357 ; Similarly, a four-bit immediate field.
1358 (dnf f-u4 "Quick unsigned 4-bit" () 3 4)
1360 ; An 8-bit signed value, which doesn't have a general graphic description.
1361 (df f-s8 "Source signed byte" () 7 8 INT #f #f)
1363 ; The 9-bit branch offset, with bit 0 in the field being bit 8 in the
1364 ; offset, and bit 0 in the offset always 0.
1365 (df f-disp9-hi "PC-relative 9-bit offset, sign bit" () 0 1 INT #f #f)
1366 (dnf f-disp9-lo "PC-relative 9-bit offset, low bits" () 7 7)
1368 ; It would work to have this in two mach-specific variants, but
1369 ; considering that current-mach-is-v32 is a compile-time constant, we
1370 ; don't win any simulator performance.
1372 f-disp9 "PC-relative 9-bit offset"
1375 (f-disp9-hi f-disp9-lo)
1379 (set absval (srl (sub (sub SI (ifield f-disp9) pc)
1380 (if SI current-mach-is-v32 0 2)) 1))
1381 (set (ifield f-disp9-hi) (if (lt absval 0) 1 0))
1382 (set (ifield f-disp9-lo) (and absval) #x7f))
1385 ((SI abslo) (SI absval))
1386 (set abslo (sll (ifield f-disp9-lo) 1))
1388 (or (if SI (ne (ifield f-disp9-hi) 0)
1392 (set (ifield f-disp9)
1393 (add SI (add SI pc absval) (if SI current-mach-is-v32 0 2))))
1396 ; The operand of LAPCQ is PC-relative, similar to f-disp9 but unsigned,
1397 ; and only four bits.
1400 "PC-relative 4-bit unsigned offset, counted from start of insn"
1401 (MACH-V32 PCREL-ADDR)
1405 ((value pc) (srl SI (sub SI value pc) 1))
1407 ((value pc) (add SI pc (sll SI value 1)))
1410 ; 8-bit, 16-bit and 32-bit immediates. The 8-bit values are constructed
1411 ; through encoding/decoding functions, since the PC increment is by a
1413 (define-pmacro (dcrisf x-name x-comment x-attrs x-word-offset x-word-length
1414 x-start x-length x-mode x-encode x-decode)
1418 (.splice attrs (.unsplice x-attrs))
1419 (word-offset x-word-offset)
1420 (word-length x-word-length)
1424 (.splice encode (.unsplice x-encode))
1425 (.splice decode (.unsplice x-decode))
1430 f-indir-pc+-byte "[PC+] 8-bit field" (SIGN-OPT)
1432 15 16 ; CGEN-FIXME: Should be 7 8
1437 f-indir-pc+-word "[PC+] 16-bit field" (SIGN-OPT)
1438 16 16 15 16 INT (#f) (#f)
1441 ; CGEN-FIXME: I shouldn't have to use trunc here, should I?
1442 ; Sign-extension should be implicit through use of SI (as opposed to USI)
1443 ; and additionally through SIGN-OPT. The ext isn't actually needed, but
1444 ; having it there rather than implicit makes more sense than to just have
1447 f-indir-pc+-word-pcrel "[PC+] PC-relative 16-bit field"
1448 (PCREL-ADDR SIGN-OPT)
1450 ((value pc) (sub SI value (add SI pc (if SI current-mach-is-v32 0 4))))
1451 ((value pc) (add SI (ext SI (trunc HI value)) (add SI pc (if SI current-mach-is-v32 0 4))))
1455 f-indir-pc+-dword "PC autoincrement - 32-bit field" (SIGN-OPT)
1456 16 32 31 32 INT (#f) (#f)
1460 f-indir-pc+-dword-pcrel
1461 "[PC+] PC-relative 32-bit field, counted from start of insn"
1462 (SIGN-OPT MACH-V32 PCREL-ADDR)
1464 ((value pc) (sub SI value pc))
1465 ((value pc) (add SI pc value))
1468 ;;;;;;;;;;;;;;;;;; -insn-enum -normal-operand -normal-derived-operand
1470 ;; How different fields are transformed into something we put in insns.
1472 ; m := size modifier, byte (00), word (01) or dword (10)
1473 ; z := size modifier, byte (0) or word (1)
1474 ; (For the latter, the "higher" bit is always 0, mapping trivially on m.)
1476 (define-normal-insn-enum
1478 "Standard instruction operand size"
1482 ("BYTE" "WORD" "DWORD" "FIXED")
1485 ; The mode field for insns with "s" operand (perhaps with a partial set of
1487 (define-normal-insn-enum
1489 "Standard instruction addressing modes"
1493 ("QUICK_IMMEDIATE" "REGISTER" "INDIRECT" "AUTOINCREMENT")
1496 (define-normal-insn-enum
1497 insn-memoryness-mode
1498 "Whether the operand is indirect"
1506 (define-normal-insn-enum
1507 insn-memincness-mode
1508 "Whether the indirect operand is autoincrement"
1515 ; Special semantics for multiply.
1516 (define-pmacro MODE_MULU MODE_INDIRECT)
1517 (define-pmacro MODE_MULS MODE_AUTOINCREMENT)
1519 (define-normal-insn-enum
1521 "Signed instruction operand size"
1525 ("UNDEF_SIZE_0" "UNDEF_SIZE_1" "BYTE" "WORD")
1528 (define-normal-insn-enum
1530 "Unsigned instruction operand size"
1534 ("BYTE" "WORD" "UNDEF_SIZE_2" "UNDEF_SIZE_3")
1537 ; Rs := source operand, register addressing mode
1538 (dnop Rs "Source general register" () h-gr f-source)
1540 ; [Rs] := source operand, indirect addressing mode
1541 ; = MODE_INDIRECT Rs
1543 ; [Rs+] := source operand, autoincrement addressing mode (see note!)
1544 ; = MODE_AUTOINCREMENT Rs
1546 ; The union of [Rs] and [Rs(+)]
1549 ; Whether an indirect operand is increment can be obtained as an operand by
1551 (dnop inc "Incrementness of indirect operand" () h-inc f-memmode)
1553 ; or as an affirmative specifier
1557 ; s := source operand, any of the modes Rs, [Rs] or [Rs+]
1558 ; No common operand; each are handled separately, using the above definitions.
1560 ; Ps := source operand, special register
1561 ; It's in the field usually used for the destination.
1562 (dnop Ps "Source special register" () h-sr f-dest)
1564 ; Ss := source operand, support register
1565 ; It's in the field usually used for the destination.
1566 (dnop Ss "Source support register" (MACH-V32) h-supr f-dest)
1568 ; Sd := source operand, support register
1569 (dnop Sd "Destination support register" (MACH-V32) h-supr f-dest)
1571 ; i := 6-bit signed immediate operand
1572 (dnop i "Quick signed 6-bit" () h-sint f-s6)
1574 ; j := 6-bit unsigned immediate operand
1575 (dnop j "Quick unsigned 6-bit" () h-uint f-u6)
1577 ; c := 5-bit immediate shift value
1578 (dnop c "Quick unsigned 5-bit" () h-uint f-u5)
1580 ; qo := 4-bit unsigned immediate operand
1581 (dnop qo "Quick unsigned 4-bit, PC-relative" (MACH-V32) h-addr f-qo)
1583 ; Rd := destination operand, register addressing mode
1584 (dnop Rd "Destination general register" () h-gr f-dest)
1585 (define-pmacro Rd-sfield Rs)
1586 (define-pmacro Rs-dfield Rd)
1588 ; [Rd] := destination operand, indirect addressing mode
1589 ; = MODE_INDIRECT Rd
1591 ; [Rd+] := destination operand, autoincrement addressing mode
1592 ; = MODE_AUTOINCREMENT Rd
1594 ; [PC+] := destination operand PC, autoincrement addressing mode
1595 ; = MODE_AUTOINCREMENT (f-dest 15) X
1596 ; where X is one of sconst8, uconst8, sconst16, uconst16 or const32.
1597 (dnop sconst8 "Signed byte [PC+]" () h-sint f-indir-pc+-byte)
1598 (dnop uconst8 "Unsigned byte [PC+]" () h-uint f-indir-pc+-byte)
1599 (dnop sconst16 "Signed word [PC+]" () h-sint f-indir-pc+-word)
1600 (dnop uconst16 "Unsigned word [PC+]" () h-uint f-indir-pc+-word)
1601 (dnop const32 "Dword [PC+]" () h-uint f-indir-pc+-dword)
1602 (dnop const32-pcrel "Dword [PC+]" () h-addr f-indir-pc+-dword-pcrel)
1604 ; d := destination operand, any of the modes Rd, [Rd] or [Rd+]
1605 ; No common operand; each are handled separately, using the above definitions.
1607 ; Pd := destination operand, special register
1608 (dnop Pd "Destination special register" () h-sr f-dest)
1610 ; o := 8-bit immediate offset value
1611 (dnop o "Signed 8-bit" () h-sint f-s8)
1613 ; The division of operand semantics and insn fields in the CRIS
1614 ; instruction set reference doesn't permit a simple mapping to a
1615 ; simulator description, and the division of insn fields and
1616 ; semantics in CGEN is not between the define-normal-ifield
1617 ; vs. define-normal-operand. For example, the "o" operand is
1618 ; PC-relative for branch insns, as described by the CGEN f-disp9
1620 ; See comment at f-disp9; thankfully the mach
1621 ; attribute works here to have two different definitions by the
1623 (dnop o-pcrel "9-bit signed immediate PC-rel"
1627 (dnop o-word-pcrel "16-bit signed immediate PC-rel"
1629 h-iaddr f-indir-pc+-word-pcrel)
1631 ; cc := condition code
1632 (dnop cc "Condition codes" () h-ccode f-dest)
1634 ; n := 4 bit breakpoint exception vector index
1635 (dnop n "Quick unsigned 4-bit" () h-uint f-u4)
1637 ; The "option" in the SWAP insn.
1638 (dnop swapoption "Swap option" () h-swap f-dest)
1640 (dnop list-of-flags "Flag bits as operand" () h-flagbits f-dstsrc)
1642 ; Enumerations for insn codes, for use in insn definitions
1643 ; instead of raw numbers. See it as operand definitions for the
1646 (define-normal-insn-enum
1648 "Insns for MODE_QUICK_IMMEDIATE"
1652 ("BCC_0" "BCC_1" "BCC_2" "BCC_3"
1653 "BDAP_0" "BDAP_1" "BDAP_2" "BDAP_3"
1654 "ADDQ" "MOVEQ" "SUBQ" "CMPQ"
1655 "ANDQ" "ORQ" "ASHQ" "LSHQ")
1658 (define-normal-insn-enum
1660 "Same as insn-qi-opc, though using only the high two bits of the opcode"
1664 ("BCC" "BDAP" "OTHER2" "OTHER3")
1666 (define-pmacro QHI_ADDOQ QHI_BDAP)
1668 (define-normal-insn-enum
1670 "Insns for MODE_REGISTER and either SIZE_BYTE, SIZE_WORD or SIZE_DWORD"
1674 ("ADDX" "MOVX" "SUBX" "LSL"
1675 "ADDI" "BIAP" "NEG" "BOUND"
1676 "ADD" "MOVE" "SUB" "CMP"
1677 "AND" "OR" "ASR" "LSR")
1679 (define-pmacro R_ADDI_ACR R_BIAP)
1681 (define-normal-insn-enum
1683 "Insns for MODE_REGISTER and SIZE_FIXED"
1687 ("ADDX" "MOVX" "SUBX" "BTST"
1688 "SCC" "ADDC" "SETF" "CLEARF"
1689 "MOVE_R_S" "MOVE_S_R" "ABS" "DSTEP"
1690 "LZ" "SWAP" "XOR" "MSTEP")
1692 (define-pmacro RFIX_MCP RFIX_MSTEP)
1694 (define-normal-insn-enum
1696 "Insns for (MODE_INDIRECT or MODE_AUTOINCREMENT) and either SIZE_BYTE, SIZE_WORD or SIZE_DWORD"
1700 ("ADDX" "MOVX" "SUBX" "CMPX"
1701 "MUL" "BDAP_M" "ADDC" "BOUND"
1702 "ADD" "MOVE_M_R" "SUB" "CMP"
1703 "AND" "OR" "TEST" "MOVE_R_M")
1705 (define-pmacro INDIR_ADDO INDIR_BDAP_M)
1707 (define-normal-insn-enum
1709 "Insns for (MODE_INDIRECT or MODE_AUTOINCREMENT) and SIZE_FIXED"
1713 ("ADDX" "MOVX" "SUBX" "CMPX"
1714 "JUMP_M" "DIP" "JUMP_R" "BCC_M"
1715 "MOVE_M_S" "MOVE_S_M" "BMOD" "BSTORE"
1716 "RBF" "SBFS" "MOVEM_M_R" "MOVEM_R_M")
1719 (define-pmacro INFIX_MOVE_SS INFIX_SBFS)
1720 (define-pmacro INFIX_LAPC INFIX_DIP)
1721 (define-pmacro INFIX_RFE INFIX_JUMP_M)
1722 (define-pmacro INFIX_RFN INFIX_JUMP_M)
1723 (define-pmacro INFIX_HALT INFIX_JUMP_M)
1724 (define-pmacro INFIX_SFE INFIX_JUMP_M)
1725 (define-pmacro INFIX_RFG INFIX_JUMP_M)
1726 (define-pmacro INFIX_JAS_R INFIX_JUMP_R)
1727 (define-pmacro INFIX_JAS_M INFIX_JUMP_R)
1728 (define-pmacro INFIX_JASC INFIX_RBF)
1729 (define-pmacro INFIX_JUMP_P INFIX_BCC_M)
1730 (define-pmacro INFIX_BAS INFIX_BMOD)
1731 (define-pmacro INFIX_BASC INFIX_BSTORE)
1732 (define-pmacro INFIX_BREAK INFIX_JUMP_M)
1733 (define-pmacro INFIX_FIDXI INFIX_JUMP_M)
1734 (define-pmacro INFIX_FIDXD INFIX_BAS)
1735 (define-pmacro INFIX_FTAGI INFIX_JUMP_M)
1736 (define-pmacro INFIX_FTAGD INFIX_BAS)
1739 ; Move-to-register, move-to-memory, move-to/from-other-register,
1740 ; logical, arithmetic, branch.
1741 ; Classes of operands:
1742 ; quick, register, memory-indirect, memory-postinc.
1745 ;;;;;;;;;;;;;;;;;; -normal-insn
1747 (define-pmacro (dni-bwd-attr name comment attr syntax fmt fsem timing)
1749 (dni (.sym name .b) (.str "byte " comment) attr (.str name ".b " syntax)
1750 (.splice (.unsplice fmt) SIZE_BYTE)
1753 (dni (.sym name .w) (.str "word " comment) attr (.str name ".w " syntax)
1754 (.splice (.unsplice fmt) SIZE_WORD)
1757 (dni (.sym name .d) (.str "dword " comment) attr (.str name ".d " syntax)
1758 (.splice (.unsplice fmt) SIZE_DWORD)
1763 (define-pmacro (dni-cdt-attr name comment attr syntax fmt semantics)
1764 "dni without specifying timing"
1765 (dni name comment attr syntax fmt semantics (cris-timing))
1768 (define-pmacro (dni-cdt-bwd-attr name comment attr syntax fmt fsem)
1770 (dni-cdt-attr (.sym name .b-r) (.str "byte " comment) attr (.str name ".b " syntax)
1771 (.splice (.unsplice fmt) SIZE_BYTE)
1773 (dni-cdt-attr (.sym name .w-r) (.str "word " comment) attr (.str name ".w " syntax)
1774 (.splice (.unsplice fmt) SIZE_WORD)
1776 (dni-cdt-attr (.sym name .d-r) (.str "dword " comment) attr (.str name ".d " syntax)
1777 (.splice (.unsplice fmt) SIZE_DWORD)
1781 ; Some convenience macros based on the above ones.
1782 (define-pmacro (dni-cdt-bwd name comment syntax fmt fsem)
1783 (dni-cdt-bwd-attr name comment () syntax fmt fsem)
1786 (define-pmacro (dni-bwd name comment syntax fmt fsem timing)
1787 (dni-bwd-attr comment () syntax fmt fsem timing)
1791 (((dni-cdt name comment syntax fmt semantics)
1792 (dni-cdt-attr name comment () syntax fmt semantics))
1793 ((dni-c-QI-attr name comment attr syntax fmt fsem)
1794 (dni name comment attr syntax fmt fsem (cris-timing-const-QI)))
1795 ((dni-c-HI-attr name comment attr syntax fmt fsem)
1796 (dni name comment attr syntax fmt fsem (cris-timing-const-HI)))
1797 ((dni-c-SI-attr name comment attr syntax fmt fsem)
1798 (dni name comment attr syntax fmt fsem (cris-timing-const-SI))))
1802 (((dni-c-QI name comment syntax fmt fsem)
1803 (dni-c-QI-attr name comment () syntax fmt fsem))
1804 ((dni-c-HI name comment syntax fmt fsem)
1805 (dni-c-HI-attr name comment () syntax fmt fsem))
1806 ((dni-c-SI name comment syntax fmt fsem)
1807 (dni-c-SI-attr name comment () syntax fmt fsem)))
1810 ; These flags are both cleared by all insns except prefixes (before
1811 ; CRISv32) and "setf x", so we put them in a handy macro.
1820 ; NOP | 0 0 0 0| 0 1| 0 1 0 0| 0 0| 1 1 1 1|
1821 ; (For V32, "SETF" (no flags) is used.)
1823 nop "nop" (MACH-PC) "nop"
1824 (+ (f-operand2 0) R_ADDI MODE_REGISTER SIZE_BYTE (f-operand1 15))
1828 ; Pre- and v32+ variants MOVE insns set flags differently. These two
1829 ; macros for flag settings are meant to be used in all MOVE insns.
1830 (define-pmacro (setf-moveq value)
1833 (set-quiet nbit-move (lt SI value 0))
1834 (set-quiet zbit-move (andif BI (eq SI value 0) (if BI xbit zbit 1)))
1835 (set-quiet cbit-move 0)
1836 (set-quiet vbit-move 0)
1840 (define-pmacro (setf-move size value)
1843 (set nbit (lt size value 0))
1844 (set zbit (andif BI (eq size value 0) (if BI xbit zbit 1)))
1845 (set-quiet cbit-move 0)
1846 (set-quiet vbit-move 0)
1849 ; The CGEN binop-with-bit operations are not documented well enough that I
1850 ; trust their semantics to remain stable. Better define local ones: the
1851 ; semantics become explicit.
1853 (((add-overflow size R D S carry)
1854 (orif BI (andif BI (andif BI (lt size S 0) (lt size D 0)) (ge size R 0))
1855 (andif BI (andif BI (ge size S 0) (ge size D 0)) (lt size R 0))))
1856 ((add-carry size R D S carry)
1857 (orif BI (andif BI (lt size S 0) (lt size D 0))
1858 (orif BI (andif BI (lt size D 0) (ge size R 0))
1859 (andif BI (lt size S 0) (ge size R 0)))))
1860 ((sub-overflow size R D S carry)
1861 (orif BI (andif BI (andif BI (ge size S 0) (lt size D 0)) (ge size R 0))
1862 (andif BI (andif BI (lt size S 0) (ge size D 0)) (lt size R 0))))
1863 ((sub-carry size R D S carry)
1864 (orif BI (andif BI (lt size S 0) (ge size D 0))
1865 (orif BI (andif BI (ge size D 0) (lt size R 0))
1866 (andif BI (lt size S 0) (lt size R 0)))))
1867 ; Only valid for size := DI
1868 ((mulu-overflow size R D S carry)
1869 (ne DI R (zext DI (trunc SI R))))
1870 ((mulu-carry size R D S carry)
1871 (andif current-mach-is-v32 carry))
1872 ((muls-overflow size R D S carry)
1873 (ne DI R (ext DI (trunc SI R))))
1874 ((muls-carry size R D S carry)
1875 (andif current-mach-is-v32 carry)))
1878 (define-pmacro (setf-arit2 size op source1 source2 result carryin carryout)
1879 "Set no-prefix, x=0, carryout, v, z and n according to operation OP in size SIZE"
1882 (set carryout ((.sym op -carry) size result source1 source2 carryin))
1883 (set nbit (lt size result 0))
1884 (set zbit (andif BI (eq size result 0) (orif BI zbit (not BI xbit))))
1885 (set vbit ((.sym op -overflow) size result source1 source2 carryin))
1888 (define-pmacro (setf-arit size op source1 source2 result carry)
1889 "Set no-prefix, x=0, c, v, z and n according to operation OP in size SIZE"
1890 (setf-arit2 size op source1 source2 result carry cbit)
1893 ; Let's have convienence macros for arithmetic, including evaluation of the
1894 ; operation, destination modification, flag setting and carry propagation.
1896 (cris-arit6-int arit size fdest fdest_op srcop1 srcop2 carryout carryin)
1897 "Core for performing some three-operand arithmetic with carry as parameter"
1899 ((size tmpopd) (size tmpops) (BI carry) (size newval))
1903 (set newval ((.sym arit c) tmpopd tmpops (if BI (eq xbit 0) 0 carry)))
1904 (fdest size fdest_op newval)
1905 (setf-arit2 size arit tmpopd tmpops newval carry carryout))
1909 (cris-arit5-int arit size destregno srcop1 srcop2 carryout carryin)
1910 "As cris-arit6-int, but to set a part of a general register"
1914 (.pmacro (sz regno val) (set-subreg-gr sz regno val))
1922 (define-pmacro (cris-arit5 arit size destreg srcop1 srcop2 carryout carryin)
1923 "As cris-arit5-int, but takes a register as parameter, not register number"
1924 (cris-arit5-int arit size (regno destreg) srcop1 srcop2 carryout carryin)
1926 (define-pmacro (cris-arit3-int arit size destregno srcop1 srcop2)
1927 "As cris-arit5-int, but with carry-in same as carry-out"
1928 (cris-arit5-int arit size destregno srcop1 srcop2 cbit cbit)
1930 (define-pmacro (cris-arit3 arit size destreg srcop1 srcop2)
1931 "As cris-arit3-int, but takes a register as parameter, not register number"
1932 (cris-arit3-int arit size (regno destreg) srcop1 srcop2)
1934 (define-pmacro (cris-arit arit size destreg srcop)
1935 "As cris-arit3, but with destination same as srcop1"
1936 (cris-arit3 arit size destreg destreg srcop)
1938 (define-pmacro (cris-arit-3op arit size destsrcop2 srcop1 dest-3op)
1939 "Similar to cris-arit3-int, but for prefixed operand only"
1940 (cris-arit3-int arit size
1941 (if SI (andif prefix-set (not inc))
1947 ; Convenience macros to select a part of a value and its complement, for
1948 ; the <op>.b, <op>.w and <op>.d operations.
1949 (define-pmacro (QI-part val) (and SI val #xff))
1950 (define-pmacro (non-QI-part val) (and SI val #xffffff00))
1951 (define-pmacro (HI-part val) (and SI val #xffff))
1952 (define-pmacro (non-HI-part val) (and SI val #xffff0000))
1953 (define-pmacro (SI-part val) val)
1954 (define-pmacro (non-SI-part val) 0)
1956 (set-subreg-gr-bw BWD gregno newval)
1957 "Set a byte or word part or full dword of a general register"
1960 (set oldregval (reg h-raw-gr gregno))
1961 (set (reg h-gr gregno)
1962 (or SI ((.sym BWD -part) newval) ((.sym non- BWD -part) oldregval))))
1964 (define-pmacro (set-subreg-gr BWD gregno newval)
1965 ((.sym set-subreg-gr- BWD) BWD gregno newval)
1967 (define-pmacro (set-subreg-gr-SI SI gregno newval)
1968 (set (reg h-gr gregno) newval)
1970 (define-pmacro set-subreg-gr-HI set-subreg-gr-bw)
1971 (define-pmacro set-subreg-gr-QI set-subreg-gr-bw)
1973 ; MOVE.m Rs,Rd [ Rd | 011001mm | Rs ]
1976 "move.m ${Rs},${Rd}"
1977 (+ Rd MODE_REGISTER R_MOVE Rs)
1983 (set-subreg-gr BWD (regno Rd) newval)
1984 (setf-move BWD newval)))
1987 ; MOVE.D PC,Rd [ Rd | 01100110 | 1111 ]
1988 ; This insn is used in PIC code to find out the code address. It's an
1989 ; exception to the (guarded) non-implementation of PC operands in this
1992 movepcr "move.d PC,R"
1993 (MACH-PC UNCOND-CTI)
1995 (+ Rd MODE_REGISTER R_MOVE SIZE_DWORD (f-source 15))
1998 (set pcval (add SI pc 2))
2000 (setf-move SI pcval))
2003 ; MOVEQ i,Rd [ Rd | 001001 | i ]
2007 (+ Rd MODE_QUICK_IMMEDIATE Q_MOVEQ i)
2012 (setf-moveq newval))
2015 (define-pmacro (dni-cdt-sbw name comment syntax fmt fsem)
2016 "Insn generator for insns with signed <op>.b and <op>.w variants"
2019 (.sym name .b-r) (.str "byte " comment) (.str name ".b " syntax)
2020 (.splice (.unsplice fmt) SIGNED_BYTE)
2023 (.sym name .w-r) (.str "word " comment) (.str name ".w " syntax)
2024 (.splice (.unsplice fmt) SIGNED_WORD)
2028 ; MOVS.z Rs,Rd [ Rd | 0100011z | Rs ]
2031 "movs.m ${Rs},${Rd}"
2032 (+ Rd MODE_REGISTER R_MOVX Rs)
2038 (set Rd (ext SI newval))
2039 (setf-move SI newval)))
2042 (define-pmacro (dni-cdt-ubw name comment syntax fmt fsem)
2043 "Similar to dni-cdt-sbw but for unsigned operations"
2046 (.sym name .b-r) (.str "byte " comment) (.str name ".b " syntax)
2047 (.splice (.unsplice fmt) UNSIGNED_BYTE)
2050 (.sym name .w-r) (.str "word " comment) (.str name ".w " syntax)
2051 (.splice (.unsplice fmt) UNSIGNED_WORD)
2055 ; MOVU.z Rs,Rd [ Rd | 0100010z | Rs ]
2058 "movu.m ${Rs},${Rd}"
2059 (+ Rd MODE_REGISTER R_MOVX Rs)
2065 (set Rd (zext SI newval))
2066 (setf-move SI newval)))
2069 ; (MOVE.m [PC+],Rd [ Rd | 111001mm | 1111 ])
2070 ; For the moment, it doesn't seem worthwhile to make a dni-c-bwd macro;
2071 ; too many places to parametrize.
2073 movecbr "move.b [PC+],R"
2074 "move.b ${sconst8},${Rd}"
2075 (+ Rd MODE_AUTOINCREMENT INDIR_MOVE_M_R SIZE_BYTE (f-source 15) sconst8)
2078 (set newval sconst8)
2079 (set-subreg-gr QI (regno Rd) newval)
2080 (setf-move QI newval))
2084 movecwr "move.w [PC+],R"
2085 "move.w ${sconst16},${Rd}"
2086 (+ Rd MODE_AUTOINCREMENT INDIR_MOVE_M_R SIZE_WORD (f-source 15) sconst16)
2089 (set newval sconst16)
2090 (set-subreg-gr HI (regno Rd) newval)
2091 (setf-move HI newval))
2095 movecdr "move.d [PC+],R"
2096 "move.d ${const32},${Rd}"
2097 (+ Rd MODE_AUTOINCREMENT INDIR_MOVE_M_R SIZE_DWORD (f-source 15) const32)
2100 (set newval const32)
2102 (setf-move SI newval))
2105 ; (MOVS.z [PC+],Rd [ Rd | 1100011z | 1111 ])
2106 ; Similarly, no likely net improvement for a dni-c-bw.
2108 movscbr "movs.b [PC+],R"
2109 "movs.b ${sconst8},${Rd}"
2110 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX SIGNED_BYTE (f-source 15) sconst8)
2113 ; FIXME: Make trunc unnecessary.
2114 (set newval (ext SI (trunc QI sconst8)))
2116 (setf-move SI newval))
2120 movscwr "movs.w [PC+],R"
2121 "movs.w ${sconst16},${Rd}"
2122 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX SIGNED_WORD (f-source 15) sconst16)
2125 ; FIXME: Make trunc unnecessary.
2126 (set newval (ext SI (trunc HI sconst16)))
2128 (setf-move SI newval))
2131 ; (MOVU.z [PC+],Rd [ Rd | 1100010z | 1111 ])
2133 movucbr "movu.b [PC+],R"
2134 "movu.b ${uconst8},${Rd}"
2135 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX UNSIGNED_BYTE (f-source 15) uconst8)
2138 ; FIXME: Make trunc unnecessary.
2139 (set newval (zext SI (trunc QI uconst8)))
2141 (setf-move SI newval))
2145 movucwr "movu.w [PC+],R"
2146 "movu.w ${uconst16},${Rd}"
2147 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX UNSIGNED_WORD (f-source 15) uconst16)
2150 ; FIXME: Make trunc unnecessary.
2151 (set newval (zext SI (trunc HI uconst16)))
2153 (setf-move SI newval))
2156 ; ADDQ j,Rd [ Rd | 001000 | j ]
2160 (+ Rd MODE_QUICK_IMMEDIATE Q_ADDQ j)
2161 (cris-arit add SI Rd j)
2164 ; SUBQ j,Rd [ Rd | 001010| j ]
2168 (+ Rd MODE_QUICK_IMMEDIATE Q_SUBQ j)
2169 (cris-arit sub SI Rd j)
2172 ; Convenience macros for insns with a memory operand.
2174 (dni-cmt-attr-tim name comment attr syntax fmt semantics timing)
2175 "dni with memory-access"
2176 (dni name comment attr syntax
2177 ; Specifying MODE_INDIRECT and MODE_AUTOINCREMENT in this
2178 ; manner makes the autoincrementness handily available.
2179 ; It also effectively excludes non-memory use of dni-cmt.
2180 (.splice (.unsplice fmt) MODEMEMP_YES inc)
2185 (define-pmacro (dni-cmt-attr name comment attr syntax fmt semantics)
2186 "dni with read memory-access timing"
2187 (dni-cmt-attr-tim name comment attr syntax fmt semantics
2191 (define-pmacro (dni-cmwt-attr name comment attr syntax fmt semantics)
2192 "dni with write memory-access timing"
2193 (dni-cmt-attr-tim name comment attr syntax fmt semantics
2194 (cris-mem-write-timing))
2197 (define-pmacro QI-size 1)
2198 (define-pmacro HI-size 2)
2199 (define-pmacro SI-size 4)
2201 (define-pmacro (cris-get-mem size regop)
2202 "Handle reading memory in <size>, with source address register\
2203 (read once, maybe set once) in <regop> or prefixed"
2206 ((SI addr) (size tmp-mem) (BI postinc))
2208 ; Cache the incrementness of the operand.
2211 ; Get the address from somewhere.
2213 (if SI (eq prefix-set 0)
2214 ; If the insn was prefixed, it's in the prefix-register.
2218 ; Get the memory contents.
2219 (set tmp-mem (mem size addr))
2221 ; For non-prefixed post-increment, we increment the address by the
2222 ; size of the memory access.
2226 (if (eq prefix-set 0)
2227 (set addr (add addr (.sym size -size))))
2228 ; Update the source-register for post-increments.
2231 ; Don't forget the return-value.
2235 (define-pmacro (cris-set-mem size regop value)
2236 "Handle writing <value> of <size> to memory, with memory address register\
2237 (read once, maybe set once) in <regop> or prefixed."
2239 ((SI addr) (BI postinc))
2241 ; Cache the incrementness of the operand.
2244 ; Get the address from somewhere.
2246 (if SI (eq prefix-set 0)
2247 ; If the insn was prefixed, it's in the prefix-register.
2251 ; Set the memory contents. Integral-write semantics apply.
2252 ; FIXME: currently v32 only; when proper semantics needed, fix v10.
2253 (if (andif current-mach-is-v32 (ne xbit 0))
2257 (set (mem size addr) value)
2258 ; Write failures are signalled (by whatever entity "sends
2259 ; the signal") by setting P at time of the write above, if X
2260 ; is set. Here, we just need to copy P into C.
2263 (set (mem size addr) value))
2265 ; For non-prefixed post-increment, we increment the address by the
2266 ; size of the memory access. As for the integral-write, this needs to
2267 ; be tweaked for pre-v32: increment should have been performed if
2268 ; there's a fault at the memory access above.
2272 (if (eq prefix-set 0)
2273 (set addr (add addr (.sym size -size))))
2274 ; Update the source-register for post-increments.
2279 (dni-cmt-bwd-attr-tim name comment attr syntax fmt fsem timing)
2280 "Core generator macro for insns with <op>.b, <op>.w and <op>.d variants\
2281 and a memory operand."
2285 (.str "byte mem " comment)
2287 (.str name ".b " syntax)
2288 (.splice (.unsplice fmt) SIZE_BYTE)
2293 (.str "word mem " comment)
2295 (.str name ".w " syntax)
2296 (.splice (.unsplice fmt) SIZE_WORD)
2301 (.str "dword mem " comment)
2303 (.str name ".d " syntax)
2304 (.splice (.unsplice fmt) SIZE_DWORD)
2309 ; Further refinement macros.
2310 (define-pmacro (dni-cmt-bwd-attr name comment attr syntax fmt fsem)
2311 (dni-cmt-bwd-attr-tim name comment attr syntax fmt fsem
2315 (define-pmacro (dni-cmwt-bwd name comment syntax fmt fsem)
2316 (dni-cmt-bwd-attr-tim name comment () syntax fmt fsem
2317 (cris-mem-write-timing))
2320 (define-pmacro (dni-cmt-bwd name comment syntax fmt fsem)
2321 (dni-cmt-bwd-attr name comment () syntax fmt fsem)
2324 (define-pmacro (dni-cmt-sbw name comment syntax fmt fsem)
2325 "Core generator macro for insns with <op>.b and <op>.w variants\
2326 and a signed memory operand."
2329 (.sym name .b-m) (.str "byte mem " comment)
2331 (.str name ".b " syntax)
2332 (.splice (.unsplice fmt) SIGNED_BYTE)
2335 (.sym name .w-m) (.str "word mem " comment)
2337 (.str name ".w " syntax)
2338 (.splice (.unsplice fmt) SIGNED_WORD)
2342 (define-pmacro (dni-cmt-ubw name comment syntax fmt fsem)
2343 "Core generator macro for insns with <op>.b and <op>.w variants\
2344 and an unsigned memory operand."
2347 (.sym name .b-m) (.str "byte mem " comment)
2349 (.str name ".b " syntax)
2350 (.splice (.unsplice fmt) UNSIGNED_BYTE)
2353 (.sym name .w-m) (.str "word mem " comment)
2355 (.str name ".w " syntax)
2356 (.splice (.unsplice fmt) UNSIGNED_WORD)
2360 ; CMP.m Rs,Rd [ Rd | 011011mm | Rs ]
2362 cmp-r "compare register to register"
2364 (+ Rd MODE_REGISTER R_CMP Rs)
2368 sub BWD (.pmacro (sz regno val) (nop)) 0
2372 ; CMP.m [Rs],Rd [ Rd | 101011mm | Rs ]
2373 ; CMP.m [Rs+],Rd [ Rd | 111011mm | Rs ]
2375 cmp-m "compare memory to register"
2376 "[${Rs}${inc}],${Rd}"
2381 sub BWD (.pmacro (sz regno val) (nop)) 0
2382 Rd (cris-get-mem BWD Rs) cbit cbit))
2385 ; (CMP.m [PC+],Rd [ Rd | 111011mm | 1111 ])
2387 cmpcbr "cmp constant byte to register"
2388 "cmp.b $sconst8,$Rd"
2389 (+ Rd MODE_AUTOINCREMENT INDIR_CMP SIZE_BYTE (f-source 15) sconst8)
2391 sub QI (.pmacro (sz regno val) (nop)) 0
2392 Rd (trunc QI sconst8) cbit cbit)
2396 cmpcwr "cmp constant word to register"
2397 "cmp.w $sconst16,$Rd"
2398 (+ Rd MODE_AUTOINCREMENT INDIR_CMP SIZE_WORD (f-source 15) sconst16)
2400 sub HI (.pmacro (sz regno val) (nop)) 0
2401 Rd (trunc HI sconst16) cbit cbit)
2405 cmpcdr "cmp constant dword to register"
2406 "cmp.d $const32,$Rd"
2407 (+ Rd MODE_AUTOINCREMENT INDIR_CMP SIZE_DWORD (f-source 15) const32)
2409 sub SI (.pmacro (sz regno val) (nop)) 0
2410 Rd const32 cbit cbit)
2413 ; CMPQ i,Rd [ Rd | 001011 | i ]
2417 (+ Rd MODE_QUICK_IMMEDIATE Q_CMPQ i)
2419 sub SI (.pmacro (sz regno val) (nop)) 0
2423 ; CMPS.z [Rs],Rd [ Rd | 1000111z | Rs ]
2424 ; CMPS.z [Rs+],Rd [ Rd | 1100111z | Rs ]
2426 cmps-m "cmp sign-extended from memory to register"
2428 (+ Rd INDIR_CMPX Rs)
2432 sub SI (.pmacro (sz regno val) (nop)) 0
2433 Rd ((.sym BW -ext) (cris-get-mem BW Rs)) cbit cbit))
2436 ; (CMPS.z [PC+],Rd [ Rd | 1100111z | 1111 ])
2438 cmpscbr "cmp sign-extended constant byte to register"
2440 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX SIGNED_BYTE (f-source 15) sconst8)
2442 sub SI (.pmacro (sz regno val) (nop)) 0
2443 Rd (ext SI (trunc QI sconst8)) cbit cbit)
2446 cmpscwr "cmp sign-extended constant word to register"
2448 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX SIGNED_WORD (f-source 15) sconst16)
2450 sub SI (.pmacro (sz regno val) (nop)) 0
2451 Rd (ext SI (trunc HI sconst16)) cbit cbit)
2454 ; CMPU.z [Rs],Rd [ Rd | 1000110z | Rs ]
2455 ; CMPU.z [Rs+],Rd [ Rd | 1100110z | Rs ]
2457 cmpu-m "cmp zero-extended from memory to register"
2459 (+ Rd INDIR_CMPX Rs)
2463 sub SI (.pmacro (sz regno val) (nop)) 0
2464 Rd ((.sym BW -zext) (cris-get-mem BW Rs)) cbit cbit))
2467 ; (CMPU.z [PC+],Rd [ Rd | 1100110z | 1111 ])
2469 cmpucbr "cmp zero-extended constant byte to register"
2471 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX UNSIGNED_BYTE (f-source 15) uconst8)
2473 sub SI (.pmacro (sz regno val) (nop)) 0
2474 Rd (zext SI (trunc QI uconst8)) cbit cbit)
2477 cmpucwr "cmp zero-extended constant word to register"
2479 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX UNSIGNED_WORD (f-source 15) uconst16)
2481 sub SI (.pmacro (sz regno val) (nop)) 0
2482 Rd (zext SI (trunc HI uconst16)) cbit cbit)
2485 ; MOVE.m [Rs],Rd [ Rd | 101001mm | Rs ]
2486 ; MOVE.m [Rs+],Rd [ Rd | 111001mm | Rs ]
2488 move-m "move from memory to register"
2489 "[${Rs}${inc}],${Rd}"
2490 (+ INDIR_MOVE_M_R Rs Rd)
2495 (set tmp (cris-get-mem BWD Rs))
2498 (if SI (andif prefix-set (not inc)) (regno Rs) (regno Rd))
2500 (setf-move BWD tmp)))
2503 ; MOVS.z [Rs],Rd [ Rd | 1000011z | Rs ]
2504 ; MOVS.z [Rs+],Rd [ Rd | 1100011z | Rs ]
2506 movs-m "movs from memory to register"
2507 "[${Rs}${inc}],${Rd}"
2508 (+ INDIR_MOVX Rs Rd)
2513 (set tmp (ext SI (cris-get-mem BW Rs)))
2514 (if (andif prefix-set (not inc))
2517 (setf-move SI tmp)))
2520 ; MOVU.z [Rs],Rd [ Rd | 1000010z | Rs ]
2521 ; MOVU.z [Rs+],Rd [ Rd | 1100010z | Rs ]
2523 movu-m "movu from memory to register"
2524 "[${Rs}${inc}],${Rd}"
2525 (+ INDIR_MOVX Rs Rd)
2530 (set tmp (zext SI (cris-get-mem BW Rs)))
2531 (if (andif prefix-set (not inc))
2534 (setf-move SI tmp)))
2537 ; MOVE Rs,Pd [ Pd | 01100011 | Rs ]
2545 (.sym move-r-spr VER)
2546 "Move from general register to special register"
2547 ((MACH (.sym cris VER)))
2549 (+ RFIX_MOVE_R_S MODE_REGISTER SIZE_FIXED Rs Pd)
2553 (set rno (regno Pd))
2555 ; See reg-sr setter for most of the special-register semantics.
2556 ; The sanity check for known read-only registers is for program
2557 ; debug help; the real insn would be harmless and have no effect.
2558 ; CGEN-FIXME: regno of symbolic h-sr names doesn't work here.
2559 ((orif (orif (eq rno 0) (eq rno 1)) (orif (eq rno 4) (eq rno 8)))
2560 (error "move-r-spr: trying to set a read-only special register"))
2561 (else (set Pd tmp)))
2563 (cris-reg-sr-timing)))
2567 (define-pmacro (dni-cdt-ver-attr name comment fattr syntax fmt fsem)
2568 "Generator for each MACH, using default timing."
2573 (.pmacro (v) (dni-cdt-attr name comment (fattr v) syntax fmt (fsem v)))
2574 (cris-cpu-models))))
2577 ; MOVE Ps,Rd [ Ps | 01100111 | Rd ]
2578 ; Note that in the insn format, the Rd operand is in the Rs field (the
2579 ; Rd field by the definition used everywhere else is the Ps position in
2581 ; It gets a little weird here because we can't get this insn into a
2582 ; define-pmacro unless we make named pmacros for e.g. a separate attr
2583 ; function and a semantics function: a .pmacro can't refer to the
2584 ; parameters of the outer define-pmacro. (The manual refers to this as
2585 ; not implementing "lexical scoping").
2593 (.sym move-spr-r VER)
2594 "Move from special register to general register"
2595 ((MACH (.sym cris VER)))
2596 "move ${Ps},${Rd-sfield}"
2597 (+ Ps RFIX_MOVE_S_R MODE_REGISTER SIZE_FIXED Rd-sfield)
2599 ((SI grno) (SI prno) (SI newval))
2600 (set prno (regno Ps))
2601 ; CGEN-FIXME: Can't use the following and then "grno" below because
2602 ; CGEN will emit a "tmp_grno" *also* in decodev32.c:crisv32f_decode
2603 ; (set grno (regno Rd-sfield))
2611 ((eq prno (.cadr2 r))
2612 (set-subreg-gr (.car2 r) (regno Rd-sfield) newval)))
2613 ((.sym cris-implemented-readable-specregs- VER))))
2614 (else (error "move-spr-r from unimplemented register")))
2619 ; MOVE Ps,PC [ Ps | 01100111 | 1111 ]
2620 ; The move-special-register-to-pc insns are return-type instructions and
2621 ; have to be special-cased to get the delay-slot and avoid being indicated
2628 (+ Ps MODE_REGISTER RFIX_MOVE_S_R SIZE_FIXED (f-source 15))
2633 (delay 1 (set pc retaddr)))
2636 ; MOVE [Rs],Pd [ Pd | 10100011 | Rs ]
2637 ; MOVE [Rs+],Pd [ Pd | 11100011 | Rs ]
2638 ; We make variants that loads constants or memory for each MACH version,
2639 ; since each consider some subset of the "special registers" to have
2640 ; different sizes. FIXME: Should be able to simplify this.
2648 (.sym move-m-spr VER)
2649 "Move from memory to special register"
2650 ((MACH (.sym cris VER)))
2651 "move [${Rs}${inc}],${Pd}"
2652 (+ Pd INFIX_MOVE_M_S MODEMEMP_YES inc SIZE_FIXED Rs)
2654 ((SI rno) (SI newval))
2655 (set rno (regno Pd))
2658 ; No sanity check for constant special register here, since the
2659 ; memory read side-effect or post-increment may be the goal, or
2660 ; for pre-v32 a prefix assignment side-effect.
2665 ((eq rno (.cadr2 r))
2666 (set newval ((.sym (.car2 r) -ext) (cris-get-mem (.car2 r) Rs)))))
2667 ((.sym cris-implemented-writable-specregs- VER))))
2668 (else (error "Trying to set unimplemented special register")))
2671 (cris-mem-sr-timing)))
2675 (define-pmacro QI-operand sconst8)
2676 (define-pmacro HI-operand sconst16)
2677 (define-pmacro SI-operand const32)
2680 (cris-move-c-spr VER VERFN)
2681 "Generator for loading constant into special register"
2689 (.sym move-c-spr v -p (.cadr2 srdef))
2690 (.str "Move constant to special register p" (.cadr2 srdef))
2691 ((MACH (.sym cris v)))
2692 (.str "move ${" (.sym (.car2 srdef) -operand) "},${Pd}")
2693 ; We use Pd in semantics without naming it in the format (which
2694 ; would CGEN-FIXME: cause a CGEN error for some reason, likely
2695 ; related to specifying an insn field multiple times). This
2696 ; currently works and is guarded with test-cases (specifically
2697 ; wrt. the timing model) but may need to be tweaked in the future.
2698 ; Note that using instead (ifield f-dest) causes incorrect timing
2699 ; model to be generated; the timing model requires that Pd is set.
2700 (+ (f-dest (.cadr2 srdef)) MODE_AUTOINCREMENT INFIX_MOVE_M_S SIZE_FIXED
2701 (f-source 15) (.sym (.car2 srdef) -operand))
2704 (set Pd (.sym (.car2 srdef) -operand)) ; (reg h-sr (.cadr2 srdef))
2706 ((.sym cris-timing-const-sr- (.car2 srdef)))))
2707 ((.sym cris-implemented-specregs-const- VER))
2708 (.map VERFN ((.sym cris-implemented-specregs-const- VER))))))
2712 ; Unfortunately we can't iterate over the list of models due to the
2713 ; problem with referring to the parameters of a surrounding pmacro from
2714 ; within an enclosed .pmacro (perhaps related to "lexical scoping").
2715 ; We get e.g. 'insn already defined:: (move-c-sprvn-p0)' with this:
2717 ; begin (.unsplice (.map (.pmacro (vn) (cris-move-c-spr vn (.pmacro (x) vn)))
2718 ; (cris-cpu-models)))
2720 (cris-move-c-spr v0 (.pmacro (x) v0))
2721 (cris-move-c-spr v3 (.pmacro (x) v3))
2722 (cris-move-c-spr v8 (.pmacro (x) v8))
2723 (cris-move-c-spr v10 (.pmacro (x) v10))
2724 (cris-move-c-spr v32 (.pmacro (x) v32))
2726 ; MOVE Ps,[Rd] [ Ps | 10100111 | Rd ]
2727 ; MOVE Ps,[Rd+] [ Ps | 11100111 | Rd ]
2735 (.sym move-spr-m VER)
2736 "Move from special register to memory"
2737 ((MACH (.sym cris VER)))
2738 "move ${Ps},[${Rd-sfield}${inc}]"
2739 (+ INFIX_MOVE_S_M SIZE_FIXED Rd-sfield Ps)
2742 (set rno (regno Ps))
2749 ((eq rno (.cadr2 r))
2750 (cris-set-mem (.car2 r) Rd-sfield Ps)))
2751 ((.sym cris-implemented-readable-specregs- VER))))
2752 (else (error "write from unimplemented special register")))
2758 ; Instruction format: |0 0 1 1 1 m 1 1 0 1 1 1| Dest. |
2763 "sbfs [${Rd-sfield}${inc}]"
2764 (+ (f-dest 3) INFIX_SBFS SIZE_FIXED MODEMEMP_YES inc Rd-sfield)
2765 (error "SBFS isn't implemented")
2768 ; MOVE Ss,Rd [ Ss | 11110111 | Rd ]
2771 "move from support register to general register"
2773 "move ${Ss},${Rd-sfield}"
2774 (+ Ss INFIX_MOVE_SS SIZE_FIXED (f-mode 3) Rd-sfield)
2781 ; MOVE Rs,Sd [ Sd | 10110111 | Rs ]
2784 "move from general register to support register"
2787 (+ Sd INFIX_MOVE_SS SIZE_FIXED (f-mode 2) Rs)
2794 ; MOVEM Rs,[Rd] [ Rs | 10111111 | Rd ]
2795 ; MOVEM Rs,[Rd+] [ Rs | 11111111 | Rd ]
2797 (define-pmacro (movem-to-mem-step regn)
2798 ; Without the SI attribute, UINT is generated, which isn't supported by
2799 ; the sim framework.
2800 (if (ge SI (regno Rs-dfield) regn)
2803 (set tmp (reg h-gr regn))
2804 (set (mem SI addr) tmp)
2805 (set addr (add addr 4))))
2812 "movem ${Rs-dfield},[${Rd-sfield}${inc}]"
2813 (+ INFIX_MOVEM_R_M MODEMEMP_YES inc SIZE_FIXED Rs-dfield Rd-sfield)
2815 ((SI addr) (BI postinc))
2816 ; FIXME: A copy of what's in cris-get-mem.
2818 ; Cache the incrementness of the operand.
2821 ; CGEN-FIXME: Kludge to work around a CGEN bug: it doesn't see that
2822 ; Rs-dfield is used as an input, causing the timing model to be wrong.
2823 (sequence ((SI dummy)) (set dummy Rs-dfield))
2825 ; Get the address from somewhere. If the insn was prefixed, it's in
2826 ; the prefix-register.
2828 (if SI (eq prefix-set 0)
2834 (.unsplice (.map movem-to-mem-step (.iota 16 15 -1))))
2836 ; Update the source-register for post-increments.
2839 (if SI (eq prefix-set 0) addr prefixreg)))
2841 (simplecris-movem-timing)
2848 "movem ${Rs-dfield},[${Rd-sfield}${inc}]"
2849 (+ INFIX_MOVEM_R_M MODEMEMP_YES inc SIZE_FIXED Rs-dfield Rd-sfield)
2851 ((SI addr) (BI postinc))
2852 ; FIXME: Mostly a copy of what's in cris-get-mem.
2854 ; Cache the incrementness of the operand.
2857 ; CGEN-FIXME: See movem-r-m.
2858 (sequence ((SI dummy)) (set dummy Rs-dfield))
2860 (set addr Rd-sfield)
2864 (.unsplice (.map movem-to-mem-step (.iota 16))))
2866 ; Update the source-register for post-increments.
2868 (set Rd-sfield addr))
2870 ; Unit u-mem must be specified before the u-movem-* for memory address
2871 ; register stall count to be right.
2872 ((crisv32 (unit u-mem) (unit u-movem-rtom) (unit u-exec-movem)
2876 ; MOVEM [Rs],Rd [ Rd | 10111011 | Rs ]
2877 ; MOVEM [Rs+],Rd [ Rd | 11111011 | Rs ]
2880 (movem-to-reg-step regn)
2881 ; Without the SI attribute, UINT is generated, which isn't supported by
2882 ; the sim framework.
2883 (if (ge SI (regno Rd) regn)
2886 (set tmp (mem SI addr))
2887 (set (reg h-gr regn) tmp)
2888 (set addr (add addr 4))))
2895 "movem [${Rs}${inc}],${Rd}"
2896 (+ Rd INFIX_MOVEM_M_R MODEMEMP_YES inc SIZE_FIXED Rs)
2898 ((SI addr) (BI postinc))
2899 ; FIXME: Mostly a copy of what's in cris-get-mem.
2901 ; Cache the incrementness of the operand.
2904 ; Get the address from somewhere. If the insn was prefixed, it's in
2905 ; the prefix-register.
2907 (if SI (eq prefix-set 0)
2911 ; CGEN-FIXME: See movem-r-m.
2912 (sequence ((SI dummy)) (set dummy Rd))
2916 ; The first movem step is left out because it can't happen; it's for
2917 ; PC destination. See the pattern below.
2918 (.unsplice (.map movem-to-reg-step (.iota 15 14 -1))))
2920 ; Update the source-register for post-increments.
2921 ; FIXME: No postinc-prefixed for v0 IIRC.
2923 (set Rs (if SI (eq prefix-set 0) addr prefixreg)))
2925 (simplecris-movem-timing)
2928 ; (MOVEM [Rs],PC [ 1111 | 10111011 | Rs ])
2929 ; (MOVEM [Rs+],PC [ 1111 | 11111011 | Rs ])
2930 ; We have to special-case it for PC destination; used in longjump.
2931 ; We shouldn't *have* to special-case it; the main reason is (FIXME:)
2932 ; misgeneration of the simulator when the PC case is folded into the
2933 ; generic PRE-V32 movem; possibly related to then being a COND-CTI rather
2934 ; than an UNCOND-CTI.
2937 "movem to register, ending with PC"
2939 "movem [${Rs}${inc}],${Rd}"
2940 (+ (f-dest 15) INFIX_MOVEM_M_R SIZE_FIXED Rs)
2942 ((SI addr) (BI postinc))
2943 ; FIXME: Mostly a copy of what's in cris-get-mem.
2945 ; Cache the incrementness of the operand.
2948 ; Get the address from somewhere. If the insn was prefixed, it's in
2949 ; the prefix-register.
2951 (if SI (eq prefix-set 0)
2955 ; FIXME: Add kludge here too *and* a test-case.
2959 ; The first movem step is for PC destination, used in longjmp.
2960 (set pc (mem SI addr))
2961 (set addr (add addr 4))
2968 (set tmp (mem SI addr))
2969 (set (reg h-gr regn) tmp)
2970 (set addr (add addr 4))))
2973 ; Update the source-register for post-increments.
2974 ; FIXME: No postinc-prefixed for v0.
2976 (set Rs (if SI (eq prefix-set 0) addr prefixreg)))
2984 "movem [${Rs}${inc}],${Rd}"
2985 (+ INFIX_MOVEM_M_R MODEMEMP_YES inc SIZE_FIXED Rs Rd)
2987 ((SI addr) (BI postinc))
2988 ; FIXME: A copy of what's in cris-get-mem
2990 ; Cache the incrementness of the operand.
2993 ; Get the address from somewhere.
2996 ; CGEN-FIXME: See movem-r-m.
2997 (sequence ((SI dummy)) (set dummy Rd))
3001 (.unsplice (.map movem-to-reg-step (.iota 16))))
3003 ; Update the source-register for post-increments.
3004 ; FIXME: No postinc-prefixed for v0 IIRC.
3008 ; u-mem must be specified before the u-movem-* for memory source
3009 ; register stall count to be right.
3010 ((crisv32 (unit u-mem) (unit u-mem-r) (unit u-movem-mtor)
3011 (unit u-exec-movem)))
3014 ; ADD.m Rs,Rd [ Rd | 011000mm | Rs ]
3016 add "add from register to register"
3018 (+ Rd MODE_REGISTER R_ADD Rs)
3019 (.pmacro (BWD) (cris-arit add BWD Rd Rs))
3022 ; ADD.m [Rs],Rd [ Rd | 101000mm | Rs ]
3023 ; ADD.m [Rs+],Rd [ Rd | 111000mm | Rs ]
3025 add-m "add from memory to register"
3026 "[${Rs}${inc}],${Rd}"
3028 (.pmacro (BWD) (cris-arit-3op add BWD Rd (cris-get-mem BWD Rs) Rs))
3030 ; (ADD.m [PC+],Rd [ Rd | 111000mm | 1111 ])
3032 addcbr "add constant byte to register"
3033 "add.b ${sconst8}],${Rd}"
3034 (+ Rd MODE_AUTOINCREMENT INDIR_ADD SIZE_BYTE (f-source 15) sconst8)
3035 (cris-arit add QI Rd sconst8)
3039 addcwr "add constant word to register"
3040 "add.w ${sconst16}],${Rd}"
3041 (+ Rd MODE_AUTOINCREMENT INDIR_ADD SIZE_WORD (f-source 15) sconst16)
3042 (cris-arit add HI Rd sconst16)
3046 addcdr "add constant dword to register"
3047 "add.d ${const32}],${Rd}"
3048 (+ Rd MODE_AUTOINCREMENT INDIR_ADD SIZE_DWORD (f-source 15) const32)
3049 (cris-arit add SI Rd const32)
3052 ; (ADD.D [PC+],PC [ 1111 | 11100010 | 1111 ])
3053 ; This insn is used for DSO-local jumps in PIC code.
3055 addcpc "Relative jump by adding constant to PC"
3057 "add.d ${sconst32},PC"
3058 (+ (f-dest 15) MODE_AUTOINCREMENT INDIR_ADD SIZE_DWORD (f-source 15) const32)
3060 ((SI newpc) (SI oldpc) (SI offs))
3062 (set oldpc (add SI pc 6))
3063 (set newpc (add SI oldpc offs))
3065 (setf-arit SI add oldpc offs newpc cbit))
3066 (simplecris-common-timing ((unit u-const32) (unit u-stall) (unit u-exec)))
3069 ; ADDS.z Rs,Rd [ Rd | 0100001z | Rs ]
3071 adds "add sign-extended from register to register"
3073 (+ Rd MODE_REGISTER R_ADDX Rs)
3074 (.pmacro (BW) (cris-arit add SI Rd ((.sym BW -ext) (trunc BW Rs))))
3077 ; ADDS.z [Rs],Rd [ Rd | 1000001z | Rs ]
3078 ; ADDS.z [Rs+],Rd [ Rd | 1100001z | Rs ]
3080 adds-m "add sign-extended from memory to register"
3082 (+ Rd INDIR_ADDX Rs)
3083 (.pmacro (BW) (cris-arit-3op add SI Rd ((.sym BW -ext) (cris-get-mem BW Rs)) Rs))
3086 ; (ADDS.z [PC+],Rd [ Rd | 1100001z | 1111 ])
3088 addscbr "add sign-extended constant byte to register"
3090 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX SIGNED_BYTE (f-source 15) sconst8)
3091 (cris-arit add SI Rd (ext SI (trunc QI sconst8)))
3094 addscwr "add sign-extended constant word to register"
3096 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX SIGNED_WORD (f-source 15) sconst16)
3097 (cris-arit add SI Rd (ext SI (trunc HI sconst16)))
3100 ; (ADDS.w [],PC [ 1111 | 10000011 | 1111 ])
3101 ; For a PC destination, we support only the two-operand case
3102 ; (dest == src), which is used in switch/case statements.
3103 ; FIXME: Should implement ADD.D [PC],PC and ADDS.B [PC],PC for use if/when
3104 ; implementing CASE_VECTOR_SHORTEN_MODE.
3106 addspcpc "add sign-extended prefixed arg to PC"
3109 (+ (f-dest 15) MODE_INDIRECT INDIR_ADDX SIGNED_WORD (f-source 15))
3111 ((SI newpc) (SI oldpc) (HI offs))
3112 (if (not prefix-set)
3113 (error "Unexpected adds.w [PC],PC without prefix"))
3114 ; We don't use cris-get-mem but instead special-case this one, since we
3115 ; have most instruction fields fixed where cris-get-mem expects
3116 ; field-parametrization by certain names.
3117 (set offs (mem HI prefixreg))
3118 (set oldpc (add SI pc 2))
3119 (set newpc (add SI oldpc offs))
3121 (setf-arit SI add oldpc (ext SI offs) newpc cbit))
3122 (simplecris-common-timing ((unit u-mem) (unit u-stall) (unit u-exec)))
3125 ; ADDU.z Rs,Rd [ Rd | 0100000z | Rs ]
3127 addu "add zero-extended from register to register"
3129 (+ Rd MODE_REGISTER R_ADDX Rs)
3130 (.pmacro (BW) (cris-arit add SI Rd ((.sym BW -zext) (trunc BW Rs))))
3133 ; ADDU.z [Rs],Rd [ Rd | 1000000z | Rs ]
3134 ; ADDU.z [Rs+],Rd [ Rd | 1100000z | Rs ]
3136 addu-m "add zero-extended from memory to register"
3138 (+ Rd INDIR_ADDX Rs)
3140 (cris-arit-3op add SI Rd ((.sym BW -zext) (cris-get-mem BW Rs)) Rs))
3143 ; (ADDU.z [PC+],Rd [ Rd | 1100000z | 1111 ])
3145 adducbr "add zero-extended constant byte to register"
3147 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX UNSIGNED_BYTE (f-source 15) sconst8)
3148 (cris-arit add SI Rd (zext SI (trunc QI sconst8)))
3151 adducwr "add zero-extended constant word to register"
3153 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX UNSIGNED_WORD (f-source 15) sconst16)
3154 (cris-arit add SI Rd (zext SI (trunc HI sconst16)))
3157 ; SUB.m Rs,Rd [ Rd | 011010mm | Rs ]
3159 sub "subtract from register to register"
3161 (+ Rd MODE_REGISTER R_SUB Rs)
3162 (.pmacro (BWD) (cris-arit sub BWD Rd Rs))
3165 ; SUB.m [Rs],Rd [ Rd | 101010mm | Rs ]
3166 ; SUB.m [Rs+],Rd [ Rd | 111010mm | Rs ]
3168 sub-m "subtract from memory to register"
3169 "[${Rs}${inc}],${Rd}"
3171 (.pmacro (BWD) (cris-arit-3op sub BWD Rd (cris-get-mem BWD Rs) Rs))
3174 ; (SUB.m [PC+],Rd [ Rd | 111010mm | 1111 ]
3176 subcbr "subtract constant byte from register"
3177 "sub.b ${sconst8}],${Rd}"
3178 (+ Rd MODE_AUTOINCREMENT INDIR_SUB SIZE_BYTE (f-source 15) sconst8)
3179 (cris-arit sub QI Rd sconst8)
3183 subcwr "subtract constant word from register"
3184 "sub.w ${sconst16}],${Rd}"
3185 (+ Rd MODE_AUTOINCREMENT INDIR_SUB SIZE_WORD (f-source 15) sconst16)
3186 (cris-arit sub HI Rd sconst16)
3190 subcdr "subtract constant dword from register"
3191 "sub.d ${const32}],${Rd}"
3192 (+ Rd MODE_AUTOINCREMENT INDIR_SUB SIZE_DWORD (f-source 15) const32)
3193 (cris-arit sub SI Rd const32)
3196 ; SUBS.z Rs,Rd [ Rd | 0100101z | Rs ]
3198 subs "sub sign-extended from register to register"
3200 (+ Rd MODE_REGISTER R_SUBX Rs)
3201 (.pmacro (BW) (cris-arit sub SI Rd ((.sym BW -ext) (trunc BW Rs))))
3204 ; SUBS.z [Rs],Rd [ Rd | 1000101z | Rs ]
3205 ; SUBS.z [Rs+],Rd [ Rd | 1100101z | Rs ]
3207 subs-m "sub sign-extended from memory to register"
3209 (+ Rd INDIR_SUBX Rs)
3211 (cris-arit-3op sub SI Rd ((.sym BW -ext) (cris-get-mem BW Rs)) Rs))
3214 ; (SUBS.z [PC+],Rd [ Rd | 1100101z | 1111 ])
3216 subscbr "sub sign-extended constant byte to register"
3218 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX SIGNED_BYTE (f-source 15) sconst8)
3219 (cris-arit sub SI Rd (ext SI (trunc QI sconst8)))
3222 subscwr "sub sign-extended constant word to register"
3224 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX SIGNED_WORD (f-source 15) sconst16)
3225 (cris-arit sub SI Rd (ext SI (trunc HI sconst16)))
3228 ; SUBU.z Rs,Rd [ Rd | 0100100z | Rs ]
3230 subu "sub zero-extended from register to register"
3232 (+ Rd MODE_REGISTER R_SUBX Rs)
3233 (.pmacro (BW) (cris-arit sub SI Rd ((.sym BW -zext) (trunc BW Rs))))
3236 ; SUBU.z [Rs],Rd [ Rd | 1000100z | Rs ]
3237 ; SUBU.z [Rs+],Rd [ Rd | 1100100z | Rs ]
3239 subu-m "sub zero-extended from memory to register"
3241 (+ Rd INDIR_SUBX Rs)
3243 (cris-arit-3op sub SI Rd ((.sym BW -zext) (cris-get-mem BW Rs)) Rs))
3246 ; (SUBU.z [PC+],Rd [ Rd | 1100100z | 1111 ])
3248 subucbr "sub zero-extended constant byte to register"
3250 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX UNSIGNED_BYTE (f-source 15) sconst8)
3251 (cris-arit sub SI Rd (zext SI (trunc QI sconst8)))
3254 subucwr "sub zero-extended constant word to register"
3256 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX UNSIGNED_WORD (f-source 15) sconst16)
3257 (cris-arit sub SI Rd (zext SI (trunc HI sconst16)))
3260 ; ADDC Rs,Rd [ Rd | 01010111 | Rs ]
3262 addc-r "addc from register to register"
3265 (+ Rd MODE_REGISTER RFIX_ADDC SIZE_FIXED Rs)
3266 ; Since this is equivalent to "ax" plus "add.d Rs,Rd", we'll just do
3267 ; that, semantically.
3271 (cris-arit add SI Rd Rs))
3274 ; ADDC [Rs],Rd [ Rd | 10011010 | Rs ]
3275 ; ADDC [Rs+],Rd [ Rd | 11011010 | Rs ]
3277 addc-m "addc from memory to register"
3279 "addc [${Rs}${inc}],${Rd}"
3280 (+ Rd INDIR_ADDC SIZE_DWORD Rs)
3284 (cris-arit add SI Rd (cris-get-mem SI Rs)))
3287 ; (ADDC [Rs+],Rd [ Rd | 11011010 | 1111 ])
3289 addc-c "addc constant to register"
3291 "addc ${const32},${Rd}"
3292 (+ Rd MODE_AUTOINCREMENT INDIR_ADDC SIZE_DWORD (f-source 15) const32)
3296 (cris-arit add SI Rd const32))
3299 ; LAPC [PC+],Rd [ Rd | 11010111 1111 ]
3303 "lapc.d ${const32-pcrel},${Rd}"
3304 (+ Rd MODE_AUTOINCREMENT INFIX_LAPC SIZE_FIXED (f-source 15) const32-pcrel)
3307 (set Rd const32-pcrel)
3311 ; LAPCQ qo,Rd [ Rd | 10010111 | qo ]
3316 (+ Rd MODE_INDIRECT INFIX_LAPC SIZE_FIXED qo)
3323 ; ADDI Rs.m,Rd [ Rs | 010100mm | Rd ]
3326 "${Rs-dfield}.m,${Rd-sfield}"
3327 (+ Rd-sfield MODE_REGISTER R_ADDI Rs-dfield)
3332 (set Rd-sfield (add SI Rd-sfield (mul Rs-dfield (.sym BWD -size))))
3336 ; NEG.m Rs,Rd [ Rd | 010110mm | Rs ]
3340 (+ Rd MODE_REGISTER R_NEG Rs)
3341 (.pmacro (BWD) (cris-arit3 sub BWD Rd 0 Rs))
3344 ; TEST.m [Rs] [ 0000101110mm | Rs ]
3345 ; TEST.m [Rs+] [ 0000111110mm | Rs ]
3347 test-m "test.m [Rs(+)]"
3349 (+ (f-dest 0) INDIR_TEST Rs)
3354 (set tmpd (cris-get-mem BWD Rs))
3355 ; This is supposed to be the same result as for cmpq 0,X, hence same code.
3357 sub BWD (.pmacro (sz regno val) (nop)) 0 tmpd 0 cbit cbit)))
3360 ; MOVE.m Rs,[Rd] [ Rs | 101111mm | Rd ]
3361 ; MOVE.m Rs,[Rd+] [ Rs | 111111mm | Rd ]
3364 move-r-m "move.m R,[]"
3365 "${Rs-dfield},[${Rd-sfield}${inc}]"
3366 (+ Rs-dfield INDIR_MOVE_R_M Rd-sfield)
3371 (set tmpd Rs-dfield)
3372 (cris-set-mem BWD Rd-sfield tmpd)
3376 ; MULS.m Rs,Rd [ Rd | 110100mm | Rs ]
3379 ((MACH crisv10,crisv32))
3381 (+ Rd MODE_MULS INDIR_MUL Rs)
3385 ((DI src1) (DI src2) (DI tmpr))
3386 (set src1 (ext DI (trunc BWD Rs)))
3387 (set src2 (ext DI (trunc BWD Rd)))
3388 (set tmpr (mul src1 src2))
3389 (set Rd (trunc SI tmpr))
3390 (set mof (trunc SI (srl tmpr 32)))
3391 (setf-arit DI muls src1 src2 tmpr cbit)))
3392 ((crisv10 (unit u-multiply) (unit u-exec))
3393 (crisv32 (unit u-multiply) (unit u-exec)))
3396 ; MULU.m Rs,Rd [ Rd | 100100mm | Rs ]
3399 ((MACH crisv10,crisv32))
3401 (+ Rd MODE_MULU INDIR_MUL Rs)
3405 ((DI src1) (DI src2) (DI tmpr))
3406 (set src1 (zext DI (trunc BWD Rs)))
3407 (set src2 (zext DI (trunc BWD Rd)))
3408 (set tmpr (mul src1 src2))
3409 (set Rd (trunc SI tmpr))
3410 (set mof (trunc SI (srl tmpr 32)))
3411 (setf-arit DI mulu src1 src2 tmpr cbit)))
3412 ((crisv10 (unit u-multiply) (unit u-exec))
3413 (crisv32 (unit u-multiply) (unit u-exec)))
3416 ; MCP Ps,Rd [ Ps | 01111111 | Rd ]
3418 mcp "Multiply Carry Propagation"
3421 (+ Ps MODE_REGISTER RFIX_MCP SIZE_FIXED Rd-sfield)
3426 (cris-arit5 add SI Rd-sfield Rd-sfield Ps rbit rbit))
3429 ; MSTEP Rs,Rd [ Rd | 01111111 | Rs ]
3431 mstep "Multiply step"
3434 (+ Rd MODE_REGISTER RFIX_MSTEP SIZE_FIXED Rs)
3436 ((SI tmpd) (SI tmps))
3438 (set tmpd (add (sll Rd 1) (if SI nbit tmps 0)))
3440 (setf-move SI tmpd))
3443 ; DSTEP Rs,Rd [ Rd | 01101111 | Rs ]
3445 dstep "Division step"
3447 (+ Rd MODE_REGISTER RFIX_DSTEP SIZE_FIXED Rs)
3449 ((SI tmp) (SI tmps) (SI tmpd))
3451 (set tmp (sll Rd 1))
3452 (set tmpd (if SI (geu tmp tmps) (sub tmp tmps) tmp))
3454 (setf-move SI tmpd))
3457 ; ABS Rs,Rd [ Rd | 01101011 | Rs ]
3459 abs "Absolut Instruction"
3461 (+ Rd MODE_REGISTER RFIX_ABS SIZE_FIXED Rs)
3466 (setf-move SI tmpd))
3469 ; AND.m Rs,Rd [ Rd | 011100mm | Rs ]
3471 and "And from register to register"
3473 (+ Rd MODE_REGISTER R_AND Rs)
3478 (set tmpd (and BWD Rd Rs))
3479 (set-subreg-gr BWD (regno Rd) tmpd)
3480 (setf-move BWD tmpd)))
3483 ; AND.m [Rs],Rd [ Rd | 101100mm | Rs ]
3484 ; AND.m [Rs+],Rd [ Rd | 111100mm | Rs ]
3486 and-m "And from memory to register"
3487 "[${Rs}${inc}],${Rd}"
3493 (set tmpd (and BWD Rd (cris-get-mem BWD Rs)))
3496 (if SI (andif prefix-set (not inc)) (regno Rs) (regno Rd))
3498 (setf-move BWD tmpd)))
3501 ; (AND.m [PC+],Rd [ Rd | 111100mm | 1111 ])
3503 andcbr "And constant byte to register"
3504 "and.b ${sconst8}],${Rd}"
3505 (+ Rd MODE_AUTOINCREMENT INDIR_AND SIZE_BYTE (f-source 15) sconst8)
3508 (set tmpd (and QI Rd sconst8))
3509 (set-subreg-gr QI (regno Rd) tmpd)
3510 (setf-move QI tmpd))
3514 andcwr "And constant word to register"
3515 "and.w ${sconst16}],${Rd}"
3516 (+ Rd MODE_AUTOINCREMENT INDIR_AND SIZE_WORD (f-source 15) sconst16)
3519 (set tmpd (and HI Rd sconst16))
3520 (set-subreg-gr HI (regno Rd) tmpd)
3521 (setf-move HI tmpd))
3525 andcdr "And constant dword to register"
3526 "and.d ${const32}],${Rd}"
3527 (+ Rd MODE_AUTOINCREMENT INDIR_AND SIZE_DWORD (f-source 15) const32)
3530 (set tmpd (and SI Rd const32))
3531 (set-subreg-gr SI (regno Rd) tmpd)
3532 (setf-move SI tmpd))
3535 ; ANDQ i,Rd [ Rd | 001100 | i ]
3537 andq "And quick-immediate to register"
3539 (+ Rd MODE_QUICK_IMMEDIATE Q_ANDQ i)
3542 (set tmpd (and SI Rd i))
3543 (set-subreg-gr SI (regno Rd) tmpd)
3544 (setf-move SI tmpd))
3547 ; OR.m Rs,Rd [ Rd | 011101mm | Rs ]
3549 orr "Or from register to register"
3551 (+ Rd MODE_REGISTER R_OR Rs)
3556 (set tmpd (or BWD Rd Rs))
3557 (set-subreg-gr BWD (regno Rd) tmpd)
3558 (setf-move BWD tmpd)))
3561 ; OR.m [Rs],Rd [ Rd | 101101mm | Rs ]
3562 ; OR.m [Rs+],Rd [ Rd | 111101mm | Rs ]
3564 or-m "Or from memory to register"
3565 "[${Rs}${inc}],${Rd}"
3571 (set tmpd (or BWD Rd (cris-get-mem BWD Rs)))
3574 (if SI (andif prefix-set (not inc)) (regno Rs) (regno Rd))
3576 (setf-move BWD tmpd)))
3579 ; (OR.m [PC+],Rd [ Rd | 111101mm | 1111 ])
3581 orcbr "Or constant byte to register"
3582 "or.b ${sconst8}],${Rd}"
3583 (+ Rd MODE_AUTOINCREMENT INDIR_OR SIZE_BYTE (f-source 15) sconst8)
3586 (set tmpd (or QI Rd sconst8))
3587 (set-subreg-gr QI (regno Rd) tmpd)
3588 (setf-move QI tmpd))
3592 orcwr "Or constant word to register"
3593 "or.w ${sconst16}],${Rd}"
3594 (+ Rd MODE_AUTOINCREMENT INDIR_OR SIZE_WORD (f-source 15) sconst16)
3597 (set tmpd (or HI Rd sconst16))
3598 (set-subreg-gr HI (regno Rd) tmpd)
3599 (setf-move HI tmpd))
3603 orcdr "Or constant dword to register"
3604 "or.d ${const32}],${Rd}"
3605 (+ Rd MODE_AUTOINCREMENT INDIR_OR SIZE_DWORD (f-source 15) const32)
3608 (set tmpd (or SI Rd const32))
3609 (set-subreg-gr SI (regno Rd) tmpd)
3610 (setf-move SI tmpd))
3613 ; ORQ i,Rd [ Rd | 001101 | i ]
3615 orq "Or quick-immediate to register"
3617 (+ Rd MODE_QUICK_IMMEDIATE Q_ORQ i)
3620 (set tmpd (or SI Rd i))
3621 (set-subreg-gr SI (regno Rd) tmpd)
3622 (setf-move SI tmpd))
3625 ; XOR Rs,Rd [ Rd | 01111011 | Rs ]
3627 xor "Xor from register to register"
3629 (+ Rd MODE_REGISTER RFIX_XOR SIZE_FIXED Rs)
3632 (set tmpd (xor SI Rd Rs))
3634 (setf-move SI tmpd))
3637 (define-pmacro (swap-r x)
3638 "Perform bit-wise swap within each byte"
3643 (or (sll (and tmpr #x1010101) 7)
3644 (or (sll (and tmpr #x2020202) 5)
3645 (or (sll (and tmpr #x4040404) 3)
3646 (or (sll (and tmpr #x8080808) 1)
3647 (or (srl (and tmpr #x10101010) 1)
3648 (or (srl (and tmpr #x20202020) 3)
3649 (or (srl (and tmpr #x40404040) 5)
3650 (srl (and tmpr #x80808080) 7)))))))))
3653 (define-pmacro (swap-b x)
3654 "Perform byte-wise swap within each word"
3659 (or (and (sll tmpb 8) #xff00ff00)
3660 (and (srl tmpb 8) #xff00ff)))
3663 (define-pmacro (swap-w x)
3664 "Perform word-wise swap within each dword"
3669 (or (and (sll tmpb 16) #xffff0000)
3670 (and (srl tmpb 16) #xffff)))
3673 (define-pmacro (swap-_ x)
3674 "Do nothing swap-wise"
3675 (error SI "SWAP without swap modifier isn't implemented")
3678 (define-pmacro (swap-n x)
3679 "Perform bitwise not (that is, perform a not, not not perform)"
3683 (define-pmacro (swap-br x) "Combine swap-r and swap-b" (swap-r (swap-b x)))
3684 (define-pmacro (swap-wr x) "Combine swap-r and swap-w" (swap-r (swap-w x)))
3685 (define-pmacro (swap-wb x) "Combine swap-b and swap-w" (swap-b (swap-w x)))
3686 (define-pmacro (swap-wbr x) "Combine swap-r and swap-wb" (swap-r (swap-wb x)))
3687 (define-pmacro (swap-nr x) "Combine swap-r and swap-n" (swap-r (swap-n x)))
3688 (define-pmacro (swap-nb x) "Combine swap-n and swap-b" (swap-b (swap-n x)))
3689 (define-pmacro (swap-nbr x) "Combine swap-r and swap-nb" (swap-r (swap-nb x)))
3690 (define-pmacro (swap-nw x) "Combine swap-n and swap-w" (swap-w (swap-n x)))
3691 (define-pmacro (swap-nwr x) "Combine swap-r and swap-nw" (swap-r (swap-nw x)))
3692 (define-pmacro (swap-nwb x) "Combine swap-b and swap-nw" (swap-b (swap-nw x)))
3693 (define-pmacro (swap-nwbr x) "Combine swap-r and swap-nwb" (swap-r (swap-nwb x)))
3695 (define-pmacro (cris-swap swapcode val)
3698 ((SI tmpcode) (SI tmpval) (SI tmpres))
3699 (set tmpcode swapcode)
3707 ((eq tmpcode x-swapcode)
3708 (set tmpres ((.sym swap- x-swap) tmpval))))
3710 (.splice _ (.unsplice cris-swap-codes)))))
3714 ; NOT Rd alias for SWAPN Rd
3717 ((MACH crisv0,crisv3))
3719 (+ (f-dest 8) RFIX_SWAP MODE_REGISTER SIZE_FIXED Rd-sfield)
3721 ((SI tmp) (SI tmpd))
3723 (set tmpd (cris-swap 8 tmp))
3724 (set Rd-sfield tmpd)
3725 (setf-move SI tmpd))
3728 ; SWAP<option> Rd [ N W B R | 01110111 | Rd ]
3731 ((MACH crisv8,crisv10,crisv32))
3732 "swap${swapoption} ${Rs}"
3733 (+ swapoption RFIX_SWAP MODE_REGISTER SIZE_FIXED Rd-sfield)
3735 ((SI tmps) (SI tmpd))
3736 (set tmps Rd-sfield)
3737 (set tmpd (cris-swap swapoption tmps))
3738 (set Rd-sfield tmpd)
3739 (setf-move SI tmpd))
3742 ; ASR.m Rs,Rd [ Rd | 011110mm | Rs ]
3744 asrr "Arithmetic shift right register count"
3746 (+ Rd MODE_REGISTER R_ASR Rs)
3750 ((BWD tmpd) (SI cnt1) (SI cnt2))
3752 (set cnt2 (if SI (ne (and cnt1 32) 0) 31 (and cnt1 31)))
3753 (set tmpd (sra SI (ext SI (trunc BWD Rd)) cnt2))
3754 (set-subreg-gr BWD (regno Rd) tmpd)
3755 (setf-move BWD tmpd)))
3758 ; ASRQ c,Rd [ Rd | 0011101 | c ]
3760 asrq "Arithmetic shift right quick-immediate count"
3762 (+ Rd Q_ASHQ MODE_QUICK_IMMEDIATE (f-b5 1) c)
3765 (set tmpd (sra Rd c))
3767 (setf-move SI tmpd))
3770 ; LSR.m Rs,Rd [ Rd | 011111mm | Rs ]
3772 lsrr "Logical shift right register count"
3774 (+ Rd MODE_REGISTER R_LSR Rs)
3778 ((SI tmpd) (SI cnt))
3779 (set cnt (and Rs 63))
3782 (if SI (ne (and cnt 32) 0)
3784 (srl SI (zext SI (trunc BWD Rd)) (and cnt 31))))
3785 (set-subreg-gr BWD (regno Rd) tmpd)
3786 (setf-move BWD tmpd)))
3789 ; LSRQ c,Rd [ Rd | 0011111 | c ]
3791 lsrq "Logical shift right quick-immediate count"
3793 (+ Rd Q_LSHQ MODE_QUICK_IMMEDIATE (f-b5 1) c)
3796 (set tmpd (srl Rd c))
3798 (setf-move SI tmpd))
3801 ; LSL.m Rs,Rd [ Rd | 010011mm | Rs ]
3803 lslr "Logical shift left register count"
3805 (+ Rd MODE_REGISTER R_LSL Rs)
3809 ((SI tmpd) (SI cnt))
3810 (set cnt (and Rs 63))
3813 (if SI (ne (and cnt 32) 0)
3815 (sll SI (zext SI (trunc BWD Rd)) (and cnt 31))))
3816 (set-subreg-gr BWD (regno Rd) tmpd)
3817 (setf-move BWD tmpd)))
3820 ; LSLQ c,Rd [ Rd | 0011110 | c ]
3822 lslq "Logical shift left quick-immediate count"
3824 (+ Rd Q_LSHQ MODE_QUICK_IMMEDIATE (f-b5 0) c)
3827 (set tmpd (sll Rd c))
3829 (setf-move SI tmpd))
3832 ; BTST Rs,Rd [ Rd | 01001111 | Rs ]
3834 btst "Bit test register number"
3836 (+ Rd MODE_REGISTER RFIX_BTST SIZE_FIXED Rs)
3838 ((SI tmpd) (SI cnt))
3839 (set tmpd (sll Rd (sub 31 (and Rs 31))))
3840 (setf-move SI tmpd))
3843 ; BTSTQ c,Rd [ Rd | 0011100 | c ]
3845 btstq "Bit test quick-immediate number"
3847 (+ Rd Q_ASHQ MODE_QUICK_IMMEDIATE (f-b5 0) c)
3850 (set tmpd (sll Rd (sub 31 c)))
3851 (setf-move SI tmpd))
3854 ; SETF <list of flags> [ P U I X | 01011011 | N Z V C ]
3856 setf "Set condition code flags explicitly"
3857 "setf ${list-of-flags}"
3858 ; The zero-flags case gets flag operands wrong; there's a "_"
3859 ; where there should have been nothing. Also, flags are in
3860 ; assembly code allowed to be specified in any order, which
3861 ; doesn't match the "flagbits" settings. Luckily we don't
3862 ; use this field for assembly.
3863 (+ RFIX_SETF MODE_REGISTER SIZE_FIXED list-of-flags)
3867 (set tmp list-of-flags)
3871 (if (ne (and tmp (sll 1 (.sym ccbit -bitnumber))) 0)
3872 (set (.sym ccbit bit) 1)))
3875 ; Unless x was specified to be set, set it to 0.
3876 (if (eq (and tmp (sll 1 x-bitnumber)) 0)
3880 ; CLEARF <list of flags> [ P U I X | 01011111 | N Z V C ]
3882 clearf "Clear condition code flags explicitly"
3883 "clearf ${list-of-flags}"
3884 ; The zero-flags case gets flag operands wrong; there's a "_"
3885 ; where there should have been nothing. Also, flags are in
3886 ; assembly code allowed to be specified in any order, which
3887 ; doesn't match the "flagbits" settings. Luckily we don't
3888 ; use this field for assembly.
3889 (+ RFIX_CLEARF MODE_REGISTER SIZE_FIXED list-of-flags)
3893 (set tmp list-of-flags)
3897 (if (ne (and tmp (sll 1 (.sym ccbit -bitnumber))) 0)
3898 (set (.sym ccbit bit) 0)))
3905 "Common parts of RFE and RFN"
3907 ((USI oldccs) (USI samebits) (USI shiftbits) (USI keepmask) (BI p1))
3909 ; Keeping U, S and I in user mode is handled by the CCS setter, so we
3910 ; don't have to bother. Actually Q and M are handled too. The reason
3911 ; to mask those out is to not have them shifted down into the second
3913 (set keepmask #xc0000000)
3914 (set samebits (and oldccs keepmask))
3915 ; The P bit has its own equation.
3916 (set shiftbits (and (srl (and oldccs #x3ffdfc00) 10) (inv keepmask)))
3917 (set p1 (ne 0 (and oldccs #x20000)))
3918 (set ccs (or (or samebits shiftbits)
3919 (if SI (and rbit (not p1)) 0 #x80))))
3922 ; RFE [ 0010 10010011 0000 ]
3928 (+ (f-dest 2) MODE_INDIRECT INFIX_RFE SIZE_FIXED (f-source 0))
3932 ; SFE [ 0011 10010011 0000 ]
3938 (+ (f-dest 3) MODE_INDIRECT INFIX_SFE SIZE_FIXED (f-source 0))
3940 ((SI oldccs) (SI savemask))
3941 (set savemask #xc0000000)
3944 (or (and savemask oldccs)
3945 (and (inv savemask) (sll oldccs 10)))))
3948 ; RFG [ 0100 10010011 0000 ]
3954 (+ (f-dest 4) MODE_INDIRECT INFIX_RFG SIZE_FIXED (f-source 0))
3955 (c-call VOID "@cpu@_rfg_handler" pc)
3958 ; RFN [ 0101 10010011 0000 ]
3964 (+ (f-dest 5) MODE_INDIRECT INFIX_RFN SIZE_FIXED (f-source 0))
3965 (sequence () (rfe-rfn-guts) (set mbit 1))
3968 ; HALT [ 1111 10010011 0000 ]
3974 (+ (f-dest 15) MODE_INDIRECT INFIX_HALT SIZE_FIXED (f-source 0))
3975 (set pc (c-call USI "@cpu@_halt_handler" pc))
3978 ; Bcc o [ cc | 0000 | o ]
3980 bcc-b "bcc byte operand"
3983 (+ cc QHI_BCC MODE_QUICK_IMMEDIATE o-pcrel)
3986 (set truthval (cris-condition cc))
3988 ; Amazing as it may seem, there's no simpler way to find out
3989 ; whether a branch is taken or not than to mark it through a kludge
3991 (c-call VOID "@cpu@_branch_taken" pc o-pcrel truthval)
3997 (.splice (.unsplice (simplecris-timing))
3998 (crisv32 (unit u-branch) (unit u-exec)))
4001 ba-b "ba byte operand"
4004 (+ (f-dest 14) QHI_BCC MODE_QUICK_IMMEDIATE o-pcrel)
4010 ((crisv32 (unit u-jump) (unit u-exec)))
4013 ; Bcc [PC+] [ cc | 11011111 1111 ]
4014 ; (We don't implement the generic for pre-V32 but unused variant
4015 ; "Bcc [Rn(+)]" where n != 15.)
4017 bcc-w "bcc, word operand"
4019 "b${cc} ${o-word-pcrel}"
4020 (+ cc MODE_AUTOINCREMENT INFIX_BCC_M SIZE_FIXED (f-source 15) o-word-pcrel)
4023 (set truthval (cris-condition cc))
4025 ; Amazing as it may seem, there's no simpler way to find out
4026 ; whether a branch is taken or not than to mark it through a kludge
4028 (c-call VOID "@cpu@_branch_taken" pc o-word-pcrel truthval)
4033 (set pc o-word-pcrel))))
4035 (.unsplice (simplecris-common-timing ((unit u-const16) (unit u-exec))))
4036 (crisv32 (unit u-const16) (unit u-branch) (unit u-exec)))
4039 ba-w "ba word operand"
4041 "ba ${o-word-pcrel}"
4042 (+ (f-dest 14) MODE_AUTOINCREMENT INFIX_BCC_M SIZE_FIXED (f-source 15) o-word-pcrel)
4047 (set pc o-word-pcrel)))
4049 (.unsplice (simplecris-common-timing ((unit u-const16) (unit u-exec))))
4050 (crisv32 (unit u-const16) (unit u-jump) (unit u-exec)))
4053 ; JAS Rs,Pd [ Pd | 10011011 | Rs ]
4055 jas-r "JAS register"
4058 (+ Pd MODE_INDIRECT INFIX_JAS_R SIZE_FIXED Rs)
4062 (if (andif (eq (regno Rs) 1) (eq (regno Pd) 11))
4063 ; We use this as a trigger; a normally reasonably rare instruction
4064 ; used in the v32 trampoline. See comment at bdapqpc.
4065 ; CGEN-FIXME: can't use (regno srp) [== (regno (reg h-sr 11))]
4066 (c-call VOID "cris_flush_simulator_decode_cache" pc))
4070 (set Pd (add SI pc 4))
4072 ((crisv32 (unit u-jump-r) (unit u-jump) (unit u-exec)))
4074 ; Same semantics in pre-V32, except no delay-slot.
4075 ; FIXME: Missing JIRC/JSRC/JBRC.
4077 jump-r "JUMP/JSR/JIR register"
4079 "jump/jsr/jir ${Rs}"
4080 (+ Pd MODE_INDIRECT INFIX_JUMP_R SIZE_FIXED Rs)
4083 (set Pd (add SI pc 2))
4088 ; JAS [PC+],Pd [ Pd | 11011011 1111 ]
4090 jas-c "JAS constant"
4092 "jas ${const32},${Pd}"
4093 (+ Pd MODE_AUTOINCREMENT INFIX_JAS_M SIZE_FIXED (f-source 15) const32)
4100 (set Pd (add SI pc 8))
4102 ((crisv32 (unit u-const32) (unit u-jump) (unit u-exec)))
4105 ; JUMP/JSR/JIR | Special r.| 1 m| 0 1 0 0| 1 1| Source |
4107 jump-m "JUMP/JSR/JIR memory"
4109 "jump/jsr/jir [${Rs}${inc}]"
4110 (+ Pd INFIX_JUMP_M SIZE_FIXED Rs)
4113 (set Pd (add SI pc 2))
4114 (set pc (cris-get-mem SI Rs))
4118 jump-c "JUMP/JSR/JIR constant"
4120 "jump/jsr/jir ${const32}"
4121 (+ Pd MODE_AUTOINCREMENT INFIX_JUMP_M SIZE_FIXED (f-source 15) const32)
4124 (set Pd (add SI pc 6))
4129 ; JUMP Ps [ Ps | 10011111 0000 ]
4131 jump-p "JUMP special register"
4134 (+ Ps MODE_INDIRECT INFIX_JUMP_P SIZE_FIXED (f-source 0))
4140 ((crisv32 (unit u-jump-sr)
4144 ; BAS [PC+],Pd [ Pd | 11101011 1111 ]
4146 bas-c "BAS constant"
4148 "bas ${const32},${Pd}"
4149 (+ Pd MODE_AUTOINCREMENT INFIX_BAS SIZE_FIXED (f-source 15) const32-pcrel)
4156 (set Pd (add SI pc 8))
4157 (set pc const32-pcrel))))
4158 ((crisv32 (unit u-const32) (unit u-jump) (unit u-exec)))
4161 ; JASC Rs,Pd [ Pd | 10110011 | Rs ]
4163 jasc-r "JASC register"
4166 (+ Pd MODE_INDIRECT INFIX_JASC SIZE_FIXED Rs)
4173 (set Pd (add SI pc 8))
4175 ((crisv32 (unit u-jump-r) (unit u-skip4) (unit u-jump) (unit u-exec)))
4178 ; JASC [PC+],Pd [ Pd | 11110011 1111 ]
4180 jasc-c "JASC constant"
4182 "jasc ${const32},${Pd}"
4183 (+ Pd MODE_AUTOINCREMENT INFIX_JASC SIZE_FIXED (f-source 15) const32)
4190 (set Pd (add SI pc 12))
4192 ((crisv32 (unit u-const32) (unit u-skip4) (unit u-jump) (unit u-exec)))
4195 ; BASC [PC+],Pd [ Pd | 11101111 1111 ]
4197 basc-c "BASC constant"
4199 "basc ${const32},${Pd}"
4200 (+ Pd MODE_AUTOINCREMENT INFIX_BASC SIZE_FIXED (f-source 15) const32-pcrel)
4207 (set Pd (add SI pc 12))
4208 (set pc const32-pcrel))))
4209 ((crisv32 (unit u-const32) (unit u-skip4) (unit u-jump) (unit u-exec)))
4212 ; BREAK n [ 1110 | 10010011 | n ]
4217 (+ (f-operand2 #xe) MODE_INDIRECT INFIX_BREAK SIZE_FIXED n)
4218 (sequence () (reset-x-p) (set pc (c-call USI "@cpu@_break_handler" n pc)))
4221 ; BOUND.m Rs,Rd [ Rd | 010111mm | Rs ]
4223 bound-r "Bound register"
4225 (+ Rd R_BOUND MODE_REGISTER Rs)
4229 ((SI tmpopd) (SI tmpops) (SI newval))
4230 (set tmpops ((.sym BWD -zext) (trunc BWD Rs)))
4232 (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
4234 (setf-move SI newval)))
4237 ; BOUND.m [Rs],Rd [ Rd | 100111mm | Rs ]
4238 ; BOUND.m [Rs+],Rd [ Rd | 110111mm | Rs ]
4240 bound-m "Bound memory"
4242 "[${Rs}${inc}],${Rd}"
4243 (+ Rd INDIR_BOUND Rs)
4247 ((SI tmpopd) (SI tmpops) (SI newval))
4248 (set tmpops ((.sym BWD -zext) (cris-get-mem BWD Rs)))
4250 (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
4251 (if (andif prefix-set (not inc))
4254 (setf-move SI newval)))
4257 ; (BOUND.m [PC+],Rd [ Rd | 110111mm | 1111 ])
4259 bound-cb "Bound constant byte"
4260 "bound.b [PC+],${Rd}"
4261 (+ Rd MODE_AUTOINCREMENT INDIR_BOUND SIZE_BYTE (f-source 15) uconst8)
4263 ((SI tmpopd) (SI tmpops) (SI newval))
4264 (set tmpops (zext SI (trunc QI uconst8)))
4266 (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
4268 (setf-move SI newval))
4271 bound-cw "Bound constant word"
4272 "bound.w [PC+],${Rd}"
4273 (+ Rd MODE_AUTOINCREMENT INDIR_BOUND SIZE_WORD (f-source 15) uconst16)
4275 ((SI tmpopd) (SI tmpops) (SI newval))
4276 (set tmpops (zext SI uconst16))
4278 (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
4280 (setf-move SI newval))
4283 bound-cd "Bound constant dword"
4284 "bound.d [PC+],${Rd}"
4285 (+ Rd MODE_AUTOINCREMENT INDIR_BOUND SIZE_DWORD (f-source 15) const32)
4287 ((SI tmpopd) (SI tmpops) (SI newval))
4288 (set tmpops const32)
4290 (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
4292 (setf-move SI newval))
4295 ; Scc Rd [ cc | 01010011 | Rd ]
4298 "s${cc} ${Rd-sfield}"
4299 (+ cc MODE_REGISTER RFIX_SCC SIZE_FIXED Rd-sfield)
4302 (set truthval (cris-condition cc))
4303 (set Rd-sfield (zext SI truthval))
4307 ; LZ Rs,Rd [ Rd | 01110011 | Rs ]
4312 (+ Rd MODE_REGISTER RFIX_LZ SIZE_FIXED Rs)
4314 ((SI tmpd) (SI tmp))
4326 (set tmp (sll tmp 1))
4327 (set tmpd (add tmpd 1)))))
4330 (setf-move SI tmpd))
4333 ; ADDOQ o,Rs,ACR [ Rs | 0001 | o ]
4337 (+ Rs-dfield MODE_QUICK_IMMEDIATE QHI_ADDOQ o)
4340 (set prefixreg (add SI Rs-dfield o))
4344 ; (BDAPQ o,PC [ 1111 | 0001 | o ])
4345 ; This [PC+I] prefix is used in trampolines.
4347 bdapqpc "bdapq pc operand"
4348 (MACH-PC UNCOND-CTI)
4350 (+ (f-dest 15) MODE_QUICK_IMMEDIATE QHI_BDAP o)
4353 (set prefixreg (add SI (add SI pc 2) o))
4355 ; When this *rare* instruction is seen, we're may be about to write
4356 ; into code to be executed soon, *probably* covering addresses decoded
4357 ; and executed before. If the simulator does not implement snooping
4358 ; and automatic decoder flush, it will execute old code. This call
4359 ; is a kludge for such simulators, asking it to abandon such cached
4360 ; information. Anyway, it is hopefully enough to make CGEN-sim not
4361 ; hork on gcc trampolines.
4362 ; We mark this insn as UNCOND-CTI so this insn will end a simulator
4363 ; basic block (the atomic unit of translation).
4364 (c-call VOID "cris_flush_simulator_decode_cache" pc))
4367 ; (BDAP.D [PC+],PC [ 1111 | 11010110 | 1111 ]
4368 ; This [PC+I] prefix is used for DSO-local jumps in PIC code, together with
4369 ; move-m-pcplus-p0: "move [pc=pc+N],p0"
4371 bdap-32-pc "bdap.d [PC+],PC"
4373 "bdap ${sconst32},PC"
4374 (+ (f-dest 15) MODE_AUTOINCREMENT INDIR_BDAP_M SIZE_DWORD (f-source 15) const32)
4376 ((SI newpc) (SI oldpc) (SI offs))
4378 (set oldpc (add SI pc 6))
4379 (set newpc (add SI oldpc offs))
4380 (set prefixreg newpc)
4384 ; (MOVE [PC+],P0 [ 0000 | 11100011 | 1111 ])
4385 ; This insn is used for DSO-local jumps in PIC code. See bdap-32-pc.
4386 (dni ; Must not use dni-cmt-* because we force MODE_AUTOINCREMENT.
4387 move-m-pcplus-p0 "move [PC+],P0"
4390 (+ (f-dest 0) MODE_AUTOINCREMENT INFIX_MOVE_M_S SIZE_FIXED (f-source 15))
4394 ; We model the memory read, but throw the result away, as the
4395 ; destination register is read-only. We need to assign the result of
4396 ; cris-get-mem though, as CGEN-FIXME: invalid C code will otherwise
4398 (set dummy (cris-get-mem QI pc))
4400 (error "move [PC+],P0 without prefix is not implemented"))
4404 ; This insn is used in Linux in the form "move [$sp=$sp+16],$p8"; it's
4405 ; similar to move-m-pcplus-p0 above. The same comments apply here.
4407 move-m-spplus-p8 "move [SP+],P8"
4410 (+ (f-dest 8) MODE_AUTOINCREMENT INFIX_MOVE_M_S SIZE_FIXED (f-source 14))
4414 (set dummy (cris-get-mem SI sp))
4416 (error "move [SP+],P8 without prefix is not implemented"))
4420 ; ADDO.m [Rs],Rd,ACR [ Rd | 100101mm | Rs ]
4421 ; ADDO.m [Rs+],Rd,ACR [ Rd | 110101mm | Rs ]
4423 addo-m "addo.m memory"
4424 "[${Rs}${inc}],$Rd,ACR"
4425 (+ Rd INDIR_ADDO Rs)
4430 (set tmps (cris-get-mem BWD Rs))
4431 (set prefixreg (add SI Rd ((.sym BWD -ext) tmps)))
4432 (set prefix-set 1)))
4435 ; (ADDO.m [PC+],Rd,ACR [ Rd | 110101mm | 1111 ]
4437 addo-cb "addo.b const"
4438 "addo.b [PC+],$Rd,ACR"
4439 (+ Rd MODE_AUTOINCREMENT INDIR_ADDO SIZE_BYTE (f-source 15) sconst8)
4442 (set prefixreg (add SI Rd (ext SI (trunc QI sconst8))))
4446 addo-cw "addo.w const"
4447 "addo.w [PC+],$Rd,ACR"
4448 (+ Rd MODE_AUTOINCREMENT INDIR_ADDO SIZE_WORD (f-source 15) sconst16)
4451 (set prefixreg (add SI Rd (ext SI (trunc HI sconst16))))
4455 addo-cd "addo.d const"
4456 "addo.d [PC+],$Rd,ACR"
4457 (+ Rd MODE_AUTOINCREMENT INDIR_ADDO SIZE_DWORD (f-source 15) const32)
4460 (set prefixreg (add SI Rd const32))
4464 ; DIP [] | 0 0 0 0| 1 m| 0 1 0 1| 1 1| Source |
4470 (+ (f-dest 0) INFIX_DIP SIZE_FIXED Rs)
4473 (set tmps (cris-get-mem SI Rs))
4474 (set prefixreg tmps)
4478 ; (DIP [] | 0 0 0 0| 1 m| 0 1 0 1| 1 1| Source | )
4483 (+ (f-dest 0) MODE_AUTOINCREMENT INFIX_DIP SIZE_FIXED (f-source 15) const32)
4486 (set prefixreg const32)
4490 ; ADDI Rs.m,Rd,ACR [ Rs | 010101mm | Rd ]
4493 addi-acr "addi prefix"
4494 "${Rs-dfield}.m,${Rd-sfield},ACR"
4495 (+ Rd-sfield MODE_REGISTER R_ADDI_ACR Rs-dfield)
4500 (set prefixreg (add SI Rd-sfield (mul Rs-dfield (.sym BWD -size))))
4501 (set prefix-set 1)))
4505 biap-pc "biap.m ${Rs-dfield},PC"
4508 (+ Rs-dfield MODE_REGISTER R_ADDI_ACR (f-source 15))
4513 (set prefixreg (add SI (add SI pc 4) (mul Rs-dfield (.sym BWD -size))))
4514 (set prefix-set 1)))
4517 ; FIDXI [Rs] [ 0000 | 11010011 | Rs ]
4522 (+ (f-dest 0) MODE_AUTOINCREMENT INFIX_FIDXI SIZE_FIXED Rs)
4523 (set pc (c-call USI "@cpu@_fidxi_handler" pc Rs))
4526 ; FTAGI [Rs] [ 0001 | 11010011 | Rs ]
4531 (+ (f-dest 1) MODE_AUTOINCREMENT INFIX_FTAGI SIZE_FIXED Rs)
4532 (set pc (c-call USI "@cpu@_ftagi_handler" pc Rs))
4535 ; FIDXD [Rs] [ 0000 | 10101011 | Rs ]
4540 (+ (f-dest 0) MODE_INDIRECT INFIX_FIDXD SIZE_FIXED Rs)
4541 (set pc (c-call USI "@cpu@_fidxd_handler" pc Rs))
4544 ; FTAGD [Rs] [ 0001 | 10101011 | Rs ]
4549 (+ (f-dest 1) MODE_INDIRECT INFIX_FTAGD SIZE_FIXED Rs)
4550 (set pc (c-call USI "@cpu@_ftagd_handler" pc Rs))