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