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)
2036 ((BW tmpops) (SI newval))
2038 (set newval (ext SI tmpops))
2040 (setf-move SI newval)))
2043 (define-pmacro (dni-cdt-ubw name comment syntax fmt fsem)
2044 "Similar to dni-cdt-sbw but for unsigned operations"
2047 (.sym name .b-r) (.str "byte " comment) (.str name ".b " syntax)
2048 (.splice (.unsplice fmt) UNSIGNED_BYTE)
2051 (.sym name .w-r) (.str "word " comment) (.str name ".w " syntax)
2052 (.splice (.unsplice fmt) UNSIGNED_WORD)
2056 ; MOVU.z Rs,Rd [ Rd | 0100010z | Rs ]
2059 "movu.m ${Rs},${Rd}"
2060 (+ Rd MODE_REGISTER R_MOVX Rs)
2064 ((BW tmpops) (SI newval))
2066 (set newval (zext SI tmpops))
2068 (setf-move SI newval)))
2071 ; (MOVE.m [PC+],Rd [ Rd | 111001mm | 1111 ])
2072 ; For the moment, it doesn't seem worthwhile to make a dni-c-bwd macro;
2073 ; too many places to parametrize.
2075 movecbr "move.b [PC+],R"
2076 "move.b ${sconst8},${Rd}"
2077 (+ Rd MODE_AUTOINCREMENT INDIR_MOVE_M_R SIZE_BYTE (f-source 15) sconst8)
2080 (set newval sconst8)
2081 (set-subreg-gr QI (regno Rd) newval)
2082 (setf-move QI newval))
2086 movecwr "move.w [PC+],R"
2087 "move.w ${sconst16},${Rd}"
2088 (+ Rd MODE_AUTOINCREMENT INDIR_MOVE_M_R SIZE_WORD (f-source 15) sconst16)
2091 (set newval sconst16)
2092 (set-subreg-gr HI (regno Rd) newval)
2093 (setf-move HI newval))
2097 movecdr "move.d [PC+],R"
2098 "move.d ${const32},${Rd}"
2099 (+ Rd MODE_AUTOINCREMENT INDIR_MOVE_M_R SIZE_DWORD (f-source 15) const32)
2102 (set newval const32)
2104 (setf-move SI newval))
2107 ; (MOVS.z [PC+],Rd [ Rd | 1100011z | 1111 ])
2108 ; Similarly, no likely net improvement for a dni-c-bw.
2110 movscbr "movs.b [PC+],R"
2111 "movs.b ${sconst8},${Rd}"
2112 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX SIGNED_BYTE (f-source 15) sconst8)
2115 ; FIXME: Make trunc unnecessary.
2116 (set newval (ext SI (trunc QI sconst8)))
2118 (setf-move SI newval))
2122 movscwr "movs.w [PC+],R"
2123 "movs.w ${sconst16},${Rd}"
2124 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX SIGNED_WORD (f-source 15) sconst16)
2127 ; FIXME: Make trunc unnecessary.
2128 (set newval (ext SI (trunc HI sconst16)))
2130 (setf-move SI newval))
2133 ; (MOVU.z [PC+],Rd [ Rd | 1100010z | 1111 ])
2135 movucbr "movu.b [PC+],R"
2136 "movu.b ${uconst8},${Rd}"
2137 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX UNSIGNED_BYTE (f-source 15) uconst8)
2140 ; FIXME: Make trunc unnecessary.
2141 (set newval (zext SI (trunc QI uconst8)))
2143 (setf-move SI newval))
2147 movucwr "movu.w [PC+],R"
2148 "movu.w ${uconst16},${Rd}"
2149 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX UNSIGNED_WORD (f-source 15) uconst16)
2152 ; FIXME: Make trunc unnecessary.
2153 (set newval (zext SI (trunc HI uconst16)))
2155 (setf-move SI newval))
2158 ; ADDQ j,Rd [ Rd | 001000 | j ]
2162 (+ Rd MODE_QUICK_IMMEDIATE Q_ADDQ j)
2163 (cris-arit add SI Rd j)
2166 ; SUBQ j,Rd [ Rd | 001010| j ]
2170 (+ Rd MODE_QUICK_IMMEDIATE Q_SUBQ j)
2171 (cris-arit sub SI Rd j)
2174 ; Convenience macros for insns with a memory operand.
2176 (dni-cmt-attr-tim name comment attr syntax fmt semantics timing)
2177 "dni with memory-access"
2178 (dni name comment attr syntax
2179 ; Specifying MODE_INDIRECT and MODE_AUTOINCREMENT in this
2180 ; manner makes the autoincrementness handily available.
2181 ; It also effectively excludes non-memory use of dni-cmt.
2182 (.splice (.unsplice fmt) MODEMEMP_YES inc)
2187 (define-pmacro (dni-cmt-attr name comment attr syntax fmt semantics)
2188 "dni with read memory-access timing"
2189 (dni-cmt-attr-tim name comment attr syntax fmt semantics
2193 (define-pmacro (dni-cmwt-attr name comment attr syntax fmt semantics)
2194 "dni with write memory-access timing"
2195 (dni-cmt-attr-tim name comment attr syntax fmt semantics
2196 (cris-mem-write-timing))
2199 (define-pmacro QI-size 1)
2200 (define-pmacro HI-size 2)
2201 (define-pmacro SI-size 4)
2203 (define-pmacro (cris-get-mem size regop)
2204 "Handle reading memory in <size>, with source address register\
2205 (read once, maybe set once) in <regop> or prefixed"
2208 ((SI addr) (size tmp-mem) (BI postinc))
2210 ; Cache the incrementness of the operand.
2213 ; Get the address from somewhere.
2215 (if SI (eq prefix-set 0)
2216 ; If the insn was prefixed, it's in the prefix-register.
2220 ; Get the memory contents.
2221 (set tmp-mem (mem size addr))
2223 ; For non-prefixed post-increment, we increment the address by the
2224 ; size of the memory access.
2228 (if (eq prefix-set 0)
2229 (set addr (add addr (.sym size -size))))
2230 ; Update the source-register for post-increments.
2233 ; Don't forget the return-value.
2237 (define-pmacro (cris-set-mem size regop value)
2238 "Handle writing <value> of <size> to memory, with memory address register\
2239 (read once, maybe set once) in <regop> or prefixed."
2241 ((SI addr) (BI postinc))
2243 ; Cache the incrementness of the operand.
2246 ; Get the address from somewhere.
2248 (if SI (eq prefix-set 0)
2249 ; If the insn was prefixed, it's in the prefix-register.
2253 ; Set the memory contents. Integral-write semantics apply.
2254 ; FIXME: currently v32 only; when proper semantics needed, fix v10.
2255 (if (andif current-mach-is-v32 (ne xbit 0))
2259 (set (mem size addr) value)
2260 ; Write failures are signalled (by whatever entity "sends
2261 ; the signal") by setting P at time of the write above, if X
2262 ; is set. Here, we just need to copy P into C.
2265 (set (mem size addr) value))
2267 ; For non-prefixed post-increment, we increment the address by the
2268 ; size of the memory access. As for the integral-write, this needs to
2269 ; be tweaked for pre-v32: increment should have been performed if
2270 ; there's a fault at the memory access above.
2274 (if (eq prefix-set 0)
2275 (set addr (add addr (.sym size -size))))
2276 ; Update the source-register for post-increments.
2281 (dni-cmt-bwd-attr-tim name comment attr syntax fmt fsem timing)
2282 "Core generator macro for insns with <op>.b, <op>.w and <op>.d variants\
2283 and a memory operand."
2287 (.str "byte mem " comment)
2289 (.str name ".b " syntax)
2290 (.splice (.unsplice fmt) SIZE_BYTE)
2295 (.str "word mem " comment)
2297 (.str name ".w " syntax)
2298 (.splice (.unsplice fmt) SIZE_WORD)
2303 (.str "dword mem " comment)
2305 (.str name ".d " syntax)
2306 (.splice (.unsplice fmt) SIZE_DWORD)
2311 ; Further refinement macros.
2312 (define-pmacro (dni-cmt-bwd-attr name comment attr syntax fmt fsem)
2313 (dni-cmt-bwd-attr-tim name comment attr syntax fmt fsem
2317 (define-pmacro (dni-cmwt-bwd name comment syntax fmt fsem)
2318 (dni-cmt-bwd-attr-tim name comment () syntax fmt fsem
2319 (cris-mem-write-timing))
2322 (define-pmacro (dni-cmt-bwd name comment syntax fmt fsem)
2323 (dni-cmt-bwd-attr name comment () syntax fmt fsem)
2326 (define-pmacro (dni-cmt-sbw name comment syntax fmt fsem)
2327 "Core generator macro for insns with <op>.b and <op>.w variants\
2328 and a signed memory operand."
2331 (.sym name .b-m) (.str "byte mem " comment)
2333 (.str name ".b " syntax)
2334 (.splice (.unsplice fmt) SIGNED_BYTE)
2337 (.sym name .w-m) (.str "word mem " comment)
2339 (.str name ".w " syntax)
2340 (.splice (.unsplice fmt) SIGNED_WORD)
2344 (define-pmacro (dni-cmt-ubw name comment syntax fmt fsem)
2345 "Core generator macro for insns with <op>.b and <op>.w variants\
2346 and an unsigned memory operand."
2349 (.sym name .b-m) (.str "byte mem " comment)
2351 (.str name ".b " syntax)
2352 (.splice (.unsplice fmt) UNSIGNED_BYTE)
2355 (.sym name .w-m) (.str "word mem " comment)
2357 (.str name ".w " syntax)
2358 (.splice (.unsplice fmt) UNSIGNED_WORD)
2362 ; CMP.m Rs,Rd [ Rd | 011011mm | Rs ]
2364 cmp-r "compare register to register"
2366 (+ Rd MODE_REGISTER R_CMP Rs)
2370 sub BWD (.pmacro (sz regno val) (nop)) 0
2374 ; CMP.m [Rs],Rd [ Rd | 101011mm | Rs ]
2375 ; CMP.m [Rs+],Rd [ Rd | 111011mm | Rs ]
2377 cmp-m "compare memory to register"
2378 "[${Rs}${inc}],${Rd}"
2383 sub BWD (.pmacro (sz regno val) (nop)) 0
2384 Rd (cris-get-mem BWD Rs) cbit cbit))
2387 ; (CMP.m [PC+],Rd [ Rd | 111011mm | 1111 ])
2389 cmpcbr "cmp constant byte to register"
2390 "cmp.b $sconst8,$Rd"
2391 (+ Rd MODE_AUTOINCREMENT INDIR_CMP SIZE_BYTE (f-source 15) sconst8)
2393 sub QI (.pmacro (sz regno val) (nop)) 0
2394 Rd (trunc QI sconst8) cbit cbit)
2398 cmpcwr "cmp constant word to register"
2399 "cmp.w $sconst16,$Rd"
2400 (+ Rd MODE_AUTOINCREMENT INDIR_CMP SIZE_WORD (f-source 15) sconst16)
2402 sub HI (.pmacro (sz regno val) (nop)) 0
2403 Rd (trunc HI sconst16) cbit cbit)
2407 cmpcdr "cmp constant dword to register"
2408 "cmp.d $const32,$Rd"
2409 (+ Rd MODE_AUTOINCREMENT INDIR_CMP SIZE_DWORD (f-source 15) const32)
2411 sub SI (.pmacro (sz regno val) (nop)) 0
2412 Rd const32 cbit cbit)
2415 ; CMPQ i,Rd [ Rd | 001011 | i ]
2419 (+ Rd MODE_QUICK_IMMEDIATE Q_CMPQ i)
2421 sub SI (.pmacro (sz regno val) (nop)) 0
2425 ; CMPS.z [Rs],Rd [ Rd | 1000111z | Rs ]
2426 ; CMPS.z [Rs+],Rd [ Rd | 1100111z | Rs ]
2428 cmps-m "cmp sign-extended from memory to register"
2430 (+ Rd INDIR_CMPX Rs)
2434 sub SI (.pmacro (sz regno val) (nop)) 0
2435 Rd ((.sym BW -ext) (cris-get-mem BW Rs)) cbit cbit))
2438 ; (CMPS.z [PC+],Rd [ Rd | 1100111z | 1111 ])
2440 cmpscbr "cmp sign-extended constant byte to register"
2442 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX SIGNED_BYTE (f-source 15) sconst8)
2444 sub SI (.pmacro (sz regno val) (nop)) 0
2445 Rd (ext SI (trunc QI sconst8)) cbit cbit)
2448 cmpscwr "cmp sign-extended constant word to register"
2450 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX SIGNED_WORD (f-source 15) sconst16)
2452 sub SI (.pmacro (sz regno val) (nop)) 0
2453 Rd (ext SI (trunc HI sconst16)) cbit cbit)
2456 ; CMPU.z [Rs],Rd [ Rd | 1000110z | Rs ]
2457 ; CMPU.z [Rs+],Rd [ Rd | 1100110z | Rs ]
2459 cmpu-m "cmp zero-extended from memory to register"
2461 (+ Rd INDIR_CMPX Rs)
2465 sub SI (.pmacro (sz regno val) (nop)) 0
2466 Rd ((.sym BW -zext) (cris-get-mem BW Rs)) cbit cbit))
2469 ; (CMPU.z [PC+],Rd [ Rd | 1100110z | 1111 ])
2471 cmpucbr "cmp zero-extended constant byte to register"
2473 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX UNSIGNED_BYTE (f-source 15) uconst8)
2475 sub SI (.pmacro (sz regno val) (nop)) 0
2476 Rd (zext SI (trunc QI uconst8)) cbit cbit)
2479 cmpucwr "cmp zero-extended constant word to register"
2481 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX UNSIGNED_WORD (f-source 15) uconst16)
2483 sub SI (.pmacro (sz regno val) (nop)) 0
2484 Rd (zext SI (trunc HI uconst16)) cbit cbit)
2487 ; MOVE.m [Rs],Rd [ Rd | 101001mm | Rs ]
2488 ; MOVE.m [Rs+],Rd [ Rd | 111001mm | Rs ]
2490 move-m "move from memory to register"
2491 "[${Rs}${inc}],${Rd}"
2492 (+ INDIR_MOVE_M_R Rs Rd)
2497 (set tmp (cris-get-mem BWD Rs))
2500 (if SI (andif prefix-set (not inc)) (regno Rs) (regno Rd))
2502 (setf-move BWD tmp)))
2505 ; MOVS.z [Rs],Rd [ Rd | 1000011z | Rs ]
2506 ; MOVS.z [Rs+],Rd [ Rd | 1100011z | Rs ]
2508 movs-m "movs from memory to register"
2509 "[${Rs}${inc}],${Rd}"
2510 (+ INDIR_MOVX Rs Rd)
2515 (set tmp (ext SI (cris-get-mem BW Rs)))
2516 (if (andif prefix-set (not inc))
2519 (setf-move SI tmp)))
2522 ; MOVU.z [Rs],Rd [ Rd | 1000010z | Rs ]
2523 ; MOVU.z [Rs+],Rd [ Rd | 1100010z | Rs ]
2525 movu-m "movu from memory to register"
2526 "[${Rs}${inc}],${Rd}"
2527 (+ INDIR_MOVX Rs Rd)
2532 (set tmp (zext SI (cris-get-mem BW Rs)))
2533 (if (andif prefix-set (not inc))
2536 (setf-move SI tmp)))
2539 ; MOVE Rs,Pd [ Pd | 01100011 | Rs ]
2547 (.sym move-r-spr VER)
2548 "Move from general register to special register"
2549 ((MACH (.sym cris VER)))
2551 (+ RFIX_MOVE_R_S MODE_REGISTER SIZE_FIXED Rs Pd)
2555 (set rno (regno Pd))
2557 ; See reg-sr setter for most of the special-register semantics.
2558 ; The sanity check for known read-only registers is for program
2559 ; debug help; the real insn would be harmless and have no effect.
2560 ; CGEN-FIXME: regno of symbolic h-sr names doesn't work here.
2561 ((orif (orif (eq rno 0) (eq rno 1)) (orif (eq rno 4) (eq rno 8)))
2562 (error "move-r-spr: trying to set a read-only special register"))
2563 (else (set Pd tmp)))
2565 (cris-reg-sr-timing)))
2569 (define-pmacro (dni-cdt-ver-attr name comment fattr syntax fmt fsem)
2570 "Generator for each MACH, using default timing."
2575 (.pmacro (v) (dni-cdt-attr name comment (fattr v) syntax fmt (fsem v)))
2576 (cris-cpu-models))))
2579 ; MOVE Ps,Rd [ Ps | 01100111 | Rd ]
2580 ; Note that in the insn format, the Rd operand is in the Rs field (the
2581 ; Rd field by the definition used everywhere else is the Ps position in
2583 ; It gets a little weird here because we can't get this insn into a
2584 ; define-pmacro unless we make named pmacros for e.g. a separate attr
2585 ; function and a semantics function: a .pmacro can't refer to the
2586 ; parameters of the outer define-pmacro. (The manual refers to this as
2587 ; not implementing "lexical scoping").
2595 (.sym move-spr-r VER)
2596 "Move from special register to general register"
2597 ((MACH (.sym cris VER)))
2598 "move ${Ps},${Rd-sfield}"
2599 (+ Ps RFIX_MOVE_S_R MODE_REGISTER SIZE_FIXED Rd-sfield)
2601 ((SI grno) (SI prno) (SI newval))
2602 (set prno (regno Ps))
2603 ; CGEN-FIXME: Can't use the following and then "grno" below because
2604 ; CGEN will emit a "tmp_grno" *also* in decodev32.c:crisv32f_decode
2605 ; (set grno (regno Rd-sfield))
2613 ((eq prno (.cadr2 r))
2614 (set-subreg-gr (.car2 r) (regno Rd-sfield) newval)))
2615 ((.sym cris-implemented-readable-specregs- VER))))
2616 (else (error "move-spr-r from unimplemented register")))
2621 ; MOVE Ps,PC [ Ps | 01100111 | 1111 ]
2622 ; The move-special-register-to-pc insns are return-type instructions and
2623 ; have to be special-cased to get the delay-slot and avoid being indicated
2630 (+ Ps MODE_REGISTER RFIX_MOVE_S_R SIZE_FIXED (f-source 15))
2635 (delay 1 (set pc retaddr)))
2638 ; MOVE [Rs],Pd [ Pd | 10100011 | Rs ]
2639 ; MOVE [Rs+],Pd [ Pd | 11100011 | Rs ]
2640 ; We make variants that loads constants or memory for each MACH version,
2641 ; since each consider some subset of the "special registers" to have
2642 ; different sizes. FIXME: Should be able to simplify this.
2650 (.sym move-m-spr VER)
2651 "Move from memory to special register"
2652 ((MACH (.sym cris VER)))
2653 "move [${Rs}${inc}],${Pd}"
2654 (+ Pd INFIX_MOVE_M_S MODEMEMP_YES inc SIZE_FIXED Rs)
2656 ((SI rno) (SI newval))
2657 (set rno (regno Pd))
2660 ; No sanity check for constant special register here, since the
2661 ; memory read side-effect or post-increment may be the goal, or
2662 ; for pre-v32 a prefix assignment side-effect.
2667 ((eq rno (.cadr2 r))
2668 (set newval ((.sym (.car2 r) -ext) (cris-get-mem (.car2 r) Rs)))))
2669 ((.sym cris-implemented-writable-specregs- VER))))
2670 (else (error "Trying to set unimplemented special register")))
2673 (cris-mem-sr-timing)))
2677 (define-pmacro QI-operand sconst8)
2678 (define-pmacro HI-operand sconst16)
2679 (define-pmacro SI-operand const32)
2682 (cris-move-c-spr VER VERFN)
2683 "Generator for loading constant into special register"
2691 (.sym move-c-spr v -p (.cadr2 srdef))
2692 (.str "Move constant to special register p" (.cadr2 srdef))
2693 ((MACH (.sym cris v)))
2694 (.str "move ${" (.sym (.car2 srdef) -operand) "},${Pd}")
2695 ; We use Pd in semantics without naming it in the format (which
2696 ; would CGEN-FIXME: cause a CGEN error for some reason, likely
2697 ; related to specifying an insn field multiple times). This
2698 ; currently works and is guarded with test-cases (specifically
2699 ; wrt. the timing model) but may need to be tweaked in the future.
2700 ; Note that using instead (ifield f-dest) causes incorrect timing
2701 ; model to be generated; the timing model requires that Pd is set.
2702 (+ (f-dest (.cadr2 srdef)) MODE_AUTOINCREMENT INFIX_MOVE_M_S SIZE_FIXED
2703 (f-source 15) (.sym (.car2 srdef) -operand))
2706 (set Pd (.sym (.car2 srdef) -operand)) ; (reg h-sr (.cadr2 srdef))
2708 ((.sym cris-timing-const-sr- (.car2 srdef)))))
2709 ((.sym cris-implemented-specregs-const- VER))
2710 (.map VERFN ((.sym cris-implemented-specregs-const- VER))))))
2714 ; Unfortunately we can't iterate over the list of models due to the
2715 ; problem with referring to the parameters of a surrounding pmacro from
2716 ; within an enclosed .pmacro (perhaps related to "lexical scoping").
2717 ; We get e.g. 'insn already defined:: (move-c-sprvn-p0)' with this:
2719 ; begin (.unsplice (.map (.pmacro (vn) (cris-move-c-spr vn (.pmacro (x) vn)))
2720 ; (cris-cpu-models)))
2722 (cris-move-c-spr v0 (.pmacro (x) v0))
2723 (cris-move-c-spr v3 (.pmacro (x) v3))
2724 (cris-move-c-spr v8 (.pmacro (x) v8))
2725 (cris-move-c-spr v10 (.pmacro (x) v10))
2726 (cris-move-c-spr v32 (.pmacro (x) v32))
2728 ; MOVE Ps,[Rd] [ Ps | 10100111 | Rd ]
2729 ; MOVE Ps,[Rd+] [ Ps | 11100111 | Rd ]
2737 (.sym move-spr-m VER)
2738 "Move from special register to memory"
2739 ((MACH (.sym cris VER)))
2740 "move ${Ps},[${Rd-sfield}${inc}]"
2741 (+ INFIX_MOVE_S_M SIZE_FIXED Rd-sfield Ps)
2744 (set rno (regno Ps))
2751 ((eq rno (.cadr2 r))
2752 (cris-set-mem (.car2 r) Rd-sfield Ps)))
2753 ((.sym cris-implemented-readable-specregs- VER))))
2754 (else (error "write from unimplemented special register")))
2760 ; Instruction format: |0 0 1 1 1 m 1 1 0 1 1 1| Dest. |
2765 "sbfs [${Rd-sfield}${inc}]"
2766 (+ (f-dest 3) INFIX_SBFS SIZE_FIXED MODEMEMP_YES inc Rd-sfield)
2767 (error "SBFS isn't implemented")
2770 ; MOVE Ss,Rd [ Ss | 11110111 | Rd ]
2773 "move from support register to general register"
2775 "move ${Ss},${Rd-sfield}"
2776 (+ Ss INFIX_MOVE_SS SIZE_FIXED (f-mode 3) Rd-sfield)
2783 ; MOVE Rs,Sd [ Sd | 10110111 | Rs ]
2786 "move from general register to support register"
2789 (+ Sd INFIX_MOVE_SS SIZE_FIXED (f-mode 2) Rs)
2796 ; MOVEM Rs,[Rd] [ Rs | 10111111 | Rd ]
2797 ; MOVEM Rs,[Rd+] [ Rs | 11111111 | Rd ]
2799 (define-pmacro (movem-to-mem-step regn)
2800 ; Without the SI attribute, UINT is generated, which isn't supported by
2801 ; the sim framework.
2802 (if (ge SI (regno Rs-dfield) regn)
2805 (set tmp (reg h-gr regn))
2806 (set (mem SI addr) tmp)
2807 (set addr (add addr 4))))
2814 "movem ${Rs-dfield},[${Rd-sfield}${inc}]"
2815 (+ INFIX_MOVEM_R_M MODEMEMP_YES inc SIZE_FIXED Rs-dfield Rd-sfield)
2817 ((SI addr) (BI postinc))
2818 ; FIXME: A copy of what's in cris-get-mem.
2820 ; Cache the incrementness of the operand.
2823 ; CGEN-FIXME: Kludge to work around a CGEN bug: it doesn't see that
2824 ; Rs-dfield is used as an input, causing the timing model to be wrong.
2825 (sequence ((SI dummy)) (set dummy Rs-dfield))
2827 ; Get the address from somewhere. If the insn was prefixed, it's in
2828 ; the prefix-register.
2830 (if SI (eq prefix-set 0)
2836 (.unsplice (.map movem-to-mem-step (.iota 16 15 -1))))
2838 ; Update the source-register for post-increments.
2841 (if SI (eq prefix-set 0) addr prefixreg)))
2843 (simplecris-movem-timing)
2850 "movem ${Rs-dfield},[${Rd-sfield}${inc}]"
2851 (+ INFIX_MOVEM_R_M MODEMEMP_YES inc SIZE_FIXED Rs-dfield Rd-sfield)
2853 ((SI addr) (BI postinc))
2854 ; FIXME: Mostly a copy of what's in cris-get-mem.
2856 ; Cache the incrementness of the operand.
2859 ; CGEN-FIXME: See movem-r-m.
2860 (sequence ((SI dummy)) (set dummy Rs-dfield))
2862 (set addr Rd-sfield)
2866 (.unsplice (.map movem-to-mem-step (.iota 16))))
2868 ; Update the source-register for post-increments.
2870 (set Rd-sfield addr))
2872 ; Unit u-mem must be specified before the u-movem-* for memory address
2873 ; register stall count to be right.
2874 ((crisv32 (unit u-mem) (unit u-movem-rtom) (unit u-exec-movem)
2878 ; MOVEM [Rs],Rd [ Rd | 10111011 | Rs ]
2879 ; MOVEM [Rs+],Rd [ Rd | 11111011 | Rs ]
2882 (movem-to-reg-step regn)
2883 ; Without the SI attribute, UINT is generated, which isn't supported by
2884 ; the sim framework.
2885 (if (ge SI (regno Rd) regn)
2888 (set tmp (mem SI addr))
2889 (set (reg h-gr regn) tmp)
2890 (set addr (add addr 4))))
2897 "movem [${Rs}${inc}],${Rd}"
2898 (+ Rd INFIX_MOVEM_M_R MODEMEMP_YES inc SIZE_FIXED Rs)
2900 ((SI addr) (BI postinc))
2901 ; FIXME: Mostly a copy of what's in cris-get-mem.
2903 ; Cache the incrementness of the operand.
2906 ; Get the address from somewhere. If the insn was prefixed, it's in
2907 ; the prefix-register.
2909 (if SI (eq prefix-set 0)
2913 ; CGEN-FIXME: See movem-r-m.
2914 (sequence ((SI dummy)) (set dummy Rd))
2918 ; The first movem step is left out because it can't happen; it's for
2919 ; PC destination. See the pattern below.
2920 (.unsplice (.map movem-to-reg-step (.iota 15 14 -1))))
2922 ; Update the source-register for post-increments.
2923 ; FIXME: No postinc-prefixed for v0 IIRC.
2925 (set Rs (if SI (eq prefix-set 0) addr prefixreg)))
2927 (simplecris-movem-timing)
2930 ; (MOVEM [Rs],PC [ 1111 | 10111011 | Rs ])
2931 ; (MOVEM [Rs+],PC [ 1111 | 11111011 | Rs ])
2932 ; We have to special-case it for PC destination; used in longjump.
2933 ; We shouldn't *have* to special-case it; the main reason is (FIXME:)
2934 ; misgeneration of the simulator when the PC case is folded into the
2935 ; generic PRE-V32 movem; possibly related to then being a COND-CTI rather
2936 ; than an UNCOND-CTI.
2939 "movem to register, ending with PC"
2941 "movem [${Rs}${inc}],${Rd}"
2942 (+ (f-dest 15) INFIX_MOVEM_M_R SIZE_FIXED Rs)
2944 ((SI addr) (BI postinc))
2945 ; FIXME: Mostly a copy of what's in cris-get-mem.
2947 ; Cache the incrementness of the operand.
2950 ; Get the address from somewhere. If the insn was prefixed, it's in
2951 ; the prefix-register.
2953 (if SI (eq prefix-set 0)
2957 ; FIXME: Add kludge here too *and* a test-case.
2961 ; The first movem step is for PC destination, used in longjmp.
2962 (set pc (mem SI addr))
2963 (set addr (add addr 4))
2970 (set tmp (mem SI addr))
2971 (set (reg h-gr regn) tmp)
2972 (set addr (add addr 4))))
2975 ; Update the source-register for post-increments.
2976 ; FIXME: No postinc-prefixed for v0.
2978 (set Rs (if SI (eq prefix-set 0) addr prefixreg)))
2986 "movem [${Rs}${inc}],${Rd}"
2987 (+ INFIX_MOVEM_M_R MODEMEMP_YES inc SIZE_FIXED Rs Rd)
2989 ((SI addr) (BI postinc))
2990 ; FIXME: A copy of what's in cris-get-mem
2992 ; Cache the incrementness of the operand.
2995 ; Get the address from somewhere.
2998 ; CGEN-FIXME: See movem-r-m.
2999 (sequence ((SI dummy)) (set dummy Rd))
3003 (.unsplice (.map movem-to-reg-step (.iota 16))))
3005 ; Update the source-register for post-increments.
3006 ; FIXME: No postinc-prefixed for v0 IIRC.
3010 ; u-mem must be specified before the u-movem-* for memory source
3011 ; register stall count to be right.
3012 ((crisv32 (unit u-mem) (unit u-mem-r) (unit u-movem-mtor)
3013 (unit u-exec-movem)))
3016 ; ADD.m Rs,Rd [ Rd | 011000mm | Rs ]
3018 add "add from register to register"
3020 (+ Rd MODE_REGISTER R_ADD Rs)
3021 (.pmacro (BWD) (cris-arit add BWD Rd Rs))
3024 ; ADD.m [Rs],Rd [ Rd | 101000mm | Rs ]
3025 ; ADD.m [Rs+],Rd [ Rd | 111000mm | Rs ]
3027 add-m "add from memory to register"
3028 "[${Rs}${inc}],${Rd}"
3030 (.pmacro (BWD) (cris-arit-3op add BWD Rd (cris-get-mem BWD Rs) Rs))
3032 ; (ADD.m [PC+],Rd [ Rd | 111000mm | 1111 ])
3034 addcbr "add constant byte to register"
3035 "add.b ${sconst8}],${Rd}"
3036 (+ Rd MODE_AUTOINCREMENT INDIR_ADD SIZE_BYTE (f-source 15) sconst8)
3037 (cris-arit add QI Rd sconst8)
3041 addcwr "add constant word to register"
3042 "add.w ${sconst16}],${Rd}"
3043 (+ Rd MODE_AUTOINCREMENT INDIR_ADD SIZE_WORD (f-source 15) sconst16)
3044 (cris-arit add HI Rd sconst16)
3048 addcdr "add constant dword to register"
3049 "add.d ${const32}],${Rd}"
3050 (+ Rd MODE_AUTOINCREMENT INDIR_ADD SIZE_DWORD (f-source 15) const32)
3051 (cris-arit add SI Rd const32)
3054 ; (ADD.D [PC+],PC [ 1111 | 11100010 | 1111 ])
3055 ; This insn is used for DSO-local jumps in PIC code.
3057 addcpc "Relative jump by adding constant to PC"
3059 "add.d ${sconst32},PC"
3060 (+ (f-dest 15) MODE_AUTOINCREMENT INDIR_ADD SIZE_DWORD (f-source 15) const32)
3062 ((SI newpc) (SI oldpc) (SI offs))
3064 (set oldpc (add SI pc 6))
3065 (set newpc (add SI oldpc offs))
3067 (setf-arit SI add oldpc offs newpc cbit))
3068 (simplecris-common-timing ((unit u-const32) (unit u-stall) (unit u-exec)))
3071 ; ADDS.z Rs,Rd [ Rd | 0100001z | Rs ]
3073 adds "add sign-extended from register to register"
3075 (+ Rd MODE_REGISTER R_ADDX Rs)
3076 (.pmacro (BW) (cris-arit add SI Rd ((.sym BW -ext) (trunc BW Rs))))
3079 ; ADDS.z [Rs],Rd [ Rd | 1000001z | Rs ]
3080 ; ADDS.z [Rs+],Rd [ Rd | 1100001z | Rs ]
3082 adds-m "add sign-extended from memory to register"
3084 (+ Rd INDIR_ADDX Rs)
3085 (.pmacro (BW) (cris-arit-3op add SI Rd ((.sym BW -ext) (cris-get-mem BW Rs)) Rs))
3088 ; (ADDS.z [PC+],Rd [ Rd | 1100001z | 1111 ])
3090 addscbr "add sign-extended constant byte to register"
3092 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX SIGNED_BYTE (f-source 15) sconst8)
3093 (cris-arit add SI Rd (ext SI (trunc QI sconst8)))
3096 addscwr "add sign-extended constant word to register"
3098 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX SIGNED_WORD (f-source 15) sconst16)
3099 (cris-arit add SI Rd (ext SI (trunc HI sconst16)))
3102 ; (ADDS.w [],PC [ 1111 | 10000011 | 1111 ])
3103 ; For a PC destination, we support only the two-operand case
3104 ; (dest == src), which is used in switch/case statements.
3105 ; FIXME: Should implement ADD.D [PC],PC and ADDS.B [PC],PC for use if/when
3106 ; implementing CASE_VECTOR_SHORTEN_MODE.
3108 addspcpc "add sign-extended prefixed arg to PC"
3111 (+ (f-dest 15) MODE_INDIRECT INDIR_ADDX SIGNED_WORD (f-source 15))
3113 ((SI newpc) (SI oldpc) (HI offs))
3114 (if (not prefix-set)
3115 (error "Unexpected adds.w [PC],PC without prefix"))
3116 ; We don't use cris-get-mem but instead special-case this one, since we
3117 ; have most instruction fields fixed where cris-get-mem expects
3118 ; field-parametrization by certain names.
3119 (set offs (mem HI prefixreg))
3120 (set oldpc (add SI pc 2))
3121 (set newpc (add SI oldpc offs))
3123 (setf-arit SI add oldpc (ext SI offs) newpc cbit))
3124 (simplecris-common-timing ((unit u-mem) (unit u-stall) (unit u-exec)))
3127 ; ADDU.z Rs,Rd [ Rd | 0100000z | Rs ]
3129 addu "add zero-extended from register to register"
3131 (+ Rd MODE_REGISTER R_ADDX Rs)
3132 (.pmacro (BW) (cris-arit add SI Rd ((.sym BW -zext) (trunc BW Rs))))
3135 ; ADDU.z [Rs],Rd [ Rd | 1000000z | Rs ]
3136 ; ADDU.z [Rs+],Rd [ Rd | 1100000z | Rs ]
3138 addu-m "add zero-extended from memory to register"
3140 (+ Rd INDIR_ADDX Rs)
3142 (cris-arit-3op add SI Rd ((.sym BW -zext) (cris-get-mem BW Rs)) Rs))
3145 ; (ADDU.z [PC+],Rd [ Rd | 1100000z | 1111 ])
3147 adducbr "add zero-extended constant byte to register"
3149 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX UNSIGNED_BYTE (f-source 15) sconst8)
3150 (cris-arit add SI Rd (zext SI (trunc QI sconst8)))
3153 adducwr "add zero-extended constant word to register"
3155 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX UNSIGNED_WORD (f-source 15) sconst16)
3156 (cris-arit add SI Rd (zext SI (trunc HI sconst16)))
3159 ; SUB.m Rs,Rd [ Rd | 011010mm | Rs ]
3161 sub "subtract from register to register"
3163 (+ Rd MODE_REGISTER R_SUB Rs)
3164 (.pmacro (BWD) (cris-arit sub BWD Rd Rs))
3167 ; SUB.m [Rs],Rd [ Rd | 101010mm | Rs ]
3168 ; SUB.m [Rs+],Rd [ Rd | 111010mm | Rs ]
3170 sub-m "subtract from memory to register"
3171 "[${Rs}${inc}],${Rd}"
3173 (.pmacro (BWD) (cris-arit-3op sub BWD Rd (cris-get-mem BWD Rs) Rs))
3176 ; (SUB.m [PC+],Rd [ Rd | 111010mm | 1111 ]
3178 subcbr "subtract constant byte from register"
3179 "sub.b ${sconst8}],${Rd}"
3180 (+ Rd MODE_AUTOINCREMENT INDIR_SUB SIZE_BYTE (f-source 15) sconst8)
3181 (cris-arit sub QI Rd sconst8)
3185 subcwr "subtract constant word from register"
3186 "sub.w ${sconst16}],${Rd}"
3187 (+ Rd MODE_AUTOINCREMENT INDIR_SUB SIZE_WORD (f-source 15) sconst16)
3188 (cris-arit sub HI Rd sconst16)
3192 subcdr "subtract constant dword from register"
3193 "sub.d ${const32}],${Rd}"
3194 (+ Rd MODE_AUTOINCREMENT INDIR_SUB SIZE_DWORD (f-source 15) const32)
3195 (cris-arit sub SI Rd const32)
3198 ; SUBS.z Rs,Rd [ Rd | 0100101z | Rs ]
3200 subs "sub sign-extended from register to register"
3202 (+ Rd MODE_REGISTER R_SUBX Rs)
3203 (.pmacro (BW) (cris-arit sub SI Rd ((.sym BW -ext) (trunc BW Rs))))
3206 ; SUBS.z [Rs],Rd [ Rd | 1000101z | Rs ]
3207 ; SUBS.z [Rs+],Rd [ Rd | 1100101z | Rs ]
3209 subs-m "sub sign-extended from memory to register"
3211 (+ Rd INDIR_SUBX Rs)
3213 (cris-arit-3op sub SI Rd ((.sym BW -ext) (cris-get-mem BW Rs)) Rs))
3216 ; (SUBS.z [PC+],Rd [ Rd | 1100101z | 1111 ])
3218 subscbr "sub sign-extended constant byte to register"
3220 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX SIGNED_BYTE (f-source 15) sconst8)
3221 (cris-arit sub SI Rd (ext SI (trunc QI sconst8)))
3224 subscwr "sub sign-extended constant word to register"
3226 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX SIGNED_WORD (f-source 15) sconst16)
3227 (cris-arit sub SI Rd (ext SI (trunc HI sconst16)))
3230 ; SUBU.z Rs,Rd [ Rd | 0100100z | Rs ]
3232 subu "sub zero-extended from register to register"
3234 (+ Rd MODE_REGISTER R_SUBX Rs)
3235 (.pmacro (BW) (cris-arit sub SI Rd ((.sym BW -zext) (trunc BW Rs))))
3238 ; SUBU.z [Rs],Rd [ Rd | 1000100z | Rs ]
3239 ; SUBU.z [Rs+],Rd [ Rd | 1100100z | Rs ]
3241 subu-m "sub zero-extended from memory to register"
3243 (+ Rd INDIR_SUBX Rs)
3245 (cris-arit-3op sub SI Rd ((.sym BW -zext) (cris-get-mem BW Rs)) Rs))
3248 ; (SUBU.z [PC+],Rd [ Rd | 1100100z | 1111 ])
3250 subucbr "sub zero-extended constant byte to register"
3252 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX UNSIGNED_BYTE (f-source 15) sconst8)
3253 (cris-arit sub SI Rd (zext SI (trunc QI sconst8)))
3256 subucwr "sub zero-extended constant word to register"
3258 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX UNSIGNED_WORD (f-source 15) sconst16)
3259 (cris-arit sub SI Rd (zext SI (trunc HI sconst16)))
3262 ; ADDC Rs,Rd [ Rd | 01010111 | Rs ]
3264 addc-r "addc from register to register"
3267 (+ Rd MODE_REGISTER RFIX_ADDC SIZE_FIXED Rs)
3268 ; Since this is equivalent to "ax" plus "add.d Rs,Rd", we'll just do
3269 ; that, semantically.
3273 (cris-arit add SI Rd Rs))
3276 ; ADDC [Rs],Rd [ Rd | 10011010 | Rs ]
3277 ; ADDC [Rs+],Rd [ Rd | 11011010 | Rs ]
3279 addc-m "addc from memory to register"
3281 "addc [${Rs}${inc}],${Rd}"
3282 (+ Rd INDIR_ADDC SIZE_DWORD Rs)
3286 (cris-arit add SI Rd (cris-get-mem SI Rs)))
3289 ; (ADDC [Rs+],Rd [ Rd | 11011010 | 1111 ])
3291 addc-c "addc constant to register"
3293 "addc ${const32},${Rd}"
3294 (+ Rd MODE_AUTOINCREMENT INDIR_ADDC SIZE_DWORD (f-source 15) const32)
3298 (cris-arit add SI Rd const32))
3301 ; LAPC [PC+],Rd [ Rd | 11010111 1111 ]
3305 "lapc.d ${const32-pcrel},${Rd}"
3306 (+ Rd MODE_AUTOINCREMENT INFIX_LAPC SIZE_FIXED (f-source 15) const32-pcrel)
3309 (set Rd const32-pcrel)
3313 ; LAPCQ qo,Rd [ Rd | 10010111 | qo ]
3318 (+ Rd MODE_INDIRECT INFIX_LAPC SIZE_FIXED qo)
3325 ; ADDI Rs.m,Rd [ Rs | 010100mm | Rd ]
3328 "${Rs-dfield}.m,${Rd-sfield}"
3329 (+ Rd-sfield MODE_REGISTER R_ADDI Rs-dfield)
3334 (set Rd-sfield (add SI Rd-sfield (mul Rs-dfield (.sym BWD -size))))
3338 ; NEG.m Rs,Rd [ Rd | 010110mm | Rs ]
3342 (+ Rd MODE_REGISTER R_NEG Rs)
3343 (.pmacro (BWD) (cris-arit3 sub BWD Rd 0 Rs))
3346 ; TEST.m [Rs] [ 0000101110mm | Rs ]
3347 ; TEST.m [Rs+] [ 0000111110mm | Rs ]
3349 test-m "test.m [Rs(+)]"
3351 (+ (f-dest 0) INDIR_TEST Rs)
3356 (set tmpd (cris-get-mem BWD Rs))
3357 ; This is supposed to be the same result as for cmpq 0,X, hence same code.
3359 sub BWD (.pmacro (sz regno val) (nop)) 0 tmpd 0 cbit cbit)))
3362 ; MOVE.m Rs,[Rd] [ Rs | 101111mm | Rd ]
3363 ; MOVE.m Rs,[Rd+] [ Rs | 111111mm | Rd ]
3366 move-r-m "move.m R,[]"
3367 "${Rs-dfield},[${Rd-sfield}${inc}]"
3368 (+ Rs-dfield INDIR_MOVE_R_M Rd-sfield)
3373 (set tmpd Rs-dfield)
3374 (cris-set-mem BWD Rd-sfield tmpd)
3378 ; MULS.m Rs,Rd [ Rd | 110100mm | Rs ]
3381 ((MACH crisv10,crisv32))
3383 (+ Rd MODE_MULS INDIR_MUL Rs)
3387 ((DI src1) (DI src2) (DI tmpr))
3388 (set src1 (ext DI (trunc BWD Rs)))
3389 (set src2 (ext DI (trunc BWD Rd)))
3390 (set tmpr (mul src1 src2))
3391 (set Rd (trunc SI tmpr))
3392 (set mof (trunc SI (srl tmpr 32)))
3393 (setf-arit DI muls src1 src2 tmpr cbit)))
3394 ((crisv10 (unit u-multiply) (unit u-exec))
3395 (crisv32 (unit u-multiply) (unit u-exec)))
3398 ; MULU.m Rs,Rd [ Rd | 100100mm | Rs ]
3401 ((MACH crisv10,crisv32))
3403 (+ Rd MODE_MULU INDIR_MUL Rs)
3407 ((DI src1) (DI src2) (DI tmpr))
3408 (set src1 (zext DI (trunc BWD Rs)))
3409 (set src2 (zext DI (trunc BWD Rd)))
3410 (set tmpr (mul src1 src2))
3411 (set Rd (trunc SI tmpr))
3412 (set mof (trunc SI (srl tmpr 32)))
3413 (setf-arit DI mulu src1 src2 tmpr cbit)))
3414 ((crisv10 (unit u-multiply) (unit u-exec))
3415 (crisv32 (unit u-multiply) (unit u-exec)))
3418 ; MCP Ps,Rd [ Ps | 01111111 | Rd ]
3420 mcp "Multiply Carry Propagation"
3423 (+ Ps MODE_REGISTER RFIX_MCP SIZE_FIXED Rd-sfield)
3428 (cris-arit5 add SI Rd-sfield Rd-sfield Ps rbit rbit))
3431 ; MSTEP Rs,Rd [ Rd | 01111111 | Rs ]
3433 mstep "Multiply step"
3436 (+ Rd MODE_REGISTER RFIX_MSTEP SIZE_FIXED Rs)
3438 ((SI tmpd) (SI tmps))
3440 (set tmpd (add (sll Rd 1) (if SI nbit tmps 0)))
3442 (setf-move SI tmpd))
3445 ; DSTEP Rs,Rd [ Rd | 01101111 | Rs ]
3447 dstep "Division step"
3449 (+ Rd MODE_REGISTER RFIX_DSTEP SIZE_FIXED Rs)
3451 ((SI tmp) (SI tmps) (SI tmpd))
3453 (set tmp (sll Rd 1))
3454 (set tmpd (if SI (geu tmp tmps) (sub tmp tmps) tmp))
3456 (setf-move SI tmpd))
3459 ; ABS Rs,Rd [ Rd | 01101011 | Rs ]
3461 abs "Absolut Instruction"
3463 (+ Rd MODE_REGISTER RFIX_ABS SIZE_FIXED Rs)
3468 (setf-move SI tmpd))
3471 ; AND.m Rs,Rd [ Rd | 011100mm | Rs ]
3473 and "And from register to register"
3475 (+ Rd MODE_REGISTER R_AND Rs)
3480 (set tmpd (and BWD Rd Rs))
3481 (set-subreg-gr BWD (regno Rd) tmpd)
3482 (setf-move BWD tmpd)))
3485 ; AND.m [Rs],Rd [ Rd | 101100mm | Rs ]
3486 ; AND.m [Rs+],Rd [ Rd | 111100mm | Rs ]
3488 and-m "And from memory to register"
3489 "[${Rs}${inc}],${Rd}"
3495 (set tmpd (and BWD Rd (cris-get-mem BWD Rs)))
3498 (if SI (andif prefix-set (not inc)) (regno Rs) (regno Rd))
3500 (setf-move BWD tmpd)))
3503 ; (AND.m [PC+],Rd [ Rd | 111100mm | 1111 ])
3505 andcbr "And constant byte to register"
3506 "and.b ${sconst8}],${Rd}"
3507 (+ Rd MODE_AUTOINCREMENT INDIR_AND SIZE_BYTE (f-source 15) sconst8)
3510 (set tmpd (and QI Rd sconst8))
3511 (set-subreg-gr QI (regno Rd) tmpd)
3512 (setf-move QI tmpd))
3516 andcwr "And constant word to register"
3517 "and.w ${sconst16}],${Rd}"
3518 (+ Rd MODE_AUTOINCREMENT INDIR_AND SIZE_WORD (f-source 15) sconst16)
3521 (set tmpd (and HI Rd sconst16))
3522 (set-subreg-gr HI (regno Rd) tmpd)
3523 (setf-move HI tmpd))
3527 andcdr "And constant dword to register"
3528 "and.d ${const32}],${Rd}"
3529 (+ Rd MODE_AUTOINCREMENT INDIR_AND SIZE_DWORD (f-source 15) const32)
3532 (set tmpd (and SI Rd const32))
3533 (set-subreg-gr SI (regno Rd) tmpd)
3534 (setf-move SI tmpd))
3537 ; ANDQ i,Rd [ Rd | 001100 | i ]
3539 andq "And quick-immediate to register"
3541 (+ Rd MODE_QUICK_IMMEDIATE Q_ANDQ i)
3544 (set tmpd (and SI Rd i))
3545 (set-subreg-gr SI (regno Rd) tmpd)
3546 (setf-move SI tmpd))
3549 ; OR.m Rs,Rd [ Rd | 011101mm | Rs ]
3551 orr "Or from register to register"
3553 (+ Rd MODE_REGISTER R_OR Rs)
3558 (set tmpd (or BWD Rd Rs))
3559 (set-subreg-gr BWD (regno Rd) tmpd)
3560 (setf-move BWD tmpd)))
3563 ; OR.m [Rs],Rd [ Rd | 101101mm | Rs ]
3564 ; OR.m [Rs+],Rd [ Rd | 111101mm | Rs ]
3566 or-m "Or from memory to register"
3567 "[${Rs}${inc}],${Rd}"
3573 (set tmpd (or BWD Rd (cris-get-mem BWD Rs)))
3576 (if SI (andif prefix-set (not inc)) (regno Rs) (regno Rd))
3578 (setf-move BWD tmpd)))
3581 ; (OR.m [PC+],Rd [ Rd | 111101mm | 1111 ])
3583 orcbr "Or constant byte to register"
3584 "or.b ${sconst8}],${Rd}"
3585 (+ Rd MODE_AUTOINCREMENT INDIR_OR SIZE_BYTE (f-source 15) sconst8)
3588 (set tmpd (or QI Rd sconst8))
3589 (set-subreg-gr QI (regno Rd) tmpd)
3590 (setf-move QI tmpd))
3594 orcwr "Or constant word to register"
3595 "or.w ${sconst16}],${Rd}"
3596 (+ Rd MODE_AUTOINCREMENT INDIR_OR SIZE_WORD (f-source 15) sconst16)
3599 (set tmpd (or HI Rd sconst16))
3600 (set-subreg-gr HI (regno Rd) tmpd)
3601 (setf-move HI tmpd))
3605 orcdr "Or constant dword to register"
3606 "or.d ${const32}],${Rd}"
3607 (+ Rd MODE_AUTOINCREMENT INDIR_OR SIZE_DWORD (f-source 15) const32)
3610 (set tmpd (or SI Rd const32))
3611 (set-subreg-gr SI (regno Rd) tmpd)
3612 (setf-move SI tmpd))
3615 ; ORQ i,Rd [ Rd | 001101 | i ]
3617 orq "Or quick-immediate to register"
3619 (+ Rd MODE_QUICK_IMMEDIATE Q_ORQ i)
3622 (set tmpd (or SI Rd i))
3623 (set-subreg-gr SI (regno Rd) tmpd)
3624 (setf-move SI tmpd))
3627 ; XOR Rs,Rd [ Rd | 01111011 | Rs ]
3629 xor "Xor from register to register"
3631 (+ Rd MODE_REGISTER RFIX_XOR SIZE_FIXED Rs)
3634 (set tmpd (xor SI Rd Rs))
3636 (setf-move SI tmpd))
3639 (define-pmacro (swap-r x)
3640 "Perform bit-wise swap within each byte"
3645 (or (sll (and tmpr #x1010101) 7)
3646 (or (sll (and tmpr #x2020202) 5)
3647 (or (sll (and tmpr #x4040404) 3)
3648 (or (sll (and tmpr #x8080808) 1)
3649 (or (srl (and tmpr #x10101010) 1)
3650 (or (srl (and tmpr #x20202020) 3)
3651 (or (srl (and tmpr #x40404040) 5)
3652 (srl (and tmpr #x80808080) 7)))))))))
3655 (define-pmacro (swap-b x)
3656 "Perform byte-wise swap within each word"
3661 (or (and (sll tmpb 8) #xff00ff00)
3662 (and (srl tmpb 8) #xff00ff)))
3665 (define-pmacro (swap-w x)
3666 "Perform word-wise swap within each dword"
3671 (or (and (sll tmpb 16) #xffff0000)
3672 (and (srl tmpb 16) #xffff)))
3675 (define-pmacro (swap-_ x)
3676 "Do nothing swap-wise"
3677 (error SI "SWAP without swap modifier isn't implemented")
3680 (define-pmacro (swap-n x)
3681 "Perform bitwise not (that is, perform a not, not not perform)"
3685 (define-pmacro (swap-br x) "Combine swap-r and swap-b" (swap-r (swap-b x)))
3686 (define-pmacro (swap-wr x) "Combine swap-r and swap-w" (swap-r (swap-w x)))
3687 (define-pmacro (swap-wb x) "Combine swap-b and swap-w" (swap-b (swap-w x)))
3688 (define-pmacro (swap-wbr x) "Combine swap-r and swap-wb" (swap-r (swap-wb x)))
3689 (define-pmacro (swap-nr x) "Combine swap-r and swap-n" (swap-r (swap-n x)))
3690 (define-pmacro (swap-nb x) "Combine swap-n and swap-b" (swap-b (swap-n x)))
3691 (define-pmacro (swap-nbr x) "Combine swap-r and swap-nb" (swap-r (swap-nb x)))
3692 (define-pmacro (swap-nw x) "Combine swap-n and swap-w" (swap-w (swap-n x)))
3693 (define-pmacro (swap-nwr x) "Combine swap-r and swap-nw" (swap-r (swap-nw x)))
3694 (define-pmacro (swap-nwb x) "Combine swap-b and swap-nw" (swap-b (swap-nw x)))
3695 (define-pmacro (swap-nwbr x) "Combine swap-r and swap-nwb" (swap-r (swap-nwb x)))
3697 (define-pmacro (cris-swap swapcode val)
3700 ((SI tmpcode) (SI tmpval) (SI tmpres))
3701 (set tmpcode swapcode)
3709 ((eq tmpcode x-swapcode)
3710 (set tmpres ((.sym swap- x-swap) tmpval))))
3712 (.splice _ (.unsplice cris-swap-codes)))))
3716 ; NOT Rd alias for SWAPN Rd
3719 ((MACH crisv0,crisv3))
3721 (+ (f-dest 8) RFIX_SWAP MODE_REGISTER SIZE_FIXED Rd-sfield)
3723 ((SI tmp) (SI tmpd))
3725 (set tmpd (cris-swap 8 tmp))
3726 (set Rd-sfield tmpd)
3727 (setf-move SI tmpd))
3730 ; SWAP<option> Rd [ N W B R | 01110111 | Rd ]
3733 ((MACH crisv8,crisv10,crisv32))
3734 "swap${swapoption} ${Rs}"
3735 (+ swapoption RFIX_SWAP MODE_REGISTER SIZE_FIXED Rd-sfield)
3737 ((SI tmps) (SI tmpd))
3738 (set tmps Rd-sfield)
3739 (set tmpd (cris-swap swapoption tmps))
3740 (set Rd-sfield tmpd)
3741 (setf-move SI tmpd))
3744 ; ASR.m Rs,Rd [ Rd | 011110mm | Rs ]
3746 asrr "Arithmetic shift right register count"
3748 (+ Rd MODE_REGISTER R_ASR Rs)
3752 ((BWD tmpd) (SI cnt1) (SI cnt2))
3754 (set cnt2 (if SI (ne (and cnt1 32) 0) 31 (and cnt1 31)))
3755 (set tmpd (sra SI (ext SI (trunc BWD Rd)) cnt2))
3756 (set-subreg-gr BWD (regno Rd) tmpd)
3757 (setf-move BWD tmpd)))
3760 ; ASRQ c,Rd [ Rd | 0011101 | c ]
3762 asrq "Arithmetic shift right quick-immediate count"
3764 (+ Rd Q_ASHQ MODE_QUICK_IMMEDIATE (f-b5 1) c)
3767 (set tmpd (sra Rd c))
3769 (setf-move SI tmpd))
3772 ; LSR.m Rs,Rd [ Rd | 011111mm | Rs ]
3774 lsrr "Logical shift right register count"
3776 (+ Rd MODE_REGISTER R_LSR Rs)
3780 ((SI tmpd) (SI cnt))
3781 (set cnt (and Rs 63))
3784 (if SI (ne (and cnt 32) 0)
3786 (srl SI (zext SI (trunc BWD Rd)) (and cnt 31))))
3787 (set-subreg-gr BWD (regno Rd) tmpd)
3788 (setf-move BWD tmpd)))
3791 ; LSRQ c,Rd [ Rd | 0011111 | c ]
3793 lsrq "Logical shift right quick-immediate count"
3795 (+ Rd Q_LSHQ MODE_QUICK_IMMEDIATE (f-b5 1) c)
3798 (set tmpd (srl Rd c))
3800 (setf-move SI tmpd))
3803 ; LSL.m Rs,Rd [ Rd | 010011mm | Rs ]
3805 lslr "Logical shift left register count"
3807 (+ Rd MODE_REGISTER R_LSL Rs)
3811 ((SI tmpd) (SI cnt))
3812 (set cnt (and Rs 63))
3815 (if SI (ne (and cnt 32) 0)
3817 (sll SI (zext SI (trunc BWD Rd)) (and cnt 31))))
3818 (set-subreg-gr BWD (regno Rd) tmpd)
3819 (setf-move BWD tmpd)))
3822 ; LSLQ c,Rd [ Rd | 0011110 | c ]
3824 lslq "Logical shift left quick-immediate count"
3826 (+ Rd Q_LSHQ MODE_QUICK_IMMEDIATE (f-b5 0) c)
3829 (set tmpd (sll Rd c))
3831 (setf-move SI tmpd))
3834 ; BTST Rs,Rd [ Rd | 01001111 | Rs ]
3836 btst "Bit test register number"
3838 (+ Rd MODE_REGISTER RFIX_BTST SIZE_FIXED Rs)
3840 ((SI tmpd) (SI cnt))
3841 (set tmpd (sll Rd (sub 31 (and Rs 31))))
3842 (setf-move SI tmpd))
3845 ; BTSTQ c,Rd [ Rd | 0011100 | c ]
3847 btstq "Bit test quick-immediate number"
3849 (+ Rd Q_ASHQ MODE_QUICK_IMMEDIATE (f-b5 0) c)
3852 (set tmpd (sll Rd (sub 31 c)))
3853 (setf-move SI tmpd))
3856 ; SETF <list of flags> [ P U I X | 01011011 | N Z V C ]
3858 setf "Set condition code flags explicitly"
3859 "setf ${list-of-flags}"
3860 ; The zero-flags case gets flag operands wrong; there's a "_"
3861 ; where there should have been nothing. Also, flags are in
3862 ; assembly code allowed to be specified in any order, which
3863 ; doesn't match the "flagbits" settings. Luckily we don't
3864 ; use this field for assembly.
3865 (+ RFIX_SETF MODE_REGISTER SIZE_FIXED list-of-flags)
3869 (set tmp list-of-flags)
3873 (if (ne (and tmp (sll 1 (.sym ccbit -bitnumber))) 0)
3874 (set (.sym ccbit bit) 1)))
3877 ; Unless x was specified to be set, set it to 0.
3878 (if (eq (and tmp (sll 1 x-bitnumber)) 0)
3882 ; CLEARF <list of flags> [ P U I X | 01011111 | N Z V C ]
3884 clearf "Clear condition code flags explicitly"
3885 "clearf ${list-of-flags}"
3886 ; The zero-flags case gets flag operands wrong; there's a "_"
3887 ; where there should have been nothing. Also, flags are in
3888 ; assembly code allowed to be specified in any order, which
3889 ; doesn't match the "flagbits" settings. Luckily we don't
3890 ; use this field for assembly.
3891 (+ RFIX_CLEARF MODE_REGISTER SIZE_FIXED list-of-flags)
3895 (set tmp list-of-flags)
3899 (if (ne (and tmp (sll 1 (.sym ccbit -bitnumber))) 0)
3900 (set (.sym ccbit bit) 0)))
3907 "Common parts of RFE and RFN"
3909 ((USI oldccs) (USI samebits) (USI shiftbits) (USI keepmask) (BI p1))
3911 ; Keeping U, S and I in user mode is handled by the CCS setter, so we
3912 ; don't have to bother. Actually Q and M are handled too. The reason
3913 ; to mask those out is to not have them shifted down into the second
3915 (set keepmask #xc0000000)
3916 (set samebits (and oldccs keepmask))
3917 ; The P bit has its own equation.
3918 (set shiftbits (and (srl (and oldccs #x3ffdfc00) 10) (inv keepmask)))
3919 (set p1 (ne 0 (and oldccs #x20000)))
3920 (set ccs (or (or samebits shiftbits)
3921 (if SI (and rbit (not p1)) 0 #x80))))
3924 ; RFE [ 0010 10010011 0000 ]
3930 (+ (f-dest 2) MODE_INDIRECT INFIX_RFE SIZE_FIXED (f-source 0))
3934 ; SFE [ 0011 10010011 0000 ]
3940 (+ (f-dest 3) MODE_INDIRECT INFIX_SFE SIZE_FIXED (f-source 0))
3942 ((SI oldccs) (SI savemask))
3943 (set savemask #xc0000000)
3946 (or (and savemask oldccs)
3947 (and (inv savemask) (sll oldccs 10)))))
3950 ; RFG [ 0100 10010011 0000 ]
3956 (+ (f-dest 4) MODE_INDIRECT INFIX_RFG SIZE_FIXED (f-source 0))
3957 (c-call VOID "@cpu@_rfg_handler" pc)
3960 ; RFN [ 0101 10010011 0000 ]
3966 (+ (f-dest 5) MODE_INDIRECT INFIX_RFN SIZE_FIXED (f-source 0))
3967 (sequence () (rfe-rfn-guts) (set mbit 1))
3970 ; HALT [ 1111 10010011 0000 ]
3976 (+ (f-dest 15) MODE_INDIRECT INFIX_HALT SIZE_FIXED (f-source 0))
3977 (set pc (c-call USI "@cpu@_halt_handler" pc))
3980 ; Bcc o [ cc | 0000 | o ]
3982 bcc-b "bcc byte operand"
3985 (+ cc QHI_BCC MODE_QUICK_IMMEDIATE o-pcrel)
3988 (set truthval (cris-condition cc))
3990 ; Amazing as it may seem, there's no simpler way to find out
3991 ; whether a branch is taken or not than to mark it through a kludge
3993 (c-call VOID "@cpu@_branch_taken" pc o-pcrel truthval)
3999 (.splice (.unsplice (simplecris-timing))
4000 (crisv32 (unit u-branch) (unit u-exec)))
4003 ba-b "ba byte operand"
4006 (+ (f-dest 14) QHI_BCC MODE_QUICK_IMMEDIATE o-pcrel)
4012 ((crisv32 (unit u-jump) (unit u-exec)))
4015 ; Bcc [PC+] [ cc | 11011111 1111 ]
4016 ; (We don't implement the generic for pre-V32 but unused variant
4017 ; "Bcc [Rn(+)]" where n != 15.)
4019 bcc-w "bcc, word operand"
4021 "b${cc} ${o-word-pcrel}"
4022 (+ cc MODE_AUTOINCREMENT INFIX_BCC_M SIZE_FIXED (f-source 15) o-word-pcrel)
4025 (set truthval (cris-condition cc))
4027 ; Amazing as it may seem, there's no simpler way to find out
4028 ; whether a branch is taken or not than to mark it through a kludge
4030 (c-call VOID "@cpu@_branch_taken" pc o-word-pcrel truthval)
4035 (set pc o-word-pcrel))))
4037 (.unsplice (simplecris-common-timing ((unit u-const16) (unit u-exec))))
4038 (crisv32 (unit u-const16) (unit u-branch) (unit u-exec)))
4041 ba-w "ba word operand"
4043 "ba ${o-word-pcrel}"
4044 (+ (f-dest 14) MODE_AUTOINCREMENT INFIX_BCC_M SIZE_FIXED (f-source 15) o-word-pcrel)
4049 (set pc o-word-pcrel)))
4051 (.unsplice (simplecris-common-timing ((unit u-const16) (unit u-exec))))
4052 (crisv32 (unit u-const16) (unit u-jump) (unit u-exec)))
4055 ; JAS Rs,Pd [ Pd | 10011011 | Rs ]
4057 jas-r "JAS register"
4060 (+ Pd MODE_INDIRECT INFIX_JAS_R SIZE_FIXED Rs)
4064 (if (andif (eq (regno Rs) 1) (eq (regno Pd) 11))
4065 ; We use this as a trigger; a normally reasonably rare instruction
4066 ; used in the v32 trampoline. See comment at bdapqpc.
4067 ; CGEN-FIXME: can't use (regno srp) [== (regno (reg h-sr 11))]
4068 (c-call VOID "cris_flush_simulator_decode_cache" pc))
4072 (set Pd (add SI pc 4))
4074 ((crisv32 (unit u-jump-r) (unit u-jump) (unit u-exec)))
4076 ; Same semantics in pre-V32, except no delay-slot.
4077 ; FIXME: Missing JIRC/JSRC/JBRC.
4079 jump-r "JUMP/JSR/JIR register"
4081 "jump/jsr/jir ${Rs}"
4082 (+ Pd MODE_INDIRECT INFIX_JUMP_R SIZE_FIXED Rs)
4085 (set Pd (add SI pc 2))
4090 ; JAS [PC+],Pd [ Pd | 11011011 1111 ]
4092 jas-c "JAS constant"
4094 "jas ${const32},${Pd}"
4095 (+ Pd MODE_AUTOINCREMENT INFIX_JAS_M SIZE_FIXED (f-source 15) const32)
4102 (set Pd (add SI pc 8))
4104 ((crisv32 (unit u-const32) (unit u-jump) (unit u-exec)))
4107 ; JUMP/JSR/JIR | Special r.| 1 m| 0 1 0 0| 1 1| Source |
4109 jump-m "JUMP/JSR/JIR memory"
4111 "jump/jsr/jir [${Rs}${inc}]"
4112 (+ Pd INFIX_JUMP_M SIZE_FIXED Rs)
4115 (set Pd (add SI pc 2))
4116 (set pc (cris-get-mem SI Rs))
4120 jump-c "JUMP/JSR/JIR constant"
4122 "jump/jsr/jir ${const32}"
4123 (+ Pd MODE_AUTOINCREMENT INFIX_JUMP_M SIZE_FIXED (f-source 15) const32)
4126 (set Pd (add SI pc 6))
4131 ; JUMP Ps [ Ps | 10011111 0000 ]
4133 jump-p "JUMP special register"
4136 (+ Ps MODE_INDIRECT INFIX_JUMP_P SIZE_FIXED (f-source 0))
4142 ((crisv32 (unit u-jump-sr)
4146 ; BAS [PC+],Pd [ Pd | 11101011 1111 ]
4148 bas-c "BAS constant"
4150 "bas ${const32},${Pd}"
4151 (+ Pd MODE_AUTOINCREMENT INFIX_BAS SIZE_FIXED (f-source 15) const32-pcrel)
4158 (set Pd (add SI pc 8))
4159 (set pc const32-pcrel))))
4160 ((crisv32 (unit u-const32) (unit u-jump) (unit u-exec)))
4163 ; JASC Rs,Pd [ Pd | 10110011 | Rs ]
4165 jasc-r "JASC register"
4168 (+ Pd MODE_INDIRECT INFIX_JASC SIZE_FIXED Rs)
4175 (set Pd (add SI pc 8))
4177 ((crisv32 (unit u-jump-r) (unit u-skip4) (unit u-jump) (unit u-exec)))
4180 ; JASC [PC+],Pd [ Pd | 11110011 1111 ]
4182 jasc-c "JASC constant"
4184 "jasc ${const32},${Pd}"
4185 (+ Pd MODE_AUTOINCREMENT INFIX_JASC SIZE_FIXED (f-source 15) const32)
4192 (set Pd (add SI pc 12))
4194 ((crisv32 (unit u-const32) (unit u-skip4) (unit u-jump) (unit u-exec)))
4197 ; BASC [PC+],Pd [ Pd | 11101111 1111 ]
4199 basc-c "BASC constant"
4201 "basc ${const32},${Pd}"
4202 (+ Pd MODE_AUTOINCREMENT INFIX_BASC SIZE_FIXED (f-source 15) const32-pcrel)
4209 (set Pd (add SI pc 12))
4210 (set pc const32-pcrel))))
4211 ((crisv32 (unit u-const32) (unit u-skip4) (unit u-jump) (unit u-exec)))
4214 ; BREAK n [ 1110 | 10010011 | n ]
4219 (+ (f-operand2 #xe) MODE_INDIRECT INFIX_BREAK SIZE_FIXED n)
4220 (sequence () (reset-x-p) (set pc (c-call USI "@cpu@_break_handler" n pc)))
4223 ; BOUND.m Rs,Rd [ Rd | 010111mm | Rs ]
4225 bound-r "Bound register"
4227 (+ Rd R_BOUND MODE_REGISTER Rs)
4231 ((SI tmpopd) (SI tmpops) (SI newval))
4232 (set tmpops ((.sym BWD -zext) (trunc BWD Rs)))
4234 (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
4236 (setf-move SI newval)))
4239 ; BOUND.m [Rs],Rd [ Rd | 100111mm | Rs ]
4240 ; BOUND.m [Rs+],Rd [ Rd | 110111mm | Rs ]
4242 bound-m "Bound memory"
4244 "[${Rs}${inc}],${Rd}"
4245 (+ Rd INDIR_BOUND Rs)
4249 ((SI tmpopd) (SI tmpops) (SI newval))
4250 (set tmpops ((.sym BWD -zext) (cris-get-mem BWD Rs)))
4252 (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
4253 (if (andif prefix-set (not inc))
4256 (setf-move SI newval)))
4259 ; (BOUND.m [PC+],Rd [ Rd | 110111mm | 1111 ])
4261 bound-cb "Bound constant byte"
4262 "bound.b [PC+],${Rd}"
4263 (+ Rd MODE_AUTOINCREMENT INDIR_BOUND SIZE_BYTE (f-source 15) uconst8)
4265 ((SI tmpopd) (SI tmpops) (SI newval))
4266 (set tmpops (zext SI (trunc QI uconst8)))
4268 (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
4270 (setf-move SI newval))
4273 bound-cw "Bound constant word"
4274 "bound.w [PC+],${Rd}"
4275 (+ Rd MODE_AUTOINCREMENT INDIR_BOUND SIZE_WORD (f-source 15) uconst16)
4277 ((SI tmpopd) (SI tmpops) (SI newval))
4278 (set tmpops (zext SI uconst16))
4280 (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
4282 (setf-move SI newval))
4285 bound-cd "Bound constant dword"
4286 "bound.d [PC+],${Rd}"
4287 (+ Rd MODE_AUTOINCREMENT INDIR_BOUND SIZE_DWORD (f-source 15) const32)
4289 ((SI tmpopd) (SI tmpops) (SI newval))
4290 (set tmpops const32)
4292 (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
4294 (setf-move SI newval))
4297 ; Scc Rd [ cc | 01010011 | Rd ]
4300 "s${cc} ${Rd-sfield}"
4301 (+ cc MODE_REGISTER RFIX_SCC SIZE_FIXED Rd-sfield)
4304 (set truthval (cris-condition cc))
4305 (set Rd-sfield (zext SI truthval))
4309 ; LZ Rs,Rd [ Rd | 01110011 | Rs ]
4314 (+ Rd MODE_REGISTER RFIX_LZ SIZE_FIXED Rs)
4316 ((SI tmpd) (SI tmp))
4328 (set tmp (sll tmp 1))
4329 (set tmpd (add tmpd 1)))))
4332 (setf-move SI tmpd))
4335 ; ADDOQ o,Rs,ACR [ Rs | 0001 | o ]
4339 (+ Rs-dfield MODE_QUICK_IMMEDIATE QHI_ADDOQ o)
4342 (set prefixreg (add SI Rs-dfield o))
4346 ; (BDAPQ o,PC [ 1111 | 0001 | o ])
4347 ; This [PC+I] prefix is used in trampolines.
4349 bdapqpc "bdapq pc operand"
4350 (MACH-PC UNCOND-CTI)
4352 (+ (f-dest 15) MODE_QUICK_IMMEDIATE QHI_BDAP o)
4355 (set prefixreg (add SI (add SI pc 2) o))
4357 ; When this *rare* instruction is seen, we're may be about to write
4358 ; into code to be executed soon, *probably* covering addresses decoded
4359 ; and executed before. If the simulator does not implement snooping
4360 ; and automatic decoder flush, it will execute old code. This call
4361 ; is a kludge for such simulators, asking it to abandon such cached
4362 ; information. Anyway, it is hopefully enough to make CGEN-sim not
4363 ; hork on gcc trampolines.
4364 ; We mark this insn as UNCOND-CTI so this insn will end a simulator
4365 ; basic block (the atomic unit of translation).
4366 (c-call VOID "cris_flush_simulator_decode_cache" pc))
4369 ; (BDAP.D [PC+],PC [ 1111 | 11010110 | 1111 ]
4370 ; This [PC+I] prefix is used for DSO-local jumps in PIC code, together with
4371 ; move-m-pcplus-p0: "move [pc=pc+N],p0"
4373 bdap-32-pc "bdap.d [PC+],PC"
4375 "bdap ${sconst32},PC"
4376 (+ (f-dest 15) MODE_AUTOINCREMENT INDIR_BDAP_M SIZE_DWORD (f-source 15) const32)
4378 ((SI newpc) (SI oldpc) (SI offs))
4380 (set oldpc (add SI pc 6))
4381 (set newpc (add SI oldpc offs))
4382 (set prefixreg newpc)
4386 ; (MOVE [PC+],P0 [ 0000 | 11100011 | 1111 ])
4387 ; This insn is used for DSO-local jumps in PIC code. See bdap-32-pc.
4388 (dni ; Must not use dni-cmt-* because we force MODE_AUTOINCREMENT.
4389 move-m-pcplus-p0 "move [PC+],P0"
4392 (+ (f-dest 0) MODE_AUTOINCREMENT INFIX_MOVE_M_S SIZE_FIXED (f-source 15))
4396 ; We model the memory read, but throw the result away, as the
4397 ; destination register is read-only. We need to assign the result of
4398 ; cris-get-mem though, as CGEN-FIXME: invalid C code will otherwise
4400 (set dummy (cris-get-mem QI pc))
4402 (error "move [PC+],P0 without prefix is not implemented"))
4406 ; This insn is used in Linux in the form "move [$sp=$sp+16],$p8"; it's
4407 ; similar to move-m-pcplus-p0 above. The same comments apply here.
4409 move-m-spplus-p8 "move [SP+],P8"
4412 (+ (f-dest 8) MODE_AUTOINCREMENT INFIX_MOVE_M_S SIZE_FIXED (f-source 14))
4416 (set dummy (cris-get-mem SI sp))
4418 (error "move [SP+],P8 without prefix is not implemented"))
4422 ; ADDO.m [Rs],Rd,ACR [ Rd | 100101mm | Rs ]
4423 ; ADDO.m [Rs+],Rd,ACR [ Rd | 110101mm | Rs ]
4425 addo-m "addo.m memory"
4426 "[${Rs}${inc}],$Rd,ACR"
4427 (+ Rd INDIR_ADDO Rs)
4432 (set tmps (cris-get-mem BWD Rs))
4433 (set prefixreg (add SI Rd ((.sym BWD -ext) tmps)))
4434 (set prefix-set 1)))
4437 ; (ADDO.m [PC+],Rd,ACR [ Rd | 110101mm | 1111 ]
4439 addo-cb "addo.b const"
4440 "addo.b [PC+],$Rd,ACR"
4441 (+ Rd MODE_AUTOINCREMENT INDIR_ADDO SIZE_BYTE (f-source 15) sconst8)
4444 (set prefixreg (add SI Rd (ext SI (trunc QI sconst8))))
4448 addo-cw "addo.w const"
4449 "addo.w [PC+],$Rd,ACR"
4450 (+ Rd MODE_AUTOINCREMENT INDIR_ADDO SIZE_WORD (f-source 15) sconst16)
4453 (set prefixreg (add SI Rd (ext SI (trunc HI sconst16))))
4457 addo-cd "addo.d const"
4458 "addo.d [PC+],$Rd,ACR"
4459 (+ Rd MODE_AUTOINCREMENT INDIR_ADDO SIZE_DWORD (f-source 15) const32)
4462 (set prefixreg (add SI Rd const32))
4466 ; DIP [] | 0 0 0 0| 1 m| 0 1 0 1| 1 1| Source |
4472 (+ (f-dest 0) INFIX_DIP SIZE_FIXED Rs)
4475 (set tmps (cris-get-mem SI Rs))
4476 (set prefixreg tmps)
4480 ; (DIP [] | 0 0 0 0| 1 m| 0 1 0 1| 1 1| Source | )
4485 (+ (f-dest 0) MODE_AUTOINCREMENT INFIX_DIP SIZE_FIXED (f-source 15) const32)
4488 (set prefixreg const32)
4492 ; ADDI Rs.m,Rd,ACR [ Rs | 010101mm | Rd ]
4495 addi-acr "addi prefix"
4496 "${Rs-dfield}.m,${Rd-sfield},ACR"
4497 (+ Rd-sfield MODE_REGISTER R_ADDI_ACR Rs-dfield)
4502 (set prefixreg (add SI Rd-sfield (mul Rs-dfield (.sym BWD -size))))
4503 (set prefix-set 1)))
4507 biap-pc "biap.m ${Rs-dfield},PC"
4510 (+ Rs-dfield MODE_REGISTER R_ADDI_ACR (f-source 15))
4515 (set prefixreg (add SI (add SI pc 4) (mul Rs-dfield (.sym BWD -size))))
4516 (set prefix-set 1)))
4519 ; FIDXI [Rs] [ 0000 | 11010011 | Rs ]
4524 (+ (f-dest 0) MODE_AUTOINCREMENT INFIX_FIDXI SIZE_FIXED Rs)
4525 (set pc (c-call USI "@cpu@_fidxi_handler" pc Rs))
4528 ; FTAGI [Rs] [ 0001 | 11010011 | Rs ]
4533 (+ (f-dest 1) MODE_AUTOINCREMENT INFIX_FTAGI SIZE_FIXED Rs)
4534 (set pc (c-call USI "@cpu@_ftagi_handler" pc Rs))
4537 ; FIDXD [Rs] [ 0000 | 10101011 | Rs ]
4542 (+ (f-dest 0) MODE_INDIRECT INFIX_FIDXD SIZE_FIXED Rs)
4543 (set pc (c-call USI "@cpu@_fidxd_handler" pc Rs))
4546 ; FTAGD [Rs] [ 0001 | 10101011 | Rs ]
4551 (+ (f-dest 1) MODE_INDIRECT INFIX_FTAGD SIZE_FIXED Rs)
4552 (set pc (c-call USI "@cpu@_ftagd_handler" pc Rs))