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