OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [binutils-2.18.50/] [cpu/] [cris.cpu] - Diff between revs 156 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 156 Rev 816
; CRIS CPU description.  -*- Scheme -*-
; CRIS CPU description.  -*- Scheme -*-
;
;
; Copyright 2003, 2004, 2007 Free Software Foundation, Inc.
; Copyright 2003, 2004, 2007 Free Software Foundation, Inc.
;
;
; Contributed by Axis Communications AB.
; Contributed by Axis Communications AB.
;
;
; This file is part of the GNU Binutils.
; This file is part of the GNU Binutils.
;
;
; This program is free software; you can redistribute it and/or modify
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 3 of the License, or
; the Free Software Foundation; either version 3 of the License, or
; (at your option) any later version.
; (at your option) any later version.
;
;
; This program is distributed in the hope that it will be useful,
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
; GNU General Public License for more details.
;
;
; You should have received a copy of the GNU General Public License
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; along with this program; if not, write to the Free Software
; Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
; Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
; MA 02110-1301, USA.
; MA 02110-1301, USA.
(include "simplify.inc")
(include "simplify.inc")
;;;;;;;;;;;;;;;;;; -pmacro (generic ones)
;;;;;;;;;;;;;;;;;; -pmacro (generic ones)
(define-pmacro (.car2 l) (.apply (.pmacro (a b) a) l))
(define-pmacro (.car2 l) (.apply (.pmacro (a b) a) l))
(define-pmacro (.cadr2 l) (.apply (.pmacro (a b) b) l))
(define-pmacro (.cadr2 l) (.apply (.pmacro (a b) b) l))
(define-pmacro (SI-ext x) "How to sign-extend a dword to dword (a nop)" x)
(define-pmacro (SI-ext x) "How to sign-extend a dword to dword (a nop)" x)
(define-pmacro (HI-ext x) "How to sign-extend a word to dword" (ext SI x))
(define-pmacro (HI-ext x) "How to sign-extend a word to dword" (ext SI x))
(define-pmacro (QI-ext x) "How to sign-extend a byte to dword" (ext SI x))
(define-pmacro (QI-ext x) "How to sign-extend a byte to dword" (ext SI x))
(define-pmacro (SI-zext x) "How to zero-extend a dword to dword (a nop)" x)
(define-pmacro (SI-zext x) "How to zero-extend a dword to dword (a nop)" x)
(define-pmacro (HI-zext x) "How to zero-extend a word to dword" (zext SI x))
(define-pmacro (HI-zext x) "How to zero-extend a word to dword" (zext SI x))
(define-pmacro (QI-zext x) "How to zero-extend a byte to dword" (zext SI x))
(define-pmacro (QI-zext x) "How to zero-extend a byte to dword" (zext SI x))
(define-pmacro
(define-pmacro
  (define-pmacro-map x)
  (define-pmacro-map x)
  "On a list ((x0 y0) .. (xN yN)), 0 <= m <= N, (define-pmacro xm ym)"
  "On a list ((x0 y0) .. (xN yN)), 0 <= m <= N, (define-pmacro xm ym)"
  (.splice
  (.splice
   begin
   begin
   (.unsplice
   (.unsplice
    (.map
    (.map
     (.pmacro (l) (.apply (.pmacro (xm ym) (define-pmacro xm ym)) l)) x)))
     (.pmacro (l) (.apply (.pmacro (xm ym) (define-pmacro xm ym)) l)) x)))
)
)
;;;;;;;;;;;;;;;;;; -arch -isa -cpu -model
;;;;;;;;;;;;;;;;;; -arch -isa -cpu -model
(define-arch
(define-arch
  (name cris)
  (name cris)
  (comment "Axis Communications CRIS")
  (comment "Axis Communications CRIS")
  (default-alignment unaligned)
  (default-alignment unaligned)
  (insn-lsb0? #t)
  (insn-lsb0? #t)
  (machs crisv0 crisv3 crisv8 crisv10 crisv32)
  (machs crisv0 crisv3 crisv8 crisv10 crisv32)
  (isas cris)
  (isas cris)
)
)
(define-isa
(define-isa
  (name cris)
  (name cris)
  (base-insn-bitsize 16)
  (base-insn-bitsize 16)
  (liw-insns 1)
  (liw-insns 1)
  (parallel-insns 1)
  (parallel-insns 1)
)
)
(define-pmacro
(define-pmacro
  (define-cpu-cris x-suffix x-comment)
  (define-cpu-cris x-suffix x-comment)
  "Define a CRIS CPU family"
  "Define a CRIS CPU family"
  (define-cpu
  (define-cpu
    (name (.sym cris x-suffix f))
    (name (.sym cris x-suffix f))
    (comment x-comment)
    (comment x-comment)
    (endian little)
    (endian little)
    ; CGEN-FIXME: Should be deduced from the default?
    ; CGEN-FIXME: Should be deduced from the default?
    (word-bitsize 32)
    (word-bitsize 32)
    (file-transform (.str x-suffix))
    (file-transform (.str x-suffix))
  )
  )
)
)
; Useful when there's a need to iterate over all models.
; Useful when there's a need to iterate over all models.
(define-pmacro (cris-cpu-model-numbers)
(define-pmacro (cris-cpu-model-numbers)
  "List of CRIS CPU model numbers (version register contents)"
  "List of CRIS CPU model numbers (version register contents)"
  (0 3 8 10 32)
  (0 3 8 10 32)
)
)
(define-pmacro (cris-cpu-models)
(define-pmacro (cris-cpu-models)
  "List of CRIS CPU model names"
  "List of CRIS CPU model names"
  (.map (.pmacro (n) (.sym v n)) (cris-cpu-model-numbers))
  (.map (.pmacro (n) (.sym v n)) (cris-cpu-model-numbers))
)
)
; Mapping from model name to number.
; Mapping from model name to number.
(define-pmacro-map
(define-pmacro-map
  (.map (.pmacro (n) ((.sym v n -number) n))
  (.map (.pmacro (n) ((.sym v n -number) n))
        (cris-cpu-model-numbers)))
        (cris-cpu-model-numbers)))
; FIXME: Rationalize these rules.
; FIXME: Rationalize these rules.
; CPU names must be distinct from the architecture name and machine names.
; CPU names must be distinct from the architecture name and machine names.
; The "b" suffix stands for "base" and is the convention.
; The "b" suffix stands for "base" and is the convention.
; The "f" suffix stands for "family" and is the convention.
; The "f" suffix stands for "family" and is the convention.
; We ignore the "b" convention, partly because v0 isn't really a "base", at
; We ignore the "b" convention, partly because v0 isn't really a "base", at
; least not for some aspects of v32.
; least not for some aspects of v32.
(define-cpu-cris v0 "CRIS base family")
(define-cpu-cris v0 "CRIS base family")
(define-cpu-cris v3 "CRIS v3 family")
(define-cpu-cris v3 "CRIS v3 family")
(define-cpu-cris v8 "CRIS v8 family")
(define-cpu-cris v8 "CRIS v8 family")
(define-cpu-cris v10 "CRIS v10 family")
(define-cpu-cris v10 "CRIS v10 family")
(define-cpu-cris v32 "CRIS v32 family")
(define-cpu-cris v32 "CRIS v32 family")
(define-pmacro MACH-PRE-V32 (MACH crisv0,crisv3,crisv8,crisv10))
(define-pmacro MACH-PRE-V32 (MACH crisv0,crisv3,crisv8,crisv10))
(define-pmacro MACH-V3-UP (MACH crisv3,crisv8,crisv10,crisv32))
(define-pmacro MACH-V3-UP (MACH crisv3,crisv8,crisv10,crisv32))
(define-pmacro MACH-V32 (MACH crisv32))
(define-pmacro MACH-V32 (MACH crisv32))
(define-pmacro MACH-PC MACH-PRE-V32)
(define-pmacro MACH-PC MACH-PRE-V32)
(define-pmacro MACH-ACR MACH-V32)
(define-pmacro MACH-ACR MACH-V32)
(define-pmacro MACH-BRANCH-OFFSET-AT-INSN MACH-V32)
(define-pmacro MACH-BRANCH-OFFSET-AT-INSN MACH-V32)
(define-pmacro MACH-BRANCH-OFFSET-AFTER-INSN MACH-PRE-V32)
(define-pmacro MACH-BRANCH-OFFSET-AFTER-INSN MACH-PRE-V32)
(define-pmacro
(define-pmacro
  current-mach-is-v32
  current-mach-is-v32
  "Whether the generated code is for V32.  See comment at h-v32."
  "Whether the generated code is for V32.  See comment at h-v32."
  (reg h-v32)
  (reg h-v32)
)
)
(define-pmacro (define-mach-cris x-suffix x-comment x-name)
(define-pmacro (define-mach-cris x-suffix x-comment x-name)
  "Define a CRIS mach"
  "Define a CRIS mach"
  (define-mach
  (define-mach
    (name (.sym cris x-suffix))
    (name (.sym cris x-suffix))
    ; They're all called "cris" in bfd.  Watch out for breakages for some
    ; They're all called "cris" in bfd.  Watch out for breakages for some
    ; uses.
    ; uses.
    (bfd-name x-name)
    (bfd-name x-name)
    (comment x-comment)
    (comment x-comment)
    (cpu (.sym cris x-suffix f)))
    (cpu (.sym cris x-suffix f)))
)
)
(define-mach-cris v0 "Generic CRIS v0 CPU, ETRAX 1 .. 3" "cris")
(define-mach-cris v0 "Generic CRIS v0 CPU, ETRAX 1 .. 3" "cris")
(define-mach-cris v3 "Generic CRIS v3 CPU, ETRAX 4" "cris")
(define-mach-cris v3 "Generic CRIS v3 CPU, ETRAX 4" "cris")
(define-mach-cris v8 "Generic CRIS v8 CPU, ETRAX 100" "cris")
(define-mach-cris v8 "Generic CRIS v8 CPU, ETRAX 100" "cris")
(define-mach-cris v10 "Generic CRIS v10 CPU, ETRAX 100 LX" "cris")
(define-mach-cris v10 "Generic CRIS v10 CPU, ETRAX 100 LX" "cris")
(define-mach-cris v32 "Generic CRIS v32 CPU, ETRAX FS" "crisv32")
(define-mach-cris v32 "Generic CRIS v32 CPU, ETRAX FS" "crisv32")
(define-pmacro (define-model-simplecris x-name x-comment)
(define-pmacro (define-model-simplecris x-name x-comment)
  "Define a simple CRIS model"
  "Define a simple CRIS model"
  (define-model
  (define-model
    (name (.sym cris x-name))
    (name (.sym cris x-name))
    (comment x-comment)
    (comment x-comment)
    (mach (.sym cris x-name))
    (mach (.sym cris x-name))
    (unit u-exec "Execution Unit" () 1 1 () () () ())
    (unit u-exec "Execution Unit" () 1 1 () () () ())
    (unit u-mem "Memory Unit" () 1 1 () () () ())
    (unit u-mem "Memory Unit" () 1 1 () () () ())
    (unit u-const16 "Fetch 16-bit operand" () 1 1 () () () ())
    (unit u-const16 "Fetch 16-bit operand" () 1 1 () () () ())
    (unit u-const32 "Fetch 32-bit operand" () 1 1
    (unit u-const32 "Fetch 32-bit operand" () 1 1
          () () () ())
          () () () ())
    ; Used in special-case insn, for example arithmetic with PC destination.
    ; Used in special-case insn, for example arithmetic with PC destination.
    (unit u-stall "Stall unit" () 1 1 () () () ())
    (unit u-stall "Stall unit" () 1 1 () () () ())
    (unit u-skip4 "Skip 4 bytes" () 1 1 () () () ())
    (unit u-skip4 "Skip 4 bytes" () 1 1 () () () ())
    (unit u-multiply "Multiply Unit" () 1 1 ((MACH crisv10)) () () ())
    (unit u-multiply "Multiply Unit" () 1 1 ((MACH crisv10)) () () ())
    (unit u-movem "Movem Unit" () 1 1 ()
    (unit u-movem "Movem Unit" () 1 1 ()
          ((Rd INT -1))
          ((Rd INT -1))
          () ()))
          () ()))
)
)
(define-model-simplecris v0 "Model of CRIS v0, ETRAX 1 .. 3")
(define-model-simplecris v0 "Model of CRIS v0, ETRAX 1 .. 3")
(define-model-simplecris v3 "Model of CRIS v3, ETRAX 4")
(define-model-simplecris v3 "Model of CRIS v3, ETRAX 4")
(define-model-simplecris v8 "Model of CRIS v8, ETRAX 100")
(define-model-simplecris v8 "Model of CRIS v8, ETRAX 100")
(define-model-simplecris v10 "Model of CRIS v10, ETRAX 100 LX")
(define-model-simplecris v10 "Model of CRIS v10, ETRAX 100 LX")
; For some reason, we get an error:
; For some reason, we get an error:
;  Generating arch.h ...
;  Generating arch.h ...
;  ERROR: In procedure vector-ref:
;  ERROR: In procedure vector-ref:
;  ERROR: Wrong type argument in position 1: ()
;  ERROR: Wrong type argument in position 1: ()
; if we include timings for machs that we don't generate sims for.
; if we include timings for machs that we don't generate sims for.
; Last checked: CVS as of 2004-11-18.
; Last checked: CVS as of 2004-11-18.
; CGEN-FIXME: Looks like another CGEN bug.  When it's fixed (or when
; CGEN-FIXME: Looks like another CGEN bug.  When it's fixed (or when
; generating sims for v0, v3 or v8), add 0, 3 and 8 to
; generating sims for v0, v3 or v8), add 0, 3 and 8 to
; simplecris-timing-models.  But before that, simplecris-timing-x has to
; simplecris-timing-models.  But before that, simplecris-timing-x has to
; be rewritten to work on a multiple-element-list, not assume a single
; be rewritten to work on a multiple-element-list, not assume a single
; element.  (A change which seems likely to depend on lexical scoping for
; element.  (A change which seems likely to depend on lexical scoping for
; macros to be introduced: try the obvious implementation.)
; macros to be introduced: try the obvious implementation.)
(define-pmacro simplecris-timing-models (10))
(define-pmacro simplecris-timing-models (10))
(define-pmacro (simplecris-common-timing x-units)
(define-pmacro (simplecris-common-timing x-units)
  "Make timing models, using x-units for all simplecris-timing-models"
  "Make timing models, using x-units for all simplecris-timing-models"
  ; CGEN-FIXME: Another CGEN bug: the part (.unsplice (10)) will remain
  ; CGEN-FIXME: Another CGEN bug: the part (.unsplice (10)) will remain
  ; unexpanded in (.sym crisv (.unsplice (10)) if we write this as
  ; unexpanded in (.sym crisv (.unsplice (10)) if we write this as
  ; ((.splice (.sym crisv (.unsplice simplecris-timing-models))
  ; ((.splice (.sym crisv (.unsplice simplecris-timing-models))
  ;           (.unsplice x-units)))
  ;           (.unsplice x-units)))
  ((.splice (.sym crisv (.apply (.pmacro (x) x) simplecris-timing-models))
  ((.splice (.sym crisv (.apply (.pmacro (x) x) simplecris-timing-models))
            (.unsplice x-units)))
            (.unsplice x-units)))
)
)
(define-pmacro-map
(define-pmacro-map
  (
  (
   ; Timing for memory instructions running on a simple cris model.
   ; Timing for memory instructions running on a simple cris model.
   ((simplecris-mem-timing)     (simplecris-common-timing
   ((simplecris-mem-timing)     (simplecris-common-timing
                                 ((unit u-mem) (unit u-exec))))
                                 ((unit u-mem) (unit u-exec))))
   ; Timing for movem instructions running on a simple cris model.
   ; Timing for movem instructions running on a simple cris model.
   ((simplecris-movem-timing)   (simplecris-common-timing
   ((simplecris-movem-timing)   (simplecris-common-timing
                                 ((unit u-movem) (unit u-exec))))
                                 ((unit u-movem) (unit u-exec))))
   ; Similar, for an 8- or 16-bit constant ([PC+]) operand.
   ; Similar, for an 8- or 16-bit constant ([PC+]) operand.
   ((simplecris-const-timing-HI)
   ((simplecris-const-timing-HI)
                                (simplecris-common-timing
                                (simplecris-common-timing
                                 ((unit u-const16) (unit u-exec))))
                                 ((unit u-const16) (unit u-exec))))
   ; Similar, for a 32-bit constant ([PC+]) operand.
   ; Similar, for a 32-bit constant ([PC+]) operand.
   ((simplecris-const-timing-SI)
   ((simplecris-const-timing-SI)
                                (simplecris-common-timing
                                (simplecris-common-timing
                                 ((unit u-const32) (unit u-exec))))
                                 ((unit u-const32) (unit u-exec))))
   ; Similar, no particular operand.
   ; Similar, no particular operand.
   ((simplecris-timing)         (simplecris-common-timing
   ((simplecris-timing)         (simplecris-common-timing
                                 ((unit u-exec)))))
                                 ((unit u-exec)))))
)
)
(define-model
(define-model
  (name crisv32)
  (name crisv32)
  (comment "Model of CRISv32")
  (comment "Model of CRISv32")
  (mach crisv32)
  (mach crisv32)
  (state
  (state
    ; Bitmask of h-gr register (0..15) and h-sr register (17..31)
    ; Bitmask of h-gr register (0..15) and h-sr register (17..31)
    ; modified by 3rd previous insn, updated by the u-exec unit.
    ; modified by 3rd previous insn, updated by the u-exec unit.
    ; Because there's no need to mark writes to special registers BZ and
    ; Because there's no need to mark writes to special registers BZ and
    ; WZ, bit 16 is for jump mark and bit 20 for memory-write mark.
    ; WZ, bit 16 is for jump mark and bit 20 for memory-write mark.
    (prev-prev-prev-modf-regs UINT)
    (prev-prev-prev-modf-regs UINT)
    ; Ditto for the 2nd previous insn.
    ; Ditto for the 2nd previous insn.
    (prev-prev-modf-regs UINT)
    (prev-prev-modf-regs UINT)
    ; Ditto for the previous insn.
    ; Ditto for the previous insn.
    (prev-modf-regs UINT)
    (prev-modf-regs UINT)
    ; Bit-mask for regs modified by the current insn, propagated to
    ; Bit-mask for regs modified by the current insn, propagated to
    ; prev-modf-regs.
    ; prev-modf-regs.
    (modf-regs UINT)
    (modf-regs UINT)
    ; Registers loaded by movem are not forwarded to the execution
    ; Registers loaded by movem are not forwarded to the execution
    ; stage, so we need to insert stall-cycles for ordinary insns
    ; stage, so we need to insert stall-cycles for ordinary insns
    ; accessing such registers.  In addition to the *modf-regs
    ; accessing such registers.  In addition to the *modf-regs
    ; above, these are set to tell *ordinary* insns which registers
    ; above, these are set to tell *ordinary* insns which registers
    ; are inaccessible.
    ; are inaccessible.
    (prev-prev-prev-movem-dest-regs UINT)
    (prev-prev-prev-movem-dest-regs UINT)
    ; Ditto for the 2nd previous insn.
    ; Ditto for the 2nd previous insn.
    (prev-prev-movem-dest-regs UINT)
    (prev-prev-movem-dest-regs UINT)
    ; Ditto for the previous insn.
    ; Ditto for the previous insn.
    (prev-movem-dest-regs UINT)
    (prev-movem-dest-regs UINT)
    ; Bit-mask for regs modified by the current insn, propagated to
    ; Bit-mask for regs modified by the current insn, propagated to
    ; prev-movem-dest-regs.
    ; prev-movem-dest-regs.
    (movem-dest-regs UINT))
    (movem-dest-regs UINT))
  ; It seems this pipeline description isn't used at all; this is just
  ; It seems this pipeline description isn't used at all; this is just
  ; for show.
  ; for show.
  ; Noteworthy is the placement of the memory stage before the execute stage.
  ; Noteworthy is the placement of the memory stage before the execute stage.
  (pipeline all "" () ((fetch) (decode) (memory) (execute) (writeback)))
  (pipeline all "" () ((fetch) (decode) (memory) (execute) (writeback)))
  ; Units that contribute only a constant pipeline delay are not included.
  ; Units that contribute only a constant pipeline delay are not included.
  (unit u-mem "Memory Unit" () 1 1 ()
  (unit u-mem "Memory Unit" () 1 1 ()
        ((Rs INT -1))
        ((Rs INT -1))
        () ())
        () ())
  ; Artificial units for read/write-related hazard accounting.
  ; Artificial units for read/write-related hazard accounting.
  (unit u-mem-r "Memory Unit Read" () 1 1 () () () ())
  (unit u-mem-r "Memory Unit Read" () 1 1 () () () ())
  (unit u-mem-w "Memory Unit Write" () 1 1 () () () ())
  (unit u-mem-w "Memory Unit Write" () 1 1 () () () ())
  (unit u-movem-rtom "Movem-to-memory Unit" () 1 1 ()
  (unit u-movem-rtom "Movem-to-memory Unit" () 1 1 ()
        ((Rs INT -1) (Rd INT -1))
        ((Rs INT -1) (Rd INT -1))
        () ())
        () ())
  (unit u-movem-mtor "Movem-to-register Unit" () 1 1 ()
  (unit u-movem-mtor "Movem-to-register Unit" () 1 1 ()
        ((Rs INT -1) (Rd INT -1))
        ((Rs INT -1) (Rd INT -1))
        () ())
        () ())
  (unit u-multiply "Multiply Unit" () 1 1 ()
  (unit u-multiply "Multiply Unit" () 1 1 ()
        ((Rs INT -1) (Rd INT -1))
        ((Rs INT -1) (Rd INT -1))
        () ())
        () ())
  (unit u-branch "Branch Unit" () 1 1 ()
  (unit u-branch "Branch Unit" () 1 1 ()
        ()
        ()
        () ())
        () ())
  (unit u-jump-r "Jump-to-register Unit" () 1 1 ()
  (unit u-jump-r "Jump-to-register Unit" () 1 1 ()
        ((Rs INT -1))
        ((Rs INT -1))
        () ())
        () ())
  (unit u-jump-sr "Jump-to-special-register Unit" () 1 1 ()
  (unit u-jump-sr "Jump-to-special-register Unit" () 1 1 ()
        ((Ps INT -1))
        ((Ps INT -1))
        () ())
        () ())
  (unit u-jump "JAS/BAS Unit, saving PC" () 1 1 ()
  (unit u-jump "JAS/BAS Unit, saving PC" () 1 1 ()
        ()
        ()
        ((Pd INT -1)) ())
        ((Pd INT -1)) ())
  ; To keep track of PC; not really functional units.
  ; To keep track of PC; not really functional units.
  (unit u-const16 "Fetch 16-bit operand" () 1 1 () () () ())
  (unit u-const16 "Fetch 16-bit operand" () 1 1 () () () ())
  (unit u-const32 "Fetch 32-bit operand" () 1 1 () () () ())
  (unit u-const32 "Fetch 32-bit operand" () 1 1 () () () ())
  (unit u-skip4 "Skip 4 bytes" () 1 1 () () () ())
  (unit u-skip4 "Skip 4 bytes" () 1 1 () () () ())
  ; For v32, we need to keep track of inputs (for movem destination
  ; For v32, we need to keep track of inputs (for movem destination
  ; cycle penalties) and output (for e.g. memory source and jump
  ; cycle penalties) and output (for e.g. memory source and jump
  ; source cycle penalties).
  ; source cycle penalties).
  (unit u-exec "Execution Unit" () 1 1 ()
  (unit u-exec "Execution Unit" () 1 1 ()
        ((Rd INT -1) (Rs INT -1))
        ((Rd INT -1) (Rs INT -1))
        ((Rd INT -1))
        ((Rd INT -1))
        ())
        ())
  ; Special case of u-exec for movem: don't treat Rd as an incoming
  ; Special case of u-exec for movem: don't treat Rd as an incoming
  ; parameter.
  ; parameter.
  (unit u-exec-movem "Execution Unit" () 1 1 ()
  (unit u-exec-movem "Execution Unit" () 1 1 ()
        ((Rs INT -1))
        ((Rs INT -1))
        ((Rd INT -1))
        ((Rd INT -1))
        ())
        ())
  ; Special case of u-exec when the destination is a special
  ; Special case of u-exec when the destination is a special
  ; register.
  ; register.
  (unit u-exec-to-sr "Execution Unit" () 1 1 ()
  (unit u-exec-to-sr "Execution Unit" () 1 1 ()
        ((Rs INT -1))
        ((Rs INT -1))
        ((Pd INT -1)) ())
        ((Pd INT -1)) ())
)
)
(define-pmacro (crisv32-timing-destreg d)
(define-pmacro (crisv32-timing-destreg d)
  "Timing for instructions running on a crisv32 model"
  "Timing for instructions running on a crisv32 model"
  ((crisv32
  ((crisv32
    (.splice unit u-exec (.unsplice d))))
    (.splice unit u-exec (.unsplice d))))
)
)
(define-pmacro (crisv32-timing) (crisv32-timing-destreg ()))
(define-pmacro (crisv32-timing) (crisv32-timing-destreg ()))
(define-pmacro (cris-timing-Rd-sfield)
(define-pmacro (cris-timing-Rd-sfield)
  (crisv32-timing-destreg ((out Rd Rd-sfield)))
  (crisv32-timing-destreg ((out Rd Rd-sfield)))
)
)
(define-pmacro (crisv32-timing-c-HI)
(define-pmacro (crisv32-timing-c-HI)
  ((crisv32 (unit u-const16) (unit u-exec)))
  ((crisv32 (unit u-const16) (unit u-exec)))
)
)
(define-pmacro-map
(define-pmacro-map
  ((crisv32-timing-c-QI crisv32-timing-c-HI)
  ((crisv32-timing-c-QI crisv32-timing-c-HI)
   ((crisv32-timing-c-SI) ((crisv32 (unit u-const32) (unit u-exec))))
   ((crisv32-timing-c-SI) ((crisv32 (unit u-const32) (unit u-exec))))
   ((crisv32-timing-c-sr-SI) ((crisv32 (unit u-const32) (unit u-exec-to-sr))))
   ((crisv32-timing-c-sr-SI) ((crisv32 (unit u-const32) (unit u-exec-to-sr))))
   ((crisv32-reg-sr-timing) ((crisv32 (unit u-exec-to-sr))))
   ((crisv32-reg-sr-timing) ((crisv32 (unit u-exec-to-sr))))
   ((crisv32-mem-sr-timing)
   ((crisv32-mem-sr-timing)
    ((crisv32 (unit u-mem) (unit u-mem-r) (unit u-exec-to-sr))))
    ((crisv32 (unit u-mem) (unit u-mem-r) (unit u-exec-to-sr))))
   ((crisv32-mem-timing) ((crisv32 (unit u-mem) (unit u-mem-r) (unit u-exec))))
   ((crisv32-mem-timing) ((crisv32 (unit u-mem) (unit u-mem-r) (unit u-exec))))
   ((crisv32-mem-write-timing) ((crisv32 (unit u-mem) (unit u-exec) (unit u-mem-w)))))
   ((crisv32-mem-write-timing) ((crisv32 (unit u-mem) (unit u-exec) (unit u-mem-w)))))
)
)
(define-pmacro-map
(define-pmacro-map
  (
  (
   ; Timing for instructions using memory operands.
   ; Timing for instructions using memory operands.
   ((cris-mem-timing)           (.splice (.unsplice (simplecris-mem-timing))
   ((cris-mem-timing)           (.splice (.unsplice (simplecris-mem-timing))
                                         (.unsplice (crisv32-mem-timing))))
                                         (.unsplice (crisv32-mem-timing))))
  ; Timing for instructions using memory operands.
  ; Timing for instructions using memory operands.
   ((cris-mem-write-timing)     (.splice
   ((cris-mem-write-timing)     (.splice
                                 (.unsplice (simplecris-mem-timing))
                                 (.unsplice (simplecris-mem-timing))
                                 (.unsplice (crisv32-mem-write-timing))))
                                 (.unsplice (crisv32-mem-write-timing))))
   ; Timing for moves from general register to special register.
   ; Timing for moves from general register to special register.
   ((cris-reg-sr-timing)        (.splice (.unsplice (simplecris-timing))
   ((cris-reg-sr-timing)        (.splice (.unsplice (simplecris-timing))
                                         (.unsplice (crisv32-reg-sr-timing))))
                                         (.unsplice (crisv32-reg-sr-timing))))
   ; Timing for moves from memory to special register.
   ; Timing for moves from memory to special register.
   ((cris-mem-sr-timing)        (.splice (.unsplice (simplecris-mem-timing))
   ((cris-mem-sr-timing)        (.splice (.unsplice (simplecris-mem-timing))
                                         (.unsplice (crisv32-mem-sr-timing))))
                                         (.unsplice (crisv32-mem-sr-timing))))
   ; Timing for non-mul, non-memory, non-special-register, 16-bit instructions.
   ; Timing for non-mul, non-memory, non-special-register, 16-bit instructions.
   ((cris-timing)               (.splice (.unsplice (simplecris-timing))
   ((cris-timing)               (.splice (.unsplice (simplecris-timing))
                                         (.unsplice (crisv32-timing))))
                                         (.unsplice (crisv32-timing))))
   ; Timing for instructions with 8- or 16-bit constant operand ([PC+]).
   ; Timing for instructions with 8- or 16-bit constant operand ([PC+]).
   ((cris-timing-const-HI)      (.splice
   ((cris-timing-const-HI)      (.splice
                                 (.unsplice (simplecris-const-timing-HI))
                                 (.unsplice (simplecris-const-timing-HI))
                                 (.unsplice (crisv32-timing-c-HI))))
                                 (.unsplice (crisv32-timing-c-HI))))
   ; Timing for instructions with a 32-bit constant operand ([PC+]).
   ; Timing for instructions with a 32-bit constant operand ([PC+]).
   ((cris-timing-const-SI)      (.splice
   ((cris-timing-const-SI)      (.splice
                                 (.unsplice (simplecris-const-timing-SI))
                                 (.unsplice (simplecris-const-timing-SI))
                                 (.unsplice (crisv32-timing-c-SI))))
                                 (.unsplice (crisv32-timing-c-SI))))
   ; Like cris-timing-const-SI, but destination special register.
   ; Like cris-timing-const-SI, but destination special register.
   ((cris-timing-const-sr-SI)   (.splice
   ((cris-timing-const-sr-SI)   (.splice
                                 (.unsplice (simplecris-const-timing-SI))
                                 (.unsplice (simplecris-const-timing-SI))
                                 (.unsplice (crisv32-timing-c-sr-SI))))
                                 (.unsplice (crisv32-timing-c-sr-SI))))
   ; Like cris-timing-const-HI, but destination special register.
   ; Like cris-timing-const-HI, but destination special register.
   ((cris-timing-const-sr-HI)   (.splice
   ((cris-timing-const-sr-HI)   (.splice
                                 (.unsplice (simplecris-const-timing-HI))
                                 (.unsplice (simplecris-const-timing-HI))
                                 (.unsplice (crisv32-timing-c-sr-SI)))))
                                 (.unsplice (crisv32-timing-c-sr-SI)))))
)
)
(define-pmacro cris-timing-const-QI cris-timing-const-HI)
(define-pmacro cris-timing-const-QI cris-timing-const-HI)
(define-pmacro cris-timing-const-sr-QI cris-timing-const-sr-HI)
(define-pmacro cris-timing-const-sr-QI cris-timing-const-sr-HI)
(define-pmacro (simplecris-common-writable-specregs)
(define-pmacro (simplecris-common-writable-specregs)
  "The common writable special registers in pre-v32 models."
  "The common writable special registers in pre-v32 models."
  ((HI 5) (SI 9) (SI 10) (SI 11) (SI 12) (SI 13))
  ((HI 5) (SI 9) (SI 10) (SI 11) (SI 12) (SI 13))
)
)
(define-pmacro (simplecris-common-readable-specregs)
(define-pmacro (simplecris-common-readable-specregs)
  "The common readable special registers in pre-v32 models."
  "The common readable special registers in pre-v32 models."
  (.splice (.unsplice (simplecris-common-writable-specregs))
  (.splice (.unsplice (simplecris-common-writable-specregs))
           (QI 0) (QI 1) (HI 4) (SI 8))
           (QI 0) (QI 1) (HI 4) (SI 8))
)
)
(define-pmacro (cris-implemented-writable-specregs-v0)
(define-pmacro (cris-implemented-writable-specregs-v0)
  "Special writable registers in v0 and their sizes"
  "Special writable registers in v0 and their sizes"
  (.splice (.unsplice (simplecris-common-writable-specregs)) (HI 6) (HI 7))
  (.splice (.unsplice (simplecris-common-writable-specregs)) (HI 6) (HI 7))
)
)
(define-pmacro
(define-pmacro
  cris-implemented-specregs-const-v0
  cris-implemented-specregs-const-v0
  cris-implemented-writable-specregs-v0
  cris-implemented-writable-specregs-v0
)
)
(define-pmacro (cris-implemented-readable-specregs-v0)
(define-pmacro (cris-implemented-readable-specregs-v0)
  "Special readable registers in v0 and their sizes"
  "Special readable registers in v0 and their sizes"
  (.splice (.unsplice (simplecris-common-readable-specregs)) (HI 6) (HI 7))
  (.splice (.unsplice (simplecris-common-readable-specregs)) (HI 6) (HI 7))
)
)
(define-pmacro (cris-implemented-writable-specregs-v3)
(define-pmacro (cris-implemented-writable-specregs-v3)
  "Special writable registers in v3 and their sizes"
  "Special writable registers in v3 and their sizes"
  (.splice (.unsplice (cris-implemented-writable-specregs-v0)) (SI 14))
  (.splice (.unsplice (cris-implemented-writable-specregs-v0)) (SI 14))
)
)
(define-pmacro
(define-pmacro
  cris-implemented-specregs-const-v3
  cris-implemented-specregs-const-v3
  cris-implemented-writable-specregs-v3
  cris-implemented-writable-specregs-v3
)
)
(define-pmacro (cris-implemented-readable-specregs-v3)
(define-pmacro (cris-implemented-readable-specregs-v3)
  "Special readable registers in v3 and their sizes"
  "Special readable registers in v3 and their sizes"
  (.splice (.unsplice (cris-implemented-readable-specregs-v0)) (SI 14))
  (.splice (.unsplice (cris-implemented-readable-specregs-v0)) (SI 14))
)
)
(define-pmacro (cris-implemented-writable-specregs-v8)
(define-pmacro (cris-implemented-writable-specregs-v8)
  "Special writable registers in v8 and their sizes"
  "Special writable registers in v8 and their sizes"
  (.splice (.unsplice (simplecris-common-writable-specregs)) (SI 14))
  (.splice (.unsplice (simplecris-common-writable-specregs)) (SI 14))
)
)
(define-pmacro
(define-pmacro
  cris-implemented-specregs-const-v8
  cris-implemented-specregs-const-v8
  cris-implemented-writable-specregs-v8
  cris-implemented-writable-specregs-v8
)
)
(define-pmacro (cris-implemented-readable-specregs-v8)
(define-pmacro (cris-implemented-readable-specregs-v8)
  "Special readable registers in v8 and their sizes"
  "Special readable registers in v8 and their sizes"
  (.splice (.unsplice (simplecris-common-readable-specregs)) (SI 14))
  (.splice (.unsplice (simplecris-common-readable-specregs)) (SI 14))
)
)
(define-pmacro (cris-implemented-writable-specregs-v10)
(define-pmacro (cris-implemented-writable-specregs-v10)
  "Special writable registers in v10 and their sizes"
  "Special writable registers in v10 and their sizes"
  (.splice (.unsplice (simplecris-common-writable-specregs))
  (.splice (.unsplice (simplecris-common-writable-specregs))
           (SI 7) (SI 14) (SI 15))
           (SI 7) (SI 14) (SI 15))
)
)
(define-pmacro
(define-pmacro
  cris-implemented-specregs-const-v10
  cris-implemented-specregs-const-v10
  cris-implemented-writable-specregs-v10
  cris-implemented-writable-specregs-v10
)
)
(define-pmacro (cris-implemented-readable-specregs-v10)
(define-pmacro (cris-implemented-readable-specregs-v10)
  "Special registers in v10 and their sizes"
  "Special registers in v10 and their sizes"
  (.splice (.unsplice (simplecris-common-readable-specregs))
  (.splice (.unsplice (simplecris-common-readable-specregs))
           (SI 7) (SI 14) (SI 15))
           (SI 7) (SI 14) (SI 15))
)
)
(define-pmacro (cris-implemented-writable-specregs-v32)
(define-pmacro (cris-implemented-writable-specregs-v32)
  "Special writable registers in v32 and their sizes"
  "Special writable registers in v32 and their sizes"
  ((QI 2) (QI 3)
  ((QI 2) (QI 3)
   (SI 5) (SI 6) (SI 7) (SI 9)
   (SI 5) (SI 6) (SI 7) (SI 9)
   (SI 10) (SI 11) (SI 12) (SI 13) (SI 14) (SI 15))
   (SI 10) (SI 11) (SI 12) (SI 13) (SI 14) (SI 15))
)
)
(define-pmacro (cris-implemented-readable-specregs-v32)
(define-pmacro (cris-implemented-readable-specregs-v32)
  "Special readable registers in v32 and their sizes"
  "Special readable registers in v32 and their sizes"
  (.splice (.unsplice (cris-implemented-writable-specregs-v32))
  (.splice (.unsplice (cris-implemented-writable-specregs-v32))
           (QI 0) (QI 1) (HI 4) (SI 8))
           (QI 0) (QI 1) (HI 4) (SI 8))
)
)
; For v32, all special register operations on constants (that is,
; For v32, all special register operations on constants (that is,
; move) take 32-bit operands, not the real size of the register, as in
; move) take 32-bit operands, not the real size of the register, as in
; other move operations.
; other move operations.
(define-pmacro (cris-implemented-specregs-const-v32)
(define-pmacro (cris-implemented-specregs-const-v32)
  (.map (.pmacro (x) (SI (.cadr2 x)))
  (.map (.pmacro (x) (SI (.cadr2 x)))
        (cris-implemented-writable-specregs-v32))
        (cris-implemented-writable-specregs-v32))
)
)
(define-pmacro cris-swap-codes
(define-pmacro cris-swap-codes
  "CRIS Swap codes in numeric order (no zero)"
  "CRIS Swap codes in numeric order (no zero)"
  (   r  b  br  w  wr  wb  wbr
  (   r  b  br  w  wr  wb  wbr
   n nr nb nbr nw nwr nwb nwbr)
   n nr nb nbr nw nwr nwb nwbr)
)
)
(define-pmacro cris-flagnames
(define-pmacro cris-flagnames
  "CRIS flag field values, dest and src fields concatenated"
  "CRIS flag field values, dest and src fields concatenated"
  (c v z n x i u p) ; ... b m for pre-v32
  (c v z n x i u p) ; ... b m for pre-v32
)
)
(define-pmacro-map
(define-pmacro-map
  ; Bitnumber for each respective flag.
  ; Bitnumber for each respective flag.
  (.map (.pmacro (x num) ((.sym x -bitnumber) num))
  (.map (.pmacro (x num) ((.sym x -bitnumber) num))
        cris-flagnames (.iota 8))
        cris-flagnames (.iota 8))
)
)
; I give up.  Here's a perl-script to get the values I want for this macro
; I give up.  Here's a perl-script to get the values I want for this macro
; (not working along list principles, though).  You can run this region.
; (not working along list principles, though).  You can run this region.
; perl -e '$x = "cvznxiup"; for ($i = 0; $i < 256; $i++) { $s = "";
; perl -e '$x = "cvznxiup"; for ($i = 0; $i < 256; $i++) { $s = "";
;  for ($j = 0; $j < 8; $j++) { if ($i & (1 << $j)) {
;  for ($j = 0; $j < 8; $j++) { if ($i & (1 << $j)) {
; $s .= substr ($x, $j, 1);}}
; $s .= substr ($x, $j, 1);}}
; printf ("%s%s", $s eq "" ? "_" : $s, (($i + 1) % 8) == 0 ? "\n   " : " "); }'
; printf ("%s%s", $s eq "" ? "_" : $s, (($i + 1) % 8) == 0 ? "\n   " : " "); }'
(define-pmacro cris-flag-combinations
(define-pmacro cris-flag-combinations
  "Combinations of flags in numeric order"
  "Combinations of flags in numeric order"
  (_ c v cv z cz vz cvz
  (_ c v cv z cz vz cvz
   n cn vn cvn zn czn vzn cvzn
   n cn vn cvn zn czn vzn cvzn
   x cx vx cvx zx czx vzx cvzx
   x cx vx cvx zx czx vzx cvzx
   nx cnx vnx cvnx znx cznx vznx cvznx
   nx cnx vnx cvnx znx cznx vznx cvznx
   i ci vi cvi zi czi vzi cvzi
   i ci vi cvi zi czi vzi cvzi
   ni cni vni cvni zni czni vzni cvzni
   ni cni vni cvni zni czni vzni cvzni
   xi cxi vxi cvxi zxi czxi vzxi cvzxi
   xi cxi vxi cvxi zxi czxi vzxi cvzxi
   nxi cnxi vnxi cvnxi znxi cznxi vznxi cvznxi
   nxi cnxi vnxi cvnxi znxi cznxi vznxi cvznxi
   u cu vu cvu zu czu vzu cvzu
   u cu vu cvu zu czu vzu cvzu
   nu cnu vnu cvnu znu cznu vznu cvznu
   nu cnu vnu cvnu znu cznu vznu cvznu
   xu cxu vxu cvxu zxu czxu vzxu cvzxu
   xu cxu vxu cvxu zxu czxu vzxu cvzxu
   nxu cnxu vnxu cvnxu znxu cznxu vznxu cvznxu
   nxu cnxu vnxu cvnxu znxu cznxu vznxu cvznxu
   iu ciu viu cviu ziu cziu vziu cvziu
   iu ciu viu cviu ziu cziu vziu cvziu
   niu cniu vniu cvniu zniu czniu vzniu cvzniu
   niu cniu vniu cvniu zniu czniu vzniu cvzniu
   xiu cxiu vxiu cvxiu zxiu czxiu vzxiu cvzxiu
   xiu cxiu vxiu cvxiu zxiu czxiu vzxiu cvzxiu
   nxiu cnxiu vnxiu cvnxiu znxiu cznxiu vznxiu cvznxiu
   nxiu cnxiu vnxiu cvnxiu znxiu cznxiu vznxiu cvznxiu
   p cp vp cvp zp czp vzp cvzp
   p cp vp cvp zp czp vzp cvzp
   np cnp vnp cvnp znp cznp vznp cvznp
   np cnp vnp cvnp znp cznp vznp cvznp
   xp cxp vxp cvxp zxp czxp vzxp cvzxp
   xp cxp vxp cvxp zxp czxp vzxp cvzxp
   nxp cnxp vnxp cvnxp znxp cznxp vznxp cvznxp
   nxp cnxp vnxp cvnxp znxp cznxp vznxp cvznxp
   ip cip vip cvip zip czip vzip cvzip
   ip cip vip cvip zip czip vzip cvzip
   nip cnip vnip cvnip znip cznip vznip cvznip
   nip cnip vnip cvnip znip cznip vznip cvznip
   xip cxip vxip cvxip zxip czxip vzxip cvzxip
   xip cxip vxip cvxip zxip czxip vzxip cvzxip
   nxip cnxip vnxip cvnxip znxip cznxip vznxip cvznxip
   nxip cnxip vnxip cvnxip znxip cznxip vznxip cvznxip
   up cup vup cvup zup czup vzup cvzup
   up cup vup cvup zup czup vzup cvzup
   nup cnup vnup cvnup znup cznup vznup cvznup
   nup cnup vnup cvnup znup cznup vznup cvznup
   xup cxup vxup cvxup zxup czxup vzxup cvzxup
   xup cxup vxup cvxup zxup czxup vzxup cvzxup
   nxup cnxup vnxup cvnxup znxup cznxup vznxup cvznxup
   nxup cnxup vnxup cvnxup znxup cznxup vznxup cvznxup
   iup ciup viup cviup ziup cziup vziup cvziup
   iup ciup viup cviup ziup cziup vziup cvziup
   niup cniup vniup cvniup zniup czniup vzniup cvzniup
   niup cniup vniup cvniup zniup czniup vzniup cvzniup
   xiup cxiup vxiup cvxiup zxiup czxiup vzxiup cvzxiup
   xiup cxiup vxiup cvxiup zxiup czxiup vzxiup cvzxiup
   nxiup cnxiup vnxiup cvnxiup znxiup cznxiup vznxiup cvznxiup
   nxiup cnxiup vnxiup cvnxiup znxiup cznxiup vznxiup cvznxiup
  )
  )
)
)
(define-pmacro cc-condition (not cbit))
(define-pmacro cc-condition (not cbit))
(define-pmacro cs-condition cbit)
(define-pmacro cs-condition cbit)
(define-pmacro ne-condition (not zbit))
(define-pmacro ne-condition (not zbit))
(define-pmacro eq-condition zbit)
(define-pmacro eq-condition zbit)
(define-pmacro vc-condition (not vbit))
(define-pmacro vc-condition (not vbit))
(define-pmacro vs-condition vbit)
(define-pmacro vs-condition vbit)
(define-pmacro pl-condition (not nbit))
(define-pmacro pl-condition (not nbit))
(define-pmacro mi-condition nbit)
(define-pmacro mi-condition nbit)
(define-pmacro ls-condition (or cbit zbit))
(define-pmacro ls-condition (or cbit zbit))
(define-pmacro hi-condition (not (or cbit zbit)))
(define-pmacro hi-condition (not (or cbit zbit)))
(define-pmacro ge-condition (not (xor vbit nbit)))
(define-pmacro ge-condition (not (xor vbit nbit)))
(define-pmacro lt-condition (xor vbit nbit))
(define-pmacro lt-condition (xor vbit nbit))
(define-pmacro gt-condition (not (or (xor vbit nbit) zbit)))
(define-pmacro gt-condition (not (or (xor vbit nbit) zbit)))
(define-pmacro le-condition (or (xor vbit nbit) zbit))
(define-pmacro le-condition (or (xor vbit nbit) zbit))
(define-pmacro a-condition 1)
(define-pmacro a-condition 1)
; FIXME: define this properly for v10 and pre-v10.
; FIXME: define this properly for v10 and pre-v10.
(define-pmacro wf-condition pbit)
(define-pmacro wf-condition pbit)
(define-pmacro (cris-condition condno)
(define-pmacro (cris-condition condno)
  "Return condition state for condition number CONDNO"
  "Return condition state for condition number CONDNO"
  (sequence
  (sequence
    BI
    BI
    ((SI tmpcond) (BI condres))
    ((SI tmpcond) (BI condres))
    (set tmpcond condno)
    (set tmpcond condno)
     (.splice
     (.splice
      cond
      cond
      (.unsplice
      (.unsplice
       (.map
       (.map
        (.pmacro
        (.pmacro
         (condn condc)
         (condn condc)
         ((eq tmpcond condn) (set condres (.sym condc -condition))))
         ((eq tmpcond condn) (set condres (.sym condc -condition))))
        (.iota 16)
        (.iota 16)
        cris-condition-codes)))
        cris-condition-codes)))
     condres)
     condres)
)
)
;;;;;;;;;;;;;;;;;; -keyword
;;;;;;;;;;;;;;;;;; -keyword
; General registers.
; General registers.
(define-pmacro (cris-general-gregs)
(define-pmacro (cris-general-gregs)
  (.splice (SP 14) (.unsplice (.map (.pmacro (n) ((.sym R n) n)) (.iota 15))))
  (.splice (SP 14) (.unsplice (.map (.pmacro (n) ((.sym R n) n)) (.iota 15))))
)
)
; Can't keep more than one gr-names definition at the same time;
; Can't keep more than one gr-names definition at the same time;
; generated enum declarations in sim/cris/cris-desc.h will collide.
; generated enum declarations in sim/cris/cris-desc.h will collide.
; FIXME: (include "different-mach-parts")
; FIXME: (include "different-mach-parts")
(define-keyword
(define-keyword
  (name gr-names-pcreg)
  (name gr-names-pcreg)
  (attrs MACH-PC)
  (attrs MACH-PC)
  (print-name h-gr-real-pc)
  (print-name h-gr-real-pc)
  ; Put PC first so it is preferred over r15.
  ; Put PC first so it is preferred over r15.
  (.splice values (PC 15) (.unsplice (cris-general-gregs)))
  (.splice values (PC 15) (.unsplice (cris-general-gregs)))
)
)
(define-keyword
(define-keyword
  (name gr-names-acr)
  (name gr-names-acr)
  (attrs MACH-ACR)
  (attrs MACH-ACR)
  ; The print-name directive will control the enum prefix.  With the
  ; The print-name directive will control the enum prefix.  With the
  ; arguably more appropriate h-gr-v32 or h-gr-acr, we'd get names like
  ; arguably more appropriate h-gr-v32 or h-gr-acr, we'd get names like
  ; H_GR_ACR_R0 instead of H_GR_R0.  Since we have to choose something for
  ; H_GR_ACR_R0 instead of H_GR_R0.  Since we have to choose something for
  ; unprefixed names, we use the CRISv32 names.  FIXME: All users should
  ; unprefixed names, we use the CRISv32 names.  FIXME: All users should
  ; change to use H_GR_V32_R0 (etc.), then change this to h-gr-v32.
  ; change to use H_GR_V32_R0 (etc.), then change this to h-gr-v32.
  (print-name h-gr)
  (print-name h-gr)
  ; Put ACR first so it is preferred over r15.
  ; Put ACR first so it is preferred over r15.
  (.splice values (ACR 15) (.unsplice (cris-general-gregs)))
  (.splice values (ACR 15) (.unsplice (cris-general-gregs)))
)
)
(define-keyword
(define-keyword
  (name gr-names-v32)
  (name gr-names-v32)
  (attrs MACH-V32)
  (attrs MACH-V32)
  ; In preparation for implementing the FIXME above.
  ; In preparation for implementing the FIXME above.
  (print-name h-gr-v32)
  (print-name h-gr-v32)
  ; Put ACR first so it is preferred over r15.
  ; Put ACR first so it is preferred over r15.
  (.splice values (ACR 15) (.unsplice (cris-general-gregs)))
  (.splice values (ACR 15) (.unsplice (cris-general-gregs)))
)
)
; Special registers with names common to all.
; Special registers with names common to all.
(define-pmacro (cris-general-pregs)
(define-pmacro (cris-general-pregs)
  (.splice
  (.splice
   (VR 1)
   (VR 1)
   (SRP 11)
   (SRP 11)
   (.unsplice (.map (.pmacro (n) ((.sym P n) n)) (.iota 15))))
   (.unsplice (.map (.pmacro (n) ((.sym P n) n)) (.iota 15))))
)
)
(define-keyword
(define-keyword
  (name p-names-v10)
  (name p-names-v10)
  (attrs MACH-PRE-V32)
  (attrs MACH-PRE-V32)
  (print-name h-sr-pre-v32)
  (print-name h-sr-pre-v32)
  (.splice
  (.splice
   values
   values
   (CCR 5)
   (CCR 5)
   (MOF 7)
   (MOF 7)
   (IBR 9)
   (IBR 9)
   (IRP 10)
   (IRP 10)
   (BAR 12)
   (BAR 12)
   (DCCR 13)
   (DCCR 13)
   (BRP 14)
   (BRP 14)
   (USP 15)
   (USP 15)
   (.unsplice (cris-general-pregs)))
   (.unsplice (cris-general-pregs)))
)
)
(define-keyword
(define-keyword
  (name p-names-v32)
  (name p-names-v32)
  (attrs MACH-V32)
  (attrs MACH-V32)
  ; See comment for gr-names-acr.
  ; See comment for gr-names-acr.
  (print-name h-sr)
  (print-name h-sr)
  (.splice
  (.splice
   values
   values
   (BZ 0)
   (BZ 0)
   (PID 2)
   (PID 2)
   (SRS 3)
   (SRS 3)
   (WZ 4)
   (WZ 4)
   (EXS 5)
   (EXS 5)
   (EDA 6)
   (EDA 6)
   (MOF 7)
   (MOF 7)
   (DZ 8)
   (DZ 8)
   (EBP 9)
   (EBP 9)
   (ERP 10)
   (ERP 10)
   (NRP 12)
   (NRP 12)
   (CCS 13)
   (CCS 13)
   (USP 14)
   (USP 14)
   (SPC 15)
   (SPC 15)
   (.unsplice (cris-general-pregs)))
   (.unsplice (cris-general-pregs)))
)
)
; Similarly as for h-gr-v32, in preparation.
; Similarly as for h-gr-v32, in preparation.
(define-keyword
(define-keyword
  (name p-names-v32-x)
  (name p-names-v32-x)
  (attrs MACH-V32)
  (attrs MACH-V32)
  ; See comment for gr-names-acr.
  ; See comment for gr-names-acr.
  (print-name h-sr-v32)
  (print-name h-sr-v32)
  (.splice
  (.splice
   values
   values
   (BZ 0)
   (BZ 0)
   (PID 2)
   (PID 2)
   (SRS 3)
   (SRS 3)
   (WZ 4)
   (WZ 4)
   (EXS 5)
   (EXS 5)
   (EDA 6)
   (EDA 6)
   (MOF 7)
   (MOF 7)
   (DZ 8)
   (DZ 8)
   (EBP 9)
   (EBP 9)
   (ERP 10)
   (ERP 10)
   (NRP 12)
   (NRP 12)
   (CCS 13)
   (CCS 13)
   (USP 14)
   (USP 14)
   (SPC 15)
   (SPC 15)
   (.unsplice (cris-general-pregs)))
   (.unsplice (cris-general-pregs)))
)
)
(define-pmacro p0 (reg h-sr 0))
(define-pmacro p0 (reg h-sr 0))
(define-pmacro vr (reg h-sr 1))
(define-pmacro vr (reg h-sr 1))
(define-pmacro pid (reg h-sr 2))
(define-pmacro pid (reg h-sr 2))
(define-pmacro srs (reg h-sr 3))
(define-pmacro srs (reg h-sr 3))
(define-pmacro p4 (reg h-sr 4))
(define-pmacro p4 (reg h-sr 4))
(define-pmacro ccr (reg h-sr 5))
(define-pmacro ccr (reg h-sr 5))
(define-pmacro mof (reg h-sr 7))
(define-pmacro mof (reg h-sr 7))
(define-pmacro p8 (reg h-sr 8))
(define-pmacro p8 (reg h-sr 8))
(define-pmacro ibr (reg h-sr 9))
(define-pmacro ibr (reg h-sr 9))
(define-pmacro ebp (reg h-sr 9))
(define-pmacro ebp (reg h-sr 9))
(define-pmacro erp (reg h-sr 10))
(define-pmacro erp (reg h-sr 10))
(define-pmacro srp (reg h-sr 11))
(define-pmacro srp (reg h-sr 11))
(define-pmacro ccs (reg h-sr 13))
(define-pmacro ccs (reg h-sr 13))
(define-pmacro dccr (reg h-sr 13))
(define-pmacro dccr (reg h-sr 13))
(define-pmacro usp (reg h-sr 14))
(define-pmacro usp (reg h-sr 14))
(define-pmacro spc (reg h-sr 15))
(define-pmacro spc (reg h-sr 15))
(define-pmacro sp (reg h-gr 14))
(define-pmacro sp (reg h-gr 14))
(define-pmacro acr (reg h-gr 15))
(define-pmacro acr (reg h-gr 15))
(define-pmacro cris-condition-codes
(define-pmacro cris-condition-codes
  "CRIS condition codes in numeric order"
  "CRIS condition codes in numeric order"
  (cc cs ne eq vc vs pl mi ls hi ge lt gt le a wf)
  (cc cs ne eq vc vs pl mi ls hi ge lt gt le a wf)
)
)
; No use having different lists; this is the only CC that
; No use having different lists; this is the only CC that
; differs between v10 and v32, and mostly in the name.
; differs between v10 and v32, and mostly in the name.
(define-pmacro sb wf)
(define-pmacro sb wf)
;;;;;;;;;;;;;;;;;; -hardware
;;;;;;;;;;;;;;;;;; -hardware
;; Various constant generators.
;; Various constant generators.
(define-hardware
(define-hardware
  (name h-inc)
  (name h-inc)
  (comment "autoincrement-bit syntax specifier")
  (comment "autoincrement-bit syntax specifier")
  (type immediate (UINT 1))
  (type immediate (UINT 1))
  (values keyword "" (("" 0) ("+" 1)))
  (values keyword "" (("" 0) ("+" 1)))
)
)
(define-hardware
(define-hardware
  (name h-ccode)
  (name h-ccode)
  (comment "Condition code specifier")
  (comment "Condition code specifier")
  (type immediate (UINT 4))
  (type immediate (UINT 4))
  (values keyword ""
  (values keyword ""
          (.map (.pmacro (x y) ((.str x) y))
          (.map (.pmacro (x y) ((.str x) y))
                cris-condition-codes (.iota 16)))
                cris-condition-codes (.iota 16)))
)
)
(define-hardware
(define-hardware
  (name h-swap)
  (name h-swap)
  (comment "Swap option specifier")
  (comment "Swap option specifier")
  (type immediate (UINT 4))
  (type immediate (UINT 4))
  (values
  (values
   keyword ""
   keyword ""
   (.splice
   (.splice
    (" " 0)
    (" " 0)
    (.unsplice
    (.unsplice
     (.map
     (.map
      (.pmacro (x y) ((.str x) y)) cris-swap-codes (.iota 15 1)))))
      (.pmacro (x y) ((.str x) y)) cris-swap-codes (.iota 15 1)))))
)
)
(define-hardware
(define-hardware
  (name h-flagbits)
  (name h-flagbits)
  (comment "Flag bits specifier")
  (comment "Flag bits specifier")
  (type immediate (UINT 8))
  (type immediate (UINT 8))
  (values
  (values
   keyword ""
   keyword ""
   (.map (.pmacro (x y) ((.str x) y)) cris-flag-combinations (.iota 256)))
   (.map (.pmacro (x y) ((.str x) y)) cris-flag-combinations (.iota 256)))
)
)
; Apparently, the semantic-name isn't used for accessors, so external
; Apparently, the semantic-name isn't used for accessors, so external
; users like the sim glue and SID sees the -v32 and -pre-v32 munged names.
; users like the sim glue and SID sees the -v32 and -pre-v32 munged names.
; Defining "dispatchers"; virtual registers whose getter and setter works
; Defining "dispatchers"; virtual registers whose getter and setter works
; on the "real" mach variants, seems to help.  CGEN-FIXME: Make
; on the "real" mach variants, seems to help.  CGEN-FIXME: Make
; semantic-name set the generated names.
; semantic-name set the generated names.
(define-pmacro (cris-d-hwreg x-name x-type)
(define-pmacro (cris-d-hwreg x-name x-type)
  (define-hardware
  (define-hardware
    (name x-name)
    (name x-name)
    (comment (.str "Dispatcher for " x-name))
    (comment (.str "Dispatcher for " x-name))
    (attrs VIRTUAL)
    (attrs VIRTUAL)
    (type register x-type)
    (type register x-type)
    (get () (reg (.sym x-name -x)))
    (get () (reg (.sym x-name -x)))
    (set (val) (set (reg (.sym x-name -x)) val)))
    (set (val) (set (reg (.sym x-name -x)) val)))
)
)
(define-pmacro (cris-d-hwregf-a x-name x-type x-n x-attrs)
(define-pmacro (cris-d-hwregf-a x-name x-type x-n x-attrs)
  (define-hardware
  (define-hardware
    (name x-name)
    (name x-name)
    (comment (.str "Dispatcher for " x-name))
    (comment (.str "Dispatcher for " x-name))
    (.splice attrs VIRTUAL (.unsplice x-attrs))
    (.splice attrs VIRTUAL (.unsplice x-attrs))
    (type register x-type (x-n))
    (type register x-type (x-n))
    (get (index) (reg (.sym x-name -x) index))
    (get (index) (reg (.sym x-name -x) index))
    (set (index val) (set-quiet (reg (.sym x-name -x) index) val)))
    (set (index val) (set-quiet (reg (.sym x-name -x) index) val)))
)
)
(define-pmacro (cris-d-hwregf x-name x-type x-n)
(define-pmacro (cris-d-hwregf x-name x-type x-n)
  (cris-d-hwregf-a x-name x-type x-n ())
  (cris-d-hwregf-a x-name x-type x-n ())
)
)
(define-pmacro (cris-d-hwregf-p x-name x-type x-n)
(define-pmacro (cris-d-hwregf-p x-name x-type x-n)
  (cris-d-hwregf-a x-name x-type x-n (PROFILE))
  (cris-d-hwregf-a x-name x-type x-n (PROFILE))
)
)
; At first glance we could use (eq-attr (current-mach) ...) for
; At first glance we could use (eq-attr (current-mach) ...) for
; everything, but that seems sometimes (always?) to yield false.  For
; everything, but that seems sometimes (always?) to yield false.  For
; ifields, it causes noncompilable C-code.  For the insn semantics code,
; ifields, it causes noncompilable C-code.  For the insn semantics code,
; it causes tests movei.ms and mulv32.ms to fail, apparently because the
; it causes tests movei.ms and mulv32.ms to fail, apparently because the
; current-mach-is-v32 usage in flags setting is miscompiled as 0 (or
; current-mach-is-v32 usage in flags setting is miscompiled as 0 (or
; rather, misgenerated).  Instead we use different definitions of a
; rather, misgenerated).  Instead we use different definitions of a
; MACH-tagged virtual register yielding a constant, together with a
; MACH-tagged virtual register yielding a constant, together with a
; pmacro.  CGEN-FIXME: If eq-attr is someday fixed, we could just remove
; pmacro.  CGEN-FIXME: If eq-attr is someday fixed, we could just remove
; these h-v32 virtual register definitions and change the pmacro
; these h-v32 virtual register definitions and change the pmacro
; definition for current-mach-is-v32.
; definition for current-mach-is-v32.
(define-hardware
(define-hardware
  (semantic-name h-v32)
  (semantic-name h-v32)
  (name h-v32-v32)
  (name h-v32-v32)
  (attrs MACH-V32 VIRTUAL)
  (attrs MACH-V32 VIRTUAL)
  (type register BI)
  (type register BI)
  (get () (const BI 1))
  (get () (const BI 1))
  (set (val) (error "Can't set h-v32"))
  (set (val) (error "Can't set h-v32"))
)
)
(define-hardware
(define-hardware
  (semantic-name h-v32)
  (semantic-name h-v32)
  (name h-v32-non-v32)
  (name h-v32-non-v32)
  (attrs MACH-PRE-V32 VIRTUAL)
  (attrs MACH-PRE-V32 VIRTUAL)
  (type register BI)
  (type register BI)
  (get () (const BI 0))
  (get () (const BI 0))
  (set (val) (error "Can't set h-v32"))
  (set (val) (error "Can't set h-v32"))
)
)
;; "Real" hardware.
;; "Real" hardware.
(define-hardware
(define-hardware
  (name h-pc)
  (name h-pc)
  (comment "program counter")
  (comment "program counter")
  (attrs PC PROFILE)
  (attrs PC PROFILE)
  (type pc)
  (type pc)
  ; There's no bit 0 in PC, so just ignore it when jumping etc.
  ; There's no bit 0 in PC, so just ignore it when jumping etc.
  (set (val) (set (raw-reg h-pc) (and val (inv 1))))
  (set (val) (set (raw-reg h-pc) (and val (inv 1))))
)
)
; Note that setting register 15 isn't handled here, but in each insn, so
; Note that setting register 15 isn't handled here, but in each insn, so
; the proper "jump" attributes and other special stuff for speedy
; the proper "jump" attributes and other special stuff for speedy
; execution can be present.
; execution can be present.
(cris-d-hwregf-p h-gr SI 16)
(cris-d-hwregf-p h-gr SI 16)
(define-hardware
(define-hardware
  (semantic-name h-gr-x)
  (semantic-name h-gr-x)
  (name h-gr-pc)
  (name h-gr-pc)
  (attrs MACH-PC VIRTUAL)
  (attrs MACH-PC VIRTUAL)
  (comment "General purpose registers, aborting on PC access")
  (comment "General purpose registers, aborting on PC access")
  (type register SI (16))
  (type register SI (16))
  (indices extern-keyword gr-names-pcreg)
  (indices extern-keyword gr-names-pcreg)
  (get
  (get
   (index)
   (index)
   (if SI (eq index 15)
   (if SI (eq index 15)
       (error SI "General register read of PC is not implemented.")
       (error SI "General register read of PC is not implemented.")
       (reg SI h-gr-real-pc index)))
       (reg SI h-gr-real-pc index)))
  (set
  (set
   (index val)
   (index val)
   (sequence
   (sequence
     ()
     ()
     (if (eq index 15)
     (if (eq index 15)
         (error "General register write to PC is not implemented."))
         (error "General register write to PC is not implemented."))
     (set (reg SI h-gr-real-pc index) val)))
     (set (reg SI h-gr-real-pc index) val)))
)
)
(define-hardware
(define-hardware
  (name h-gr-real-pc)
  (name h-gr-real-pc)
  (attrs MACH-PC)
  (attrs MACH-PC)
  (comment "General purpose registers")
  (comment "General purpose registers")
  (type register SI (16))
  (type register SI (16))
  (indices extern-keyword gr-names-pcreg)
  (indices extern-keyword gr-names-pcreg)
)
)
; We have to use a virtual register trick to get the "raw", unaccounted
; We have to use a virtual register trick to get the "raw", unaccounted
; contents of the global register; the raw-reg RTX only works for
; contents of the global register; the raw-reg RTX only works for
; non-virtual register files.
; non-virtual register files.
(define-hardware
(define-hardware
  (semantic-name h-raw-gr)
  (semantic-name h-raw-gr)
  (name h-raw-gr-pc)
  (name h-raw-gr-pc)
  (attrs MACH-PC VIRTUAL)
  (attrs MACH-PC VIRTUAL)
  (comment "Unaccounted version of general purpose registers")
  (comment "Unaccounted version of general purpose registers")
  (type register SI (16))
  (type register SI (16))
  (get (index) (raw-reg h-gr-real-pc index))
  (get (index) (raw-reg h-gr-real-pc index))
  (set (index val) (set-quiet (raw-reg h-gr-real-pc index) val))
  (set (index val) (set-quiet (raw-reg h-gr-real-pc index) val))
)
)
(define-hardware
(define-hardware
  (semantic-name h-gr-x)
  (semantic-name h-gr-x)
  (name h-gr-acr)
  (name h-gr-acr)
  (attrs MACH-ACR)
  (attrs MACH-ACR)
  (comment "General purpose registers")
  (comment "General purpose registers")
  (type register SI (16))
  (type register SI (16))
  (indices extern-keyword gr-names-acr)
  (indices extern-keyword gr-names-acr)
)
)
(define-hardware
(define-hardware
  (semantic-name h-raw-gr)
  (semantic-name h-raw-gr)
  (name h-raw-gr-acr)
  (name h-raw-gr-acr)
  (attrs MACH-ACR VIRTUAL)
  (attrs MACH-ACR VIRTUAL)
  (comment "Unaccounted version of general purpose registers")
  (comment "Unaccounted version of general purpose registers")
  (type register SI (16))
  (type register SI (16))
  (get (index) (raw-reg h-gr-x index))
  (get (index) (raw-reg h-gr-x index))
  (set (index val) (set-quiet (raw-reg h-gr-x index) val))
  (set (index val) (set-quiet (raw-reg h-gr-x index) val))
)
)
; FIXME: get and set semantics?  Unknown how to split semantics best; with
; FIXME: get and set semantics?  Unknown how to split semantics best; with
; get/set semantics or within the insn specification.  Doing the former for
; get/set semantics or within the insn specification.  Doing the former for
; now.  Should use different names for pre-v10.
; now.  Should use different names for pre-v10.
; FIXME: No dccr for v0 and v3.  Different high flag bits.
; FIXME: No dccr for v0 and v3.  Different high flag bits.
(cris-d-hwregf-p h-sr SI 16)
(cris-d-hwregf-p h-sr SI 16)
(define-pmacro
(define-pmacro
  (cris-h-sr machver)
  (cris-h-sr machver)
  (define-hardware
  (define-hardware
    (semantic-name h-sr-x)
    (semantic-name h-sr-x)
    (name (.sym h-sr-v machver))
    (name (.sym h-sr-v machver))
    (attrs (MACH (.sym crisv machver)))
    (attrs (MACH (.sym crisv machver)))
    (comment (.str "Special registers for v" machver))
    (comment (.str "Special registers for v" machver))
    (type register SI (16))
    (type register SI (16))
    (indices extern-keyword p-names-v10)
    (indices extern-keyword p-names-v10)
    (get
    (get
     (index)
     (index)
     (cond
     (cond
      SI
      SI
      ((orif (orif (eq index (regno p0)) (eq index (regno p4)))
      ((orif (orif (eq index (regno p0)) (eq index (regno p4)))
             (eq index (regno p8))) 0)
             (eq index (regno p8))) 0)
      ((eq index (regno vr)) machver)
      ((eq index (regno vr)) machver)
      ((orif (eq index (regno ccr))
      ((orif (eq index (regno ccr))
             (eq index (regno dccr)))
             (eq index (regno dccr)))
       ; Return "P U I X N Z V C" for the low 8 bits.
       ; Return "P U I X N Z V C" for the low 8 bits.
       ; FIXME: More bits.
       ; FIXME: More bits.
       (or SI
       (or SI
           (and SI (raw-reg SI h-sr-x (regno ccr)) #xffffff00)
           (and SI (raw-reg SI h-sr-x (regno ccr)) #xffffff00)
           (or
           (or
            (zext SI (reg BI h-cbit))
            (zext SI (reg BI h-cbit))
            (or
            (or
             (sll (zext SI (reg BI h-vbit)) 1)
             (sll (zext SI (reg BI h-vbit)) 1)
             (or
             (or
              (sll (zext SI (reg BI h-zbit)) 2)
              (sll (zext SI (reg BI h-zbit)) 2)
              (or
              (or
               (sll (zext SI (reg BI h-nbit)) 3)
               (sll (zext SI (reg BI h-nbit)) 3)
               (or
               (or
                (sll (zext SI (reg BI h-xbit)) 4)
                (sll (zext SI (reg BI h-xbit)) 4)
                (or
                (or
                 (sll (zext SI (reg BI h-ibit)) 5)
                 (sll (zext SI (reg BI h-ibit)) 5)
                 (or
                 (or
                  (sll (zext SI (reg BI h-ubit)) 6)
                  (sll (zext SI (reg BI h-ubit)) 6)
                  (or
                  (or
                   (sll (zext SI (reg BI h-pbit)) 7)
                   (sll (zext SI (reg BI h-pbit)) 7)
                   0))))))))))
                   0))))))))))
      (else (raw-reg SI h-sr-x index))))
      (else (raw-reg SI h-sr-x index))))
    (set
    (set
     (index val)
     (index val)
     (cond
     (cond
      ((orif (orif (eq index (regno p0)) (eq index (regno p4)))
      ((orif (orif (eq index (regno p0)) (eq index (regno p4)))
             (orif (eq index (regno p8)) (eq index (regno vr))))
             (orif (eq index (regno p8)) (eq index (regno vr))))
       (nop))
       (nop))
      ((orif (eq index (regno ccr)) (eq index (regno dccr)))
      ((orif (eq index (regno ccr)) (eq index (regno dccr)))
       (sequence
       (sequence
         ()
         ()
         (set (reg BI h-cbit) (if BI (ne SI (and val (sll 1 0)) 0) 1 0))
         (set (reg BI h-cbit) (if BI (ne SI (and val (sll 1 0)) 0) 1 0))
         (set (reg BI h-vbit) (if BI (ne SI (and val (sll 1 1)) 0) 1 0))
         (set (reg BI h-vbit) (if BI (ne SI (and val (sll 1 1)) 0) 1 0))
         (set (reg BI h-zbit) (if BI (ne SI (and val (sll 1 2)) 0) 1 0))
         (set (reg BI h-zbit) (if BI (ne SI (and val (sll 1 2)) 0) 1 0))
         (set (reg BI h-nbit) (if BI (ne SI (and val (sll 1 3)) 0) 1 0))
         (set (reg BI h-nbit) (if BI (ne SI (and val (sll 1 3)) 0) 1 0))
         (set (reg BI h-xbit) (if BI (ne SI (and val (sll 1 4)) 0) 1 0))
         (set (reg BI h-xbit) (if BI (ne SI (and val (sll 1 4)) 0) 1 0))
         (set (reg BI h-ibit) (if BI (ne SI (and val (sll 1 5)) 0) 1 0))
         (set (reg BI h-ibit) (if BI (ne SI (and val (sll 1 5)) 0) 1 0))
         (set (reg BI h-ubit) (if BI (ne SI (and val (sll 1 6)) 0) 1 0))
         (set (reg BI h-ubit) (if BI (ne SI (and val (sll 1 6)) 0) 1 0))
         (set (reg BI h-pbit) (if BI (ne SI (and val (sll 1 7)) 0) 1 0))
         (set (reg BI h-pbit) (if BI (ne SI (and val (sll 1 7)) 0) 1 0))
         (set-quiet (raw-reg SI h-sr-x (regno ccr)) val)
         (set-quiet (raw-reg SI h-sr-x (regno ccr)) val)
         (set-quiet (raw-reg SI h-sr-x (regno dccr)) val)))
         (set-quiet (raw-reg SI h-sr-x (regno dccr)) val)))
      (else (set-quiet (raw-reg SI h-sr-x index) val)))))
      (else (set-quiet (raw-reg SI h-sr-x index) val)))))
)
)
(cris-h-sr 0)
(cris-h-sr 0)
(cris-h-sr 3)
(cris-h-sr 3)
(cris-h-sr 8)
(cris-h-sr 8)
(cris-h-sr 10)
(cris-h-sr 10)
(define-hardware
(define-hardware
  (semantic-name h-sr-x)
  (semantic-name h-sr-x)
  (name h-sr-v32)
  (name h-sr-v32)
  (attrs MACH-V32)
  (attrs MACH-V32)
  (comment "Special registers for v32")
  (comment "Special registers for v32")
  (type register SI (16))
  (type register SI (16))
  (indices extern-keyword p-names-v32)
  (indices extern-keyword p-names-v32)
  (get
  (get
   (index)
   (index)
   (cond
   (cond
    SI
    SI
    ((orif (orif (eq index (regno p0)) (eq index (regno p4)))
    ((orif (orif (eq index (regno p0)) (eq index (regno p4)))
           (eq index (regno p8))) 0)
           (eq index (regno p8))) 0)
    ((eq index (regno vr)) 32)
    ((eq index (regno vr)) 32)
    ((eq index (regno ccs))
    ((eq index (regno ccs))
     ; Return "S R P U I X N Z V C" for the low 10 bits.
     ; Return "S R P U I X N Z V C" for the low 10 bits.
     (or SI
     (or SI
         (and SI (raw-reg SI h-sr-x (regno ccs)) #x3ffffc00)
         (and SI (raw-reg SI h-sr-x (regno ccs)) #x3ffffc00)
         (or
         (or
          (zext SI (reg BI h-cbit))
          (zext SI (reg BI h-cbit))
          (or
          (or
           (sll (zext SI (reg BI h-vbit)) 1)
           (sll (zext SI (reg BI h-vbit)) 1)
           (or
           (or
            (sll (zext SI (reg BI h-zbit)) 2)
            (sll (zext SI (reg BI h-zbit)) 2)
            (or
            (or
             (sll (zext SI (reg BI h-nbit)) 3)
             (sll (zext SI (reg BI h-nbit)) 3)
             (or
             (or
              (sll (zext SI (reg BI h-xbit)) 4)
              (sll (zext SI (reg BI h-xbit)) 4)
              (or
              (or
               (sll (zext SI (reg BI h-ibit)) 5)
               (sll (zext SI (reg BI h-ibit)) 5)
               (or
               (or
                (sll (zext SI (reg BI h-ubit)) 6)
                (sll (zext SI (reg BI h-ubit)) 6)
                (or
                (or
                 (sll (zext SI (reg BI h-pbit)) 7)
                 (sll (zext SI (reg BI h-pbit)) 7)
                 (or
                 (or
                  (sll (zext SI (reg BI h-rbit)) 8)
                  (sll (zext SI (reg BI h-rbit)) 8)
                  (or
                  (or
                   (sll (zext SI (reg BI h-sbit)) 9)
                   (sll (zext SI (reg BI h-sbit)) 9)
                   (or
                   (or
                    (sll (zext SI (reg BI h-mbit)) 30)
                    (sll (zext SI (reg BI h-mbit)) 30)
                    (or
                    (or
                     (sll (zext SI (reg BI h-qbit)) 31)
                     (sll (zext SI (reg BI h-qbit)) 31)
                     0))))))))))))))
                     0))))))))))))))
    ((eq index (regno usp))
    ((eq index (regno usp))
     ; In user mode, return general stack pointer.
     ; In user mode, return general stack pointer.
     (if BI (reg BI h-ubit)
     (if BI (reg BI h-ubit)
         (raw-reg SI h-gr-x (regno sp))
         (raw-reg SI h-gr-x (regno sp))
         (raw-reg SI h-sr-x (regno usp))))
         (raw-reg SI h-sr-x (regno usp))))
    (else (raw-reg SI h-sr-x index))))
    (else (raw-reg SI h-sr-x index))))
  (set
  (set
   (index val)
   (index val)
   (cond
   (cond
    ((orif (orif (eq index (regno p0)) (eq index (regno p4)))
    ((orif (orif (eq index (regno p0)) (eq index (regno p4)))
           (orif (eq index (regno p8)) (eq index (regno vr))))
           (orif (eq index (regno p8)) (eq index (regno vr))))
     (nop))
     (nop))
    ((eq index (regno ccs))
    ((eq index (regno ccs))
     (sequence
     (sequence
       ()
       ()
       ; Protected bits are handled as such in the respective setter function.
       ; Protected bits are handled as such in the respective setter function.
       (set (reg BI h-cbit) (if BI (ne SI (and val (sll 1 0)) 0) 1 0))
       (set (reg BI h-cbit) (if BI (ne SI (and val (sll 1 0)) 0) 1 0))
       (set (reg BI h-vbit) (if BI (ne SI (and val (sll 1 1)) 0) 1 0))
       (set (reg BI h-vbit) (if BI (ne SI (and val (sll 1 1)) 0) 1 0))
       (set (reg BI h-zbit) (if BI (ne SI (and val (sll 1 2)) 0) 1 0))
       (set (reg BI h-zbit) (if BI (ne SI (and val (sll 1 2)) 0) 1 0))
       (set (reg BI h-nbit) (if BI (ne SI (and val (sll 1 3)) 0) 1 0))
       (set (reg BI h-nbit) (if BI (ne SI (and val (sll 1 3)) 0) 1 0))
       (set (reg BI h-xbit) (if BI (ne SI (and val (sll 1 4)) 0) 1 0))
       (set (reg BI h-xbit) (if BI (ne SI (and val (sll 1 4)) 0) 1 0))
       (set (reg BI h-ibit) (if BI (ne SI (and val (sll 1 5)) 0) 1 0))
       (set (reg BI h-ibit) (if BI (ne SI (and val (sll 1 5)) 0) 1 0))
       (set (reg BI h-sbit) (if BI (ne SI (and val (sll 1 9)) 0) 1 0))
       (set (reg BI h-sbit) (if BI (ne SI (and val (sll 1 9)) 0) 1 0))
       (set (reg BI h-mbit) (if BI (ne SI (and val (sll 1 30)) 0) 1 0))
       (set (reg BI h-mbit) (if BI (ne SI (and val (sll 1 30)) 0) 1 0))
       (set (reg BI h-pbit) (if BI (ne SI (and val (sll 1 7)) 0) 1 0))
       (set (reg BI h-pbit) (if BI (ne SI (and val (sll 1 7)) 0) 1 0))
       (set (reg BI h-rbit) (if BI (ne SI (and val (sll 1 8)) 0) 1 0))
       (set (reg BI h-rbit) (if BI (ne SI (and val (sll 1 8)) 0) 1 0))
       (set (reg BI h-qbit) (if BI (ne SI (and val (sll 1 31)) 0) 1 0))
       (set (reg BI h-qbit) (if BI (ne SI (and val (sll 1 31)) 0) 1 0))
       ; Set the U bit last, so the setter functions for the other bits
       ; Set the U bit last, so the setter functions for the other bits
       ; don't see it as set from this operation.  It is not cleared from
       ; don't see it as set from this operation.  It is not cleared from
       ; this operation, so we don't have to handle that; it's only
       ; this operation, so we don't have to handle that; it's only
       ; cleared "manually" from within simulator-specific context-switch
       ; cleared "manually" from within simulator-specific context-switch
       ; machinery.
       ; machinery.
       (set (reg BI h-ubit) (if BI (ne SI (and val (sll 1 6)) 0) 1 0))
       (set (reg BI h-ubit) (if BI (ne SI (and val (sll 1 6)) 0) 1 0))
       (set-quiet (raw-reg SI h-sr-x index) val)))
       (set-quiet (raw-reg SI h-sr-x index) val)))
    ((eq index (regno usp))
    ((eq index (regno usp))
     ; In user mode, set general register 14 too, whenever setting USP.
     ; In user mode, set general register 14 too, whenever setting USP.
     (sequence
     (sequence
       ()
       ()
       (if (reg BI h-ubit) (set (raw-reg SI h-gr-x (regno sp)) val))
       (if (reg BI h-ubit) (set (raw-reg SI h-gr-x (regno sp)) val))
       (set (raw-reg SI h-sr-x (regno usp)) val)))
       (set (raw-reg SI h-sr-x (regno usp)) val)))
    ((eq index (regno srs))
    ((eq index (regno srs))
     (if (not (reg BI h-ubit)) (set (raw-reg h-sr-x (regno srs)) val)))
     (if (not (reg BI h-ubit)) (set (raw-reg h-sr-x (regno srs)) val)))
    ((eq index (regno ebp))
    ((eq index (regno ebp))
     (if (not (reg BI h-ubit)) (set (raw-reg h-sr-x (regno ebp)) val)))
     (if (not (reg BI h-ubit)) (set (raw-reg h-sr-x (regno ebp)) val)))
    ((eq index (regno pid))
    ((eq index (regno pid))
     (if (not (reg BI h-ubit))
     (if (not (reg BI h-ubit))
         (sequence
         (sequence
           ()
           ()
           (c-call VOID "@cpu@_write_pid_handler" val)
           (c-call VOID "@cpu@_write_pid_handler" val)
           (set (raw-reg h-sr-x (regno pid)) val))))
           (set (raw-reg h-sr-x (regno pid)) val))))
    ((eq index (regno spc))
    ((eq index (regno spc))
     (if (not (reg BI h-ubit)) (set (raw-reg h-sr-x (regno spc)) val)))
     (if (not (reg BI h-ubit)) (set (raw-reg h-sr-x (regno spc)) val)))
    (else (set-quiet (raw-reg SI h-sr-x index) val))))
    (else (set-quiet (raw-reg SI h-sr-x index) val))))
)
)
(define-hardware
(define-hardware
  (name h-supr)
  (name h-supr)
  (attrs MACH-V32 VIRTUAL)
  (attrs MACH-V32 VIRTUAL)
  (comment "Support registers")
  (comment "Support registers")
  (type register SI (16))
  (type register SI (16))
  (values keyword "" (.map (.pmacro (y) ((.str S y) y)) (.iota 16)))
  (values keyword "" (.map (.pmacro (y) ((.str S y) y)) (.iota 16)))
  (get (index) (c-call SI "@cpu@_read_supr" index))
  (get (index) (c-call SI "@cpu@_read_supr" index))
  (set (index val) (c-call VOID "@cpu@_write_supr" index val))
  (set (index val) (c-call VOID "@cpu@_write_supr" index val))
)
)
(define-pmacro (cris-dsh semantic-name name comment attrs type)
(define-pmacro (cris-dsh semantic-name name comment attrs type)
  "Like dsh, but the semantic-name is separate"
  "Like dsh, but the semantic-name is separate"
  (define-full-hardware
  (define-full-hardware
    name comment attrs semantic-name type () () () () () ())
    name comment attrs semantic-name type () () () () () ())
)
)
; We define the condition codes that hold arithmetic flags separately
; We define the condition codes that hold arithmetic flags separately
; and "or" them in, in the get and set methods of the special
; and "or" them in, in the get and set methods of the special
; registers.  We define arithmetic flags as any of C V Z N X.  They
; registers.  We define arithmetic flags as any of C V Z N X.  They
; thankfully have that order (zero-based) in all processor versions.
; thankfully have that order (zero-based) in all processor versions.
; To avoid having two variants of most move-type instructions because V32
; To avoid having two variants of most move-type instructions because V32
; doesn't set C and V (and N and Z), we fake the setting to virtual
; doesn't set C and V (and N and Z), we fake the setting to virtual
; registers which have two different implementations.
; registers which have two different implementations.
(define-pmacro (cris-move-flag f f-name f-whence)
(define-pmacro (cris-move-flag f f-name f-whence)
  "Flag set differently in pre-v32 and v32 in some cases"
  "Flag set differently in pre-v32 and v32 in some cases"
  (begin
  (begin
    (dsh (.sym h- f bit) (.str f-name " bit") () (register BI))
    (dsh (.sym h- f bit) (.str f-name " bit") () (register BI))
    (cris-d-hwreg (.sym h- f bit-move) BI)
    (cris-d-hwreg (.sym h- f bit-move) BI)
    (define-hardware
    (define-hardware
      (semantic-name (.sym h- f bit-move-x))
      (semantic-name (.sym h- f bit-move-x))
      (name (.sym h- f bit-move-v32))
      (name (.sym h- f bit-move-v32))
      (comment (.str f-name " bit set in " f-whence " instructions, ignored"))
      (comment (.str f-name " bit set in " f-whence " instructions, ignored"))
      (attrs MACH-V32 VIRTUAL)
      (attrs MACH-V32 VIRTUAL)
      (type register BI)
      (type register BI)
      (get
      (get
       ()
       ()
       (sequence BI ()
       (sequence BI ()
                 (error (.str "Can't get h-" f "bit-move on CRISv32")) 0))
                 (error (.str "Can't get h-" f "bit-move on CRISv32")) 0))
      (set (val) (nop)))
      (set (val) (nop)))
    (define-hardware
    (define-hardware
      (semantic-name (.sym h- f bit-move-x))
      (semantic-name (.sym h- f bit-move-x))
      (name (.sym h- f bit-move-pre-v32))
      (name (.sym h- f bit-move-pre-v32))
      (comment
      (comment
       (.str
       (.str
        f-name " bit set in " f-whence " instructions, same as " f "bit"))
        f-name " bit set in " f-whence " instructions, same as " f "bit"))
      (attrs MACH-PRE-V32 VIRTUAL)
      (attrs MACH-PRE-V32 VIRTUAL)
      (type register BI)
      (type register BI)
      (get () (reg (.sym h- f bit)))
      (get () (reg (.sym h- f bit)))
      (set (val) (set (reg (.sym h- f bit)) val))))
      (set (val) (set (reg (.sym h- f bit)) val))))
)
)
(cris-move-flag c "carry" "move-type")
(cris-move-flag c "carry" "move-type")
(cris-move-flag v "overflow" "move-type")
(cris-move-flag v "overflow" "move-type")
(cris-move-flag z "zero" "moveq")
(cris-move-flag z "zero" "moveq")
(cris-move-flag n "sign" "moveq")
(cris-move-flag n "sign" "moveq")
(dsh h-xbit "extended-arithmetic bit" () (register BI))
(dsh h-xbit "extended-arithmetic bit" () (register BI))
(cris-d-hwreg h-ibit BI)
(cris-d-hwreg h-ibit BI)
(cris-dsh h-ibit-x h-ibit-pre-v32
(cris-dsh h-ibit-x h-ibit-pre-v32
          "interrupt-enable bit" (MACH-PRE-V32) (register BI))
          "interrupt-enable bit" (MACH-PRE-V32) (register BI))
(dsh h-pbit "sequence-broken bit" ((MACH crisv10,crisv32)) (register BI))
(dsh h-pbit "sequence-broken bit" ((MACH crisv10,crisv32)) (register BI))
(dsh h-rbit "carry bit for MCP+restore-p bit" (MACH-V32) (register BI))
(dsh h-rbit "carry bit for MCP+restore-p bit" (MACH-V32) (register BI))
(cris-d-hwreg h-ubit BI)
(cris-d-hwreg h-ubit BI)
(cris-dsh h-ubit-x h-ubit-pre-v32
(cris-dsh h-ubit-x h-ubit-pre-v32
          "user mode bit" ((MACH crisv10)) (register BI))
          "user mode bit" ((MACH crisv10)) (register BI))
(dsh h-gbit "guru mode bit" (MACH-V32) (register BI))
(dsh h-gbit "guru mode bit" (MACH-V32) (register BI))
; When doing a transition from kernel to user mode on V32, we save the
; When doing a transition from kernel to user mode on V32, we save the
; stack pointer in an internal register and copy USP to R14, so we don't
; stack pointer in an internal register and copy USP to R14, so we don't
; need non-trivial handlers for general registers.
; need non-trivial handlers for general registers.
(dsh
(dsh
 h-kernel-sp
 h-kernel-sp
 "Kernel stack pointer during user mode"
 "Kernel stack pointer during user mode"
 (MACH-V32)
 (MACH-V32)
 (register SI)
 (register SI)
)
)
(define-hardware
(define-hardware
  (semantic-name h-ubit-x)
  (semantic-name h-ubit-x)
  (name h-ubit-v32)
  (name h-ubit-v32)
  (comment "User mode bit")
  (comment "User mode bit")
  (attrs MACH-V32)
  (attrs MACH-V32)
  (type register BI)
  (type register BI)
  (set
  (set
   (val)
   (val)
   (sequence
   (sequence
     ()
     ()
     (if (andif val (not (raw-reg BI h-ubit-x)))
     (if (andif val (not (raw-reg BI h-ubit-x)))
         (sequence
         (sequence
           ()
           ()
           (set (reg SI h-kernel-sp) (raw-reg h-gr-x (regno sp)))
           (set (reg SI h-kernel-sp) (raw-reg h-gr-x (regno sp)))
           (set (raw-reg h-gr-x (regno sp)) (raw-reg h-sr-x (regno usp)))
           (set (raw-reg h-gr-x (regno sp)) (raw-reg h-sr-x (regno usp)))
           (set (raw-reg BI h-ubit-x) val)
           (set (raw-reg BI h-ubit-x) val)
           (c-call VOID "@cpu@_usermode_enabled")))))
           (c-call VOID "@cpu@_usermode_enabled")))))
)
)
(define-hardware
(define-hardware
  (semantic-name h-ibit-x)
  (semantic-name h-ibit-x)
  (name h-ibit-v32)
  (name h-ibit-v32)
  (comment "Interrupt-enable bit")
  (comment "Interrupt-enable bit")
  (attrs MACH-V32)
  (attrs MACH-V32)
  (type register BI)
  (type register BI)
  (set
  (set
   (val)
   (val)
   (sequence
   (sequence
     ()
     ()
     (if (not (reg BI h-ubit))
     (if (not (reg BI h-ubit))
         (sequence
         (sequence
           ((BI enabled))
           ((BI enabled))
           (set enabled (andif val (not (raw-reg BI h-ibit-x))))
           (set enabled (andif val (not (raw-reg BI h-ibit-x))))
           (set (raw-reg BI h-ibit-x) val)
           (set (raw-reg BI h-ibit-x) val)
           ; Call handler when enabling.
           ; Call handler when enabling.
           (if enabled (c-call VOID "@cpu@_interrupts_enabled"))))))
           (if enabled (c-call VOID "@cpu@_interrupts_enabled"))))))
)
)
(define-hardware
(define-hardware
  (name h-mbit)
  (name h-mbit)
  (comment "NMI enable bit")
  (comment "NMI enable bit")
  (attrs MACH-V32)
  (attrs MACH-V32)
  (type register BI)
  (type register BI)
  (set
  (set
   (val)
   (val)
   (sequence
   (sequence
     ()
     ()
     ; Don't allow clearing (through this handler) when once set.
     ; Don't allow clearing (through this handler) when once set.
     (if (andif val (andif (not (raw-reg BI h-mbit)) (not (reg BI h-ubit))))
     (if (andif val (andif (not (raw-reg BI h-mbit)) (not (reg BI h-ubit))))
         (sequence
         (sequence
           ()
           ()
           (set (raw-reg BI h-mbit) 1)
           (set (raw-reg BI h-mbit) 1)
           ; Call handler when enabling.
           ; Call handler when enabling.
           (c-call VOID "@cpu@_nmi_enabled")))))
           (c-call VOID "@cpu@_nmi_enabled")))))
)
)
(define-pmacro
(define-pmacro
  (dsh-cond-bit-v32 x-name x-comment x-cond)
  (dsh-cond-bit-v32 x-name x-comment x-cond)
  "dsh bit for MACH-V32, with bit only changeable when X-COND"
  "dsh bit for MACH-V32, with bit only changeable when X-COND"
  (define-hardware
  (define-hardware
    (name x-name)
    (name x-name)
    (comment x-comment)
    (comment x-comment)
    (attrs MACH-V32)
    (attrs MACH-V32)
    (type register BI)
    (type register BI)
    (set (val) (sequence () (if x-cond (set (raw-reg BI x-name) val)))))
    (set (val) (sequence () (if x-cond (set (raw-reg BI x-name) val)))))
)
)
(define-pmacro
(define-pmacro
  (dsh-protected-bit-v32 x-name x-comment)
  (dsh-protected-bit-v32 x-name x-comment)
  "dsh bit for MACH-V32, with bit only changeable in kernel mode"
  "dsh bit for MACH-V32, with bit only changeable in kernel mode"
  (dsh-cond-bit-v32 x-name x-comment (not (reg BI h-ubit)))
  (dsh-cond-bit-v32 x-name x-comment (not (reg BI h-ubit)))
)
)
(dsh-protected-bit-v32 h-qbit "Pending single-step bit")
(dsh-protected-bit-v32 h-qbit "Pending single-step bit")
(define-hardware
(define-hardware
  (name h-sbit)
  (name h-sbit)
  (comment "Cause single step exception on ... [see CRISv32 ref] bit")
  (comment "Cause single step exception on ... [see CRISv32 ref] bit")
  (attrs MACH-V32)
  (attrs MACH-V32)
  (type register BI)
  (type register BI)
  (set
  (set
   (val)
   (val)
   (sequence
   (sequence
     ()
     ()
     (if (not (reg BI h-ubit))
     (if (not (reg BI h-ubit))
         (sequence
         (sequence
           ((BI enabled))
           ((BI enabled))
           (set enabled (andif val (not (raw-reg BI h-sbit))))
           (set enabled (andif val (not (raw-reg BI h-sbit))))
           (set (raw-reg BI h-sbit) val)
           (set (raw-reg BI h-sbit) val)
           ; Call handler when enabling.
           ; Call handler when enabling.
           (if enabled (c-call VOID "@cpu@_single_step_enabled"))))))
           (if enabled (c-call VOID "@cpu@_single_step_enabled"))))))
)
)
(dnop cbit "" (SEM-ONLY) h-cbit f-nil)
(dnop cbit "" (SEM-ONLY) h-cbit f-nil)
(dnop cbit-move
(dnop cbit-move
      "cbit for pre-V32, nothing for newer" (SEM-ONLY) h-cbit-move f-nil)
      "cbit for pre-V32, nothing for newer" (SEM-ONLY) h-cbit-move f-nil)
(dnop vbit "" (SEM-ONLY) h-vbit f-nil)
(dnop vbit "" (SEM-ONLY) h-vbit f-nil)
(dnop vbit-move
(dnop vbit-move
      "vbit for pre-V32, nothing for newer" (SEM-ONLY) h-vbit-move f-nil)
      "vbit for pre-V32, nothing for newer" (SEM-ONLY) h-vbit-move f-nil)
(dnop zbit "" (SEM-ONLY) h-zbit f-nil)
(dnop zbit "" (SEM-ONLY) h-zbit f-nil)
(dnop zbit-move
(dnop zbit-move
      "zbit for pre-V32, nothing for newer" (SEM-ONLY) h-zbit-move f-nil)
      "zbit for pre-V32, nothing for newer" (SEM-ONLY) h-zbit-move f-nil)
(dnop nbit "" (SEM-ONLY) h-nbit f-nil)
(dnop nbit "" (SEM-ONLY) h-nbit f-nil)
(dnop nbit-move
(dnop nbit-move
      "nbit for pre-V32, nothing for newer" (SEM-ONLY) h-nbit-move f-nil)
      "nbit for pre-V32, nothing for newer" (SEM-ONLY) h-nbit-move f-nil)
(dnop xbit "" (SEM-ONLY) h-xbit f-nil)
(dnop xbit "" (SEM-ONLY) h-xbit f-nil)
(dnop ibit "" (SEM-ONLY) h-ibit f-nil)
(dnop ibit "" (SEM-ONLY) h-ibit f-nil)
(dnop ubit "" (SEM-ONLY (MACH crisv10,crisv32)) h-ubit f-nil)
(dnop ubit "" (SEM-ONLY (MACH crisv10,crisv32)) h-ubit f-nil)
(dnop pbit "" (SEM-ONLY (MACH crisv10,crisv32)) h-pbit f-nil)
(dnop pbit "" (SEM-ONLY (MACH crisv10,crisv32)) h-pbit f-nil)
(dnop
(dnop
 rbit "carry bit for MCP+restore-P flag bit" (SEM-ONLY MACH-V32) h-rbit f-nil)
 rbit "carry bit for MCP+restore-P flag bit" (SEM-ONLY MACH-V32) h-rbit f-nil)
(dnop sbit "" (SEM-ONLY MACH-V32) h-sbit f-nil)
(dnop sbit "" (SEM-ONLY MACH-V32) h-sbit f-nil)
(dnop mbit "" (SEM-ONLY MACH-V32) h-mbit f-nil)
(dnop mbit "" (SEM-ONLY MACH-V32) h-mbit f-nil)
(dnop qbit "" (SEM-ONLY MACH-V32) h-qbit f-nil)
(dnop qbit "" (SEM-ONLY MACH-V32) h-qbit f-nil)
(cris-d-hwreg h-insn-prefixed-p BI)
(cris-d-hwreg h-insn-prefixed-p BI)
(cris-dsh
(cris-dsh
 h-insn-prefixed-p-x
 h-insn-prefixed-p-x
 h-insn-prefixed-p-pre-v32
 h-insn-prefixed-p-pre-v32
 "instruction-is-prefixed bit"
 "instruction-is-prefixed bit"
 (MACH-PRE-V32)
 (MACH-PRE-V32)
 (register BI)
 (register BI)
)
)
; CRISv32 has no prefixing on memory accesses.  CGEN-FIXME: [Once (eq-attr
; CRISv32 has no prefixing on memory accesses.  CGEN-FIXME: [Once (eq-attr
; (current-mach) ...) works]: can we change andif and/or orif so it
; (current-mach) ...) works]: can we change andif and/or orif so it
; doesn't look too close at short-circuited operands and avoid defining an
; doesn't look too close at short-circuited operands and avoid defining an
; operand that doesn't apply to a certain mach?
; operand that doesn't apply to a certain mach?
(define-hardware
(define-hardware
 (semantic-name h-insn-prefixed-p-x)
 (semantic-name h-insn-prefixed-p-x)
 (name h-insn-prefixed-p-v32)
 (name h-insn-prefixed-p-v32)
 (attrs MACH-V32 VIRTUAL)
 (attrs MACH-V32 VIRTUAL)
 (comment "instruction-is-prefixed bit")
 (comment "instruction-is-prefixed bit")
 (type register BI)
 (type register BI)
 (get () (const BI 0))
 (get () (const BI 0))
 (set (val) (nop))
 (set (val) (nop))
)
)
(dnop
(dnop
 prefix-set
 prefix-set
 "Instruction-prefixed flag"
 "Instruction-prefixed flag"
 (SEM-ONLY)
 (SEM-ONLY)
 h-insn-prefixed-p
 h-insn-prefixed-p
 f-nil
 f-nil
)
)
(cris-dsh
(cris-dsh
 h-prefixreg h-prefixreg-pre-v32
 h-prefixreg h-prefixreg-pre-v32
 "Prefix-address register" (MACH-PRE-V32) (register SI))
 "Prefix-address register" (MACH-PRE-V32) (register SI))
(define-hardware
(define-hardware
  (semantic-name h-prefixreg)
  (semantic-name h-prefixreg)
  (name h-prefixreg-v32)
  (name h-prefixreg-v32)
  (comment "Prefix-address register, redirecting to ACR")
  (comment "Prefix-address register, redirecting to ACR")
  (attrs MACH-V32 VIRTUAL)
  (attrs MACH-V32 VIRTUAL)
  (type register SI)
  (type register SI)
  ; Why can't we have just a "acr" a.k.a "(reg h-gr 15)" here?
  ; Why can't we have just a "acr" a.k.a "(reg h-gr 15)" here?
  (get () acr)
  (get () acr)
  (set (value) (set acr value))
  (set (value) (set acr value))
)
)
(dnop
(dnop
 prefixreg
 prefixreg
 "Prefix address"
 "Prefix address"
 (SEM-ONLY)
 (SEM-ONLY)
 h-prefixreg
 h-prefixreg
 f-nil
 f-nil
)
)
;;;;;;;;;;;;;;;;;; -ifield
;;;;;;;;;;;;;;;;;; -ifield
;         15                                            0
;         15                                            0
;        +-----------+-----+-----------+-----+-----------+
;        +-----------+-----+-----------+-----+-----------+
;        | Operand2  | Mode| Opcode    | Size| Operand1  |
;        | Operand2  | Mode| Opcode    | Size| Operand1  |
;        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
;        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
;
;
;        Figure 5.  General instruction format.
;        Figure 5.  General instruction format.
;
;
; Some deviations from this format exist, [see below].
; Some deviations from this format exist, [see below].
; Field specifiers in CGEN specify the highest numbered bit followed by
; Field specifiers in CGEN specify the highest numbered bit followed by
; the number of bits.
; the number of bits.
(dnf f-operand1 "Operand1" () 3 4)
(dnf f-operand1 "Operand1" () 3 4)
(dnf f-size "Size" () 5 2)
(dnf f-size "Size" () 5 2)
(dnf f-opcode "Opcode" () 9 4)
(dnf f-opcode "Opcode" () 9 4)
(dnf f-mode "Mode" () 11 2)
(dnf f-mode "Mode" () 11 2)
(dnf f-operand2 "Operand2" () 15 4)
(dnf f-operand2 "Operand2" () 15 4)
; Subfields.  FIXME: unfortunately there's some limitation in CGEN so we
; Subfields.  FIXME: unfortunately there's some limitation in CGEN so we
; can't (as would be somewhat intuitive) make f-mode a multi-ifield
; can't (as would be somewhat intuitive) make f-mode a multi-ifield
; consisting of these two, concatenated.
; consisting of these two, concatenated.
(dnf f-memmode "Indirect of autoincrement" () 10 1)
(dnf f-memmode "Indirect of autoincrement" () 10 1)
(dnf f-membit "Memory specifier" () 11 1)
(dnf f-membit "Memory specifier" () 11 1)
(dnf f-b5 "Bit 5 (zero for some quick operands)" () 5 1)
(dnf f-b5 "Bit 5 (zero for some quick operands)" () 5 1)
; When the addressing mode is quick immediate, the low bits are
; When the addressing mode is quick immediate, the low bits are
; part of the operand.
; part of the operand.
(dnf f-opcode-hi "Opcode field, high bits" () 9 2)
(dnf f-opcode-hi "Opcode field, high bits" () 9 2)
; Common synonyms for those fields.
; Common synonyms for those fields.
(define-pmacro f-source f-operand1)
(define-pmacro f-source f-operand1)
(define-pmacro f-dest f-operand2)
(define-pmacro f-dest f-operand2)
(dnmf
(dnmf
 f-dstsrc "Dest and source fields concatenated" () UINT
 f-dstsrc "Dest and source fields concatenated" () UINT
 (f-dest f-source)
 (f-dest f-source)
 ; Insert-code.
 ; Insert-code.
 (sequence
 (sequence
   ((SI tmpval))
   ((SI tmpval))
   (set tmpval (ifield f-dstsrc))
   (set tmpval (ifield f-dstsrc))
   (set (ifield f-dest) (and (srl tmpval 4) #xf))
   (set (ifield f-dest) (and (srl tmpval 4) #xf))
   (set (ifield f-source) (and tmpval #xf)))
   (set (ifield f-source) (and tmpval #xf)))
 ; Extract-code.
 ; Extract-code.
 (set
 (set
  (ifield f-dstsrc)
  (ifield f-dstsrc)
  (and (or (ifield f-source) (sll (ifield f-dest) 4)) #xff))
  (and (or (ifield f-source) (sll (ifield f-dest) 4)) #xff))
)
)
;The 6-bit value may be sign or zero extended depending on the instruction.
;The 6-bit value may be sign or zero extended depending on the instruction.
;
;
;         15                                            0
;         15                                            0
;        +-----------+-----+-----------+-----+-----------+
;        +-----------+-----+-----------+-----+-----------+
;        | Operand2  | Mode| Opcode    | Immediate value |
;        | Operand2  | Mode| Opcode    | Immediate value |
;        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
;        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
;
;
;   Figure 6.  Quick immediate addressing mode instruction format.
;   Figure 6.  Quick immediate addressing mode instruction format.
(dnf f-u6 "Quick immediate unsigned 6-bit" () 5 6)
(dnf f-u6 "Quick immediate unsigned 6-bit" () 5 6)
(df f-s6 "Quick signed 6-bit" () 5 6 INT #f #f)
(df f-s6 "Quick signed 6-bit" () 5 6 INT #f #f)
; There's also a variant used with shift insns, with one bit larger opcode
; There's also a variant used with shift insns, with one bit larger opcode
; and one bit smaller immediate value, though it doesn't have a general
; and one bit smaller immediate value, though it doesn't have a general
; graphic description.
; graphic description.
(dnf f-u5 "Quick unsigned 5-bit" () 4 5)
(dnf f-u5 "Quick unsigned 5-bit" () 4 5)
; Similarly, a four-bit immediate field.
; Similarly, a four-bit immediate field.
(dnf f-u4 "Quick unsigned 4-bit" () 3 4)
(dnf f-u4 "Quick unsigned 4-bit" () 3 4)
; An 8-bit signed value, which doesn't have a general graphic description.
; An 8-bit signed value, which doesn't have a general graphic description.
(df f-s8 "Source signed byte" () 7 8 INT #f #f)
(df f-s8 "Source signed byte" () 7 8 INT #f #f)
; The 9-bit branch offset, with bit 0 in the field being bit 8 in the
; The 9-bit branch offset, with bit 0 in the field being bit 8 in the
; offset, and bit 0 in the offset always 0.
; offset, and bit 0 in the offset always 0.
(df f-disp9-hi "PC-relative 9-bit offset, sign bit" () 0 1 INT #f #f)
(df f-disp9-hi "PC-relative 9-bit offset, sign bit" () 0 1 INT #f #f)
(dnf f-disp9-lo "PC-relative 9-bit offset, low bits" () 7 7)
(dnf f-disp9-lo "PC-relative 9-bit offset, low bits" () 7 7)
; It would work to have this in two mach-specific variants, but
; It would work to have this in two mach-specific variants, but
; considering that current-mach-is-v32 is a compile-time constant, we
; considering that current-mach-is-v32 is a compile-time constant, we
; don't win any simulator performance.
; don't win any simulator performance.
(dnmf
(dnmf
 f-disp9 "PC-relative 9-bit offset"
 f-disp9 "PC-relative 9-bit offset"
 (PCREL-ADDR)
 (PCREL-ADDR)
 INT
 INT
 (f-disp9-hi f-disp9-lo)
 (f-disp9-hi f-disp9-lo)
 ; Insert-code.
 ; Insert-code.
 (sequence
 (sequence
   ((SI absval))
   ((SI absval))
   (set absval (srl (sub (sub SI (ifield f-disp9) pc)
   (set absval (srl (sub (sub SI (ifield f-disp9) pc)
                         (if SI current-mach-is-v32 0 2)) 1))
                         (if SI current-mach-is-v32 0 2)) 1))
   (set (ifield f-disp9-hi) (if (lt absval 0) 1 0))
   (set (ifield f-disp9-hi) (if (lt absval 0) 1 0))
   (set (ifield f-disp9-lo) (and absval) #x7f))
   (set (ifield f-disp9-lo) (and absval) #x7f))
 ; Extract-code.
 ; Extract-code.
 (sequence
 (sequence
   ((SI abslo) (SI absval))
   ((SI abslo) (SI absval))
   (set abslo (sll (ifield f-disp9-lo) 1))
   (set abslo (sll (ifield f-disp9-lo) 1))
   (set absval
   (set absval
        (or (if SI (ne (ifield f-disp9-hi) 0)
        (or (if SI (ne (ifield f-disp9-hi) 0)
                (inv SI #xff)
                (inv SI #xff)
                0)
                0)
            abslo))
            abslo))
   (set (ifield f-disp9)
   (set (ifield f-disp9)
        (add SI (add SI pc absval) (if SI current-mach-is-v32 0 2))))
        (add SI (add SI pc absval) (if SI current-mach-is-v32 0 2))))
)
)
; The operand of LAPCQ is PC-relative, similar to f-disp9 but unsigned,
; The operand of LAPCQ is PC-relative, similar to f-disp9 but unsigned,
; and only four bits.
; and only four bits.
(df
(df
 f-qo
 f-qo
 "PC-relative 4-bit unsigned offset, counted from start of insn"
 "PC-relative 4-bit unsigned offset, counted from start of insn"
 (MACH-V32 PCREL-ADDR)
 (MACH-V32 PCREL-ADDR)
 3 4
 3 4
 UINT
 UINT
 ; Insert-code.
 ; Insert-code.
 ((value pc) (srl SI (sub SI value pc) 1))
 ((value pc) (srl SI (sub SI value pc) 1))
 ; Extract-code.
 ; Extract-code.
 ((value pc) (add SI pc (sll SI value 1)))
 ((value pc) (add SI pc (sll SI value 1)))
)
)
; 8-bit, 16-bit and 32-bit immediates.  The 8-bit values are constructed
; 8-bit, 16-bit and 32-bit immediates.  The 8-bit values are constructed
; through encoding/decoding functions, since the PC increment is by a
; through encoding/decoding functions, since the PC increment is by a
; word.
; word.
(define-pmacro (dcrisf x-name x-comment x-attrs x-word-offset x-word-length
(define-pmacro (dcrisf x-name x-comment x-attrs x-word-offset x-word-length
                       x-start x-length x-mode x-encode x-decode)
                       x-start x-length x-mode x-encode x-decode)
  (define-ifield
  (define-ifield
    (name x-name)
    (name x-name)
    (comment x-comment)
    (comment x-comment)
    (.splice attrs (.unsplice x-attrs))
    (.splice attrs (.unsplice x-attrs))
    (word-offset x-word-offset)
    (word-offset x-word-offset)
    (word-length x-word-length)
    (word-length x-word-length)
    (start x-start)
    (start x-start)
    (length x-length)
    (length x-length)
    (mode x-mode)
    (mode x-mode)
    (.splice encode (.unsplice x-encode))
    (.splice encode (.unsplice x-encode))
    (.splice decode (.unsplice x-decode))
    (.splice decode (.unsplice x-decode))
  )
  )
)
)
(dcrisf
(dcrisf
 f-indir-pc+-byte "[PC+] 8-bit field" (SIGN-OPT)
 f-indir-pc+-byte "[PC+] 8-bit field" (SIGN-OPT)
 16 16
 16 16
 15 16 ; CGEN-FIXME: Should be 7 8
 15 16 ; CGEN-FIXME: Should be 7 8
 INT (#f) (#f)
 INT (#f) (#f)
)
)
(dcrisf
(dcrisf
 f-indir-pc+-word "[PC+] 16-bit field" (SIGN-OPT)
 f-indir-pc+-word "[PC+] 16-bit field" (SIGN-OPT)
 16 16 15 16 INT (#f) (#f)
 16 16 15 16 INT (#f) (#f)
)
)
; CGEN-FIXME: I shouldn't have to use trunc here, should I?
; CGEN-FIXME: I shouldn't have to use trunc here, should I?
; Sign-extension should be implicit through use of SI (as opposed to USI)
; Sign-extension should be implicit through use of SI (as opposed to USI)
; and additionally through SIGN-OPT.  The ext isn't actually needed, but
; and additionally through SIGN-OPT.  The ext isn't actually needed, but
; having it there rather than implicit makes more sense than to just have
; having it there rather than implicit makes more sense than to just have
; the trunc.
; the trunc.
(dcrisf
(dcrisf
 f-indir-pc+-word-pcrel "[PC+] PC-relative 16-bit field"
 f-indir-pc+-word-pcrel "[PC+] PC-relative 16-bit field"
 (PCREL-ADDR SIGN-OPT)
 (PCREL-ADDR SIGN-OPT)
 16 16 15 16 SI
 16 16 15 16 SI
 ((value pc) (sub SI value (add SI pc (if SI current-mach-is-v32 0 4))))
 ((value pc) (sub SI value (add SI pc (if SI current-mach-is-v32 0 4))))
 ((value pc) (add SI (ext SI (trunc HI value)) (add SI pc (if SI current-mach-is-v32 0 4))))
 ((value pc) (add SI (ext SI (trunc HI value)) (add SI pc (if SI current-mach-is-v32 0 4))))
)
)
(dcrisf
(dcrisf
 f-indir-pc+-dword "PC autoincrement - 32-bit field" (SIGN-OPT)
 f-indir-pc+-dword "PC autoincrement - 32-bit field" (SIGN-OPT)
 16 32 31 32 INT (#f) (#f)
 16 32 31 32 INT (#f) (#f)
)
)
(dcrisf
(dcrisf
 f-indir-pc+-dword-pcrel
 f-indir-pc+-dword-pcrel
 "[PC+] PC-relative 32-bit field, counted from start of insn"
 "[PC+] PC-relative 32-bit field, counted from start of insn"
 (SIGN-OPT MACH-V32 PCREL-ADDR)
 (SIGN-OPT MACH-V32 PCREL-ADDR)
 16 32 31 32 INT
 16 32 31 32 INT
 ((value pc) (sub SI value pc))
 ((value pc) (sub SI value pc))
 ((value pc) (add SI pc value))
 ((value pc) (add SI pc value))
)
)
;;;;;;;;;;;;;;;;;; -insn-enum -normal-operand -normal-derived-operand
;;;;;;;;;;;;;;;;;; -insn-enum -normal-operand -normal-derived-operand
;; How different fields are transformed into something we put in insns.
;; How different fields are transformed into something we put in insns.
;        m       := size modifier, byte (00), word (01) or dword (10)
;        m       := size modifier, byte (00), word (01) or dword (10)
;        z       := size modifier, byte (0) or word (1)
;        z       := size modifier, byte (0) or word (1)
; (For the latter, the "higher" bit is always 0, mapping trivially on m.)
; (For the latter, the "higher" bit is always 0, mapping trivially on m.)
(define-normal-insn-enum
(define-normal-insn-enum
  insn-size
  insn-size
  "Standard instruction operand size"
  "Standard instruction operand size"
  ()
  ()
  SIZE_
  SIZE_
  f-size
  f-size
  ("BYTE" "WORD" "DWORD" "FIXED")
  ("BYTE" "WORD" "DWORD" "FIXED")
)
)
; The mode field for insns with "s" operand (perhaps with a partial set of
; The mode field for insns with "s" operand (perhaps with a partial set of
; operand types).
; operand types).
(define-normal-insn-enum
(define-normal-insn-enum
  insn-mode
  insn-mode
  "Standard instruction addressing modes"
  "Standard instruction addressing modes"
  ()
  ()
  MODE_
  MODE_
  f-mode
  f-mode
  ("QUICK_IMMEDIATE" "REGISTER" "INDIRECT" "AUTOINCREMENT")
  ("QUICK_IMMEDIATE" "REGISTER" "INDIRECT" "AUTOINCREMENT")
)
)
(define-normal-insn-enum
(define-normal-insn-enum
  insn-memoryness-mode
  insn-memoryness-mode
  "Whether the operand is indirect"
  "Whether the operand is indirect"
  ()
  ()
  MODEMEMP_
  MODEMEMP_
  f-membit
  f-membit
  ("NO" "YES")
  ("NO" "YES")
)
)
; FIXME: Needed?
; FIXME: Needed?
(define-normal-insn-enum
(define-normal-insn-enum
  insn-memincness-mode
  insn-memincness-mode
  "Whether the indirect operand is autoincrement"
  "Whether the indirect operand is autoincrement"
  ()
  ()
  MODEINCP_
  MODEINCP_
  f-memmode
  f-memmode
  ("NO" "YES")
  ("NO" "YES")
)
)
; Special semantics for multiply.
; Special semantics for multiply.
(define-pmacro MODE_MULU MODE_INDIRECT)
(define-pmacro MODE_MULU MODE_INDIRECT)
(define-pmacro MODE_MULS MODE_AUTOINCREMENT)
(define-pmacro MODE_MULS MODE_AUTOINCREMENT)
(define-normal-insn-enum
(define-normal-insn-enum
  insn-signed-size
  insn-signed-size
  "Signed instruction operand size"
  "Signed instruction operand size"
  ()
  ()
  SIGNED_
  SIGNED_
  f-size
  f-size
  ("UNDEF_SIZE_0" "UNDEF_SIZE_1" "BYTE" "WORD")
  ("UNDEF_SIZE_0" "UNDEF_SIZE_1" "BYTE" "WORD")
)
)
(define-normal-insn-enum
(define-normal-insn-enum
  insn-unsigned-size
  insn-unsigned-size
  "Unsigned instruction operand size"
  "Unsigned instruction operand size"
  ()
  ()
  UNSIGNED_
  UNSIGNED_
  f-size
  f-size
  ("BYTE" "WORD" "UNDEF_SIZE_2" "UNDEF_SIZE_3")
  ("BYTE" "WORD" "UNDEF_SIZE_2" "UNDEF_SIZE_3")
)
)
;        Rs      := source operand, register addressing mode
;        Rs      := source operand, register addressing mode
(dnop Rs "Source general register" () h-gr f-source)
(dnop Rs "Source general register" () h-gr f-source)
;        [Rs]    := source operand, indirect addressing mode
;        [Rs]    := source operand, indirect addressing mode
; = MODE_INDIRECT Rs
; = MODE_INDIRECT Rs
;        [Rs+]   := source operand, autoincrement addressing mode  (see note!)
;        [Rs+]   := source operand, autoincrement addressing mode  (see note!)
; = MODE_AUTOINCREMENT Rs
; = MODE_AUTOINCREMENT Rs
; The union of [Rs] and [Rs(+)]
; The union of [Rs] and [Rs(+)]
; = MODEMEMP_YES Rs
; = MODEMEMP_YES Rs
; Whether an indirect operand is increment can be obtained as an operand by
; Whether an indirect operand is increment can be obtained as an operand by
; = inc
; = inc
(dnop inc "Incrementness of indirect operand" () h-inc f-memmode)
(dnop inc "Incrementness of indirect operand" () h-inc f-memmode)
; or as an affirmative specifier
; or as an affirmative specifier
; = MODEINCP_YES
; = MODEINCP_YES
; (or MODEINCP_NO)
; (or MODEINCP_NO)
;        s       := source operand, any of the modes Rs, [Rs] or [Rs+]
;        s       := source operand, any of the modes Rs, [Rs] or [Rs+]
; No common operand; each are handled separately, using the above definitions.
; No common operand; each are handled separately, using the above definitions.
;        Ps      := source operand, special register
;        Ps      := source operand, special register
; It's in the field usually used for the destination.
; It's in the field usually used for the destination.
(dnop Ps "Source special register" () h-sr f-dest)
(dnop Ps "Source special register" () h-sr f-dest)
;        Ss      := source operand, support register
;        Ss      := source operand, support register
; It's in the field usually used for the destination.
; It's in the field usually used for the destination.
(dnop Ss "Source support register" (MACH-V32) h-supr f-dest)
(dnop Ss "Source support register" (MACH-V32) h-supr f-dest)
;        Sd      := source operand, support register
;        Sd      := source operand, support register
(dnop Sd "Destination support register" (MACH-V32) h-supr f-dest)
(dnop Sd "Destination support register" (MACH-V32) h-supr f-dest)
;        i       := 6-bit signed immediate operand
;        i       := 6-bit signed immediate operand
(dnop i "Quick signed 6-bit" () h-sint f-s6)
(dnop i "Quick signed 6-bit" () h-sint f-s6)
;        j       := 6-bit unsigned immediate operand
;        j       := 6-bit unsigned immediate operand
(dnop j "Quick unsigned 6-bit" () h-uint f-u6)
(dnop j "Quick unsigned 6-bit" () h-uint f-u6)
;        c       := 5-bit immediate shift value
;        c       := 5-bit immediate shift value
(dnop c "Quick unsigned 5-bit" () h-uint f-u5)
(dnop c "Quick unsigned 5-bit" () h-uint f-u5)
;        qo      := 4-bit unsigned immediate operand
;        qo      := 4-bit unsigned immediate operand
(dnop qo "Quick unsigned 4-bit, PC-relative" (MACH-V32) h-addr f-qo)
(dnop qo "Quick unsigned 4-bit, PC-relative" (MACH-V32) h-addr f-qo)
;        Rd      := destination operand, register addressing mode
;        Rd      := destination operand, register addressing mode
(dnop Rd "Destination general register" () h-gr f-dest)
(dnop Rd "Destination general register" () h-gr f-dest)
(define-pmacro Rd-sfield Rs)
(define-pmacro Rd-sfield Rs)
(define-pmacro Rs-dfield Rd)
(define-pmacro Rs-dfield Rd)
;        [Rd]    := destination operand, indirect addressing mode
;        [Rd]    := destination operand, indirect addressing mode
; = MODE_INDIRECT Rd
; = MODE_INDIRECT Rd
;        [Rd+]   := destination operand, autoincrement addressing mode
;        [Rd+]   := destination operand, autoincrement addressing mode
; = MODE_AUTOINCREMENT Rd
; = MODE_AUTOINCREMENT Rd
;        [PC+]   := destination operand PC, autoincrement addressing mode
;        [PC+]   := destination operand PC, autoincrement addressing mode
; = MODE_AUTOINCREMENT (f-dest 15) X
; = MODE_AUTOINCREMENT (f-dest 15) X
; where X is one of sconst8, uconst8, sconst16, uconst16 or const32.
; where X is one of sconst8, uconst8, sconst16, uconst16 or const32.
(dnop sconst8 "Signed byte [PC+]" () h-sint f-indir-pc+-byte)
(dnop sconst8 "Signed byte [PC+]" () h-sint f-indir-pc+-byte)
(dnop uconst8 "Unsigned byte [PC+]" () h-uint f-indir-pc+-byte)
(dnop uconst8 "Unsigned byte [PC+]" () h-uint f-indir-pc+-byte)
(dnop sconst16 "Signed word [PC+]" () h-sint f-indir-pc+-word)
(dnop sconst16 "Signed word [PC+]" () h-sint f-indir-pc+-word)
(dnop uconst16 "Unsigned word [PC+]" () h-uint f-indir-pc+-word)
(dnop uconst16 "Unsigned word [PC+]" () h-uint f-indir-pc+-word)
(dnop const32 "Dword [PC+]" () h-uint f-indir-pc+-dword)
(dnop const32 "Dword [PC+]" () h-uint f-indir-pc+-dword)
(dnop const32-pcrel "Dword [PC+]" () h-addr f-indir-pc+-dword-pcrel)
(dnop const32-pcrel "Dword [PC+]" () h-addr f-indir-pc+-dword-pcrel)
;        d       := destination operand, any of the modes Rd, [Rd] or [Rd+]
;        d       := destination operand, any of the modes Rd, [Rd] or [Rd+]
; No common operand; each are handled separately, using the above definitions.
; No common operand; each are handled separately, using the above definitions.
;        Pd      := destination operand, special register
;        Pd      := destination operand, special register
(dnop Pd "Destination special register" () h-sr f-dest)
(dnop Pd "Destination special register" () h-sr f-dest)
;        o       := 8-bit immediate offset value
;        o       := 8-bit immediate offset value
(dnop o "Signed 8-bit" () h-sint f-s8)
(dnop o "Signed 8-bit" () h-sint f-s8)
; The division of operand semantics and insn fields in the CRIS
; The division of operand semantics and insn fields in the CRIS
; instruction set reference doesn't permit a simple mapping to a
; instruction set reference doesn't permit a simple mapping to a
; simulator description, and the division of insn fields and
; simulator description, and the division of insn fields and
; semantics in CGEN is not between the define-normal-ifield
; semantics in CGEN is not between the define-normal-ifield
; vs. define-normal-operand.  For example, the "o" operand is
; vs. define-normal-operand.  For example, the "o" operand is
; PC-relative for branch insns, as described by the CGEN f-disp9
; PC-relative for branch insns, as described by the CGEN f-disp9
; field.
; field.
; See comment at f-disp9; thankfully the mach
; See comment at f-disp9; thankfully the mach
; attribute works here to have two different definitions by the
; attribute works here to have two different definitions by the
; same name.
; same name.
(dnop o-pcrel "9-bit signed immediate PC-rel"
(dnop o-pcrel "9-bit signed immediate PC-rel"
      ()
      ()
      h-iaddr f-disp9)
      h-iaddr f-disp9)
(dnop o-word-pcrel "16-bit signed immediate PC-rel"
(dnop o-word-pcrel "16-bit signed immediate PC-rel"
      ()
      ()
      h-iaddr f-indir-pc+-word-pcrel)
      h-iaddr f-indir-pc+-word-pcrel)
;        cc      := condition code
;        cc      := condition code
(dnop cc "Condition codes" () h-ccode f-dest)
(dnop cc "Condition codes" () h-ccode f-dest)
;        n       := 4 bit breakpoint exception vector index
;        n       := 4 bit breakpoint exception vector index
(dnop n "Quick unsigned 4-bit" () h-uint f-u4)
(dnop n "Quick unsigned 4-bit" () h-uint f-u4)
; The "option" in the SWAP insn.
; The "option" in the SWAP insn.
(dnop swapoption "Swap option" () h-swap f-dest)
(dnop swapoption "Swap option" () h-swap f-dest)
(dnop list-of-flags "Flag bits as operand" () h-flagbits f-dstsrc)
(dnop list-of-flags "Flag bits as operand" () h-flagbits f-dstsrc)
; Enumerations for insn codes, for use in insn definitions
; Enumerations for insn codes, for use in insn definitions
; instead of raw numbers.  See it as operand definitions for the
; instead of raw numbers.  See it as operand definitions for the
; opcode field.
; opcode field.
(define-normal-insn-enum
(define-normal-insn-enum
  insn-qi-opc
  insn-qi-opc
  "Insns for MODE_QUICK_IMMEDIATE"
  "Insns for MODE_QUICK_IMMEDIATE"
  ()
  ()
  Q_
  Q_
  f-opcode
  f-opcode
  ("BCC_0" "BCC_1" "BCC_2" "BCC_3"
  ("BCC_0" "BCC_1" "BCC_2" "BCC_3"
   "BDAP_0" "BDAP_1" "BDAP_2" "BDAP_3"
   "BDAP_0" "BDAP_1" "BDAP_2" "BDAP_3"
   "ADDQ" "MOVEQ" "SUBQ" "CMPQ"
   "ADDQ" "MOVEQ" "SUBQ" "CMPQ"
   "ANDQ" "ORQ" "ASHQ" "LSHQ")
   "ANDQ" "ORQ" "ASHQ" "LSHQ")
)
)
(define-normal-insn-enum
(define-normal-insn-enum
  insn-qihi-opc
  insn-qihi-opc
  "Same as insn-qi-opc, though using only the high two bits of the opcode"
  "Same as insn-qi-opc, though using only the high two bits of the opcode"
  ()
  ()
  QHI_
  QHI_
  f-opcode-hi
  f-opcode-hi
  ("BCC" "BDAP" "OTHER2" "OTHER3")
  ("BCC" "BDAP" "OTHER2" "OTHER3")
)
)
(define-pmacro QHI_ADDOQ QHI_BDAP)
(define-pmacro QHI_ADDOQ QHI_BDAP)
(define-normal-insn-enum
(define-normal-insn-enum
  insn-r-opc
  insn-r-opc
  "Insns for MODE_REGISTER and either SIZE_BYTE, SIZE_WORD or SIZE_DWORD"
  "Insns for MODE_REGISTER and either SIZE_BYTE, SIZE_WORD or SIZE_DWORD"
  ()
  ()
  R_
  R_
  f-opcode
  f-opcode
  ("ADDX" "MOVX" "SUBX" "LSL"
  ("ADDX" "MOVX" "SUBX" "LSL"
   "ADDI" "BIAP" "NEG" "BOUND"
   "ADDI" "BIAP" "NEG" "BOUND"
   "ADD" "MOVE" "SUB" "CMP"
   "ADD" "MOVE" "SUB" "CMP"
   "AND" "OR" "ASR" "LSR")
   "AND" "OR" "ASR" "LSR")
)
)
(define-pmacro R_ADDI_ACR R_BIAP)
(define-pmacro R_ADDI_ACR R_BIAP)
(define-normal-insn-enum
(define-normal-insn-enum
  insn-rfix-opc
  insn-rfix-opc
  "Insns for MODE_REGISTER and SIZE_FIXED"
  "Insns for MODE_REGISTER and SIZE_FIXED"
  ()
  ()
  RFIX_
  RFIX_
  f-opcode
  f-opcode
  ("ADDX" "MOVX" "SUBX" "BTST"
  ("ADDX" "MOVX" "SUBX" "BTST"
   "SCC" "ADDC" "SETF" "CLEARF"
   "SCC" "ADDC" "SETF" "CLEARF"
   "MOVE_R_S" "MOVE_S_R" "ABS" "DSTEP"
   "MOVE_R_S" "MOVE_S_R" "ABS" "DSTEP"
   "LZ" "SWAP" "XOR" "MSTEP")
   "LZ" "SWAP" "XOR" "MSTEP")
)
)
(define-pmacro RFIX_MCP RFIX_MSTEP)
(define-pmacro RFIX_MCP RFIX_MSTEP)
(define-normal-insn-enum
(define-normal-insn-enum
  insn-indir-opc
  insn-indir-opc
  "Insns for (MODE_INDIRECT or MODE_AUTOINCREMENT) and either SIZE_BYTE, SIZE_WORD or SIZE_DWORD"
  "Insns for (MODE_INDIRECT or MODE_AUTOINCREMENT) and either SIZE_BYTE, SIZE_WORD or SIZE_DWORD"
  ()
  ()
  INDIR_
  INDIR_
  f-opcode
  f-opcode
  ("ADDX" "MOVX" "SUBX" "CMPX"
  ("ADDX" "MOVX" "SUBX" "CMPX"
   "MUL" "BDAP_M" "ADDC" "BOUND"
   "MUL" "BDAP_M" "ADDC" "BOUND"
   "ADD" "MOVE_M_R" "SUB" "CMP"
   "ADD" "MOVE_M_R" "SUB" "CMP"
   "AND" "OR" "TEST" "MOVE_R_M")
   "AND" "OR" "TEST" "MOVE_R_M")
)
)
(define-pmacro INDIR_ADDO INDIR_BDAP_M)
(define-pmacro INDIR_ADDO INDIR_BDAP_M)
(define-normal-insn-enum
(define-normal-insn-enum
  insn-infix-opc
  insn-infix-opc
  "Insns for (MODE_INDIRECT or MODE_AUTOINCREMENT) and SIZE_FIXED"
  "Insns for (MODE_INDIRECT or MODE_AUTOINCREMENT) and SIZE_FIXED"
  ()
  ()
  INFIX_
  INFIX_
  f-opcode
  f-opcode
  ("ADDX" "MOVX" "SUBX" "CMPX"
  ("ADDX" "MOVX" "SUBX" "CMPX"
   "JUMP_M" "DIP" "JUMP_R" "BCC_M"
   "JUMP_M" "DIP" "JUMP_R" "BCC_M"
   "MOVE_M_S" "MOVE_S_M" "BMOD" "BSTORE"
   "MOVE_M_S" "MOVE_S_M" "BMOD" "BSTORE"
   "RBF" "SBFS" "MOVEM_M_R" "MOVEM_R_M")
   "RBF" "SBFS" "MOVEM_M_R" "MOVEM_R_M")
)
)
(define-pmacro INFIX_MOVE_SS INFIX_SBFS)
(define-pmacro INFIX_MOVE_SS INFIX_SBFS)
(define-pmacro INFIX_LAPC INFIX_DIP)
(define-pmacro INFIX_LAPC INFIX_DIP)
(define-pmacro INFIX_RFE INFIX_JUMP_M)
(define-pmacro INFIX_RFE INFIX_JUMP_M)
(define-pmacro INFIX_RFN INFIX_JUMP_M)
(define-pmacro INFIX_RFN INFIX_JUMP_M)
(define-pmacro INFIX_HALT INFIX_JUMP_M)
(define-pmacro INFIX_HALT INFIX_JUMP_M)
(define-pmacro INFIX_SFE INFIX_JUMP_M)
(define-pmacro INFIX_SFE INFIX_JUMP_M)
(define-pmacro INFIX_RFG INFIX_JUMP_M)
(define-pmacro INFIX_RFG INFIX_JUMP_M)
(define-pmacro INFIX_JAS_R INFIX_JUMP_R)
(define-pmacro INFIX_JAS_R INFIX_JUMP_R)
(define-pmacro INFIX_JAS_M INFIX_JUMP_R)
(define-pmacro INFIX_JAS_M INFIX_JUMP_R)
(define-pmacro INFIX_JASC INFIX_RBF)
(define-pmacro INFIX_JASC INFIX_RBF)
(define-pmacro INFIX_JUMP_P INFIX_BCC_M)
(define-pmacro INFIX_JUMP_P INFIX_BCC_M)
(define-pmacro INFIX_BAS INFIX_BMOD)
(define-pmacro INFIX_BAS INFIX_BMOD)
(define-pmacro INFIX_BASC INFIX_BSTORE)
(define-pmacro INFIX_BASC INFIX_BSTORE)
(define-pmacro INFIX_BREAK INFIX_JUMP_M)
(define-pmacro INFIX_BREAK INFIX_JUMP_M)
(define-pmacro INFIX_FIDXI INFIX_JUMP_M)
(define-pmacro INFIX_FIDXI INFIX_JUMP_M)
(define-pmacro INFIX_FIDXD INFIX_BAS)
(define-pmacro INFIX_FIDXD INFIX_BAS)
(define-pmacro INFIX_FTAGI INFIX_JUMP_M)
(define-pmacro INFIX_FTAGI INFIX_JUMP_M)
(define-pmacro INFIX_FTAGD INFIX_BAS)
(define-pmacro INFIX_FTAGD INFIX_BAS)
; Classes of insns:
; Classes of insns:
; Move-to-register, move-to-memory, move-to/from-other-register,
; Move-to-register, move-to-memory, move-to/from-other-register,
; logical, arithmetic, branch.
; logical, arithmetic, branch.
; Classes of operands:
; Classes of operands:
; quick, register, memory-indirect, memory-postinc.
; quick, register, memory-indirect, memory-postinc.
;;;;;;;;;;;;;;;;;; -normal-insn
;;;;;;;;;;;;;;;;;; -normal-insn
(define-pmacro (dni-bwd-attr name comment attr syntax fmt fsem timing)
(define-pmacro (dni-bwd-attr name comment attr syntax fmt fsem timing)
  (begin
  (begin
    (dni (.sym name .b) (.str "byte " comment) attr (.str name ".b " syntax)
    (dni (.sym name .b) (.str "byte " comment) attr (.str name ".b " syntax)
         (.splice (.unsplice fmt) SIZE_BYTE)
         (.splice (.unsplice fmt) SIZE_BYTE)
         (fsem QI)
         (fsem QI)
         timing)
         timing)
    (dni (.sym name .w) (.str "word " comment) attr (.str name ".w " syntax)
    (dni (.sym name .w) (.str "word " comment) attr (.str name ".w " syntax)
         (.splice (.unsplice fmt) SIZE_WORD)
         (.splice (.unsplice fmt) SIZE_WORD)
         (fsem HI)
         (fsem HI)
         timing)
         timing)
    (dni (.sym name .d) (.str "dword " comment) attr (.str name ".d " syntax)
    (dni (.sym name .d) (.str "dword " comment) attr (.str name ".d " syntax)
         (.splice (.unsplice fmt) SIZE_DWORD)
         (.splice (.unsplice fmt) SIZE_DWORD)
         (fsem SI)
         (fsem SI)
         timing))
         timing))
)
)
(define-pmacro (dni-cdt-attr name comment attr syntax fmt semantics)
(define-pmacro (dni-cdt-attr name comment attr syntax fmt semantics)
  "dni without specifying timing"
  "dni without specifying timing"
  (dni name comment attr syntax fmt semantics (cris-timing))
  (dni name comment attr syntax fmt semantics (cris-timing))
)
)
(define-pmacro (dni-cdt-bwd-attr name comment attr syntax fmt fsem)
(define-pmacro (dni-cdt-bwd-attr name comment attr syntax fmt fsem)
  (begin
  (begin
    (dni-cdt-attr (.sym name .b-r) (.str "byte " comment) attr (.str name ".b " syntax)
    (dni-cdt-attr (.sym name .b-r) (.str "byte " comment) attr (.str name ".b " syntax)
                  (.splice (.unsplice fmt) SIZE_BYTE)
                  (.splice (.unsplice fmt) SIZE_BYTE)
                  (fsem QI))
                  (fsem QI))
    (dni-cdt-attr (.sym name .w-r) (.str "word " comment) attr (.str name ".w " syntax)
    (dni-cdt-attr (.sym name .w-r) (.str "word " comment) attr (.str name ".w " syntax)
                  (.splice (.unsplice fmt) SIZE_WORD)
                  (.splice (.unsplice fmt) SIZE_WORD)
                  (fsem HI))
                  (fsem HI))
    (dni-cdt-attr (.sym name .d-r) (.str "dword " comment) attr (.str name ".d " syntax)
    (dni-cdt-attr (.sym name .d-r) (.str "dword " comment) attr (.str name ".d " syntax)
                  (.splice (.unsplice fmt) SIZE_DWORD)
                  (.splice (.unsplice fmt) SIZE_DWORD)
                  (fsem SI)))
                  (fsem SI)))
)
)
; Some convenience macros based on the above ones.
; Some convenience macros based on the above ones.
(define-pmacro (dni-cdt-bwd name comment syntax fmt fsem)
(define-pmacro (dni-cdt-bwd name comment syntax fmt fsem)
  (dni-cdt-bwd-attr name comment () syntax fmt fsem)
  (dni-cdt-bwd-attr name comment () syntax fmt fsem)
)
)
(define-pmacro (dni-bwd name comment syntax fmt fsem timing)
(define-pmacro (dni-bwd name comment syntax fmt fsem timing)
  (dni-bwd-attr comment () syntax fmt fsem timing)
  (dni-bwd-attr comment () syntax fmt fsem timing)
)
)
(define-pmacro-map
(define-pmacro-map
  (((dni-cdt name comment syntax fmt semantics)
  (((dni-cdt name comment syntax fmt semantics)
    (dni-cdt-attr name comment () syntax fmt semantics))
    (dni-cdt-attr name comment () syntax fmt semantics))
   ((dni-c-QI-attr name comment attr syntax fmt fsem)
   ((dni-c-QI-attr name comment attr syntax fmt fsem)
    (dni name comment attr syntax fmt fsem (cris-timing-const-QI)))
    (dni name comment attr syntax fmt fsem (cris-timing-const-QI)))
   ((dni-c-HI-attr name comment attr syntax fmt fsem)
   ((dni-c-HI-attr name comment attr syntax fmt fsem)
    (dni name comment attr syntax fmt fsem (cris-timing-const-HI)))
    (dni name comment attr syntax fmt fsem (cris-timing-const-HI)))
   ((dni-c-SI-attr name comment attr syntax fmt fsem)
   ((dni-c-SI-attr name comment attr syntax fmt fsem)
    (dni name comment attr syntax fmt fsem (cris-timing-const-SI))))
    (dni name comment attr syntax fmt fsem (cris-timing-const-SI))))
)
)
(define-pmacro-map
(define-pmacro-map
  (((dni-c-QI name comment syntax fmt fsem)
  (((dni-c-QI name comment syntax fmt fsem)
    (dni-c-QI-attr name comment () syntax fmt fsem))
    (dni-c-QI-attr name comment () syntax fmt fsem))
   ((dni-c-HI name comment syntax fmt fsem)
   ((dni-c-HI name comment syntax fmt fsem)
    (dni-c-HI-attr name comment () syntax fmt fsem))
    (dni-c-HI-attr name comment () syntax fmt fsem))
   ((dni-c-SI name comment syntax fmt fsem)
   ((dni-c-SI name comment syntax fmt fsem)
    (dni-c-SI-attr name comment () syntax fmt fsem)))
    (dni-c-SI-attr name comment () syntax fmt fsem)))
)
)
; These flags are both cleared by all insns except prefixes (before
; These flags are both cleared by all insns except prefixes (before
; CRISv32) and "setf x", so we put them in a handy macro.
; CRISv32) and "setf x", so we put them in a handy macro.
(define-pmacro
(define-pmacro
  (reset-x-p)
  (reset-x-p)
  (sequence
  (sequence
    ()
    ()
    (set xbit 0)
    (set xbit 0)
    (set prefix-set 0))
    (set prefix-set 0))
)
)
;        NOP           | 0  0  0  0| 0  1| 0  1  0  0| 0  0| 1  1  1  1|
;        NOP           | 0  0  0  0| 0  1| 0  1  0  0| 0  0| 1  1  1  1|
; (For V32, "SETF" (no flags) is used.)
; (For V32, "SETF" (no flags) is used.)
(dni-cdt-attr
(dni-cdt-attr
 nop "nop" (MACH-PC) "nop"
 nop "nop" (MACH-PC) "nop"
 (+ (f-operand2 0) R_ADDI MODE_REGISTER SIZE_BYTE (f-operand1 15))
 (+ (f-operand2 0) R_ADDI MODE_REGISTER SIZE_BYTE (f-operand1 15))
 (reset-x-p)
 (reset-x-p)
)
)
; Pre- and v32+ variants MOVE insns set flags differently.  These two
; Pre- and v32+ variants MOVE insns set flags differently.  These two
; macros for flag settings are meant to be used in all MOVE insns.
; macros for flag settings are meant to be used in all MOVE insns.
(define-pmacro (setf-moveq value)
(define-pmacro (setf-moveq value)
  (sequence
  (sequence
    ()
    ()
    (set-quiet nbit-move (lt SI value 0))
    (set-quiet nbit-move (lt SI value 0))
    (set-quiet zbit-move (andif BI (eq SI value 0) (if BI xbit zbit 1)))
    (set-quiet zbit-move (andif BI (eq SI value 0) (if BI xbit zbit 1)))
    (set-quiet cbit-move 0)
    (set-quiet cbit-move 0)
    (set-quiet vbit-move 0)
    (set-quiet vbit-move 0)
    (reset-x-p))
    (reset-x-p))
)
)
(define-pmacro (setf-move size value)
(define-pmacro (setf-move size value)
  (sequence
  (sequence
    ()
    ()
    (set nbit (lt size value 0))
    (set nbit (lt size value 0))
    (set zbit (andif BI (eq size value 0) (if BI xbit zbit 1)))
    (set zbit (andif BI (eq size value 0) (if BI xbit zbit 1)))
    (set-quiet cbit-move 0)
    (set-quiet cbit-move 0)
    (set-quiet vbit-move 0)
    (set-quiet vbit-move 0)
    (reset-x-p))
    (reset-x-p))
)
)
; The CGEN binop-with-bit operations are not documented well enough that I
; The CGEN binop-with-bit operations are not documented well enough that I
; trust their semantics to remain stable.  Better define local ones: the
; trust their semantics to remain stable.  Better define local ones: the
; semantics become explicit.
; semantics become explicit.
(define-pmacro-map
(define-pmacro-map
  (((add-overflow size R D S carry)
  (((add-overflow size R D S carry)
    (orif BI (andif BI (andif BI (lt size S 0) (lt size D 0)) (ge size R 0))
    (orif BI (andif BI (andif BI (lt size S 0) (lt size D 0)) (ge size R 0))
          (andif BI (andif BI (ge size S 0) (ge size D 0)) (lt size R 0))))
          (andif BI (andif BI (ge size S 0) (ge size D 0)) (lt size R 0))))
   ((add-carry size R D S carry)
   ((add-carry size R D S carry)
    (orif BI (andif BI (lt size S 0) (lt size D 0))
    (orif BI (andif BI (lt size S 0) (lt size D 0))
          (orif BI (andif BI (lt size D 0) (ge size R 0))
          (orif BI (andif BI (lt size D 0) (ge size R 0))
                (andif BI (lt size S 0) (ge size R 0)))))
                (andif BI (lt size S 0) (ge size R 0)))))
   ((sub-overflow size R D S carry)
   ((sub-overflow size R D S carry)
    (orif BI (andif BI (andif BI (ge size S 0) (lt size D 0)) (ge size R 0))
    (orif BI (andif BI (andif BI (ge size S 0) (lt size D 0)) (ge size R 0))
          (andif BI (andif BI (lt size S 0) (ge size D 0)) (lt size R 0))))
          (andif BI (andif BI (lt size S 0) (ge size D 0)) (lt size R 0))))
   ((sub-carry size R D S carry)
   ((sub-carry size R D S carry)
    (orif BI (andif BI (lt size S 0) (ge size D 0))
    (orif BI (andif BI (lt size S 0) (ge size D 0))
          (orif BI (andif BI (ge size D 0) (lt size R 0))
          (orif BI (andif BI (ge size D 0) (lt size R 0))
                (andif BI (lt size S 0) (lt size R 0)))))
                (andif BI (lt size S 0) (lt size R 0)))))
   ; Only valid for size := DI
   ; Only valid for size := DI
   ((mulu-overflow size R D S carry)
   ((mulu-overflow size R D S carry)
    (ne DI R (zext DI (trunc SI R))))
    (ne DI R (zext DI (trunc SI R))))
   ((mulu-carry size R D S carry)
   ((mulu-carry size R D S carry)
    (andif current-mach-is-v32 carry))
    (andif current-mach-is-v32 carry))
   ((muls-overflow size R D S carry)
   ((muls-overflow size R D S carry)
    (ne DI R (ext DI (trunc SI R))))
    (ne DI R (ext DI (trunc SI R))))
   ((muls-carry size R D S carry)
   ((muls-carry size R D S carry)
    (andif current-mach-is-v32 carry)))
    (andif current-mach-is-v32 carry)))
)
)
(define-pmacro (setf-arit2 size op source1 source2 result carryin carryout)
(define-pmacro (setf-arit2 size op source1 source2 result carryin carryout)
  "Set no-prefix, x=0, carryout, v, z and n according to operation OP in size SIZE"
  "Set no-prefix, x=0, carryout, v, z and n according to operation OP in size SIZE"
  (sequence
  (sequence
    ()
    ()
    (set carryout ((.sym op -carry) size result source1 source2 carryin))
    (set carryout ((.sym op -carry) size result source1 source2 carryin))
    (set nbit (lt size result 0))
    (set nbit (lt size result 0))
    (set zbit (andif BI (eq size result 0) (orif BI zbit (not BI xbit))))
    (set zbit (andif BI (eq size result 0) (orif BI zbit (not BI xbit))))
    (set vbit ((.sym op -overflow) size result source1 source2 carryin))
    (set vbit ((.sym op -overflow) size result source1 source2 carryin))
    (reset-x-p))
    (reset-x-p))
)
)
(define-pmacro (setf-arit size op source1 source2 result carry)
(define-pmacro (setf-arit size op source1 source2 result carry)
  "Set no-prefix, x=0, c, v, z and n according to operation OP in size SIZE"
  "Set no-prefix, x=0, c, v, z and n according to operation OP in size SIZE"
  (setf-arit2 size op source1 source2 result carry cbit)
  (setf-arit2 size op source1 source2 result carry cbit)
)
)
; Let's have convienence macros for arithmetic, including evaluation of the
; Let's have convienence macros for arithmetic, including evaluation of the
; operation, destination modification, flag setting and carry propagation.
; operation, destination modification, flag setting and carry propagation.
(define-pmacro
(define-pmacro
  (cris-arit6-int arit size fdest fdest_op srcop1 srcop2 carryout carryin)
  (cris-arit6-int arit size fdest fdest_op srcop1 srcop2 carryout carryin)
  "Core for performing some three-operand arithmetic with carry as parameter"
  "Core for performing some three-operand arithmetic with carry as parameter"
  (sequence
  (sequence
   ((size tmpopd) (size tmpops) (BI carry) (size newval))
   ((size tmpopd) (size tmpops) (BI carry) (size newval))
   (set tmpops srcop2)
   (set tmpops srcop2)
   (set tmpopd srcop1)
   (set tmpopd srcop1)
   (set carry carryin)
   (set carry carryin)
   (set newval ((.sym arit c) tmpopd tmpops (if BI (eq xbit 0) 0 carry)))
   (set newval ((.sym arit c) tmpopd tmpops (if BI (eq xbit 0) 0 carry)))
   (fdest size fdest_op newval)
   (fdest size fdest_op newval)
   (setf-arit2 size arit tmpopd tmpops newval carry carryout))
   (setf-arit2 size arit tmpopd tmpops newval carry carryout))
)
)
(define-pmacro
(define-pmacro
  (cris-arit5-int arit size destregno srcop1 srcop2 carryout carryin)
  (cris-arit5-int arit size destregno srcop1 srcop2 carryout carryin)
  "As cris-arit6-int, but to set a part of a general register"
  "As cris-arit6-int, but to set a part of a general register"
  (cris-arit6-int
  (cris-arit6-int
   arit
   arit
   size
   size
   (.pmacro (sz regno val) (set-subreg-gr sz regno val))
   (.pmacro (sz regno val) (set-subreg-gr sz regno val))
   destregno
   destregno
   srcop1
   srcop1
   srcop2
   srcop2
   carryout
   carryout
   carryin)
   carryin)
)
)
(define-pmacro (cris-arit5 arit size destreg srcop1 srcop2 carryout carryin)
(define-pmacro (cris-arit5 arit size destreg srcop1 srcop2 carryout carryin)
  "As cris-arit5-int, but takes a register as parameter, not register number"
  "As cris-arit5-int, but takes a register as parameter, not register number"
  (cris-arit5-int arit size (regno destreg) srcop1 srcop2 carryout carryin)
  (cris-arit5-int arit size (regno destreg) srcop1 srcop2 carryout carryin)
)
)
(define-pmacro (cris-arit3-int arit size destregno srcop1 srcop2)
(define-pmacro (cris-arit3-int arit size destregno srcop1 srcop2)
  "As cris-arit5-int, but with carry-in same as carry-out"
  "As cris-arit5-int, but with carry-in same as carry-out"
  (cris-arit5-int arit size destregno srcop1 srcop2 cbit cbit)
  (cris-arit5-int arit size destregno srcop1 srcop2 cbit cbit)
)
)
(define-pmacro (cris-arit3 arit size destreg srcop1 srcop2)
(define-pmacro (cris-arit3 arit size destreg srcop1 srcop2)
  "As cris-arit3-int, but takes a register as parameter, not register number"
  "As cris-arit3-int, but takes a register as parameter, not register number"
  (cris-arit3-int arit size (regno destreg) srcop1 srcop2)
  (cris-arit3-int arit size (regno destreg) srcop1 srcop2)
)
)
(define-pmacro (cris-arit arit size destreg srcop)
(define-pmacro (cris-arit arit size destreg srcop)
  "As cris-arit3, but with destination same as srcop1"
  "As cris-arit3, but with destination same as srcop1"
  (cris-arit3 arit size destreg destreg srcop)
  (cris-arit3 arit size destreg destreg srcop)
)
)
(define-pmacro (cris-arit-3op arit size destsrcop2 srcop1 dest-3op)
(define-pmacro (cris-arit-3op arit size destsrcop2 srcop1 dest-3op)
  "Similar to cris-arit3-int, but for prefixed operand only"
  "Similar to cris-arit3-int, but for prefixed operand only"
  (cris-arit3-int arit size
  (cris-arit3-int arit size
                  (if SI (andif prefix-set (not inc))
                  (if SI (andif prefix-set (not inc))
                      (regno dest-3op)
                      (regno dest-3op)
                      (regno destsrcop2))
                      (regno destsrcop2))
                  destsrcop2 srcop1)
                  destsrcop2 srcop1)
)
)
; Convenience macros to select a part of a value and its complement, for
; Convenience macros to select a part of a value and its complement, for
; the .b, .w and .d operations.
; the .b, .w and .d operations.
(define-pmacro (QI-part val) (and SI val #xff))
(define-pmacro (QI-part val) (and SI val #xff))
(define-pmacro (non-QI-part val) (and SI val #xffffff00))
(define-pmacro (non-QI-part val) (and SI val #xffffff00))
(define-pmacro (HI-part val) (and SI val #xffff))
(define-pmacro (HI-part val) (and SI val #xffff))
(define-pmacro (non-HI-part val) (and SI val #xffff0000))
(define-pmacro (non-HI-part val) (and SI val #xffff0000))
(define-pmacro (SI-part val) val)
(define-pmacro (SI-part val) val)
(define-pmacro (non-SI-part val) 0)
(define-pmacro (non-SI-part val) 0)
(define-pmacro
(define-pmacro
  (set-subreg-gr-bw BWD gregno newval)
  (set-subreg-gr-bw BWD gregno newval)
  "Set a byte or word part or full dword of a general register"
  "Set a byte or word part or full dword of a general register"
  (sequence
  (sequence
    ((SI oldregval))
    ((SI oldregval))
    (set oldregval (reg h-raw-gr gregno))
    (set oldregval (reg h-raw-gr gregno))
    (set (reg h-gr gregno)
    (set (reg h-gr gregno)
         (or SI ((.sym BWD -part) newval) ((.sym non- BWD -part) oldregval))))
         (or SI ((.sym BWD -part) newval) ((.sym non- BWD -part) oldregval))))
)
)
(define-pmacro (set-subreg-gr BWD gregno newval)
(define-pmacro (set-subreg-gr BWD gregno newval)
  ((.sym set-subreg-gr- BWD) BWD gregno newval)
  ((.sym set-subreg-gr- BWD) BWD gregno newval)
)
)
(define-pmacro (set-subreg-gr-SI SI gregno newval)
(define-pmacro (set-subreg-gr-SI SI gregno newval)
  (set (reg h-gr gregno) newval)
  (set (reg h-gr gregno) newval)
)
)
(define-pmacro set-subreg-gr-HI set-subreg-gr-bw)
(define-pmacro set-subreg-gr-HI set-subreg-gr-bw)
(define-pmacro set-subreg-gr-QI set-subreg-gr-bw)
(define-pmacro set-subreg-gr-QI set-subreg-gr-bw)
; MOVE.m  Rs,Rd           [ Rd | 011001mm | Rs ]
; MOVE.m  Rs,Rd           [ Rd | 011001mm | Rs ]
(dni-cdt-bwd
(dni-cdt-bwd
 move "move.m r,R"
 move "move.m r,R"
 "move.m ${Rs},${Rd}"
 "move.m ${Rs},${Rd}"
 (+ Rd MODE_REGISTER R_MOVE Rs)
 (+ Rd MODE_REGISTER R_MOVE Rs)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ((BWD newval))
    ((BWD newval))
    (set newval Rs)
    (set newval Rs)
    (set-subreg-gr BWD (regno Rd) newval)
    (set-subreg-gr BWD (regno Rd) newval)
    (setf-move BWD newval)))
    (setf-move BWD newval)))
)
)
; MOVE.D  PC,Rd           [ Rd | 01100110 | 1111 ]
; MOVE.D  PC,Rd           [ Rd | 01100110 | 1111 ]
; This insn is used in PIC code to find out the code address.  It's an
; This insn is used in PIC code to find out the code address.  It's an
; exception to the (guarded) non-implementation of PC operands in this
; exception to the (guarded) non-implementation of PC operands in this
; file.
; file.
(dni-cdt-attr
(dni-cdt-attr
 movepcr "move.d PC,R"
 movepcr "move.d PC,R"
 (MACH-PC UNCOND-CTI)
 (MACH-PC UNCOND-CTI)
 "move.d PC,${Rd}"
 "move.d PC,${Rd}"
 (+ Rd MODE_REGISTER R_MOVE SIZE_DWORD (f-source 15))
 (+ Rd MODE_REGISTER R_MOVE SIZE_DWORD (f-source 15))
 (sequence
 (sequence
   ((SI pcval))
   ((SI pcval))
   (set pcval (add SI pc 2))
   (set pcval (add SI pc 2))
   (set Rd pcval)
   (set Rd pcval)
   (setf-move SI pcval))
   (setf-move SI pcval))
)
)
; MOVEQ   i,Rd            [ Rd | 001001 | i ]
; MOVEQ   i,Rd            [ Rd | 001001 | i ]
(dni-cdt
(dni-cdt
 moveq "moveq"
 moveq "moveq"
 "moveq $i,$Rd"
 "moveq $i,$Rd"
 (+ Rd MODE_QUICK_IMMEDIATE Q_MOVEQ i)
 (+ Rd MODE_QUICK_IMMEDIATE Q_MOVEQ i)
 (sequence
 (sequence
   ((SI newval))
   ((SI newval))
   (set newval i)
   (set newval i)
   (set Rd newval)
   (set Rd newval)
   (setf-moveq newval))
   (setf-moveq newval))
)
)
(define-pmacro (dni-cdt-sbw name comment syntax fmt fsem)
(define-pmacro (dni-cdt-sbw name comment syntax fmt fsem)
  "Insn generator for insns with signed .b and .w variants"
  "Insn generator for insns with signed .b and .w variants"
  (begin
  (begin
    (dni-cdt
    (dni-cdt
     (.sym name .b-r) (.str "byte " comment) (.str name ".b " syntax)
     (.sym name .b-r) (.str "byte " comment) (.str name ".b " syntax)
     (.splice (.unsplice fmt) SIGNED_BYTE)
     (.splice (.unsplice fmt) SIGNED_BYTE)
     (fsem QI))
     (fsem QI))
    (dni-cdt
    (dni-cdt
     (.sym name .w-r) (.str "word " comment) (.str name ".w " syntax)
     (.sym name .w-r) (.str "word " comment) (.str name ".w " syntax)
     (.splice (.unsplice fmt) SIGNED_WORD)
     (.splice (.unsplice fmt) SIGNED_WORD)
     (fsem HI)))
     (fsem HI)))
)
)
; MOVS.z  Rs,Rd           [ Rd | 0100011z | Rs ]
; MOVS.z  Rs,Rd           [ Rd | 0100011z | Rs ]
(dni-cdt-sbw
(dni-cdt-sbw
 movs "movs.m r,R"
 movs "movs.m r,R"
 "movs.m ${Rs},${Rd}"
 "movs.m ${Rs},${Rd}"
 (+ Rd MODE_REGISTER R_MOVX Rs)
 (+ Rd MODE_REGISTER R_MOVX Rs)
 (.pmacro
 (.pmacro
  (BW)
  (BW)
  (sequence
  (sequence
    ((BW tmpops) (SI newval))
    ((BW tmpops) (SI newval))
    (set tmpops Rs)
    (set tmpops Rs)
    (set newval (ext SI tmpops))
    (set newval (ext SI tmpops))
    (set Rd newval)
    (set Rd newval)
    (setf-move SI newval)))
    (setf-move SI newval)))
)
)
(define-pmacro (dni-cdt-ubw name comment syntax fmt fsem)
(define-pmacro (dni-cdt-ubw name comment syntax fmt fsem)
  "Similar to dni-cdt-sbw but for unsigned operations"
  "Similar to dni-cdt-sbw but for unsigned operations"
  (begin
  (begin
    (dni-cdt
    (dni-cdt
     (.sym name .b-r) (.str "byte " comment) (.str name ".b " syntax)
     (.sym name .b-r) (.str "byte " comment) (.str name ".b " syntax)
     (.splice (.unsplice fmt) UNSIGNED_BYTE)
     (.splice (.unsplice fmt) UNSIGNED_BYTE)
     (fsem QI))
     (fsem QI))
    (dni-cdt
    (dni-cdt
     (.sym name .w-r) (.str "word " comment) (.str name ".w " syntax)
     (.sym name .w-r) (.str "word " comment) (.str name ".w " syntax)
     (.splice (.unsplice fmt) UNSIGNED_WORD)
     (.splice (.unsplice fmt) UNSIGNED_WORD)
     (fsem HI)))
     (fsem HI)))
)
)
; MOVU.z  Rs,Rd           [ Rd | 0100010z | Rs ]
; MOVU.z  Rs,Rd           [ Rd | 0100010z | Rs ]
(dni-cdt-ubw
(dni-cdt-ubw
 movu "movu.m r,R"
 movu "movu.m r,R"
 "movu.m ${Rs},${Rd}"
 "movu.m ${Rs},${Rd}"
 (+ Rd MODE_REGISTER R_MOVX Rs)
 (+ Rd MODE_REGISTER R_MOVX Rs)
 (.pmacro
 (.pmacro
  (BW)
  (BW)
  (sequence
  (sequence
    ((BW tmpops) (SI newval))
    ((BW tmpops) (SI newval))
    (set tmpops Rs)
    (set tmpops Rs)
    (set newval (zext SI tmpops))
    (set newval (zext SI tmpops))
    (set Rd newval)
    (set Rd newval)
    (setf-move SI newval)))
    (setf-move SI newval)))
)
)
; (MOVE.m  [PC+],Rd        [ Rd | 111001mm | 1111 ])
; (MOVE.m  [PC+],Rd        [ Rd | 111001mm | 1111 ])
; For the moment, it doesn't seem worthwhile to make a dni-c-bwd macro;
; For the moment, it doesn't seem worthwhile to make a dni-c-bwd macro;
; too many places to parametrize.
; too many places to parametrize.
(dni-c-QI
(dni-c-QI
 movecbr "move.b [PC+],R"
 movecbr "move.b [PC+],R"
 "move.b ${sconst8},${Rd}"
 "move.b ${sconst8},${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_MOVE_M_R SIZE_BYTE (f-source 15) sconst8)
 (+ Rd MODE_AUTOINCREMENT INDIR_MOVE_M_R SIZE_BYTE (f-source 15) sconst8)
 (sequence
 (sequence
   ((QI newval))
   ((QI newval))
   (set newval sconst8)
   (set newval sconst8)
   (set-subreg-gr QI (regno Rd) newval)
   (set-subreg-gr QI (regno Rd) newval)
   (setf-move QI newval))
   (setf-move QI newval))
)
)
(dni-c-HI
(dni-c-HI
 movecwr "move.w [PC+],R"
 movecwr "move.w [PC+],R"
 "move.w ${sconst16},${Rd}"
 "move.w ${sconst16},${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_MOVE_M_R SIZE_WORD (f-source 15) sconst16)
 (+ Rd MODE_AUTOINCREMENT INDIR_MOVE_M_R SIZE_WORD (f-source 15) sconst16)
 (sequence
 (sequence
   ((HI newval))
   ((HI newval))
   (set newval sconst16)
   (set newval sconst16)
   (set-subreg-gr HI (regno Rd) newval)
   (set-subreg-gr HI (regno Rd) newval)
   (setf-move HI newval))
   (setf-move HI newval))
)
)
(dni-c-SI
(dni-c-SI
 movecdr "move.d [PC+],R"
 movecdr "move.d [PC+],R"
 "move.d ${const32},${Rd}"
 "move.d ${const32},${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_MOVE_M_R SIZE_DWORD (f-source 15) const32)
 (+ Rd MODE_AUTOINCREMENT INDIR_MOVE_M_R SIZE_DWORD (f-source 15) const32)
 (sequence
 (sequence
   ((SI newval))
   ((SI newval))
   (set newval const32)
   (set newval const32)
   (set Rd newval)
   (set Rd newval)
   (setf-move SI newval))
   (setf-move SI newval))
)
)
; (MOVS.z  [PC+],Rd        [ Rd | 1100011z | 1111 ])
; (MOVS.z  [PC+],Rd        [ Rd | 1100011z | 1111 ])
; Similarly, no likely net improvement for a dni-c-bw.
; Similarly, no likely net improvement for a dni-c-bw.
(dni-c-QI
(dni-c-QI
 movscbr "movs.b [PC+],R"
 movscbr "movs.b [PC+],R"
 "movs.b ${sconst8},${Rd}"
 "movs.b ${sconst8},${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX SIGNED_BYTE (f-source 15) sconst8)
 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX SIGNED_BYTE (f-source 15) sconst8)
 (sequence
 (sequence
   ((SI newval))
   ((SI newval))
   ; FIXME: Make trunc unnecessary.
   ; FIXME: Make trunc unnecessary.
   (set newval (ext SI (trunc QI sconst8)))
   (set newval (ext SI (trunc QI sconst8)))
   (set Rd newval)
   (set Rd newval)
   (setf-move SI newval))
   (setf-move SI newval))
)
)
(dni-c-HI
(dni-c-HI
 movscwr "movs.w [PC+],R"
 movscwr "movs.w [PC+],R"
 "movs.w ${sconst16},${Rd}"
 "movs.w ${sconst16},${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX SIGNED_WORD (f-source 15) sconst16)
 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX SIGNED_WORD (f-source 15) sconst16)
 (sequence
 (sequence
   ((SI newval))
   ((SI newval))
   ; FIXME: Make trunc unnecessary.
   ; FIXME: Make trunc unnecessary.
   (set newval (ext SI (trunc HI sconst16)))
   (set newval (ext SI (trunc HI sconst16)))
   (set Rd newval)
   (set Rd newval)
   (setf-move SI newval))
   (setf-move SI newval))
)
)
; (MOVU.z  [PC+],Rd        [ Rd | 1100010z | 1111 ])
; (MOVU.z  [PC+],Rd        [ Rd | 1100010z | 1111 ])
(dni-c-QI
(dni-c-QI
 movucbr "movu.b [PC+],R"
 movucbr "movu.b [PC+],R"
 "movu.b ${uconst8},${Rd}"
 "movu.b ${uconst8},${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX UNSIGNED_BYTE (f-source 15) uconst8)
 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX UNSIGNED_BYTE (f-source 15) uconst8)
 (sequence
 (sequence
   ((SI newval))
   ((SI newval))
   ; FIXME: Make trunc unnecessary.
   ; FIXME: Make trunc unnecessary.
   (set newval (zext SI (trunc QI uconst8)))
   (set newval (zext SI (trunc QI uconst8)))
   (set Rd newval)
   (set Rd newval)
   (setf-move SI newval))
   (setf-move SI newval))
)
)
(dni-c-HI
(dni-c-HI
 movucwr "movu.w [PC+],R"
 movucwr "movu.w [PC+],R"
 "movu.w ${uconst16},${Rd}"
 "movu.w ${uconst16},${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX UNSIGNED_WORD (f-source 15) uconst16)
 (+ Rd MODE_AUTOINCREMENT INDIR_MOVX UNSIGNED_WORD (f-source 15) uconst16)
 (sequence
 (sequence
   ((SI newval))
   ((SI newval))
   ; FIXME: Make trunc unnecessary.
   ; FIXME: Make trunc unnecessary.
   (set newval (zext SI (trunc HI uconst16)))
   (set newval (zext SI (trunc HI uconst16)))
   (set Rd newval)
   (set Rd newval)
   (setf-move SI newval))
   (setf-move SI newval))
)
)
; ADDQ    j,Rd            [ Rd | 001000 | j ]
; ADDQ    j,Rd            [ Rd | 001000 | j ]
(dni-cdt
(dni-cdt
 addq "addq j,Rd"
 addq "addq j,Rd"
 "addq $j,$Rd"
 "addq $j,$Rd"
 (+ Rd MODE_QUICK_IMMEDIATE Q_ADDQ j)
 (+ Rd MODE_QUICK_IMMEDIATE Q_ADDQ j)
 (cris-arit add SI Rd j)
 (cris-arit add SI Rd j)
)
)
; SUBQ    j,Rd            [ Rd | 001010| j ]
; SUBQ    j,Rd            [ Rd | 001010| j ]
(dni-cdt
(dni-cdt
 subq "subq j,Rd"
 subq "subq j,Rd"
 "subq $j,$Rd"
 "subq $j,$Rd"
 (+ Rd MODE_QUICK_IMMEDIATE Q_SUBQ j)
 (+ Rd MODE_QUICK_IMMEDIATE Q_SUBQ j)
 (cris-arit sub SI Rd j)
 (cris-arit sub SI Rd j)
)
)
; Convenience macros for insns with a memory operand.
; Convenience macros for insns with a memory operand.
(define-pmacro
(define-pmacro
  (dni-cmt-attr-tim name comment attr syntax fmt semantics timing)
  (dni-cmt-attr-tim name comment attr syntax fmt semantics timing)
  "dni with memory-access"
  "dni with memory-access"
  (dni name comment attr syntax
  (dni name comment attr syntax
       ; Specifying MODE_INDIRECT and MODE_AUTOINCREMENT in this
       ; Specifying MODE_INDIRECT and MODE_AUTOINCREMENT in this
       ; manner makes the autoincrementness handily available.
       ; manner makes the autoincrementness handily available.
       ; It also effectively excludes non-memory use of dni-cmt.
       ; It also effectively excludes non-memory use of dni-cmt.
       (.splice (.unsplice fmt) MODEMEMP_YES inc)
       (.splice (.unsplice fmt) MODEMEMP_YES inc)
       semantics
       semantics
       timing)
       timing)
)
)
(define-pmacro (dni-cmt-attr name comment attr syntax fmt semantics)
(define-pmacro (dni-cmt-attr name comment attr syntax fmt semantics)
  "dni with read memory-access timing"
  "dni with read memory-access timing"
  (dni-cmt-attr-tim name comment attr syntax fmt semantics
  (dni-cmt-attr-tim name comment attr syntax fmt semantics
                    (cris-mem-timing))
                    (cris-mem-timing))
)
)
(define-pmacro (dni-cmwt-attr  name comment attr syntax fmt semantics)
(define-pmacro (dni-cmwt-attr  name comment attr syntax fmt semantics)
  "dni with write memory-access timing"
  "dni with write memory-access timing"
  (dni-cmt-attr-tim name comment attr syntax fmt semantics
  (dni-cmt-attr-tim name comment attr syntax fmt semantics
                    (cris-mem-write-timing))
                    (cris-mem-write-timing))
)
)
(define-pmacro QI-size 1)
(define-pmacro QI-size 1)
(define-pmacro HI-size 2)
(define-pmacro HI-size 2)
(define-pmacro SI-size 4)
(define-pmacro SI-size 4)
(define-pmacro (cris-get-mem size regop)
(define-pmacro (cris-get-mem size regop)
  "Handle reading memory in , with source address register\
  "Handle reading memory in , with source address register\
 (read once, maybe set once) in  or prefixed"
 (read once, maybe set once) in  or prefixed"
  (sequence
  (sequence
    size
    size
    ((SI addr) (size tmp-mem) (BI postinc))
    ((SI addr) (size tmp-mem) (BI postinc))
    ; Cache the incrementness of the operand.
    ; Cache the incrementness of the operand.
    (set postinc inc)
    (set postinc inc)
    ; Get the address from somewhere.
    ; Get the address from somewhere.
    (set addr
    (set addr
         (if SI (eq prefix-set 0)
         (if SI (eq prefix-set 0)
             ; If the insn was prefixed, it's in the prefix-register.
             ; If the insn was prefixed, it's in the prefix-register.
             regop
             regop
             prefixreg))
             prefixreg))
    ; Get the memory contents.
    ; Get the memory contents.
    (set tmp-mem (mem size addr))
    (set tmp-mem (mem size addr))
    ; For non-prefixed post-increment, we increment the address by the
    ; For non-prefixed post-increment, we increment the address by the
    ; size of the memory access.
    ; size of the memory access.
    (if (ne postinc 0)
    (if (ne postinc 0)
        (sequence
        (sequence
          ()
          ()
          (if (eq prefix-set 0)
          (if (eq prefix-set 0)
              (set addr (add addr (.sym size -size))))
              (set addr (add addr (.sym size -size))))
          ; Update the source-register for post-increments.
          ; Update the source-register for post-increments.
          (set regop addr)))
          (set regop addr)))
    ; Don't forget the return-value.
    ; Don't forget the return-value.
    tmp-mem)
    tmp-mem)
)
)
(define-pmacro (cris-set-mem size regop value)
(define-pmacro (cris-set-mem size regop value)
  "Handle writing  of  to memory, with memory address register\
  "Handle writing  of  to memory, with memory address register\
 (read once, maybe set once) in  or prefixed."
 (read once, maybe set once) in  or prefixed."
  (sequence
  (sequence
    ((SI addr) (BI postinc))
    ((SI addr) (BI postinc))
    ; Cache the incrementness of the operand.
    ; Cache the incrementness of the operand.
    (set postinc inc)
    (set postinc inc)
    ; Get the address from somewhere.
    ; Get the address from somewhere.
    (set addr
    (set addr
         (if SI (eq prefix-set 0)
         (if SI (eq prefix-set 0)
             ; If the insn was prefixed, it's in the prefix-register.
             ; If the insn was prefixed, it's in the prefix-register.
             regop
             regop
             prefixreg))
             prefixreg))
    ; Set the memory contents.  Integral-write semantics apply.
    ; Set the memory contents.  Integral-write semantics apply.
    ; FIXME: currently v32 only; when proper semantics needed, fix v10.
    ; FIXME: currently v32 only; when proper semantics needed, fix v10.
    (if (andif current-mach-is-v32 (ne xbit 0))
    (if (andif current-mach-is-v32 (ne xbit 0))
        (if (eq pbit 0)
        (if (eq pbit 0)
            (sequence
            (sequence
              ()
              ()
              (set (mem size addr) value)
              (set (mem size addr) value)
              ; Write failures are signalled (by whatever entity "sends
              ; Write failures are signalled (by whatever entity "sends
              ; the signal") by setting P at time of the write above, if X
              ; the signal") by setting P at time of the write above, if X
              ; is set.  Here, we just need to copy P into C.
              ; is set.  Here, we just need to copy P into C.
              (set cbit pbit))
              (set cbit pbit))
            (set cbit 1))
            (set cbit 1))
        (set (mem size addr) value))
        (set (mem size addr) value))
    ; For non-prefixed post-increment, we increment the address by the
    ; For non-prefixed post-increment, we increment the address by the
    ; size of the memory access.  As for the integral-write, this needs to
    ; size of the memory access.  As for the integral-write, this needs to
    ; be tweaked for pre-v32: increment should have been performed if
    ; be tweaked for pre-v32: increment should have been performed if
    ; there's a fault at the memory access above.
    ; there's a fault at the memory access above.
    (if (ne postinc 0)
    (if (ne postinc 0)
        (sequence
        (sequence
          ()
          ()
          (if (eq prefix-set 0)
          (if (eq prefix-set 0)
              (set addr (add addr (.sym size -size))))
              (set addr (add addr (.sym size -size))))
          ; Update the source-register for post-increments.
          ; Update the source-register for post-increments.
          (set regop addr))))
          (set regop addr))))
)
)
(define-pmacro
(define-pmacro
  (dni-cmt-bwd-attr-tim name comment attr syntax fmt fsem timing)
  (dni-cmt-bwd-attr-tim name comment attr syntax fmt fsem timing)
  "Core generator macro for insns with .b, .w and .d variants\
  "Core generator macro for insns with .b, .w and .d variants\
 and a memory operand."
 and a memory operand."
  (begin
  (begin
    (dni-cmt-attr-tim
    (dni-cmt-attr-tim
     (.sym name .b-m)
     (.sym name .b-m)
     (.str "byte mem " comment)
     (.str "byte mem " comment)
     attr
     attr
     (.str name ".b " syntax)
     (.str name ".b " syntax)
     (.splice (.unsplice fmt) SIZE_BYTE)
     (.splice (.unsplice fmt) SIZE_BYTE)
     (fsem QI)
     (fsem QI)
     timing)
     timing)
    (dni-cmt-attr-tim
    (dni-cmt-attr-tim
     (.sym name .w-m)
     (.sym name .w-m)
     (.str "word mem " comment)
     (.str "word mem " comment)
     attr
     attr
     (.str name ".w " syntax)
     (.str name ".w " syntax)
     (.splice (.unsplice fmt) SIZE_WORD)
     (.splice (.unsplice fmt) SIZE_WORD)
     (fsem HI)
     (fsem HI)
     timing)
     timing)
    (dni-cmt-attr-tim
    (dni-cmt-attr-tim
     (.sym name .d-m)
     (.sym name .d-m)
     (.str "dword mem " comment)
     (.str "dword mem " comment)
     attr
     attr
     (.str name ".d " syntax)
     (.str name ".d " syntax)
     (.splice (.unsplice fmt) SIZE_DWORD)
     (.splice (.unsplice fmt) SIZE_DWORD)
     (fsem SI)
     (fsem SI)
     timing))
     timing))
)
)
; Further refinement macros.
; Further refinement macros.
(define-pmacro (dni-cmt-bwd-attr name comment attr syntax fmt fsem)
(define-pmacro (dni-cmt-bwd-attr name comment attr syntax fmt fsem)
  (dni-cmt-bwd-attr-tim name comment attr syntax fmt fsem
  (dni-cmt-bwd-attr-tim name comment attr syntax fmt fsem
                        (cris-mem-timing))
                        (cris-mem-timing))
)
)
(define-pmacro (dni-cmwt-bwd name comment syntax fmt fsem)
(define-pmacro (dni-cmwt-bwd name comment syntax fmt fsem)
  (dni-cmt-bwd-attr-tim name comment () syntax fmt fsem
  (dni-cmt-bwd-attr-tim name comment () syntax fmt fsem
                        (cris-mem-write-timing))
                        (cris-mem-write-timing))
)
)
(define-pmacro (dni-cmt-bwd name comment syntax fmt fsem)
(define-pmacro (dni-cmt-bwd name comment syntax fmt fsem)
  (dni-cmt-bwd-attr name comment () syntax fmt fsem)
  (dni-cmt-bwd-attr name comment () syntax fmt fsem)
)
)
(define-pmacro (dni-cmt-sbw name comment syntax fmt fsem)
(define-pmacro (dni-cmt-sbw name comment syntax fmt fsem)
  "Core generator macro for insns with .b and .w variants\
  "Core generator macro for insns with .b and .w variants\
 and a signed memory operand."
 and a signed memory operand."
  (begin
  (begin
    (dni-cmt-attr
    (dni-cmt-attr
     (.sym name .b-m) (.str "byte mem " comment)
     (.sym name .b-m) (.str "byte mem " comment)
     ()
     ()
     (.str name ".b " syntax)
     (.str name ".b " syntax)
     (.splice (.unsplice fmt) SIGNED_BYTE)
     (.splice (.unsplice fmt) SIGNED_BYTE)
     (fsem QI))
     (fsem QI))
    (dni-cmt-attr
    (dni-cmt-attr
     (.sym name .w-m) (.str "word mem " comment)
     (.sym name .w-m) (.str "word mem " comment)
     ()
     ()
     (.str name ".w " syntax)
     (.str name ".w " syntax)
     (.splice (.unsplice fmt) SIGNED_WORD)
     (.splice (.unsplice fmt) SIGNED_WORD)
     (fsem HI)))
     (fsem HI)))
)
)
(define-pmacro (dni-cmt-ubw name comment syntax fmt fsem)
(define-pmacro (dni-cmt-ubw name comment syntax fmt fsem)
  "Core generator macro for insns with .b and .w variants\
  "Core generator macro for insns with .b and .w variants\
 and an unsigned memory operand."
 and an unsigned memory operand."
  (begin
  (begin
    (dni-cmt-attr
    (dni-cmt-attr
     (.sym name .b-m) (.str "byte mem " comment)
     (.sym name .b-m) (.str "byte mem " comment)
     ()
     ()
     (.str name ".b " syntax)
     (.str name ".b " syntax)
     (.splice (.unsplice fmt) UNSIGNED_BYTE)
     (.splice (.unsplice fmt) UNSIGNED_BYTE)
     (fsem QI))
     (fsem QI))
    (dni-cmt-attr
    (dni-cmt-attr
     (.sym name .w-m) (.str "word mem " comment)
     (.sym name .w-m) (.str "word mem " comment)
     ()
     ()
     (.str name ".w " syntax)
     (.str name ".w " syntax)
     (.splice (.unsplice fmt) UNSIGNED_WORD)
     (.splice (.unsplice fmt) UNSIGNED_WORD)
     (fsem HI)))
     (fsem HI)))
)
)
; CMP.m   Rs,Rd           [ Rd | 011011mm | Rs ]
; CMP.m   Rs,Rd           [ Rd | 011011mm | Rs ]
(dni-cdt-bwd
(dni-cdt-bwd
 cmp-r "compare register to register"
 cmp-r "compare register to register"
 "$Rs,$Rd"
 "$Rs,$Rd"
 (+ Rd MODE_REGISTER R_CMP Rs)
 (+ Rd MODE_REGISTER R_CMP Rs)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (cris-arit6-int
  (cris-arit6-int
   sub BWD (.pmacro (sz regno val) (nop)) 0
   sub BWD (.pmacro (sz regno val) (nop)) 0
   Rd Rs cbit cbit))
   Rd Rs cbit cbit))
)
)
; CMP.m   [Rs],Rd         [ Rd | 101011mm | Rs ]
; CMP.m   [Rs],Rd         [ Rd | 101011mm | Rs ]
; CMP.m   [Rs+],Rd        [ Rd | 111011mm | Rs ]
; CMP.m   [Rs+],Rd        [ Rd | 111011mm | Rs ]
(dni-cmt-bwd
(dni-cmt-bwd
 cmp-m "compare memory to register"
 cmp-m "compare memory to register"
 "[${Rs}${inc}],${Rd}"
 "[${Rs}${inc}],${Rd}"
 (+ INDIR_CMP Rs Rd)
 (+ INDIR_CMP Rs Rd)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (cris-arit6-int
  (cris-arit6-int
   sub BWD (.pmacro (sz regno val) (nop)) 0
   sub BWD (.pmacro (sz regno val) (nop)) 0
   Rd (cris-get-mem BWD Rs) cbit cbit))
   Rd (cris-get-mem BWD Rs) cbit cbit))
)
)
; (CMP.m   [PC+],Rd        [ Rd | 111011mm | 1111 ])
; (CMP.m   [PC+],Rd        [ Rd | 111011mm | 1111 ])
(dni-c-QI
(dni-c-QI
 cmpcbr "cmp constant byte to register"
 cmpcbr "cmp constant byte to register"
 "cmp.b $sconst8,$Rd"
 "cmp.b $sconst8,$Rd"
 (+ Rd MODE_AUTOINCREMENT INDIR_CMP SIZE_BYTE (f-source 15) sconst8)
 (+ Rd MODE_AUTOINCREMENT INDIR_CMP SIZE_BYTE (f-source 15) sconst8)
 (cris-arit6-int
 (cris-arit6-int
  sub QI (.pmacro (sz regno val) (nop)) 0
  sub QI (.pmacro (sz regno val) (nop)) 0
  Rd (trunc QI sconst8) cbit cbit)
  Rd (trunc QI sconst8) cbit cbit)
)
)
(dni-c-HI
(dni-c-HI
 cmpcwr "cmp constant word to register"
 cmpcwr "cmp constant word to register"
 "cmp.w $sconst16,$Rd"
 "cmp.w $sconst16,$Rd"
 (+ Rd MODE_AUTOINCREMENT INDIR_CMP SIZE_WORD (f-source 15) sconst16)
 (+ Rd MODE_AUTOINCREMENT INDIR_CMP SIZE_WORD (f-source 15) sconst16)
 (cris-arit6-int
 (cris-arit6-int
  sub HI (.pmacro (sz regno val) (nop)) 0
  sub HI (.pmacro (sz regno val) (nop)) 0
  Rd (trunc HI sconst16) cbit cbit)
  Rd (trunc HI sconst16) cbit cbit)
)
)
(dni-c-SI
(dni-c-SI
 cmpcdr "cmp constant dword to register"
 cmpcdr "cmp constant dword to register"
 "cmp.d $const32,$Rd"
 "cmp.d $const32,$Rd"
 (+ Rd MODE_AUTOINCREMENT INDIR_CMP SIZE_DWORD (f-source 15) const32)
 (+ Rd MODE_AUTOINCREMENT INDIR_CMP SIZE_DWORD (f-source 15) const32)
 (cris-arit6-int
 (cris-arit6-int
  sub SI (.pmacro (sz regno val) (nop)) 0
  sub SI (.pmacro (sz regno val) (nop)) 0
  Rd const32 cbit cbit)
  Rd const32 cbit cbit)
)
)
; CMPQ    i,Rd            [ Rd | 001011 | i ]
; CMPQ    i,Rd            [ Rd | 001011 | i ]
(dni-cdt
(dni-cdt
 cmpq "cmpq i,Rd"
 cmpq "cmpq i,Rd"
 "cmpq $i,$Rd"
 "cmpq $i,$Rd"
 (+ Rd MODE_QUICK_IMMEDIATE Q_CMPQ i)
 (+ Rd MODE_QUICK_IMMEDIATE Q_CMPQ i)
 (cris-arit6-int
 (cris-arit6-int
  sub SI (.pmacro (sz regno val) (nop)) 0
  sub SI (.pmacro (sz regno val) (nop)) 0
  Rd i cbit cbit)
  Rd i cbit cbit)
)
)
; CMPS.z  [Rs],Rd         [ Rd | 1000111z | Rs ]
; CMPS.z  [Rs],Rd         [ Rd | 1000111z | Rs ]
; CMPS.z  [Rs+],Rd        [ Rd | 1100111z | Rs ]
; CMPS.z  [Rs+],Rd        [ Rd | 1100111z | Rs ]
(dni-cmt-sbw
(dni-cmt-sbw
 cmps-m "cmp sign-extended from memory to register"
 cmps-m "cmp sign-extended from memory to register"
 "[${Rs}${inc}],$Rd"
 "[${Rs}${inc}],$Rd"
 (+ Rd INDIR_CMPX Rs)
 (+ Rd INDIR_CMPX Rs)
 (.pmacro
 (.pmacro
  (BW)
  (BW)
  (cris-arit6-int
  (cris-arit6-int
   sub SI (.pmacro (sz regno val) (nop)) 0
   sub SI (.pmacro (sz regno val) (nop)) 0
   Rd ((.sym BW -ext) (cris-get-mem BW Rs)) cbit cbit))
   Rd ((.sym BW -ext) (cris-get-mem BW Rs)) cbit cbit))
)
)
; (CMPS.z  [PC+],Rd        [ Rd | 1100111z | 1111 ])
; (CMPS.z  [PC+],Rd        [ Rd | 1100111z | 1111 ])
(dni-c-QI
(dni-c-QI
 cmpscbr "cmp sign-extended constant byte to register"
 cmpscbr "cmp sign-extended constant byte to register"
 "[${Rs}${inc}],$Rd"
 "[${Rs}${inc}],$Rd"
 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX SIGNED_BYTE (f-source 15) sconst8)
 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX SIGNED_BYTE (f-source 15) sconst8)
 (cris-arit6-int
 (cris-arit6-int
  sub SI (.pmacro (sz regno val) (nop)) 0
  sub SI (.pmacro (sz regno val) (nop)) 0
  Rd (ext SI (trunc QI sconst8)) cbit cbit)
  Rd (ext SI (trunc QI sconst8)) cbit cbit)
)
)
(dni-c-HI
(dni-c-HI
 cmpscwr "cmp sign-extended constant word to register"
 cmpscwr "cmp sign-extended constant word to register"
 "[${Rs}${inc}],$Rd"
 "[${Rs}${inc}],$Rd"
 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX SIGNED_WORD (f-source 15) sconst16)
 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX SIGNED_WORD (f-source 15) sconst16)
 (cris-arit6-int
 (cris-arit6-int
  sub SI (.pmacro (sz regno val) (nop)) 0
  sub SI (.pmacro (sz regno val) (nop)) 0
  Rd (ext SI (trunc HI sconst16)) cbit cbit)
  Rd (ext SI (trunc HI sconst16)) cbit cbit)
)
)
; CMPU.z  [Rs],Rd         [ Rd | 1000110z | Rs ]
; CMPU.z  [Rs],Rd         [ Rd | 1000110z | Rs ]
; CMPU.z  [Rs+],Rd        [ Rd | 1100110z | Rs ]
; CMPU.z  [Rs+],Rd        [ Rd | 1100110z | Rs ]
(dni-cmt-ubw
(dni-cmt-ubw
 cmpu-m "cmp zero-extended from memory to register"
 cmpu-m "cmp zero-extended from memory to register"
 "[${Rs}${inc}],$Rd"
 "[${Rs}${inc}],$Rd"
 (+ Rd INDIR_CMPX Rs)
 (+ Rd INDIR_CMPX Rs)
 (.pmacro
 (.pmacro
  (BW)
  (BW)
  (cris-arit6-int
  (cris-arit6-int
   sub SI (.pmacro (sz regno val) (nop)) 0
   sub SI (.pmacro (sz regno val) (nop)) 0
   Rd ((.sym BW -zext) (cris-get-mem BW Rs)) cbit cbit))
   Rd ((.sym BW -zext) (cris-get-mem BW Rs)) cbit cbit))
)
)
; (CMPU.z  [PC+],Rd        [ Rd | 1100110z | 1111 ])
; (CMPU.z  [PC+],Rd        [ Rd | 1100110z | 1111 ])
(dni-c-QI
(dni-c-QI
 cmpucbr "cmp zero-extended constant byte to register"
 cmpucbr "cmp zero-extended constant byte to register"
 "[${Rs}${inc}],$Rd"
 "[${Rs}${inc}],$Rd"
 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX UNSIGNED_BYTE (f-source 15) uconst8)
 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX UNSIGNED_BYTE (f-source 15) uconst8)
 (cris-arit6-int
 (cris-arit6-int
  sub SI (.pmacro (sz regno val) (nop)) 0
  sub SI (.pmacro (sz regno val) (nop)) 0
  Rd (zext SI (trunc QI uconst8)) cbit cbit)
  Rd (zext SI (trunc QI uconst8)) cbit cbit)
)
)
(dni-c-HI
(dni-c-HI
 cmpucwr "cmp zero-extended constant word to register"
 cmpucwr "cmp zero-extended constant word to register"
 "[${Rs}${inc}],$Rd"
 "[${Rs}${inc}],$Rd"
 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX UNSIGNED_WORD (f-source 15) uconst16)
 (+ Rd MODE_AUTOINCREMENT INDIR_CMPX UNSIGNED_WORD (f-source 15) uconst16)
 (cris-arit6-int
 (cris-arit6-int
  sub SI (.pmacro (sz regno val) (nop)) 0
  sub SI (.pmacro (sz regno val) (nop)) 0
  Rd (zext SI (trunc HI uconst16)) cbit cbit)
  Rd (zext SI (trunc HI uconst16)) cbit cbit)
)
)
; MOVE.m  [Rs],Rd         [ Rd | 101001mm | Rs ]
; MOVE.m  [Rs],Rd         [ Rd | 101001mm | Rs ]
; MOVE.m  [Rs+],Rd        [ Rd | 111001mm | Rs ]
; MOVE.m  [Rs+],Rd        [ Rd | 111001mm | Rs ]
(dni-cmt-bwd
(dni-cmt-bwd
 move-m "move from memory to register"
 move-m "move from memory to register"
 "[${Rs}${inc}],${Rd}"
 "[${Rs}${inc}],${Rd}"
 (+ INDIR_MOVE_M_R Rs Rd)
 (+ INDIR_MOVE_M_R Rs Rd)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ((SI tmp))
    ((SI tmp))
    (set tmp (cris-get-mem BWD Rs))
    (set tmp (cris-get-mem BWD Rs))
    (set-subreg-gr
    (set-subreg-gr
     BWD
     BWD
     (if SI (andif prefix-set (not inc)) (regno Rs) (regno Rd))
     (if SI (andif prefix-set (not inc)) (regno Rs) (regno Rd))
     tmp)
     tmp)
    (setf-move BWD tmp)))
    (setf-move BWD tmp)))
)
)
; MOVS.z  [Rs],Rd         [ Rd | 1000011z | Rs ]
; MOVS.z  [Rs],Rd         [ Rd | 1000011z | Rs ]
; MOVS.z  [Rs+],Rd        [ Rd | 1100011z | Rs ]
; MOVS.z  [Rs+],Rd        [ Rd | 1100011z | Rs ]
(dni-cmt-sbw
(dni-cmt-sbw
 movs-m "movs from memory to register"
 movs-m "movs from memory to register"
 "[${Rs}${inc}],${Rd}"
 "[${Rs}${inc}],${Rd}"
 (+ INDIR_MOVX Rs Rd)
 (+ INDIR_MOVX Rs Rd)
 (.pmacro
 (.pmacro
  (BW)
  (BW)
  (sequence
  (sequence
    ((SI tmp))
    ((SI tmp))
    (set tmp (ext SI (cris-get-mem BW Rs)))
    (set tmp (ext SI (cris-get-mem BW Rs)))
    (if (andif prefix-set (not inc))
    (if (andif prefix-set (not inc))
        (set Rs tmp)
        (set Rs tmp)
        (set Rd tmp))
        (set Rd tmp))
    (setf-move SI tmp)))
    (setf-move SI tmp)))
)
)
; MOVU.z  [Rs],Rd         [ Rd | 1000010z | Rs ]
; MOVU.z  [Rs],Rd         [ Rd | 1000010z | Rs ]
; MOVU.z  [Rs+],Rd        [ Rd | 1100010z | Rs ]
; MOVU.z  [Rs+],Rd        [ Rd | 1100010z | Rs ]
(dni-cmt-ubw
(dni-cmt-ubw
 movu-m "movu from memory to register"
 movu-m "movu from memory to register"
 "[${Rs}${inc}],${Rd}"
 "[${Rs}${inc}],${Rd}"
 (+ INDIR_MOVX Rs Rd)
 (+ INDIR_MOVX Rs Rd)
 (.pmacro
 (.pmacro
  (BW)
  (BW)
  (sequence
  (sequence
    ((SI tmp))
    ((SI tmp))
    (set tmp (zext SI (cris-get-mem BW Rs)))
    (set tmp (zext SI (cris-get-mem BW Rs)))
    (if (andif prefix-set (not inc))
    (if (andif prefix-set (not inc))
        (set Rs tmp)
        (set Rs tmp)
        (set Rd tmp))
        (set Rd tmp))
    (setf-move SI tmp)))
    (setf-move SI tmp)))
)
)
; MOVE    Rs,Pd           [ Pd | 01100011 | Rs ]
; MOVE    Rs,Pd           [ Pd | 01100011 | Rs ]
(.splice
(.splice
 begin
 begin
 (.unsplice
 (.unsplice
  (.map
  (.map
   (.pmacro
   (.pmacro
    (VER)
    (VER)
    (dni
    (dni
     (.sym move-r-spr VER)
     (.sym move-r-spr VER)
     "Move from general register to special register"
     "Move from general register to special register"
     ((MACH (.sym cris VER)))
     ((MACH (.sym cris VER)))
     "move ${Rs},${Pd}"
     "move ${Rs},${Pd}"
     (+ RFIX_MOVE_R_S MODE_REGISTER SIZE_FIXED Rs Pd)
     (+ RFIX_MOVE_R_S MODE_REGISTER SIZE_FIXED Rs Pd)
     (sequence
     (sequence
       ((SI tmp) (SI rno))
       ((SI tmp) (SI rno))
       (set tmp Rs)
       (set tmp Rs)
       (set rno (regno Pd))
       (set rno (regno Pd))
       (cond
       (cond
        ; See reg-sr setter for most of the special-register semantics.
        ; See reg-sr setter for most of the special-register semantics.
        ; The sanity check for known read-only registers is for program
        ; The sanity check for known read-only registers is for program
        ; debug help; the real insn would be harmless and have no effect.
        ; debug help; the real insn would be harmless and have no effect.
        ; CGEN-FIXME: regno of symbolic h-sr names doesn't work here.
        ; CGEN-FIXME: regno of symbolic h-sr names doesn't work here.
        ((orif (orif (eq rno 0) (eq rno 1)) (orif (eq rno 4) (eq rno 8)))
        ((orif (orif (eq rno 0) (eq rno 1)) (orif (eq rno 4) (eq rno 8)))
         (error "move-r-spr: trying to set a read-only special register"))
         (error "move-r-spr: trying to set a read-only special register"))
        (else (set Pd tmp)))
        (else (set Pd tmp)))
       (reset-x-p))
       (reset-x-p))
     (cris-reg-sr-timing)))
     (cris-reg-sr-timing)))
   (cris-cpu-models)))
   (cris-cpu-models)))
)
)
(define-pmacro (dni-cdt-ver-attr name comment fattr syntax fmt fsem)
(define-pmacro (dni-cdt-ver-attr name comment fattr syntax fmt fsem)
  "Generator for each MACH, using default timing."
  "Generator for each MACH, using default timing."
  (.splice
  (.splice
   begin
   begin
   (.unsplice
   (.unsplice
    (.map
    (.map
     (.pmacro (v) (dni-cdt-attr name comment (fattr v) syntax fmt (fsem v)))
     (.pmacro (v) (dni-cdt-attr name comment (fattr v) syntax fmt (fsem v)))
     (cris-cpu-models))))
     (cris-cpu-models))))
)
)
; MOVE    Ps,Rd           [ Ps | 01100111 | Rd ]
; MOVE    Ps,Rd           [ Ps | 01100111 | Rd ]
; Note that in the insn format, the Rd operand is in the Rs field (the
; Note that in the insn format, the Rd operand is in the Rs field (the
; Rd field by the definition used everywhere else is the Ps position in
; Rd field by the definition used everywhere else is the Ps position in
; this insn).
; this insn).
; It gets a little weird here because we can't get this insn into a
; It gets a little weird here because we can't get this insn into a
; define-pmacro unless we make named pmacros for e.g. a separate attr
; define-pmacro unless we make named pmacros for e.g. a separate attr
; function and a semantics function: a .pmacro can't refer to the
; function and a semantics function: a .pmacro can't refer to the
; parameters of the outer define-pmacro.  (The manual refers to this as
; parameters of the outer define-pmacro.  (The manual refers to this as
; not implementing "lexical scoping").
; not implementing "lexical scoping").
(.splice
(.splice
 begin
 begin
 (.unsplice
 (.unsplice
  (.map
  (.map
   (.pmacro
   (.pmacro
    (VER)
    (VER)
    (dni-cdt-attr
    (dni-cdt-attr
     (.sym move-spr-r VER)
     (.sym move-spr-r VER)
     "Move from special register to general register"
     "Move from special register to general register"
     ((MACH (.sym cris VER)))
     ((MACH (.sym cris VER)))
     "move ${Ps},${Rd-sfield}"
     "move ${Ps},${Rd-sfield}"
     (+ Ps RFIX_MOVE_S_R MODE_REGISTER SIZE_FIXED Rd-sfield)
     (+ Ps RFIX_MOVE_S_R MODE_REGISTER SIZE_FIXED Rd-sfield)
     (sequence
     (sequence
       ((SI grno) (SI prno) (SI newval))
       ((SI grno) (SI prno) (SI newval))
       (set prno (regno Ps))
       (set prno (regno Ps))
       ; CGEN-FIXME: Can't use the following and then "grno" below because
       ; CGEN-FIXME: Can't use the following and then "grno" below because
       ; CGEN will emit a "tmp_grno" *also* in decodev32.c:crisv32f_decode
       ; CGEN will emit a "tmp_grno" *also* in decodev32.c:crisv32f_decode
       ; (set grno (regno Rd-sfield))
       ; (set grno (regno Rd-sfield))
       (set newval Ps)
       (set newval Ps)
       (.splice
       (.splice
        cond
        cond
        (.unsplice
        (.unsplice
         (.map
         (.map
          (.pmacro
          (.pmacro
           (r)
           (r)
           ((eq prno (.cadr2 r))
           ((eq prno (.cadr2 r))
            (set-subreg-gr (.car2 r) (regno Rd-sfield) newval)))
            (set-subreg-gr (.car2 r) (regno Rd-sfield) newval)))
          ((.sym cris-implemented-readable-specregs- VER))))
          ((.sym cris-implemented-readable-specregs- VER))))
        (else (error "move-spr-r from unimplemented register")))
        (else (error "move-spr-r from unimplemented register")))
       (reset-x-p))))
       (reset-x-p))))
   (cris-cpu-models)))
   (cris-cpu-models)))
)
)
; MOVE    Ps,PC           [ Ps | 01100111 | 1111 ]
; MOVE    Ps,PC           [ Ps | 01100111 | 1111 ]
; The move-special-register-to-pc insns are return-type instructions and
; The move-special-register-to-pc insns are return-type instructions and
; have to be special-cased to get the delay-slot and avoid being indicated
; have to be special-cased to get the delay-slot and avoid being indicated
; as invalid.
; as invalid.
(dni-cdt-attr
(dni-cdt-attr
 ret-type
 ret-type
 "ret-type"
 "ret-type"
 (MACH-PC)
 (MACH-PC)
 "ret/reti/retb"
 "ret/reti/retb"
 (+ Ps MODE_REGISTER RFIX_MOVE_S_R SIZE_FIXED (f-source 15))
 (+ Ps MODE_REGISTER RFIX_MOVE_S_R SIZE_FIXED (f-source 15))
 (sequence
 (sequence
   ((SI retaddr))
   ((SI retaddr))
   (set retaddr Ps)
   (set retaddr Ps)
   (reset-x-p)
   (reset-x-p)
   (delay 1 (set pc retaddr)))
   (delay 1 (set pc retaddr)))
)
)
; MOVE    [Rs],Pd         [ Pd | 10100011 | Rs ]
; MOVE    [Rs],Pd         [ Pd | 10100011 | Rs ]
; MOVE    [Rs+],Pd        [ Pd | 11100011 | Rs ]
; MOVE    [Rs+],Pd        [ Pd | 11100011 | Rs ]
; We make variants that loads constants or memory for each MACH version,
; We make variants that loads constants or memory for each MACH version,
; since each consider some subset of the "special registers" to have
; since each consider some subset of the "special registers" to have
; different sizes.  FIXME: Should be able to simplify this.
; different sizes.  FIXME: Should be able to simplify this.
(.splice
(.splice
 begin
 begin
 (.unsplice
 (.unsplice
  (.map
  (.map
   (.pmacro
   (.pmacro
    (VER)
    (VER)
    (dni
    (dni
     (.sym move-m-spr VER)
     (.sym move-m-spr VER)
     "Move from memory to special register"
     "Move from memory to special register"
     ((MACH (.sym cris VER)))
     ((MACH (.sym cris VER)))
     "move [${Rs}${inc}],${Pd}"
     "move [${Rs}${inc}],${Pd}"
     (+ Pd INFIX_MOVE_M_S MODEMEMP_YES inc SIZE_FIXED Rs)
     (+ Pd INFIX_MOVE_M_S MODEMEMP_YES inc SIZE_FIXED Rs)
     (sequence
     (sequence
       ((SI rno) (SI newval))
       ((SI rno) (SI newval))
       (set rno (regno Pd))
       (set rno (regno Pd))
       (.splice
       (.splice
        cond
        cond
        ; No sanity check for constant special register here, since the
        ; No sanity check for constant special register here, since the
        ; memory read side-effect or post-increment may be the goal, or
        ; memory read side-effect or post-increment may be the goal, or
        ; for pre-v32 a prefix assignment side-effect.
        ; for pre-v32 a prefix assignment side-effect.
        (.unsplice
        (.unsplice
         (.map
         (.map
          (.pmacro
          (.pmacro
           (r)
           (r)
           ((eq rno (.cadr2 r))
           ((eq rno (.cadr2 r))
            (set newval ((.sym (.car2 r) -ext) (cris-get-mem (.car2 r) Rs)))))
            (set newval ((.sym (.car2 r) -ext) (cris-get-mem (.car2 r) Rs)))))
          ((.sym cris-implemented-writable-specregs- VER))))
          ((.sym cris-implemented-writable-specregs- VER))))
        (else (error "Trying to set unimplemented special register")))
        (else (error "Trying to set unimplemented special register")))
       (set Pd newval)
       (set Pd newval)
       (reset-x-p))
       (reset-x-p))
     (cris-mem-sr-timing)))
     (cris-mem-sr-timing)))
   (cris-cpu-models)))
   (cris-cpu-models)))
)
)
(define-pmacro QI-operand sconst8)
(define-pmacro QI-operand sconst8)
(define-pmacro HI-operand sconst16)
(define-pmacro HI-operand sconst16)
(define-pmacro SI-operand const32)
(define-pmacro SI-operand const32)
(define-pmacro
(define-pmacro
  (cris-move-c-spr VER VERFN)
  (cris-move-c-spr VER VERFN)
  "Generator for loading constant into special register"
  "Generator for loading constant into special register"
  (.splice
  (.splice
   begin
   begin
   (.unsplice
   (.unsplice
    (.map
    (.map
     (.pmacro
     (.pmacro
      (srdef v)
      (srdef v)
      (dni
      (dni
       (.sym move-c-spr v -p (.cadr2 srdef))
       (.sym move-c-spr v -p (.cadr2 srdef))
       (.str "Move constant to special register p" (.cadr2 srdef))
       (.str "Move constant to special register p" (.cadr2 srdef))
       ((MACH (.sym cris v)))
       ((MACH (.sym cris v)))
       (.str "move ${" (.sym (.car2 srdef) -operand) "},${Pd}")
       (.str "move ${" (.sym (.car2 srdef) -operand) "},${Pd}")
       ; We use Pd in semantics without naming it in the format (which
       ; We use Pd in semantics without naming it in the format (which
       ; would CGEN-FIXME: cause a CGEN error for some reason, likely
       ; would CGEN-FIXME: cause a CGEN error for some reason, likely
       ; related to specifying an insn field multiple times).  This
       ; related to specifying an insn field multiple times).  This
       ; currently works and is guarded with test-cases (specifically
       ; currently works and is guarded with test-cases (specifically
       ; wrt. the timing model) but may need to be tweaked in the future.
       ; wrt. the timing model) but may need to be tweaked in the future.
       ; Note that using instead (ifield f-dest) causes incorrect timing
       ; Note that using instead (ifield f-dest) causes incorrect timing
       ; model to be generated; the timing model requires that Pd is set.
       ; model to be generated; the timing model requires that Pd is set.
       (+ (f-dest (.cadr2 srdef)) MODE_AUTOINCREMENT INFIX_MOVE_M_S SIZE_FIXED
       (+ (f-dest (.cadr2 srdef)) MODE_AUTOINCREMENT INFIX_MOVE_M_S SIZE_FIXED
          (f-source 15) (.sym (.car2 srdef) -operand))
          (f-source 15) (.sym (.car2 srdef) -operand))
       (sequence
       (sequence
         ()
         ()
         (set Pd (.sym (.car2 srdef) -operand)) ; (reg h-sr (.cadr2 srdef))
         (set Pd (.sym (.car2 srdef) -operand)) ; (reg h-sr (.cadr2 srdef))
         (reset-x-p))
         (reset-x-p))
       ((.sym cris-timing-const-sr- (.car2 srdef)))))
       ((.sym cris-timing-const-sr- (.car2 srdef)))))
     ((.sym cris-implemented-specregs-const- VER))
     ((.sym cris-implemented-specregs-const- VER))
     (.map VERFN ((.sym cris-implemented-specregs-const- VER))))))
     (.map VERFN ((.sym cris-implemented-specregs-const- VER))))))
)
)
; CGEN-FIXME:
; CGEN-FIXME:
; Unfortunately we can't iterate over the list of models due to the
; Unfortunately we can't iterate over the list of models due to the
; problem with referring to the parameters of a surrounding pmacro from
; problem with referring to the parameters of a surrounding pmacro from
; within an enclosed .pmacro (perhaps related to "lexical scoping").
; within an enclosed .pmacro (perhaps related to "lexical scoping").
; We get e.g. 'insn already defined:: (move-c-sprvn-p0)' with this:
; We get e.g. 'insn already defined:: (move-c-sprvn-p0)' with this:
;(.splice
;(.splice
; begin (.unsplice (.map (.pmacro (vn) (cris-move-c-spr vn (.pmacro (x) vn)))
; begin (.unsplice (.map (.pmacro (vn) (cris-move-c-spr vn (.pmacro (x) vn)))
;                       (cris-cpu-models)))
;                       (cris-cpu-models)))
;)
;)
(cris-move-c-spr v0 (.pmacro (x) v0))
(cris-move-c-spr v0 (.pmacro (x) v0))
(cris-move-c-spr v3 (.pmacro (x) v3))
(cris-move-c-spr v3 (.pmacro (x) v3))
(cris-move-c-spr v8 (.pmacro (x) v8))
(cris-move-c-spr v8 (.pmacro (x) v8))
(cris-move-c-spr v10 (.pmacro (x) v10))
(cris-move-c-spr v10 (.pmacro (x) v10))
(cris-move-c-spr v32 (.pmacro (x) v32))
(cris-move-c-spr v32 (.pmacro (x) v32))
; MOVE    Ps,[Rd]         [ Ps | 10100111 | Rd ]
; MOVE    Ps,[Rd]         [ Ps | 10100111 | Rd ]
; MOVE    Ps,[Rd+]        [ Ps | 11100111 | Rd ]
; MOVE    Ps,[Rd+]        [ Ps | 11100111 | Rd ]
(.splice
(.splice
 begin
 begin
 (.unsplice
 (.unsplice
  (.map
  (.map
   (.pmacro
   (.pmacro
    (VER)
    (VER)
    (dni-cmwt-attr
    (dni-cmwt-attr
     (.sym move-spr-m VER)
     (.sym move-spr-m VER)
     "Move from special register to memory"
     "Move from special register to memory"
     ((MACH (.sym cris VER)))
     ((MACH (.sym cris VER)))
     "move ${Ps},[${Rd-sfield}${inc}]"
     "move ${Ps},[${Rd-sfield}${inc}]"
     (+ INFIX_MOVE_S_M SIZE_FIXED Rd-sfield Ps)
     (+ INFIX_MOVE_S_M SIZE_FIXED Rd-sfield Ps)
     (sequence
     (sequence
       ((SI rno))
       ((SI rno))
       (set rno (regno Ps))
       (set rno (regno Ps))
       (.splice
       (.splice
        cond
        cond
        (.unsplice
        (.unsplice
         (.map
         (.map
          (.pmacro
          (.pmacro
           (r)
           (r)
           ((eq rno (.cadr2 r))
           ((eq rno (.cadr2 r))
            (cris-set-mem (.car2 r) Rd-sfield Ps)))
            (cris-set-mem (.car2 r) Rd-sfield Ps)))
          ((.sym cris-implemented-readable-specregs- VER))))
          ((.sym cris-implemented-readable-specregs- VER))))
        (else (error "write from unimplemented special register")))
        (else (error "write from unimplemented special register")))
       (reset-x-p))))
       (reset-x-p))))
   (cris-cpu-models)))
   (cris-cpu-models)))
)
)
; SBFS [Rs(+)]
; SBFS [Rs(+)]
;  Instruction format:     |0 0 1 1 1 m 1 1 0 1 1 1| Dest. |
;  Instruction format:     |0 0 1 1 1 m 1 1 0 1 1 1| Dest. |
(dni-cdt-attr
(dni-cdt-attr
 sbfs
 sbfs
 "sbfs"
 "sbfs"
 ((MACH crisv10))
 ((MACH crisv10))
 "sbfs [${Rd-sfield}${inc}]"
 "sbfs [${Rd-sfield}${inc}]"
 (+ (f-dest 3) INFIX_SBFS SIZE_FIXED MODEMEMP_YES inc Rd-sfield)
 (+ (f-dest 3) INFIX_SBFS SIZE_FIXED MODEMEMP_YES inc Rd-sfield)
 (error "SBFS isn't implemented")
 (error "SBFS isn't implemented")
)
)
;  MOVE    Ss,Rd            [ Ss | 11110111 | Rd ]
;  MOVE    Ss,Rd            [ Ss | 11110111 | Rd ]
(dni-cdt-attr
(dni-cdt-attr
 move-ss-r
 move-ss-r
 "move from support register to general register"
 "move from support register to general register"
 (MACH-V32)
 (MACH-V32)
 "move ${Ss},${Rd-sfield}"
 "move ${Ss},${Rd-sfield}"
 (+ Ss INFIX_MOVE_SS SIZE_FIXED (f-mode 3) Rd-sfield)
 (+ Ss INFIX_MOVE_SS SIZE_FIXED (f-mode 3) Rd-sfield)
 (sequence
 (sequence
   ()
   ()
   (set Rd-sfield Ss)
   (set Rd-sfield Ss)
   (reset-x-p))
   (reset-x-p))
)
)
; MOVE    Rs,Sd            [ Sd | 10110111 | Rs ]
; MOVE    Rs,Sd            [ Sd | 10110111 | Rs ]
(dni-cdt-attr
(dni-cdt-attr
 move-r-ss
 move-r-ss
 "move from general register to support register"
 "move from general register to support register"
 (MACH-V32)
 (MACH-V32)
 "move ${Rs},${Sd}"
 "move ${Rs},${Sd}"
 (+ Sd INFIX_MOVE_SS SIZE_FIXED (f-mode 2) Rs)
 (+ Sd INFIX_MOVE_SS SIZE_FIXED (f-mode 2) Rs)
 (sequence
 (sequence
   ()
   ()
   (set Sd Rs)
   (set Sd Rs)
   (reset-x-p))
   (reset-x-p))
)
)
; MOVEM   Rs,[Rd]         [ Rs | 10111111 | Rd ]
; MOVEM   Rs,[Rd]         [ Rs | 10111111 | Rd ]
; MOVEM   Rs,[Rd+]        [ Rs | 11111111 | Rd ]
; MOVEM   Rs,[Rd+]        [ Rs | 11111111 | Rd ]
(define-pmacro (movem-to-mem-step regn)
(define-pmacro (movem-to-mem-step regn)
  ; Without the SI attribute, UINT is generated, which isn't supported by
  ; Without the SI attribute, UINT is generated, which isn't supported by
  ; the sim framework.
  ; the sim framework.
  (if (ge SI (regno Rs-dfield) regn)
  (if (ge SI (regno Rs-dfield) regn)
      (sequence
      (sequence
        ((SI tmp))
        ((SI tmp))
        (set tmp (reg h-gr regn))
        (set tmp (reg h-gr regn))
        (set (mem SI addr) tmp)
        (set (mem SI addr) tmp)
        (set addr (add addr 4))))
        (set addr (add addr 4))))
)
)
(dni
(dni
 movem-r-m
 movem-r-m
 "movem to memory"
 "movem to memory"
 (MACH-PRE-V32)
 (MACH-PRE-V32)
 "movem ${Rs-dfield},[${Rd-sfield}${inc}]"
 "movem ${Rs-dfield},[${Rd-sfield}${inc}]"
 (+ INFIX_MOVEM_R_M MODEMEMP_YES inc SIZE_FIXED Rs-dfield Rd-sfield)
 (+ INFIX_MOVEM_R_M MODEMEMP_YES inc SIZE_FIXED Rs-dfield Rd-sfield)
 (sequence
 (sequence
   ((SI addr) (BI postinc))
   ((SI addr) (BI postinc))
   ; FIXME: A copy of what's in cris-get-mem.
   ; FIXME: A copy of what's in cris-get-mem.
   ; Cache the incrementness of the operand.
   ; Cache the incrementness of the operand.
   (set postinc inc)
   (set postinc inc)
   ; CGEN-FIXME: Kludge to work around a CGEN bug: it doesn't see that
   ; CGEN-FIXME: Kludge to work around a CGEN bug: it doesn't see that
   ; Rs-dfield is used as an input, causing the timing model to be wrong.
   ; Rs-dfield is used as an input, causing the timing model to be wrong.
   (sequence ((SI dummy)) (set dummy Rs-dfield))
   (sequence ((SI dummy)) (set dummy Rs-dfield))
   ; Get the address from somewhere.  If the insn was prefixed, it's in
   ; Get the address from somewhere.  If the insn was prefixed, it's in
   ; the prefix-register.
   ; the prefix-register.
   (set addr
   (set addr
        (if SI (eq prefix-set 0)
        (if SI (eq prefix-set 0)
            Rd-sfield
            Rd-sfield
            prefixreg))
            prefixreg))
   (.splice
   (.splice
    sequence ()
    sequence ()
    (.unsplice (.map movem-to-mem-step (.iota 16 15 -1))))
    (.unsplice (.map movem-to-mem-step (.iota 16 15 -1))))
   ; Update the source-register for post-increments.
   ; Update the source-register for post-increments.
   (if (ne postinc 0)
   (if (ne postinc 0)
       (set Rd-sfield
       (set Rd-sfield
            (if SI (eq prefix-set 0) addr prefixreg)))
            (if SI (eq prefix-set 0) addr prefixreg)))
   (reset-x-p))
   (reset-x-p))
   (simplecris-movem-timing)
   (simplecris-movem-timing)
)
)
(dni
(dni
 movem-r-m-v32
 movem-r-m-v32
 "movem to memory"
 "movem to memory"
 (MACH-V32)
 (MACH-V32)
 "movem ${Rs-dfield},[${Rd-sfield}${inc}]"
 "movem ${Rs-dfield},[${Rd-sfield}${inc}]"
 (+ INFIX_MOVEM_R_M MODEMEMP_YES inc SIZE_FIXED Rs-dfield Rd-sfield)
 (+ INFIX_MOVEM_R_M MODEMEMP_YES inc SIZE_FIXED Rs-dfield Rd-sfield)
 (sequence
 (sequence
   ((SI addr) (BI postinc))
   ((SI addr) (BI postinc))
   ; FIXME: Mostly a copy of what's in cris-get-mem.
   ; FIXME: Mostly a copy of what's in cris-get-mem.
   ; Cache the incrementness of the operand.
   ; Cache the incrementness of the operand.
   (set postinc inc)
   (set postinc inc)
   ; CGEN-FIXME: See movem-r-m.
   ; CGEN-FIXME: See movem-r-m.
   (sequence ((SI dummy)) (set dummy Rs-dfield))
   (sequence ((SI dummy)) (set dummy Rs-dfield))
   (set addr Rd-sfield)
   (set addr Rd-sfield)
   (.splice
   (.splice
    sequence ()
    sequence ()
    (.unsplice (.map movem-to-mem-step (.iota 16))))
    (.unsplice (.map movem-to-mem-step (.iota 16))))
   ; Update the source-register for post-increments.
   ; Update the source-register for post-increments.
   (if (ne postinc 0)
   (if (ne postinc 0)
       (set Rd-sfield addr))
       (set Rd-sfield addr))
   (reset-x-p))
   (reset-x-p))
 ; Unit u-mem must be specified before the u-movem-* for memory address
 ; Unit u-mem must be specified before the u-movem-* for memory address
 ; register stall count to be right.
 ; register stall count to be right.
 ((crisv32 (unit u-mem) (unit u-movem-rtom) (unit u-exec-movem)
 ((crisv32 (unit u-mem) (unit u-movem-rtom) (unit u-exec-movem)
           (unit u-mem-w)))
           (unit u-mem-w)))
)
)
; MOVEM   [Rs],Rd         [ Rd | 10111011 | Rs ]
; MOVEM   [Rs],Rd         [ Rd | 10111011 | Rs ]
; MOVEM   [Rs+],Rd        [ Rd | 11111011 | Rs ]
; MOVEM   [Rs+],Rd        [ Rd | 11111011 | Rs ]
(define-pmacro
(define-pmacro
  (movem-to-reg-step regn)
  (movem-to-reg-step regn)
  ; Without the SI attribute, UINT is generated, which isn't supported by
  ; Without the SI attribute, UINT is generated, which isn't supported by
  ; the sim framework.
  ; the sim framework.
  (if (ge SI (regno Rd) regn)
  (if (ge SI (regno Rd) regn)
      (sequence
      (sequence
        ((SI tmp))
        ((SI tmp))
        (set tmp (mem SI addr))
        (set tmp (mem SI addr))
        (set (reg h-gr regn) tmp)
        (set (reg h-gr regn) tmp)
        (set addr (add addr 4))))
        (set addr (add addr 4))))
)
)
(dni
(dni
 movem-m-r
 movem-m-r
 "movem to register"
 "movem to register"
 (MACH-PRE-V32)
 (MACH-PRE-V32)
 "movem [${Rs}${inc}],${Rd}"
 "movem [${Rs}${inc}],${Rd}"
 (+ Rd INFIX_MOVEM_M_R MODEMEMP_YES inc SIZE_FIXED Rs)
 (+ Rd INFIX_MOVEM_M_R MODEMEMP_YES inc SIZE_FIXED Rs)
 (sequence
 (sequence
   ((SI addr) (BI postinc))
   ((SI addr) (BI postinc))
   ; FIXME: Mostly a copy of what's in cris-get-mem.
   ; FIXME: Mostly a copy of what's in cris-get-mem.
   ; Cache the incrementness of the operand.
   ; Cache the incrementness of the operand.
   (set postinc inc)
   (set postinc inc)
   ; Get the address from somewhere.  If the insn was prefixed, it's in
   ; Get the address from somewhere.  If the insn was prefixed, it's in
   ; the prefix-register.
   ; the prefix-register.
   (set addr
   (set addr
        (if SI (eq prefix-set 0)
        (if SI (eq prefix-set 0)
            Rs
            Rs
            prefixreg))
            prefixreg))
   ; CGEN-FIXME: See movem-r-m.
   ; CGEN-FIXME: See movem-r-m.
   (sequence ((SI dummy)) (set dummy Rd))
   (sequence ((SI dummy)) (set dummy Rd))
   (.splice
   (.splice
    sequence ()
    sequence ()
    ; The first movem step is left out because it can't happen; it's for
    ; The first movem step is left out because it can't happen; it's for
    ; PC destination.  See the pattern below.
    ; PC destination.  See the pattern below.
    (.unsplice (.map movem-to-reg-step (.iota 15 14 -1))))
    (.unsplice (.map movem-to-reg-step (.iota 15 14 -1))))
   ; Update the source-register for post-increments.
   ; Update the source-register for post-increments.
   ; FIXME: No postinc-prefixed for v0 IIRC.
   ; FIXME: No postinc-prefixed for v0 IIRC.
   (if (ne postinc 0)
   (if (ne postinc 0)
       (set Rs (if SI (eq prefix-set 0) addr prefixreg)))
       (set Rs (if SI (eq prefix-set 0) addr prefixreg)))
   (reset-x-p))
   (reset-x-p))
   (simplecris-movem-timing)
   (simplecris-movem-timing)
)
)
; (MOVEM   [Rs],PC         [ 1111 | 10111011 | Rs ])
; (MOVEM   [Rs],PC         [ 1111 | 10111011 | Rs ])
; (MOVEM   [Rs+],PC        [ 1111 | 11111011 | Rs ])
; (MOVEM   [Rs+],PC        [ 1111 | 11111011 | Rs ])
; We have to special-case it for PC destination; used in longjump.
; We have to special-case it for PC destination; used in longjump.
; We shouldn't *have* to special-case it; the main reason is (FIXME:)
; We shouldn't *have* to special-case it; the main reason is (FIXME:)
; misgeneration of the simulator when the PC case is folded into the
; misgeneration of the simulator when the PC case is folded into the
; generic PRE-V32 movem; possibly related to then being a COND-CTI rather
; generic PRE-V32 movem; possibly related to then being a COND-CTI rather
; than an UNCOND-CTI.
; than an UNCOND-CTI.
(dni-cmt-attr
(dni-cmt-attr
 movem-m-pc
 movem-m-pc
 "movem to register, ending with PC"
 "movem to register, ending with PC"
 (MACH-PRE-V32)
 (MACH-PRE-V32)
 "movem [${Rs}${inc}],${Rd}"
 "movem [${Rs}${inc}],${Rd}"
 (+ (f-dest 15) INFIX_MOVEM_M_R SIZE_FIXED Rs)
 (+ (f-dest 15) INFIX_MOVEM_M_R SIZE_FIXED Rs)
 (sequence
 (sequence
   ((SI addr) (BI postinc))
   ((SI addr) (BI postinc))
   ; FIXME: Mostly a copy of what's in cris-get-mem.
   ; FIXME: Mostly a copy of what's in cris-get-mem.
   ; Cache the incrementness of the operand.
   ; Cache the incrementness of the operand.
   (set postinc inc)
   (set postinc inc)
   ; Get the address from somewhere.  If the insn was prefixed, it's in
   ; Get the address from somewhere.  If the insn was prefixed, it's in
   ; the prefix-register.
   ; the prefix-register.
   (set addr
   (set addr
        (if SI (eq prefix-set 0)
        (if SI (eq prefix-set 0)
            Rs
            Rs
            prefixreg))
            prefixreg))
   ; FIXME: Add kludge here too *and* a test-case.
   ; FIXME: Add kludge here too *and* a test-case.
   (.splice
   (.splice
    sequence ()
    sequence ()
    ; The first movem step is for PC destination, used in longjmp.
    ; The first movem step is for PC destination, used in longjmp.
    (set pc (mem SI addr))
    (set pc (mem SI addr))
    (set addr (add addr 4))
    (set addr (add addr 4))
    (.unsplice
    (.unsplice
     (.map
     (.map
      (.pmacro
      (.pmacro
       (regn)
       (regn)
       (sequence
       (sequence
         ((SI tmp))
         ((SI tmp))
         (set tmp (mem SI addr))
         (set tmp (mem SI addr))
         (set (reg h-gr regn) tmp)
         (set (reg h-gr regn) tmp)
         (set addr (add addr 4))))
         (set addr (add addr 4))))
      (.iota 15 14 -1))))
      (.iota 15 14 -1))))
   ; Update the source-register for post-increments.
   ; Update the source-register for post-increments.
   ; FIXME: No postinc-prefixed for v0.
   ; FIXME: No postinc-prefixed for v0.
   (if (ne postinc 0)
   (if (ne postinc 0)
       (set Rs (if SI (eq prefix-set 0) addr prefixreg)))
       (set Rs (if SI (eq prefix-set 0) addr prefixreg)))
   (reset-x-p))
   (reset-x-p))
)
)
(dni
(dni
 movem-m-r-v32
 movem-m-r-v32
 "movem to register"
 "movem to register"
 (MACH-V32)
 (MACH-V32)
 "movem [${Rs}${inc}],${Rd}"
 "movem [${Rs}${inc}],${Rd}"
 (+ INFIX_MOVEM_M_R MODEMEMP_YES inc SIZE_FIXED Rs Rd)
 (+ INFIX_MOVEM_M_R MODEMEMP_YES inc SIZE_FIXED Rs Rd)
 (sequence
 (sequence
   ((SI addr) (BI postinc))
   ((SI addr) (BI postinc))
   ; FIXME: A copy of what's in cris-get-mem
   ; FIXME: A copy of what's in cris-get-mem
   ; Cache the incrementness of the operand.
   ; Cache the incrementness of the operand.
   (set postinc inc)
   (set postinc inc)
   ; Get the address from somewhere.
   ; Get the address from somewhere.
   (set addr Rs)
   (set addr Rs)
   ; CGEN-FIXME: See movem-r-m.
   ; CGEN-FIXME: See movem-r-m.
   (sequence ((SI dummy)) (set dummy Rd))
   (sequence ((SI dummy)) (set dummy Rd))
   (.splice
   (.splice
    sequence ()
    sequence ()
    (.unsplice (.map movem-to-reg-step (.iota 16))))
    (.unsplice (.map movem-to-reg-step (.iota 16))))
   ; Update the source-register for post-increments.
   ; Update the source-register for post-increments.
   ; FIXME: No postinc-prefixed for v0 IIRC.
   ; FIXME: No postinc-prefixed for v0 IIRC.
   (if (ne postinc 0)
   (if (ne postinc 0)
       (set Rs addr))
       (set Rs addr))
   (reset-x-p))
   (reset-x-p))
 ; u-mem must be specified before the u-movem-* for memory source
 ; u-mem must be specified before the u-movem-* for memory source
 ; register stall count to be right.
 ; register stall count to be right.
 ((crisv32 (unit u-mem) (unit u-mem-r) (unit u-movem-mtor)
 ((crisv32 (unit u-mem) (unit u-mem-r) (unit u-movem-mtor)
           (unit u-exec-movem)))
           (unit u-exec-movem)))
)
)
; ADD.m   Rs,Rd           [ Rd | 011000mm | Rs ]
; ADD.m   Rs,Rd           [ Rd | 011000mm | Rs ]
(dni-cdt-bwd
(dni-cdt-bwd
 add "add from register to register"
 add "add from register to register"
 "$Rs,$Rd"
 "$Rs,$Rd"
 (+ Rd MODE_REGISTER R_ADD Rs)
 (+ Rd MODE_REGISTER R_ADD Rs)
 (.pmacro (BWD) (cris-arit add BWD Rd Rs))
 (.pmacro (BWD) (cris-arit add BWD Rd Rs))
)
)
; ADD.m   [Rs],Rd         [ Rd | 101000mm | Rs ]
; ADD.m   [Rs],Rd         [ Rd | 101000mm | Rs ]
; ADD.m   [Rs+],Rd        [ Rd | 111000mm | Rs ]
; ADD.m   [Rs+],Rd        [ Rd | 111000mm | Rs ]
(dni-cmt-bwd
(dni-cmt-bwd
 add-m "add from memory to register"
 add-m "add from memory to register"
 "[${Rs}${inc}],${Rd}"
 "[${Rs}${inc}],${Rd}"
 (+ INDIR_ADD Rs Rd)
 (+ INDIR_ADD Rs Rd)
 (.pmacro (BWD) (cris-arit-3op add BWD Rd (cris-get-mem BWD Rs) Rs))
 (.pmacro (BWD) (cris-arit-3op add BWD Rd (cris-get-mem BWD Rs) Rs))
)
)
; (ADD.m   [PC+],Rd        [ Rd | 111000mm | 1111 ])
; (ADD.m   [PC+],Rd        [ Rd | 111000mm | 1111 ])
(dni-c-QI
(dni-c-QI
 addcbr "add constant byte to register"
 addcbr "add constant byte to register"
 "add.b ${sconst8}],${Rd}"
 "add.b ${sconst8}],${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_ADD SIZE_BYTE (f-source 15) sconst8)
 (+ Rd MODE_AUTOINCREMENT INDIR_ADD SIZE_BYTE (f-source 15) sconst8)
 (cris-arit add QI Rd sconst8)
 (cris-arit add QI Rd sconst8)
)
)
(dni-c-HI
(dni-c-HI
 addcwr "add constant word to register"
 addcwr "add constant word to register"
 "add.w ${sconst16}],${Rd}"
 "add.w ${sconst16}],${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_ADD SIZE_WORD (f-source 15) sconst16)
 (+ Rd MODE_AUTOINCREMENT INDIR_ADD SIZE_WORD (f-source 15) sconst16)
 (cris-arit add HI Rd sconst16)
 (cris-arit add HI Rd sconst16)
)
)
(dni-c-SI
(dni-c-SI
 addcdr "add constant dword to register"
 addcdr "add constant dword to register"
 "add.d ${const32}],${Rd}"
 "add.d ${const32}],${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_ADD SIZE_DWORD (f-source 15) const32)
 (+ Rd MODE_AUTOINCREMENT INDIR_ADD SIZE_DWORD (f-source 15) const32)
 (cris-arit add SI Rd const32)
 (cris-arit add SI Rd const32)
)
)
; (ADD.D   [PC+],PC        [ 1111 | 11100010 | 1111 ])
; (ADD.D   [PC+],PC        [ 1111 | 11100010 | 1111 ])
; This insn is used for DSO-local jumps in PIC code.
; This insn is used for DSO-local jumps in PIC code.
(dni
(dni
 addcpc "Relative jump by adding constant to PC"
 addcpc "Relative jump by adding constant to PC"
 (MACH-PC)
 (MACH-PC)
 "add.d ${sconst32},PC"
 "add.d ${sconst32},PC"
 (+ (f-dest 15) MODE_AUTOINCREMENT INDIR_ADD SIZE_DWORD (f-source 15) const32)
 (+ (f-dest 15) MODE_AUTOINCREMENT INDIR_ADD SIZE_DWORD (f-source 15) const32)
 (sequence
 (sequence
   ((SI newpc) (SI oldpc) (SI offs))
   ((SI newpc) (SI oldpc) (SI offs))
   (set offs const32)
   (set offs const32)
   (set oldpc (add SI pc 6))
   (set oldpc (add SI pc 6))
   (set newpc (add SI oldpc offs))
   (set newpc (add SI oldpc offs))
   (set pc newpc)
   (set pc newpc)
   (setf-arit SI add oldpc offs newpc cbit))
   (setf-arit SI add oldpc offs newpc cbit))
 (simplecris-common-timing ((unit u-const32) (unit u-stall) (unit u-exec)))
 (simplecris-common-timing ((unit u-const32) (unit u-stall) (unit u-exec)))
)
)
; ADDS.z  Rs,Rd           [ Rd | 0100001z | Rs ]
; ADDS.z  Rs,Rd           [ Rd | 0100001z | Rs ]
(dni-cdt-sbw
(dni-cdt-sbw
 adds "add sign-extended from register to register"
 adds "add sign-extended from register to register"
 "$Rs,$Rd"
 "$Rs,$Rd"
 (+ Rd MODE_REGISTER R_ADDX Rs)
 (+ Rd MODE_REGISTER R_ADDX Rs)
 (.pmacro (BW) (cris-arit add SI Rd ((.sym BW -ext) (trunc BW Rs))))
 (.pmacro (BW) (cris-arit add SI Rd ((.sym BW -ext) (trunc BW Rs))))
)
)
; ADDS.z  [Rs],Rd         [ Rd | 1000001z | Rs ]
; ADDS.z  [Rs],Rd         [ Rd | 1000001z | Rs ]
; ADDS.z  [Rs+],Rd        [ Rd | 1100001z | Rs ]
; ADDS.z  [Rs+],Rd        [ Rd | 1100001z | Rs ]
(dni-cmt-sbw
(dni-cmt-sbw
 adds-m "add sign-extended from memory to register"
 adds-m "add sign-extended from memory to register"
 "[${Rs}${inc}],$Rd"
 "[${Rs}${inc}],$Rd"
 (+ Rd INDIR_ADDX Rs)
 (+ Rd INDIR_ADDX Rs)
 (.pmacro (BW) (cris-arit-3op add SI Rd ((.sym BW -ext) (cris-get-mem BW Rs)) Rs))
 (.pmacro (BW) (cris-arit-3op add SI Rd ((.sym BW -ext) (cris-get-mem BW Rs)) Rs))
)
)
; (ADDS.z  [PC+],Rd        [ Rd | 1100001z | 1111 ])
; (ADDS.z  [PC+],Rd        [ Rd | 1100001z | 1111 ])
(dni-c-QI
(dni-c-QI
 addscbr "add sign-extended constant byte to register"
 addscbr "add sign-extended constant byte to register"
 "[${Rs}${inc}],$Rd"
 "[${Rs}${inc}],$Rd"
 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX SIGNED_BYTE (f-source 15) sconst8)
 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX SIGNED_BYTE (f-source 15) sconst8)
 (cris-arit add SI Rd (ext SI (trunc QI sconst8)))
 (cris-arit add SI Rd (ext SI (trunc QI sconst8)))
)
)
(dni-c-HI
(dni-c-HI
 addscwr "add sign-extended constant word to register"
 addscwr "add sign-extended constant word to register"
 "[${Rs}${inc}],$Rd"
 "[${Rs}${inc}],$Rd"
 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX SIGNED_WORD (f-source 15) sconst16)
 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX SIGNED_WORD (f-source 15) sconst16)
 (cris-arit add SI Rd (ext SI (trunc HI sconst16)))
 (cris-arit add SI Rd (ext SI (trunc HI sconst16)))
)
)
; (ADDS.w  [],PC         [ 1111 | 10000011 | 1111 ])
; (ADDS.w  [],PC         [ 1111 | 10000011 | 1111 ])
; For a PC destination, we support only the two-operand case
; For a PC destination, we support only the two-operand case
; (dest == src), which is used in switch/case statements.
; (dest == src), which is used in switch/case statements.
; FIXME: Should implement ADD.D [PC],PC and ADDS.B [PC],PC for use if/when
; FIXME: Should implement ADD.D [PC],PC and ADDS.B [PC],PC for use if/when
; implementing CASE_VECTOR_SHORTEN_MODE.
; implementing CASE_VECTOR_SHORTEN_MODE.
(dni
(dni
 addspcpc "add sign-extended prefixed arg to PC"
 addspcpc "add sign-extended prefixed arg to PC"
 (MACH-PC)
 (MACH-PC)
 "adds.w [PC],PC"
 "adds.w [PC],PC"
 (+ (f-dest 15) MODE_INDIRECT INDIR_ADDX SIGNED_WORD (f-source 15))
 (+ (f-dest 15) MODE_INDIRECT INDIR_ADDX SIGNED_WORD (f-source 15))
 (sequence
 (sequence
   ((SI newpc) (SI oldpc) (HI offs))
   ((SI newpc) (SI oldpc) (HI offs))
   (if (not prefix-set)
   (if (not prefix-set)
       (error "Unexpected adds.w [PC],PC without prefix"))
       (error "Unexpected adds.w [PC],PC without prefix"))
   ; We don't use cris-get-mem but instead special-case this one, since we
   ; We don't use cris-get-mem but instead special-case this one, since we
   ; have most instruction fields fixed where cris-get-mem expects
   ; have most instruction fields fixed where cris-get-mem expects
   ; field-parametrization by certain names.
   ; field-parametrization by certain names.
   (set offs (mem HI prefixreg))
   (set offs (mem HI prefixreg))
   (set oldpc (add SI pc 2))
   (set oldpc (add SI pc 2))
   (set newpc (add SI oldpc offs))
   (set newpc (add SI oldpc offs))
   (set pc newpc)
   (set pc newpc)
   (setf-arit SI add oldpc (ext SI offs) newpc cbit))
   (setf-arit SI add oldpc (ext SI offs) newpc cbit))
 (simplecris-common-timing ((unit u-mem) (unit u-stall) (unit u-exec)))
 (simplecris-common-timing ((unit u-mem) (unit u-stall) (unit u-exec)))
)
)
; ADDU.z  Rs,Rd           [ Rd | 0100000z | Rs ]
; ADDU.z  Rs,Rd           [ Rd | 0100000z | Rs ]
(dni-cdt-ubw
(dni-cdt-ubw
 addu "add zero-extended from register to register"
 addu "add zero-extended from register to register"
 "$Rs,$Rd"
 "$Rs,$Rd"
 (+ Rd MODE_REGISTER R_ADDX Rs)
 (+ Rd MODE_REGISTER R_ADDX Rs)
 (.pmacro (BW) (cris-arit add SI Rd ((.sym BW -zext) (trunc BW Rs))))
 (.pmacro (BW) (cris-arit add SI Rd ((.sym BW -zext) (trunc BW Rs))))
)
)
; ADDU.z  [Rs],Rd         [ Rd | 1000000z | Rs ]
; ADDU.z  [Rs],Rd         [ Rd | 1000000z | Rs ]
; ADDU.z  [Rs+],Rd        [ Rd | 1100000z | Rs ]
; ADDU.z  [Rs+],Rd        [ Rd | 1100000z | Rs ]
(dni-cmt-ubw
(dni-cmt-ubw
 addu-m "add zero-extended from memory to register"
 addu-m "add zero-extended from memory to register"
 "[${Rs}${inc}],$Rd"
 "[${Rs}${inc}],$Rd"
 (+ Rd INDIR_ADDX Rs)
 (+ Rd INDIR_ADDX Rs)
 (.pmacro (BW)
 (.pmacro (BW)
          (cris-arit-3op add SI Rd ((.sym BW -zext) (cris-get-mem BW Rs)) Rs))
          (cris-arit-3op add SI Rd ((.sym BW -zext) (cris-get-mem BW Rs)) Rs))
)
)
; (ADDU.z  [PC+],Rd        [ Rd | 1100000z | 1111 ])
; (ADDU.z  [PC+],Rd        [ Rd | 1100000z | 1111 ])
(dni-c-QI
(dni-c-QI
 adducbr "add zero-extended constant byte to register"
 adducbr "add zero-extended constant byte to register"
 "[${Rs}${inc}],$Rd"
 "[${Rs}${inc}],$Rd"
 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX UNSIGNED_BYTE (f-source 15) sconst8)
 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX UNSIGNED_BYTE (f-source 15) sconst8)
 (cris-arit add SI Rd (zext SI (trunc QI sconst8)))
 (cris-arit add SI Rd (zext SI (trunc QI sconst8)))
)
)
(dni-c-HI
(dni-c-HI
 adducwr "add zero-extended constant word to register"
 adducwr "add zero-extended constant word to register"
 "[${Rs}${inc}],$Rd"
 "[${Rs}${inc}],$Rd"
 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX UNSIGNED_WORD (f-source 15) sconst16)
 (+ Rd MODE_AUTOINCREMENT INDIR_ADDX UNSIGNED_WORD (f-source 15) sconst16)
 (cris-arit add SI Rd (zext SI (trunc HI sconst16)))
 (cris-arit add SI Rd (zext SI (trunc HI sconst16)))
)
)
; SUB.m   Rs,Rd           [ Rd | 011010mm | Rs ]
; SUB.m   Rs,Rd           [ Rd | 011010mm | Rs ]
(dni-cdt-bwd
(dni-cdt-bwd
 sub "subtract from register to register"
 sub "subtract from register to register"
 "$Rs,$Rd"
 "$Rs,$Rd"
 (+ Rd MODE_REGISTER R_SUB Rs)
 (+ Rd MODE_REGISTER R_SUB Rs)
 (.pmacro (BWD) (cris-arit sub BWD Rd Rs))
 (.pmacro (BWD) (cris-arit sub BWD Rd Rs))
)
)
; SUB.m   [Rs],Rd         [ Rd | 101010mm | Rs ]
; SUB.m   [Rs],Rd         [ Rd | 101010mm | Rs ]
; SUB.m   [Rs+],Rd        [ Rd | 111010mm | Rs ]
; SUB.m   [Rs+],Rd        [ Rd | 111010mm | Rs ]
(dni-cmt-bwd
(dni-cmt-bwd
 sub-m "subtract from memory to register"
 sub-m "subtract from memory to register"
 "[${Rs}${inc}],${Rd}"
 "[${Rs}${inc}],${Rd}"
 (+ INDIR_SUB Rs Rd)
 (+ INDIR_SUB Rs Rd)
 (.pmacro (BWD) (cris-arit-3op sub BWD Rd (cris-get-mem BWD Rs) Rs))
 (.pmacro (BWD) (cris-arit-3op sub BWD Rd (cris-get-mem BWD Rs) Rs))
)
)
; (SUB.m   [PC+],Rd        [ Rd | 111010mm | 1111 ]
; (SUB.m   [PC+],Rd        [ Rd | 111010mm | 1111 ]
(dni-c-QI
(dni-c-QI
 subcbr "subtract constant byte from register"
 subcbr "subtract constant byte from register"
 "sub.b ${sconst8}],${Rd}"
 "sub.b ${sconst8}],${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_SUB SIZE_BYTE (f-source 15) sconst8)
 (+ Rd MODE_AUTOINCREMENT INDIR_SUB SIZE_BYTE (f-source 15) sconst8)
 (cris-arit sub QI Rd sconst8)
 (cris-arit sub QI Rd sconst8)
)
)
(dni-c-HI
(dni-c-HI
 subcwr "subtract constant word from register"
 subcwr "subtract constant word from register"
 "sub.w ${sconst16}],${Rd}"
 "sub.w ${sconst16}],${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_SUB SIZE_WORD (f-source 15) sconst16)
 (+ Rd MODE_AUTOINCREMENT INDIR_SUB SIZE_WORD (f-source 15) sconst16)
 (cris-arit sub HI Rd sconst16)
 (cris-arit sub HI Rd sconst16)
)
)
(dni-c-SI
(dni-c-SI
 subcdr "subtract constant dword from register"
 subcdr "subtract constant dword from register"
 "sub.d ${const32}],${Rd}"
 "sub.d ${const32}],${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_SUB SIZE_DWORD (f-source 15) const32)
 (+ Rd MODE_AUTOINCREMENT INDIR_SUB SIZE_DWORD (f-source 15) const32)
 (cris-arit sub SI Rd const32)
 (cris-arit sub SI Rd const32)
)
)
; SUBS.z  Rs,Rd           [ Rd | 0100101z | Rs ]
; SUBS.z  Rs,Rd           [ Rd | 0100101z | Rs ]
(dni-cdt-sbw
(dni-cdt-sbw
 subs "sub sign-extended from register to register"
 subs "sub sign-extended from register to register"
 "$Rs,$Rd"
 "$Rs,$Rd"
 (+ Rd MODE_REGISTER R_SUBX Rs)
 (+ Rd MODE_REGISTER R_SUBX Rs)
 (.pmacro (BW) (cris-arit sub SI Rd ((.sym BW -ext) (trunc BW Rs))))
 (.pmacro (BW) (cris-arit sub SI Rd ((.sym BW -ext) (trunc BW Rs))))
)
)
; SUBS.z  [Rs],Rd         [ Rd | 1000101z | Rs ]
; SUBS.z  [Rs],Rd         [ Rd | 1000101z | Rs ]
; SUBS.z  [Rs+],Rd        [ Rd | 1100101z | Rs ]
; SUBS.z  [Rs+],Rd        [ Rd | 1100101z | Rs ]
(dni-cmt-sbw
(dni-cmt-sbw
 subs-m "sub sign-extended from memory to register"
 subs-m "sub sign-extended from memory to register"
 "[${Rs}${inc}],$Rd"
 "[${Rs}${inc}],$Rd"
 (+ Rd INDIR_SUBX Rs)
 (+ Rd INDIR_SUBX Rs)
 (.pmacro (BW)
 (.pmacro (BW)
          (cris-arit-3op sub SI Rd ((.sym BW -ext) (cris-get-mem BW Rs)) Rs))
          (cris-arit-3op sub SI Rd ((.sym BW -ext) (cris-get-mem BW Rs)) Rs))
)
)
; (SUBS.z  [PC+],Rd        [ Rd | 1100101z | 1111 ])
; (SUBS.z  [PC+],Rd        [ Rd | 1100101z | 1111 ])
(dni-c-QI
(dni-c-QI
 subscbr "sub sign-extended constant byte to register"
 subscbr "sub sign-extended constant byte to register"
 "[${Rs}${inc}],$Rd"
 "[${Rs}${inc}],$Rd"
 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX SIGNED_BYTE (f-source 15) sconst8)
 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX SIGNED_BYTE (f-source 15) sconst8)
 (cris-arit sub SI Rd (ext SI (trunc QI sconst8)))
 (cris-arit sub SI Rd (ext SI (trunc QI sconst8)))
)
)
(dni-c-HI
(dni-c-HI
 subscwr "sub sign-extended constant word to register"
 subscwr "sub sign-extended constant word to register"
 "[${Rs}${inc}],$Rd"
 "[${Rs}${inc}],$Rd"
 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX SIGNED_WORD (f-source 15) sconst16)
 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX SIGNED_WORD (f-source 15) sconst16)
 (cris-arit sub SI Rd (ext SI (trunc HI sconst16)))
 (cris-arit sub SI Rd (ext SI (trunc HI sconst16)))
)
)
; SUBU.z  Rs,Rd           [ Rd | 0100100z | Rs ]
; SUBU.z  Rs,Rd           [ Rd | 0100100z | Rs ]
(dni-cdt-ubw
(dni-cdt-ubw
 subu "sub zero-extended from register to register"
 subu "sub zero-extended from register to register"
 "$Rs,$Rd"
 "$Rs,$Rd"
 (+ Rd MODE_REGISTER R_SUBX Rs)
 (+ Rd MODE_REGISTER R_SUBX Rs)
 (.pmacro (BW) (cris-arit sub SI Rd ((.sym BW -zext) (trunc BW Rs))))
 (.pmacro (BW) (cris-arit sub SI Rd ((.sym BW -zext) (trunc BW Rs))))
)
)
; SUBU.z  [Rs],Rd         [ Rd | 1000100z | Rs ]
; SUBU.z  [Rs],Rd         [ Rd | 1000100z | Rs ]
; SUBU.z  [Rs+],Rd        [ Rd | 1100100z | Rs ]
; SUBU.z  [Rs+],Rd        [ Rd | 1100100z | Rs ]
(dni-cmt-ubw
(dni-cmt-ubw
 subu-m "sub zero-extended from memory to register"
 subu-m "sub zero-extended from memory to register"
 "[${Rs}${inc}],$Rd"
 "[${Rs}${inc}],$Rd"
 (+ Rd INDIR_SUBX Rs)
 (+ Rd INDIR_SUBX Rs)
 (.pmacro (BW)
 (.pmacro (BW)
          (cris-arit-3op sub SI Rd ((.sym BW -zext) (cris-get-mem BW Rs)) Rs))
          (cris-arit-3op sub SI Rd ((.sym BW -zext) (cris-get-mem BW Rs)) Rs))
)
)
; (SUBU.z  [PC+],Rd        [ Rd | 1100100z | 1111 ])
; (SUBU.z  [PC+],Rd        [ Rd | 1100100z | 1111 ])
(dni-c-QI
(dni-c-QI
 subucbr "sub zero-extended constant byte to register"
 subucbr "sub zero-extended constant byte to register"
 "[${Rs}${inc}],$Rd"
 "[${Rs}${inc}],$Rd"
 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX UNSIGNED_BYTE (f-source 15) sconst8)
 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX UNSIGNED_BYTE (f-source 15) sconst8)
 (cris-arit sub SI Rd (zext SI (trunc QI sconst8)))
 (cris-arit sub SI Rd (zext SI (trunc QI sconst8)))
)
)
(dni-c-HI
(dni-c-HI
 subucwr "sub zero-extended constant word to register"
 subucwr "sub zero-extended constant word to register"
 "[${Rs}${inc}],$Rd"
 "[${Rs}${inc}],$Rd"
 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX UNSIGNED_WORD (f-source 15) sconst16)
 (+ Rd MODE_AUTOINCREMENT INDIR_SUBX UNSIGNED_WORD (f-source 15) sconst16)
 (cris-arit sub SI Rd (zext SI (trunc HI sconst16)))
 (cris-arit sub SI Rd (zext SI (trunc HI sconst16)))
)
)
; ADDC    Rs,Rd           [ Rd | 01010111 | Rs ]
; ADDC    Rs,Rd           [ Rd | 01010111 | Rs ]
(dni-cdt-attr
(dni-cdt-attr
 addc-r "addc from register to register"
 addc-r "addc from register to register"
 (MACH-V32)
 (MACH-V32)
 "addc $Rs,$Rd"
 "addc $Rs,$Rd"
 (+ Rd MODE_REGISTER RFIX_ADDC SIZE_FIXED Rs)
 (+ Rd MODE_REGISTER RFIX_ADDC SIZE_FIXED Rs)
 ; Since this is equivalent to "ax" plus "add.d Rs,Rd", we'll just do
 ; Since this is equivalent to "ax" plus "add.d Rs,Rd", we'll just do
 ; that, semantically.
 ; that, semantically.
 (sequence
 (sequence
   ()
   ()
   (set-quiet xbit 1)
   (set-quiet xbit 1)
   (cris-arit add SI Rd Rs))
   (cris-arit add SI Rd Rs))
)
)
; ADDC    [Rs],Rd         [ Rd | 10011010 | Rs ]
; ADDC    [Rs],Rd         [ Rd | 10011010 | Rs ]
; ADDC    [Rs+],Rd        [ Rd | 11011010 | Rs ]
; ADDC    [Rs+],Rd        [ Rd | 11011010 | Rs ]
(dni-cmt-attr
(dni-cmt-attr
 addc-m "addc from memory to register"
 addc-m "addc from memory to register"
 (MACH-V32)
 (MACH-V32)
 "addc [${Rs}${inc}],${Rd}"
 "addc [${Rs}${inc}],${Rd}"
 (+ Rd INDIR_ADDC SIZE_DWORD Rs)
 (+ Rd INDIR_ADDC SIZE_DWORD Rs)
 (sequence
 (sequence
   ()
   ()
   (set-quiet xbit 1)
   (set-quiet xbit 1)
   (cris-arit add SI Rd (cris-get-mem SI Rs)))
   (cris-arit add SI Rd (cris-get-mem SI Rs)))
)
)
; (ADDC    [Rs+],Rd        [ Rd | 11011010 | 1111 ])
; (ADDC    [Rs+],Rd        [ Rd | 11011010 | 1111 ])
(dni-c-SI-attr
(dni-c-SI-attr
 addc-c "addc constant to register"
 addc-c "addc constant to register"
 (MACH-V32)
 (MACH-V32)
 "addc ${const32},${Rd}"
 "addc ${const32},${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_ADDC SIZE_DWORD (f-source 15) const32)
 (+ Rd MODE_AUTOINCREMENT INDIR_ADDC SIZE_DWORD (f-source 15) const32)
 (sequence
 (sequence
   ()
   ()
   (set-quiet xbit 1)
   (set-quiet xbit 1)
   (cris-arit add SI Rd const32))
   (cris-arit add SI Rd const32))
)
)
; LAPC   [PC+],Rd         [ Rd | 11010111 1111 ]
; LAPC   [PC+],Rd         [ Rd | 11010111 1111 ]
(dni-c-SI-attr
(dni-c-SI-attr
 lapc-d "lapc.d"
 lapc-d "lapc.d"
 (MACH-V32)
 (MACH-V32)
 "lapc.d ${const32-pcrel},${Rd}"
 "lapc.d ${const32-pcrel},${Rd}"
 (+ Rd MODE_AUTOINCREMENT INFIX_LAPC SIZE_FIXED (f-source 15) const32-pcrel)
 (+ Rd MODE_AUTOINCREMENT INFIX_LAPC SIZE_FIXED (f-source 15) const32-pcrel)
 (sequence
 (sequence
   ()
   ()
   (set Rd const32-pcrel)
   (set Rd const32-pcrel)
   (reset-x-p))
   (reset-x-p))
)
)
; LAPCQ  qo,Rd            [ Rd | 10010111 | qo ]
; LAPCQ  qo,Rd            [ Rd | 10010111 | qo ]
(dni-cdt-attr
(dni-cdt-attr
 lapcq "lapcq"
 lapcq "lapcq"
 (MACH-V32)
 (MACH-V32)
 "lapcq ${qo},${Rd}"
 "lapcq ${qo},${Rd}"
 (+ Rd MODE_INDIRECT INFIX_LAPC SIZE_FIXED qo)
 (+ Rd MODE_INDIRECT INFIX_LAPC SIZE_FIXED qo)
 (sequence
 (sequence
   ()
   ()
   (set Rd qo)
   (set Rd qo)
   (reset-x-p))
   (reset-x-p))
)
)
; ADDI    Rs.m,Rd         [ Rs | 010100mm | Rd ]
; ADDI    Rs.m,Rd         [ Rs | 010100mm | Rd ]
(dni-cdt-bwd
(dni-cdt-bwd
 addi "addi"
 addi "addi"
 "${Rs-dfield}.m,${Rd-sfield}"
 "${Rs-dfield}.m,${Rd-sfield}"
 (+ Rd-sfield MODE_REGISTER R_ADDI Rs-dfield)
 (+ Rd-sfield MODE_REGISTER R_ADDI Rs-dfield)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ()
    ()
    (set Rd-sfield (add SI Rd-sfield (mul Rs-dfield (.sym BWD -size))))
    (set Rd-sfield (add SI Rd-sfield (mul Rs-dfield (.sym BWD -size))))
    (reset-x-p)))
    (reset-x-p)))
)
)
;  NEG.m   Rs,Rd           [ Rd | 010110mm | Rs ]
;  NEG.m   Rs,Rd           [ Rd | 010110mm | Rs ]
(dni-cdt-bwd
(dni-cdt-bwd
 neg "neg.m Rs,Rd"
 neg "neg.m Rs,Rd"
 "$Rs,$Rd"
 "$Rs,$Rd"
 (+ Rd MODE_REGISTER R_NEG Rs)
 (+ Rd MODE_REGISTER R_NEG Rs)
 (.pmacro (BWD) (cris-arit3 sub BWD Rd 0 Rs))
 (.pmacro (BWD) (cris-arit3 sub BWD Rd 0 Rs))
)
)
; TEST.m  [Rs]            [ 0000101110mm | Rs ]
; TEST.m  [Rs]            [ 0000101110mm | Rs ]
; TEST.m  [Rs+]           [ 0000111110mm | Rs ]
; TEST.m  [Rs+]           [ 0000111110mm | Rs ]
(dni-cmt-bwd
(dni-cmt-bwd
 test-m "test.m [Rs(+)]"
 test-m "test.m [Rs(+)]"
 "[${Rs}${inc}]"
 "[${Rs}${inc}]"
 (+ (f-dest 0) INDIR_TEST Rs)
 (+ (f-dest 0) INDIR_TEST Rs)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ((BWD tmpd))
    ((BWD tmpd))
    (set tmpd (cris-get-mem BWD Rs))
    (set tmpd (cris-get-mem BWD Rs))
    ; This is supposed to be the same result as for cmpq 0,X, hence same code.
    ; This is supposed to be the same result as for cmpq 0,X, hence same code.
    (cris-arit6-int
    (cris-arit6-int
     sub BWD (.pmacro (sz regno val) (nop)) 0 tmpd 0 cbit cbit)))
     sub BWD (.pmacro (sz regno val) (nop)) 0 tmpd 0 cbit cbit)))
)
)
; MOVE.m  Rs,[Rd]         [ Rs | 101111mm | Rd ]
; MOVE.m  Rs,[Rd]         [ Rs | 101111mm | Rd ]
; MOVE.m  Rs,[Rd+]        [ Rs | 111111mm | Rd ]
; MOVE.m  Rs,[Rd+]        [ Rs | 111111mm | Rd ]
(dni-cmwt-bwd
(dni-cmwt-bwd
 move-r-m "move.m R,[]"
 move-r-m "move.m R,[]"
 "${Rs-dfield},[${Rd-sfield}${inc}]"
 "${Rs-dfield},[${Rd-sfield}${inc}]"
 (+ Rs-dfield INDIR_MOVE_R_M Rd-sfield)
 (+ Rs-dfield INDIR_MOVE_R_M Rd-sfield)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ((BWD tmpd))
    ((BWD tmpd))
    (set tmpd Rs-dfield)
    (set tmpd Rs-dfield)
    (cris-set-mem BWD Rd-sfield tmpd)
    (cris-set-mem BWD Rd-sfield tmpd)
    (reset-x-p)))
    (reset-x-p)))
)
)
; MULS.m  Rs,Rd           [ Rd | 110100mm | Rs ]
; MULS.m  Rs,Rd           [ Rd | 110100mm | Rs ]
(dni-bwd-attr
(dni-bwd-attr
 muls "muls.m Rs,Rd"
 muls "muls.m Rs,Rd"
 ((MACH crisv10,crisv32))
 ((MACH crisv10,crisv32))
 "$Rs,$Rd"
 "$Rs,$Rd"
 (+ Rd MODE_MULS INDIR_MUL Rs)
 (+ Rd MODE_MULS INDIR_MUL Rs)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ((DI src1) (DI src2) (DI tmpr))
    ((DI src1) (DI src2) (DI tmpr))
    (set src1 (ext DI (trunc BWD Rs)))
    (set src1 (ext DI (trunc BWD Rs)))
    (set src2 (ext DI (trunc BWD Rd)))
    (set src2 (ext DI (trunc BWD Rd)))
    (set tmpr (mul src1 src2))
    (set tmpr (mul src1 src2))
    (set Rd (trunc SI tmpr))
    (set Rd (trunc SI tmpr))
    (set mof (trunc SI (srl tmpr 32)))
    (set mof (trunc SI (srl tmpr 32)))
    (setf-arit DI muls src1 src2 tmpr cbit)))
    (setf-arit DI muls src1 src2 tmpr cbit)))
 ((crisv10 (unit u-multiply) (unit u-exec))
 ((crisv10 (unit u-multiply) (unit u-exec))
  (crisv32 (unit u-multiply) (unit u-exec)))
  (crisv32 (unit u-multiply) (unit u-exec)))
)
)
; MULU.m  Rs,Rd           [ Rd | 100100mm | Rs ]
; MULU.m  Rs,Rd           [ Rd | 100100mm | Rs ]
(dni-bwd-attr
(dni-bwd-attr
 mulu "mulu.m Rs,Rd"
 mulu "mulu.m Rs,Rd"
 ((MACH crisv10,crisv32))
 ((MACH crisv10,crisv32))
 "$Rs,$Rd"
 "$Rs,$Rd"
 (+ Rd MODE_MULU INDIR_MUL Rs)
 (+ Rd MODE_MULU INDIR_MUL Rs)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ((DI src1) (DI src2) (DI tmpr))
    ((DI src1) (DI src2) (DI tmpr))
    (set src1 (zext DI (trunc BWD Rs)))
    (set src1 (zext DI (trunc BWD Rs)))
    (set src2 (zext DI (trunc BWD Rd)))
    (set src2 (zext DI (trunc BWD Rd)))
    (set tmpr (mul src1 src2))
    (set tmpr (mul src1 src2))
    (set Rd (trunc SI tmpr))
    (set Rd (trunc SI tmpr))
    (set mof (trunc SI (srl tmpr 32)))
    (set mof (trunc SI (srl tmpr 32)))
    (setf-arit DI mulu src1 src2 tmpr cbit)))
    (setf-arit DI mulu src1 src2 tmpr cbit)))
 ((crisv10 (unit u-multiply) (unit u-exec))
 ((crisv10 (unit u-multiply) (unit u-exec))
  (crisv32 (unit u-multiply) (unit u-exec)))
  (crisv32 (unit u-multiply) (unit u-exec)))
)
)
; MCP     Ps,Rd           [ Ps | 01111111 | Rd ]
; MCP     Ps,Rd           [ Ps | 01111111 | Rd ]
(dni-cdt-attr
(dni-cdt-attr
 mcp "Multiply Carry Propagation"
 mcp "Multiply Carry Propagation"
 (MACH-V32)
 (MACH-V32)
 "mcp $Ps,$Rd"
 "mcp $Ps,$Rd"
 (+ Ps MODE_REGISTER RFIX_MCP SIZE_FIXED Rd-sfield)
 (+ Ps MODE_REGISTER RFIX_MCP SIZE_FIXED Rd-sfield)
 (sequence
 (sequence
   ()
   ()
   (set-quiet xbit 1)
   (set-quiet xbit 1)
   (set-quiet zbit 1)
   (set-quiet zbit 1)
   (cris-arit5 add SI Rd-sfield Rd-sfield Ps rbit rbit))
   (cris-arit5 add SI Rd-sfield Rd-sfield Ps rbit rbit))
)
)
; MSTEP   Rs,Rd           [ Rd | 01111111 | Rs ]
; MSTEP   Rs,Rd           [ Rd | 01111111 | Rs ]
(dni-cdt-attr
(dni-cdt-attr
 mstep "Multiply step"
 mstep "Multiply step"
 (MACH-PRE-V32)
 (MACH-PRE-V32)
 "mstep $Rs,$Rd"
 "mstep $Rs,$Rd"
 (+ Rd MODE_REGISTER RFIX_MSTEP SIZE_FIXED Rs)
 (+ Rd MODE_REGISTER RFIX_MSTEP SIZE_FIXED Rs)
 (sequence
 (sequence
   ((SI tmpd) (SI tmps))
   ((SI tmpd) (SI tmps))
   (set tmps Rs)
   (set tmps Rs)
   (set tmpd (add (sll Rd 1) (if SI nbit tmps 0)))
   (set tmpd (add (sll Rd 1) (if SI nbit tmps 0)))
   (set Rd tmpd)
   (set Rd tmpd)
   (setf-move SI tmpd))
   (setf-move SI tmpd))
)
)
; DSTEP   Rs,Rd           [ Rd | 01101111 | Rs ]
; DSTEP   Rs,Rd           [ Rd | 01101111 | Rs ]
(dni-cdt
(dni-cdt
 dstep "Division step"
 dstep "Division step"
 "dstep $Rs,$Rd"
 "dstep $Rs,$Rd"
 (+ Rd MODE_REGISTER RFIX_DSTEP SIZE_FIXED Rs)
 (+ Rd MODE_REGISTER RFIX_DSTEP SIZE_FIXED Rs)
 (sequence
 (sequence
   ((SI tmp) (SI tmps) (SI tmpd))
   ((SI tmp) (SI tmps) (SI tmpd))
   (set tmps Rs)
   (set tmps Rs)
   (set tmp (sll Rd 1))
   (set tmp (sll Rd 1))
   (set tmpd (if SI (geu tmp tmps) (sub tmp tmps) tmp))
   (set tmpd (if SI (geu tmp tmps) (sub tmp tmps) tmp))
   (set Rd tmpd)
   (set Rd tmpd)
   (setf-move SI tmpd))
   (setf-move SI tmpd))
)
)
;  ABS     Rs,Rd           [ Rd | 01101011 | Rs ]
;  ABS     Rs,Rd           [ Rd | 01101011 | Rs ]
(dni-cdt
(dni-cdt
 abs "Absolut Instruction"
 abs "Absolut Instruction"
 "abs $Rs,$Rd"
 "abs $Rs,$Rd"
 (+ Rd MODE_REGISTER RFIX_ABS SIZE_FIXED Rs)
 (+ Rd MODE_REGISTER RFIX_ABS SIZE_FIXED Rs)
 (sequence
 (sequence
   ((SI tmpd))
   ((SI tmpd))
   (set tmpd (abs Rs))
   (set tmpd (abs Rs))
   (set Rd tmpd)
   (set Rd tmpd)
   (setf-move SI tmpd))
   (setf-move SI tmpd))
)
)
; AND.m   Rs,Rd           [ Rd | 011100mm | Rs ]
; AND.m   Rs,Rd           [ Rd | 011100mm | Rs ]
(dni-cdt-bwd
(dni-cdt-bwd
 and "And from register to register"
 and "And from register to register"
 "$Rs,$Rd"
 "$Rs,$Rd"
 (+ Rd MODE_REGISTER R_AND Rs)
 (+ Rd MODE_REGISTER R_AND Rs)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ((BWD tmpd))
    ((BWD tmpd))
    (set tmpd (and BWD Rd Rs))
    (set tmpd (and BWD Rd Rs))
    (set-subreg-gr BWD (regno Rd) tmpd)
    (set-subreg-gr BWD (regno Rd) tmpd)
    (setf-move BWD tmpd)))
    (setf-move BWD tmpd)))
)
)
; AND.m   [Rs],Rd         [ Rd | 101100mm | Rs ]
; AND.m   [Rs],Rd         [ Rd | 101100mm | Rs ]
; AND.m   [Rs+],Rd        [ Rd | 111100mm | Rs ]
; AND.m   [Rs+],Rd        [ Rd | 111100mm | Rs ]
(dni-cmt-bwd
(dni-cmt-bwd
 and-m "And from memory to register"
 and-m "And from memory to register"
 "[${Rs}${inc}],${Rd}"
 "[${Rs}${inc}],${Rd}"
 (+ INDIR_AND Rs Rd)
 (+ INDIR_AND Rs Rd)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ((BWD tmpd))
    ((BWD tmpd))
    (set tmpd (and BWD Rd (cris-get-mem BWD Rs)))
    (set tmpd (and BWD Rd (cris-get-mem BWD Rs)))
    (set-subreg-gr
    (set-subreg-gr
     BWD
     BWD
     (if SI (andif prefix-set (not inc)) (regno Rs) (regno Rd))
     (if SI (andif prefix-set (not inc)) (regno Rs) (regno Rd))
     tmpd)
     tmpd)
    (setf-move BWD tmpd)))
    (setf-move BWD tmpd)))
)
)
; (AND.m   [PC+],Rd        [ Rd | 111100mm | 1111 ])
; (AND.m   [PC+],Rd        [ Rd | 111100mm | 1111 ])
(dni-c-QI
(dni-c-QI
 andcbr "And constant byte to register"
 andcbr "And constant byte to register"
 "and.b ${sconst8}],${Rd}"
 "and.b ${sconst8}],${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_AND SIZE_BYTE (f-source 15) sconst8)
 (+ Rd MODE_AUTOINCREMENT INDIR_AND SIZE_BYTE (f-source 15) sconst8)
 (sequence
 (sequence
   ((QI tmpd))
   ((QI tmpd))
   (set tmpd (and QI Rd sconst8))
   (set tmpd (and QI Rd sconst8))
   (set-subreg-gr QI (regno Rd) tmpd)
   (set-subreg-gr QI (regno Rd) tmpd)
   (setf-move QI tmpd))
   (setf-move QI tmpd))
)
)
(dni-c-HI
(dni-c-HI
 andcwr "And constant word to register"
 andcwr "And constant word to register"
 "and.w ${sconst16}],${Rd}"
 "and.w ${sconst16}],${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_AND SIZE_WORD (f-source 15) sconst16)
 (+ Rd MODE_AUTOINCREMENT INDIR_AND SIZE_WORD (f-source 15) sconst16)
 (sequence
 (sequence
   ((HI tmpd))
   ((HI tmpd))
   (set tmpd (and HI Rd sconst16))
   (set tmpd (and HI Rd sconst16))
   (set-subreg-gr HI (regno Rd) tmpd)
   (set-subreg-gr HI (regno Rd) tmpd)
   (setf-move HI tmpd))
   (setf-move HI tmpd))
)
)
(dni-c-SI
(dni-c-SI
 andcdr "And constant dword to register"
 andcdr "And constant dword to register"
 "and.d ${const32}],${Rd}"
 "and.d ${const32}],${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_AND SIZE_DWORD (f-source 15) const32)
 (+ Rd MODE_AUTOINCREMENT INDIR_AND SIZE_DWORD (f-source 15) const32)
 (sequence
 (sequence
   ((SI tmpd))
   ((SI tmpd))
   (set tmpd (and SI Rd const32))
   (set tmpd (and SI Rd const32))
   (set-subreg-gr SI (regno Rd) tmpd)
   (set-subreg-gr SI (regno Rd) tmpd)
   (setf-move SI tmpd))
   (setf-move SI tmpd))
)
)
; ANDQ    i,Rd            [ Rd | 001100 | i ]
; ANDQ    i,Rd            [ Rd | 001100 | i ]
(dni-cdt
(dni-cdt
 andq "And quick-immediate to register"
 andq "And quick-immediate to register"
 "andq $i,$Rd"
 "andq $i,$Rd"
 (+ Rd MODE_QUICK_IMMEDIATE Q_ANDQ i)
 (+ Rd MODE_QUICK_IMMEDIATE Q_ANDQ i)
 (sequence
 (sequence
   ((SI tmpd))
   ((SI tmpd))
   (set tmpd (and SI Rd i))
   (set tmpd (and SI Rd i))
   (set-subreg-gr SI (regno Rd) tmpd)
   (set-subreg-gr SI (regno Rd) tmpd)
   (setf-move SI tmpd))
   (setf-move SI tmpd))
)
)
; OR.m    Rs,Rd           [ Rd | 011101mm | Rs ]
; OR.m    Rs,Rd           [ Rd | 011101mm | Rs ]
(dni-cdt-bwd
(dni-cdt-bwd
 orr "Or from register to register"
 orr "Or from register to register"
 "$Rs,$Rd"
 "$Rs,$Rd"
 (+ Rd MODE_REGISTER R_OR Rs)
 (+ Rd MODE_REGISTER R_OR Rs)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ((BWD tmpd))
    ((BWD tmpd))
    (set tmpd (or BWD Rd Rs))
    (set tmpd (or BWD Rd Rs))
    (set-subreg-gr BWD (regno Rd) tmpd)
    (set-subreg-gr BWD (regno Rd) tmpd)
    (setf-move BWD tmpd)))
    (setf-move BWD tmpd)))
)
)
; OR.m    [Rs],Rd         [ Rd | 101101mm | Rs ]
; OR.m    [Rs],Rd         [ Rd | 101101mm | Rs ]
; OR.m    [Rs+],Rd        [ Rd | 111101mm | Rs ]
; OR.m    [Rs+],Rd        [ Rd | 111101mm | Rs ]
(dni-cmt-bwd
(dni-cmt-bwd
 or-m "Or from memory to register"
 or-m "Or from memory to register"
 "[${Rs}${inc}],${Rd}"
 "[${Rs}${inc}],${Rd}"
 (+ INDIR_OR Rs Rd)
 (+ INDIR_OR Rs Rd)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ((BWD tmpd))
    ((BWD tmpd))
    (set tmpd (or BWD Rd (cris-get-mem BWD Rs)))
    (set tmpd (or BWD Rd (cris-get-mem BWD Rs)))
    (set-subreg-gr
    (set-subreg-gr
     BWD
     BWD
     (if SI (andif prefix-set (not inc)) (regno Rs) (regno Rd))
     (if SI (andif prefix-set (not inc)) (regno Rs) (regno Rd))
     tmpd)
     tmpd)
    (setf-move BWD tmpd)))
    (setf-move BWD tmpd)))
)
)
; (OR.m    [PC+],Rd        [ Rd | 111101mm | 1111 ])
; (OR.m    [PC+],Rd        [ Rd | 111101mm | 1111 ])
(dni-c-QI
(dni-c-QI
 orcbr "Or constant byte to register"
 orcbr "Or constant byte to register"
 "or.b ${sconst8}],${Rd}"
 "or.b ${sconst8}],${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_OR SIZE_BYTE (f-source 15) sconst8)
 (+ Rd MODE_AUTOINCREMENT INDIR_OR SIZE_BYTE (f-source 15) sconst8)
 (sequence
 (sequence
   ((QI tmpd))
   ((QI tmpd))
   (set tmpd (or QI Rd sconst8))
   (set tmpd (or QI Rd sconst8))
   (set-subreg-gr QI (regno Rd) tmpd)
   (set-subreg-gr QI (regno Rd) tmpd)
   (setf-move QI tmpd))
   (setf-move QI tmpd))
)
)
(dni-c-HI
(dni-c-HI
 orcwr "Or constant word to register"
 orcwr "Or constant word to register"
 "or.w ${sconst16}],${Rd}"
 "or.w ${sconst16}],${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_OR SIZE_WORD (f-source 15) sconst16)
 (+ Rd MODE_AUTOINCREMENT INDIR_OR SIZE_WORD (f-source 15) sconst16)
 (sequence
 (sequence
   ((HI tmpd))
   ((HI tmpd))
   (set tmpd (or HI Rd sconst16))
   (set tmpd (or HI Rd sconst16))
   (set-subreg-gr HI (regno Rd) tmpd)
   (set-subreg-gr HI (regno Rd) tmpd)
   (setf-move HI tmpd))
   (setf-move HI tmpd))
)
)
(dni-c-SI
(dni-c-SI
 orcdr "Or constant dword to register"
 orcdr "Or constant dword to register"
 "or.d ${const32}],${Rd}"
 "or.d ${const32}],${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_OR SIZE_DWORD (f-source 15) const32)
 (+ Rd MODE_AUTOINCREMENT INDIR_OR SIZE_DWORD (f-source 15) const32)
 (sequence
 (sequence
   ((SI tmpd))
   ((SI tmpd))
   (set tmpd (or SI Rd const32))
   (set tmpd (or SI Rd const32))
   (set-subreg-gr SI (regno Rd) tmpd)
   (set-subreg-gr SI (regno Rd) tmpd)
   (setf-move SI tmpd))
   (setf-move SI tmpd))
)
)
; ORQ     i,Rd            [ Rd | 001101 | i ]
; ORQ     i,Rd            [ Rd | 001101 | i ]
(dni-cdt
(dni-cdt
 orq "Or quick-immediate to register"
 orq "Or quick-immediate to register"
 "orq $i,$Rd"
 "orq $i,$Rd"
 (+ Rd MODE_QUICK_IMMEDIATE Q_ORQ i)
 (+ Rd MODE_QUICK_IMMEDIATE Q_ORQ i)
 (sequence
 (sequence
   ((SI tmpd))
   ((SI tmpd))
   (set tmpd (or SI Rd i))
   (set tmpd (or SI Rd i))
   (set-subreg-gr SI (regno Rd) tmpd)
   (set-subreg-gr SI (regno Rd) tmpd)
   (setf-move SI tmpd))
   (setf-move SI tmpd))
)
)
; XOR     Rs,Rd           [ Rd | 01111011 | Rs ]
; XOR     Rs,Rd           [ Rd | 01111011 | Rs ]
(dni-cdt
(dni-cdt
 xor "Xor from register to register"
 xor "Xor from register to register"
 "xor $Rs,$Rd"
 "xor $Rs,$Rd"
 (+ Rd MODE_REGISTER RFIX_XOR SIZE_FIXED Rs)
 (+ Rd MODE_REGISTER RFIX_XOR SIZE_FIXED Rs)
 (sequence
 (sequence
   ((SI tmpd))
   ((SI tmpd))
   (set tmpd (xor SI Rd Rs))
   (set tmpd (xor SI Rd Rs))
   (set Rd tmpd)
   (set Rd tmpd)
   (setf-move SI tmpd))
   (setf-move SI tmpd))
)
)
(define-pmacro (swap-r x)
(define-pmacro (swap-r x)
  "Perform bit-wise swap within each byte"
  "Perform bit-wise swap within each byte"
  (sequence
  (sequence
    SI
    SI
    ((SI tmpr))
    ((SI tmpr))
    (set tmpr x)
    (set tmpr x)
    (or (sll (and tmpr #x1010101) 7)
    (or (sll (and tmpr #x1010101) 7)
        (or (sll (and tmpr #x2020202) 5)
        (or (sll (and tmpr #x2020202) 5)
            (or (sll (and tmpr #x4040404) 3)
            (or (sll (and tmpr #x4040404) 3)
                (or (sll (and tmpr #x8080808) 1)
                (or (sll (and tmpr #x8080808) 1)
                    (or (srl (and tmpr #x10101010) 1)
                    (or (srl (and tmpr #x10101010) 1)
                        (or (srl (and tmpr #x20202020) 3)
                        (or (srl (and tmpr #x20202020) 3)
                            (or (srl (and tmpr #x40404040) 5)
                            (or (srl (and tmpr #x40404040) 5)
                                (srl (and tmpr #x80808080) 7)))))))))
                                (srl (and tmpr #x80808080) 7)))))))))
)
)
(define-pmacro (swap-b x)
(define-pmacro (swap-b x)
  "Perform byte-wise swap within each word"
  "Perform byte-wise swap within each word"
  (sequence
  (sequence
    SI
    SI
    ((SI tmpb))
    ((SI tmpb))
    (set tmpb x)
    (set tmpb x)
    (or (and (sll tmpb 8) #xff00ff00)
    (or (and (sll tmpb 8) #xff00ff00)
        (and (srl tmpb 8) #xff00ff)))
        (and (srl tmpb 8) #xff00ff)))
)
)
(define-pmacro (swap-w x)
(define-pmacro (swap-w x)
  "Perform word-wise swap within each dword"
  "Perform word-wise swap within each dword"
  (sequence
  (sequence
    SI
    SI
    ((SI tmpb))
    ((SI tmpb))
    (set tmpb x)
    (set tmpb x)
    (or (and (sll tmpb 16) #xffff0000)
    (or (and (sll tmpb 16) #xffff0000)
        (and (srl tmpb 16) #xffff)))
        (and (srl tmpb 16) #xffff)))
)
)
(define-pmacro (swap-_ x)
(define-pmacro (swap-_ x)
  "Do nothing swap-wise"
  "Do nothing swap-wise"
  (error SI "SWAP without swap modifier isn't implemented")
  (error SI "SWAP without swap modifier isn't implemented")
)
)
(define-pmacro (swap-n x)
(define-pmacro (swap-n x)
  "Perform bitwise not (that is, perform a not, not not perform)"
  "Perform bitwise not (that is, perform a not, not not perform)"
  (inv x)
  (inv x)
)
)
(define-pmacro (swap-br x) "Combine swap-r and swap-b" (swap-r (swap-b x)))
(define-pmacro (swap-br x) "Combine swap-r and swap-b" (swap-r (swap-b x)))
(define-pmacro (swap-wr x) "Combine swap-r and swap-w" (swap-r (swap-w x)))
(define-pmacro (swap-wr x) "Combine swap-r and swap-w" (swap-r (swap-w x)))
(define-pmacro (swap-wb x) "Combine swap-b and swap-w" (swap-b (swap-w x)))
(define-pmacro (swap-wb x) "Combine swap-b and swap-w" (swap-b (swap-w x)))
(define-pmacro (swap-wbr x) "Combine swap-r and swap-wb" (swap-r (swap-wb x)))
(define-pmacro (swap-wbr x) "Combine swap-r and swap-wb" (swap-r (swap-wb x)))
(define-pmacro (swap-nr x) "Combine swap-r and swap-n" (swap-r (swap-n x)))
(define-pmacro (swap-nr x) "Combine swap-r and swap-n" (swap-r (swap-n x)))
(define-pmacro (swap-nb x) "Combine swap-n and swap-b" (swap-b (swap-n x)))
(define-pmacro (swap-nb x) "Combine swap-n and swap-b" (swap-b (swap-n x)))
(define-pmacro (swap-nbr x) "Combine swap-r and swap-nb" (swap-r (swap-nb x)))
(define-pmacro (swap-nbr x) "Combine swap-r and swap-nb" (swap-r (swap-nb x)))
(define-pmacro (swap-nw x) "Combine swap-n and swap-w" (swap-w (swap-n x)))
(define-pmacro (swap-nw x) "Combine swap-n and swap-w" (swap-w (swap-n x)))
(define-pmacro (swap-nwr x) "Combine swap-r and swap-nw" (swap-r (swap-nw x)))
(define-pmacro (swap-nwr x) "Combine swap-r and swap-nw" (swap-r (swap-nw x)))
(define-pmacro (swap-nwb x) "Combine swap-b and swap-nw" (swap-b (swap-nw x)))
(define-pmacro (swap-nwb x) "Combine swap-b and swap-nw" (swap-b (swap-nw x)))
(define-pmacro (swap-nwbr x) "Combine swap-r and swap-nwb" (swap-r (swap-nwb x)))
(define-pmacro (swap-nwbr x) "Combine swap-r and swap-nwb" (swap-r (swap-nwb x)))
(define-pmacro (cris-swap swapcode val)
(define-pmacro (cris-swap swapcode val)
  (sequence
  (sequence
    SI
    SI
    ((SI tmpcode) (SI tmpval) (SI tmpres))
    ((SI tmpcode) (SI tmpval) (SI tmpres))
    (set tmpcode swapcode)
    (set tmpcode swapcode)
    (set tmpval val)
    (set tmpval val)
    (.splice
    (.splice
     cond
     cond
     (.unsplice
     (.unsplice
      (.map
      (.map
       (.pmacro
       (.pmacro
        (x-swapcode x-swap)
        (x-swapcode x-swap)
        ((eq tmpcode x-swapcode)
        ((eq tmpcode x-swapcode)
         (set tmpres ((.sym swap- x-swap) tmpval))))
         (set tmpres ((.sym swap- x-swap) tmpval))))
       (.iota 16)
       (.iota 16)
       (.splice _ (.unsplice cris-swap-codes)))))
       (.splice _ (.unsplice cris-swap-codes)))))
    tmpres)
    tmpres)
)
)
; NOT     Rd              alias for SWAPN Rd
; NOT     Rd              alias for SWAPN Rd
(dni-cdt-attr
(dni-cdt-attr
 not "Not"
 not "Not"
 ((MACH crisv0,crisv3))
 ((MACH crisv0,crisv3))
 "not ${Rs}"
 "not ${Rs}"
 (+ (f-dest 8) RFIX_SWAP MODE_REGISTER SIZE_FIXED Rd-sfield)
 (+ (f-dest 8) RFIX_SWAP MODE_REGISTER SIZE_FIXED Rd-sfield)
 (sequence
 (sequence
   ((SI tmp) (SI tmpd))
   ((SI tmp) (SI tmpd))
   (set tmp Rd-sfield)
   (set tmp Rd-sfield)
   (set tmpd (cris-swap 8 tmp))
   (set tmpd (cris-swap 8 tmp))
   (set Rd-sfield tmpd)
   (set Rd-sfield tmpd)
   (setf-move SI tmpd))
   (setf-move SI tmpd))
)
)
; SWAP
; SWAP
(dni-cdt-attr
(dni-cdt-attr
 swap "Swap"
 swap "Swap"
 ((MACH crisv8,crisv10,crisv32))
 ((MACH crisv8,crisv10,crisv32))
 "swap${swapoption} ${Rs}"
 "swap${swapoption} ${Rs}"
 (+ swapoption RFIX_SWAP MODE_REGISTER SIZE_FIXED Rd-sfield)
 (+ swapoption RFIX_SWAP MODE_REGISTER SIZE_FIXED Rd-sfield)
 (sequence
 (sequence
   ((SI tmps) (SI tmpd))
   ((SI tmps) (SI tmpd))
   (set tmps Rd-sfield)
   (set tmps Rd-sfield)
   (set tmpd (cris-swap swapoption tmps))
   (set tmpd (cris-swap swapoption tmps))
   (set Rd-sfield tmpd)
   (set Rd-sfield tmpd)
   (setf-move SI tmpd))
   (setf-move SI tmpd))
)
)
; ASR.m   Rs,Rd           [ Rd | 011110mm | Rs ]
; ASR.m   Rs,Rd           [ Rd | 011110mm | Rs ]
(dni-cdt-bwd
(dni-cdt-bwd
 asrr "Arithmetic shift right register count"
 asrr "Arithmetic shift right register count"
 "$Rs,$Rd"
 "$Rs,$Rd"
 (+ Rd MODE_REGISTER R_ASR Rs)
 (+ Rd MODE_REGISTER R_ASR Rs)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ((BWD tmpd) (SI cnt1) (SI cnt2))
    ((BWD tmpd) (SI cnt1) (SI cnt2))
    (set cnt1 Rs)
    (set cnt1 Rs)
    (set cnt2 (if SI (ne (and cnt1 32) 0) 31 (and cnt1 31)))
    (set cnt2 (if SI (ne (and cnt1 32) 0) 31 (and cnt1 31)))
    (set tmpd (sra SI (ext SI (trunc BWD Rd)) cnt2))
    (set tmpd (sra SI (ext SI (trunc BWD Rd)) cnt2))
    (set-subreg-gr BWD (regno Rd) tmpd)
    (set-subreg-gr BWD (regno Rd) tmpd)
    (setf-move BWD tmpd)))
    (setf-move BWD tmpd)))
)
)
; ASRQ    c,Rd            [ Rd | 0011101 | c ]
; ASRQ    c,Rd            [ Rd | 0011101 | c ]
(dni-cdt
(dni-cdt
 asrq "Arithmetic shift right quick-immediate count"
 asrq "Arithmetic shift right quick-immediate count"
 "asrq $c,${Rd}"
 "asrq $c,${Rd}"
 (+ Rd Q_ASHQ MODE_QUICK_IMMEDIATE (f-b5 1) c)
 (+ Rd Q_ASHQ MODE_QUICK_IMMEDIATE (f-b5 1) c)
 (sequence
 (sequence
   ((SI tmpd))
   ((SI tmpd))
   (set tmpd (sra Rd c))
   (set tmpd (sra Rd c))
   (set Rd tmpd)
   (set Rd tmpd)
   (setf-move SI tmpd))
   (setf-move SI tmpd))
)
)
; LSR.m   Rs,Rd           [ Rd | 011111mm | Rs ]
; LSR.m   Rs,Rd           [ Rd | 011111mm | Rs ]
(dni-cdt-bwd
(dni-cdt-bwd
 lsrr "Logical shift right register count"
 lsrr "Logical shift right register count"
 "$Rs,$Rd"
 "$Rs,$Rd"
 (+ Rd MODE_REGISTER R_LSR Rs)
 (+ Rd MODE_REGISTER R_LSR Rs)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ((SI tmpd) (SI cnt))
    ((SI tmpd) (SI cnt))
    (set cnt (and Rs 63))
    (set cnt (and Rs 63))
    (set
    (set
     tmpd
     tmpd
     (if SI (ne (and cnt 32) 0)
     (if SI (ne (and cnt 32) 0)
         0
         0
         (srl SI (zext SI (trunc BWD Rd)) (and cnt 31))))
         (srl SI (zext SI (trunc BWD Rd)) (and cnt 31))))
    (set-subreg-gr BWD (regno Rd) tmpd)
    (set-subreg-gr BWD (regno Rd) tmpd)
    (setf-move BWD tmpd)))
    (setf-move BWD tmpd)))
)
)
; LSRQ    c,Rd            [ Rd | 0011111 | c ]
; LSRQ    c,Rd            [ Rd | 0011111 | c ]
(dni-cdt
(dni-cdt
 lsrq "Logical shift right quick-immediate count"
 lsrq "Logical shift right quick-immediate count"
 "lsrq $c,${Rd}"
 "lsrq $c,${Rd}"
 (+ Rd Q_LSHQ MODE_QUICK_IMMEDIATE (f-b5 1) c)
 (+ Rd Q_LSHQ MODE_QUICK_IMMEDIATE (f-b5 1) c)
 (sequence
 (sequence
   ((SI tmpd))
   ((SI tmpd))
   (set tmpd (srl Rd c))
   (set tmpd (srl Rd c))
   (set Rd tmpd)
   (set Rd tmpd)
   (setf-move SI tmpd))
   (setf-move SI tmpd))
)
)
; LSL.m   Rs,Rd           [ Rd | 010011mm | Rs ]
; LSL.m   Rs,Rd           [ Rd | 010011mm | Rs ]
(dni-cdt-bwd
(dni-cdt-bwd
 lslr "Logical shift left register count"
 lslr "Logical shift left register count"
 "$Rs,$Rd"
 "$Rs,$Rd"
 (+ Rd MODE_REGISTER R_LSL Rs)
 (+ Rd MODE_REGISTER R_LSL Rs)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ((SI tmpd) (SI cnt))
    ((SI tmpd) (SI cnt))
    (set cnt (and Rs 63))
    (set cnt (and Rs 63))
    (set
    (set
     tmpd
     tmpd
     (if SI (ne (and cnt 32) 0)
     (if SI (ne (and cnt 32) 0)
         0
         0
         (sll SI (zext SI (trunc BWD Rd)) (and cnt 31))))
         (sll SI (zext SI (trunc BWD Rd)) (and cnt 31))))
    (set-subreg-gr BWD (regno Rd) tmpd)
    (set-subreg-gr BWD (regno Rd) tmpd)
    (setf-move BWD tmpd)))
    (setf-move BWD tmpd)))
)
)
; LSLQ    c,Rd            [ Rd | 0011110 | c ]
; LSLQ    c,Rd            [ Rd | 0011110 | c ]
(dni-cdt
(dni-cdt
 lslq "Logical shift left quick-immediate count"
 lslq "Logical shift left quick-immediate count"
 "lslq $c,${Rd}"
 "lslq $c,${Rd}"
 (+ Rd Q_LSHQ MODE_QUICK_IMMEDIATE (f-b5 0) c)
 (+ Rd Q_LSHQ MODE_QUICK_IMMEDIATE (f-b5 0) c)
 (sequence
 (sequence
   ((SI tmpd))
   ((SI tmpd))
   (set tmpd (sll Rd c))
   (set tmpd (sll Rd c))
   (set Rd tmpd)
   (set Rd tmpd)
   (setf-move SI tmpd))
   (setf-move SI tmpd))
)
)
; BTST    Rs,Rd           [ Rd | 01001111 | Rs ]
; BTST    Rs,Rd           [ Rd | 01001111 | Rs ]
(dni-cdt
(dni-cdt
 btst "Bit test register number"
 btst "Bit test register number"
 "$Rs,$Rd"
 "$Rs,$Rd"
 (+ Rd MODE_REGISTER RFIX_BTST SIZE_FIXED Rs)
 (+ Rd MODE_REGISTER RFIX_BTST SIZE_FIXED Rs)
 (sequence
 (sequence
   ((SI tmpd) (SI cnt))
   ((SI tmpd) (SI cnt))
   (set tmpd (sll Rd (sub 31 (and Rs 31))))
   (set tmpd (sll Rd (sub 31 (and Rs 31))))
   (setf-move SI tmpd))
   (setf-move SI tmpd))
)
)
; BTSTQ   c,Rd            [ Rd | 0011100 | c ]
; BTSTQ   c,Rd            [ Rd | 0011100 | c ]
(dni-cdt
(dni-cdt
 btstq "Bit test quick-immediate number"
 btstq "Bit test quick-immediate number"
 "btstq $c,${Rd}"
 "btstq $c,${Rd}"
 (+ Rd Q_ASHQ MODE_QUICK_IMMEDIATE (f-b5 0) c)
 (+ Rd Q_ASHQ MODE_QUICK_IMMEDIATE (f-b5 0) c)
 (sequence
 (sequence
   ((SI tmpd))
   ((SI tmpd))
   (set tmpd (sll Rd (sub 31 c)))
   (set tmpd (sll Rd (sub 31 c)))
   (setf-move SI tmpd))
   (setf-move SI tmpd))
)
)
; SETF     [ P U I X | 01011011 | N Z V C ]
; SETF     [ P U I X | 01011011 | N Z V C ]
(dni-cdt
(dni-cdt
 setf "Set condition code flags explicitly"
 setf "Set condition code flags explicitly"
 "setf ${list-of-flags}"
 "setf ${list-of-flags}"
 ; The zero-flags case gets flag operands wrong; there's a "_"
 ; The zero-flags case gets flag operands wrong; there's a "_"
 ; where there should have been nothing.  Also, flags are in
 ; where there should have been nothing.  Also, flags are in
 ; assembly code allowed to be specified in any order, which
 ; assembly code allowed to be specified in any order, which
 ; doesn't match the "flagbits" settings.  Luckily we don't
 ; doesn't match the "flagbits" settings.  Luckily we don't
 ; use this field for assembly.
 ; use this field for assembly.
 (+ RFIX_SETF MODE_REGISTER SIZE_FIXED list-of-flags)
 (+ RFIX_SETF MODE_REGISTER SIZE_FIXED list-of-flags)
 (.splice
 (.splice
  sequence
  sequence
  ((SI tmp))
  ((SI tmp))
  (set tmp list-of-flags)
  (set tmp list-of-flags)
  (.unsplice
  (.unsplice
   (.map
   (.map
    (.pmacro (ccbit)
    (.pmacro (ccbit)
             (if (ne (and tmp (sll 1 (.sym ccbit -bitnumber))) 0)
             (if (ne (and tmp (sll 1 (.sym ccbit -bitnumber))) 0)
                 (set (.sym ccbit bit) 1)))
                 (set (.sym ccbit bit) 1)))
    cris-flagnames))
    cris-flagnames))
   (set prefix-set 0)
   (set prefix-set 0)
   ; Unless x was specified to be set, set it to 0.
   ; Unless x was specified to be set, set it to 0.
   (if (eq (and tmp (sll 1 x-bitnumber)) 0)
   (if (eq (and tmp (sll 1 x-bitnumber)) 0)
       (set xbit 0)))
       (set xbit 0)))
)
)
; CLEARF   [ P U I X | 01011111 | N Z V C ]
; CLEARF   [ P U I X | 01011111 | N Z V C ]
(dni-cdt
(dni-cdt
 clearf "Clear condition code flags explicitly"
 clearf "Clear condition code flags explicitly"
 "clearf ${list-of-flags}"
 "clearf ${list-of-flags}"
 ; The zero-flags case gets flag operands wrong; there's a "_"
 ; The zero-flags case gets flag operands wrong; there's a "_"
 ; where there should have been nothing.  Also, flags are in
 ; where there should have been nothing.  Also, flags are in
 ; assembly code allowed to be specified in any order, which
 ; assembly code allowed to be specified in any order, which
 ; doesn't match the "flagbits" settings.  Luckily we don't
 ; doesn't match the "flagbits" settings.  Luckily we don't
 ; use this field for assembly.
 ; use this field for assembly.
 (+ RFIX_CLEARF MODE_REGISTER SIZE_FIXED list-of-flags)
 (+ RFIX_CLEARF MODE_REGISTER SIZE_FIXED list-of-flags)
 (.splice
 (.splice
  sequence
  sequence
  ((SI tmp))
  ((SI tmp))
  (set tmp list-of-flags)
  (set tmp list-of-flags)
  (.unsplice
  (.unsplice
   (.map
   (.map
    (.pmacro (ccbit)
    (.pmacro (ccbit)
             (if (ne (and tmp (sll 1 (.sym ccbit -bitnumber))) 0)
             (if (ne (and tmp (sll 1 (.sym ccbit -bitnumber))) 0)
                 (set (.sym ccbit bit) 0)))
                 (set (.sym ccbit bit) 0)))
    cris-flagnames))
    cris-flagnames))
   (reset-x-p))
   (reset-x-p))
)
)
(define-pmacro
(define-pmacro
  (rfe-rfn-guts)
  (rfe-rfn-guts)
  "Common parts of RFE and RFN"
  "Common parts of RFE and RFN"
  (sequence
  (sequence
    ((USI oldccs) (USI samebits) (USI shiftbits) (USI keepmask) (BI p1))
    ((USI oldccs) (USI samebits) (USI shiftbits) (USI keepmask) (BI p1))
    (set oldccs ccs)
    (set oldccs ccs)
    ; Keeping U, S and I in user mode is handled by the CCS setter, so we
    ; Keeping U, S and I in user mode is handled by the CCS setter, so we
    ; don't have to bother.  Actually Q and M are handled too.  The reason
    ; don't have to bother.  Actually Q and M are handled too.  The reason
    ; to mask those out is to not have them shifted down into the second
    ; to mask those out is to not have them shifted down into the second
    ; flags level.
    ; flags level.
    (set keepmask #xc0000000)
    (set keepmask #xc0000000)
    (set samebits (and oldccs keepmask))
    (set samebits (and oldccs keepmask))
    ; The P bit has its own equation.
    ; The P bit has its own equation.
    (set shiftbits (and (srl (and oldccs #x3ffdfc00) 10) (inv keepmask)))
    (set shiftbits (and (srl (and oldccs #x3ffdfc00) 10) (inv keepmask)))
    (set p1 (ne 0 (and oldccs #x20000)))
    (set p1 (ne 0 (and oldccs #x20000)))
    (set ccs (or (or samebits shiftbits)
    (set ccs (or (or samebits shiftbits)
                 (if SI (and rbit (not p1)) 0 #x80))))
                 (if SI (and rbit (not p1)) 0 #x80))))
)
)
; RFE                     [ 0010 10010011 0000 ]
; RFE                     [ 0010 10010011 0000 ]
(dni-cdt-attr
(dni-cdt-attr
 rfe
 rfe
 "RFE"
 "RFE"
 (MACH-V32)
 (MACH-V32)
 "rfe"
 "rfe"
 (+ (f-dest 2) MODE_INDIRECT INFIX_RFE SIZE_FIXED (f-source 0))
 (+ (f-dest 2) MODE_INDIRECT INFIX_RFE SIZE_FIXED (f-source 0))
 (rfe-rfn-guts)
 (rfe-rfn-guts)
)
)
; SFE                     [ 0011 10010011 0000 ]
; SFE                     [ 0011 10010011 0000 ]
(dni-cdt-attr
(dni-cdt-attr
 sfe
 sfe
 "SFE"
 "SFE"
 (MACH-V32)
 (MACH-V32)
 "sfe"
 "sfe"
 (+ (f-dest 3) MODE_INDIRECT INFIX_SFE SIZE_FIXED (f-source 0))
 (+ (f-dest 3) MODE_INDIRECT INFIX_SFE SIZE_FIXED (f-source 0))
 (sequence
 (sequence
   ((SI oldccs) (SI savemask))
   ((SI oldccs) (SI savemask))
   (set savemask #xc0000000)
   (set savemask #xc0000000)
   (set oldccs ccs)
   (set oldccs ccs)
   (set ccs
   (set ccs
        (or (and savemask oldccs)
        (or (and savemask oldccs)
            (and (inv savemask) (sll oldccs 10)))))
            (and (inv savemask) (sll oldccs 10)))))
)
)
; RFG                     [ 0100 10010011 0000 ]
; RFG                     [ 0100 10010011 0000 ]
(dni-cdt-attr
(dni-cdt-attr
 rfg
 rfg
 "RFG"
 "RFG"
 (MACH-V32)
 (MACH-V32)
 "rfg"
 "rfg"
 (+ (f-dest 4) MODE_INDIRECT INFIX_RFG SIZE_FIXED (f-source 0))
 (+ (f-dest 4) MODE_INDIRECT INFIX_RFG SIZE_FIXED (f-source 0))
 (c-call VOID "@cpu@_rfg_handler" pc)
 (c-call VOID "@cpu@_rfg_handler" pc)
)
)
; RFN                     [ 0101 10010011 0000 ]
; RFN                     [ 0101 10010011 0000 ]
(dni-cdt-attr
(dni-cdt-attr
 rfn
 rfn
 "RFN"
 "RFN"
 (MACH-V32)
 (MACH-V32)
 "rfn"
 "rfn"
 (+ (f-dest 5) MODE_INDIRECT INFIX_RFN SIZE_FIXED (f-source 0))
 (+ (f-dest 5) MODE_INDIRECT INFIX_RFN SIZE_FIXED (f-source 0))
 (sequence () (rfe-rfn-guts) (set mbit 1))
 (sequence () (rfe-rfn-guts) (set mbit 1))
)
)
; HALT                     [ 1111 10010011 0000 ]
; HALT                     [ 1111 10010011 0000 ]
(dni-cdt-attr
(dni-cdt-attr
 halt
 halt
 "HALT"
 "HALT"
 (MACH-V32)
 (MACH-V32)
 "halt"
 "halt"
 (+ (f-dest 15) MODE_INDIRECT INFIX_HALT SIZE_FIXED (f-source 0))
 (+ (f-dest 15) MODE_INDIRECT INFIX_HALT SIZE_FIXED (f-source 0))
 (set pc (c-call USI "@cpu@_halt_handler" pc))
 (set pc (c-call USI "@cpu@_halt_handler" pc))
)
)
; Bcc     o               [ cc | 0000 | o ]
; Bcc     o               [ cc | 0000 | o ]
(dni
(dni
 bcc-b "bcc byte operand"
 bcc-b "bcc byte operand"
 ()
 ()
 "b${cc} ${o-pcrel}"
 "b${cc} ${o-pcrel}"
 (+ cc QHI_BCC MODE_QUICK_IMMEDIATE o-pcrel)
 (+ cc QHI_BCC MODE_QUICK_IMMEDIATE o-pcrel)
 (sequence
 (sequence
   ((BI truthval))
   ((BI truthval))
   (set truthval (cris-condition cc))
   (set truthval (cris-condition cc))
   ; Amazing as it may seem, there's no simpler way to find out
   ; Amazing as it may seem, there's no simpler way to find out
   ; whether a branch is taken or not than to mark it through a kludge
   ; whether a branch is taken or not than to mark it through a kludge
   ; like this.
   ; like this.
   (c-call VOID "@cpu@_branch_taken" pc o-pcrel truthval)
   (c-call VOID "@cpu@_branch_taken" pc o-pcrel truthval)
   (reset-x-p)
   (reset-x-p)
   (if truthval
   (if truthval
       (delay 1
       (delay 1
              (set pc o-pcrel))))
              (set pc o-pcrel))))
 (.splice (.unsplice (simplecris-timing))
 (.splice (.unsplice (simplecris-timing))
          (crisv32 (unit u-branch) (unit u-exec)))
          (crisv32 (unit u-branch) (unit u-exec)))
)
)
(dni
(dni
 ba-b "ba byte operand"
 ba-b "ba byte operand"
 ()
 ()
 "ba ${o-pcrel}"
 "ba ${o-pcrel}"
 (+ (f-dest 14) QHI_BCC MODE_QUICK_IMMEDIATE o-pcrel)
 (+ (f-dest 14) QHI_BCC MODE_QUICK_IMMEDIATE o-pcrel)
 (sequence
 (sequence
   ()
   ()
   (reset-x-p)
   (reset-x-p)
   (delay 1
   (delay 1
          (set pc o-pcrel)))
          (set pc o-pcrel)))
 ((crisv32 (unit u-jump) (unit u-exec)))
 ((crisv32 (unit u-jump) (unit u-exec)))
)
)
; Bcc     [PC+]           [ cc | 11011111 1111 ]
; Bcc     [PC+]           [ cc | 11011111 1111 ]
; (We don't implement the generic for pre-V32 but unused variant
; (We don't implement the generic for pre-V32 but unused variant
; "Bcc [Rn(+)]" where n != 15.)
; "Bcc [Rn(+)]" where n != 15.)
(dni
(dni
 bcc-w "bcc, word operand"
 bcc-w "bcc, word operand"
 ()
 ()
 "b${cc} ${o-word-pcrel}"
 "b${cc} ${o-word-pcrel}"
 (+ cc MODE_AUTOINCREMENT INFIX_BCC_M SIZE_FIXED (f-source 15) o-word-pcrel)
 (+ cc MODE_AUTOINCREMENT INFIX_BCC_M SIZE_FIXED (f-source 15) o-word-pcrel)
 (sequence
 (sequence
   ((BI truthval))
   ((BI truthval))
   (set truthval (cris-condition cc))
   (set truthval (cris-condition cc))
   ; Amazing as it may seem, there's no simpler way to find out
   ; Amazing as it may seem, there's no simpler way to find out
   ; whether a branch is taken or not than to mark it through a kludge
   ; whether a branch is taken or not than to mark it through a kludge
   ; like this.
   ; like this.
   (c-call VOID "@cpu@_branch_taken" pc o-word-pcrel truthval)
   (c-call VOID "@cpu@_branch_taken" pc o-word-pcrel truthval)
   (reset-x-p)
   (reset-x-p)
   (if truthval
   (if truthval
       (delay 1
       (delay 1
              (set pc o-word-pcrel))))
              (set pc o-word-pcrel))))
 (.splice
 (.splice
  (.unsplice (simplecris-common-timing ((unit u-const16) (unit u-exec))))
  (.unsplice (simplecris-common-timing ((unit u-const16) (unit u-exec))))
  (crisv32 (unit u-const16) (unit u-branch) (unit u-exec)))
  (crisv32 (unit u-const16) (unit u-branch) (unit u-exec)))
)
)
(dni
(dni
 ba-w "ba word operand"
 ba-w "ba word operand"
 ()
 ()
 "ba ${o-word-pcrel}"
 "ba ${o-word-pcrel}"
 (+ (f-dest 14) MODE_AUTOINCREMENT INFIX_BCC_M SIZE_FIXED (f-source 15) o-word-pcrel)
 (+ (f-dest 14) MODE_AUTOINCREMENT INFIX_BCC_M SIZE_FIXED (f-source 15) o-word-pcrel)
 (sequence
 (sequence
   ()
   ()
   (reset-x-p)
   (reset-x-p)
   (delay 1
   (delay 1
          (set pc o-word-pcrel)))
          (set pc o-word-pcrel)))
 (.splice
 (.splice
  (.unsplice (simplecris-common-timing ((unit u-const16) (unit u-exec))))
  (.unsplice (simplecris-common-timing ((unit u-const16) (unit u-exec))))
  (crisv32 (unit u-const16) (unit u-jump) (unit u-exec)))
  (crisv32 (unit u-const16) (unit u-jump) (unit u-exec)))
)
)
; JAS     Rs,Pd           [ Pd | 10011011 | Rs ]
; JAS     Rs,Pd           [ Pd | 10011011 | Rs ]
(dni
(dni
 jas-r "JAS register"
 jas-r "JAS register"
 (MACH-V32)
 (MACH-V32)
 "jas ${Rs},${Pd}"
 "jas ${Rs},${Pd}"
 (+ Pd MODE_INDIRECT INFIX_JAS_R SIZE_FIXED Rs)
 (+ Pd MODE_INDIRECT INFIX_JAS_R SIZE_FIXED Rs)
 (sequence
 (sequence
   ()
   ()
   (reset-x-p)
   (reset-x-p)
   (if (andif (eq (regno Rs) 1) (eq (regno Pd) 11))
   (if (andif (eq (regno Rs) 1) (eq (regno Pd) 11))
       ; We use this as a trigger; a normally reasonably rare instruction
       ; We use this as a trigger; a normally reasonably rare instruction
       ; used in the v32 trampoline.  See comment at bdapqpc.
       ; used in the v32 trampoline.  See comment at bdapqpc.
       ; CGEN-FIXME: can't use (regno srp) [== (regno (reg h-sr 11))]
       ; CGEN-FIXME: can't use (regno srp) [== (regno (reg h-sr 11))]
       (c-call VOID "cris_flush_simulator_decode_cache" pc))
       (c-call VOID "cris_flush_simulator_decode_cache" pc))
   (delay 1
   (delay 1
          (sequence
          (sequence
            ()
            ()
            (set Pd (add SI pc 4))
            (set Pd (add SI pc 4))
            (set pc Rs))))
            (set pc Rs))))
 ((crisv32 (unit u-jump-r) (unit u-jump) (unit u-exec)))
 ((crisv32 (unit u-jump-r) (unit u-jump) (unit u-exec)))
)
)
; Same semantics in pre-V32, except no delay-slot.
; Same semantics in pre-V32, except no delay-slot.
; FIXME: Missing JIRC/JSRC/JBRC.
; FIXME: Missing JIRC/JSRC/JBRC.
(dni-cdt-attr
(dni-cdt-attr
 jump-r "JUMP/JSR/JIR register"
 jump-r "JUMP/JSR/JIR register"
 (MACH-PC)
 (MACH-PC)
 "jump/jsr/jir ${Rs}"
 "jump/jsr/jir ${Rs}"
 (+ Pd MODE_INDIRECT INFIX_JUMP_R SIZE_FIXED Rs)
 (+ Pd MODE_INDIRECT INFIX_JUMP_R SIZE_FIXED Rs)
 (sequence
 (sequence
   ()
   ()
   (set Pd (add SI pc 2))
   (set Pd (add SI pc 2))
   (set pc Rs)
   (set pc Rs)
   (reset-x-p))
   (reset-x-p))
)
)
; JAS     [PC+],Pd        [ Pd | 11011011 1111 ]
; JAS     [PC+],Pd        [ Pd | 11011011 1111 ]
(dni
(dni
 jas-c "JAS constant"
 jas-c "JAS constant"
 (MACH-V32)
 (MACH-V32)
 "jas ${const32},${Pd}"
 "jas ${const32},${Pd}"
 (+ Pd MODE_AUTOINCREMENT INFIX_JAS_M SIZE_FIXED (f-source 15) const32)
 (+ Pd MODE_AUTOINCREMENT INFIX_JAS_M SIZE_FIXED (f-source 15) const32)
 (sequence
 (sequence
   ()
   ()
   (reset-x-p)
   (reset-x-p)
   (delay 1
   (delay 1
          (sequence
          (sequence
            ()
            ()
            (set Pd (add SI pc 8))
            (set Pd (add SI pc 8))
            (set pc const32))))
            (set pc const32))))
 ((crisv32 (unit u-const32) (unit u-jump) (unit u-exec)))
 ((crisv32 (unit u-const32) (unit u-jump) (unit u-exec)))
)
)
;        JUMP/JSR/JIR  | Special r.| 1  m| 0  1  0  0| 1  1| Source    |
;        JUMP/JSR/JIR  | Special r.| 1  m| 0  1  0  0| 1  1| Source    |
(dni-cmt-attr
(dni-cmt-attr
 jump-m "JUMP/JSR/JIR memory"
 jump-m "JUMP/JSR/JIR memory"
 (MACH-PC)
 (MACH-PC)
 "jump/jsr/jir [${Rs}${inc}]"
 "jump/jsr/jir [${Rs}${inc}]"
 (+ Pd INFIX_JUMP_M SIZE_FIXED Rs)
 (+ Pd INFIX_JUMP_M SIZE_FIXED Rs)
 (sequence
 (sequence
   ()
   ()
   (set Pd (add SI pc 2))
   (set Pd (add SI pc 2))
   (set pc (cris-get-mem SI Rs))
   (set pc (cris-get-mem SI Rs))
   (reset-x-p))
   (reset-x-p))
)
)
(dni-c-SI-attr
(dni-c-SI-attr
 jump-c "JUMP/JSR/JIR constant"
 jump-c "JUMP/JSR/JIR constant"
 (MACH-PC)
 (MACH-PC)
 "jump/jsr/jir ${const32}"
 "jump/jsr/jir ${const32}"
 (+ Pd MODE_AUTOINCREMENT INFIX_JUMP_M SIZE_FIXED (f-source 15) const32)
 (+ Pd MODE_AUTOINCREMENT INFIX_JUMP_M SIZE_FIXED (f-source 15) const32)
 (sequence
 (sequence
   ()
   ()
   (set Pd (add SI pc 6))
   (set Pd (add SI pc 6))
   (set pc const32)
   (set pc const32)
   (reset-x-p))
   (reset-x-p))
)
)
; JUMP    Ps              [ Ps | 10011111 0000 ]
; JUMP    Ps              [ Ps | 10011111 0000 ]
(dni
(dni
 jump-p "JUMP special register"
 jump-p "JUMP special register"
 (MACH-V32)
 (MACH-V32)
 "jump ${Ps}"
 "jump ${Ps}"
 (+ Ps MODE_INDIRECT INFIX_JUMP_P SIZE_FIXED (f-source 0))
 (+ Ps MODE_INDIRECT INFIX_JUMP_P SIZE_FIXED (f-source 0))
 (sequence
 (sequence
   ()
   ()
   (reset-x-p)
   (reset-x-p)
   (delay 1
   (delay 1
          (set pc Ps)))
          (set pc Ps)))
 ((crisv32 (unit u-jump-sr)
 ((crisv32 (unit u-jump-sr)
           (unit u-exec)))
           (unit u-exec)))
)
)
; BAS     [PC+],Pd        [ Pd | 11101011 1111 ]
; BAS     [PC+],Pd        [ Pd | 11101011 1111 ]
(dni
(dni
 bas-c "BAS constant"
 bas-c "BAS constant"
 (MACH-V32)
 (MACH-V32)
 "bas ${const32},${Pd}"
 "bas ${const32},${Pd}"
 (+ Pd MODE_AUTOINCREMENT INFIX_BAS SIZE_FIXED (f-source 15) const32-pcrel)
 (+ Pd MODE_AUTOINCREMENT INFIX_BAS SIZE_FIXED (f-source 15) const32-pcrel)
 (sequence
 (sequence
   ()
   ()
   (reset-x-p)
   (reset-x-p)
   (delay 1
   (delay 1
          (sequence
          (sequence
            ()
            ()
            (set Pd (add SI pc 8))
            (set Pd (add SI pc 8))
            (set pc const32-pcrel))))
            (set pc const32-pcrel))))
 ((crisv32 (unit u-const32) (unit u-jump) (unit u-exec)))
 ((crisv32 (unit u-const32) (unit u-jump) (unit u-exec)))
)
)
; JASC    Rs,Pd           [ Pd | 10110011 | Rs ]
; JASC    Rs,Pd           [ Pd | 10110011 | Rs ]
(dni
(dni
 jasc-r "JASC register"
 jasc-r "JASC register"
 (MACH-V32)
 (MACH-V32)
 "jasc ${Rs},${Pd}"
 "jasc ${Rs},${Pd}"
 (+ Pd MODE_INDIRECT INFIX_JASC SIZE_FIXED Rs)
 (+ Pd MODE_INDIRECT INFIX_JASC SIZE_FIXED Rs)
 (sequence
 (sequence
   ()
   ()
   (reset-x-p)
   (reset-x-p)
   (delay 1
   (delay 1
          (sequence
          (sequence
            ()
            ()
            (set Pd (add SI pc 8))
            (set Pd (add SI pc 8))
            (set pc Rs))))
            (set pc Rs))))
 ((crisv32 (unit u-jump-r) (unit u-skip4) (unit u-jump) (unit u-exec)))
 ((crisv32 (unit u-jump-r) (unit u-skip4) (unit u-jump) (unit u-exec)))
)
)
; JASC    [PC+],Pd        [ Pd | 11110011 1111 ]
; JASC    [PC+],Pd        [ Pd | 11110011 1111 ]
(dni
(dni
 jasc-c "JASC constant"
 jasc-c "JASC constant"
 (MACH-V32)
 (MACH-V32)
 "jasc ${const32},${Pd}"
 "jasc ${const32},${Pd}"
 (+ Pd MODE_AUTOINCREMENT INFIX_JASC SIZE_FIXED (f-source 15) const32)
 (+ Pd MODE_AUTOINCREMENT INFIX_JASC SIZE_FIXED (f-source 15) const32)
 (sequence
 (sequence
   ()
   ()
   (reset-x-p)
   (reset-x-p)
   (delay 1
   (delay 1
          (sequence
          (sequence
            ()
            ()
            (set Pd (add SI pc 12))
            (set Pd (add SI pc 12))
            (set pc const32))))
            (set pc const32))))
 ((crisv32 (unit u-const32) (unit u-skip4) (unit u-jump) (unit u-exec)))
 ((crisv32 (unit u-const32) (unit u-skip4) (unit u-jump) (unit u-exec)))
)
)
; BASC    [PC+],Pd        [ Pd | 11101111 1111 ]
; BASC    [PC+],Pd        [ Pd | 11101111 1111 ]
(dni
(dni
 basc-c "BASC constant"
 basc-c "BASC constant"
 (MACH-V32)
 (MACH-V32)
 "basc ${const32},${Pd}"
 "basc ${const32},${Pd}"
 (+ Pd MODE_AUTOINCREMENT INFIX_BASC SIZE_FIXED (f-source 15) const32-pcrel)
 (+ Pd MODE_AUTOINCREMENT INFIX_BASC SIZE_FIXED (f-source 15) const32-pcrel)
 (sequence
 (sequence
   ()
   ()
   (reset-x-p)
   (reset-x-p)
   (delay 1
   (delay 1
          (sequence
          (sequence
            ()
            ()
            (set Pd (add SI pc 12))
            (set Pd (add SI pc 12))
            (set pc const32-pcrel))))
            (set pc const32-pcrel))))
 ((crisv32 (unit u-const32) (unit u-skip4) (unit u-jump) (unit u-exec)))
 ((crisv32 (unit u-const32) (unit u-skip4) (unit u-jump) (unit u-exec)))
)
)
; BREAK     n             [ 1110 | 10010011 | n ]
; BREAK     n             [ 1110 | 10010011 | n ]
(dni-cdt
(dni-cdt
 break "break"
 break "break"
 "break $n"
 "break $n"
 (+ (f-operand2 #xe) MODE_INDIRECT INFIX_BREAK SIZE_FIXED n)
 (+ (f-operand2 #xe) MODE_INDIRECT INFIX_BREAK SIZE_FIXED n)
 (sequence () (reset-x-p) (set pc (c-call USI "@cpu@_break_handler" n pc)))
 (sequence () (reset-x-p) (set pc (c-call USI "@cpu@_break_handler" n pc)))
)
)
; BOUND.m Rs,Rd           [ Rd | 010111mm | Rs ]
; BOUND.m Rs,Rd           [ Rd | 010111mm | Rs ]
(dni-cdt-bwd
(dni-cdt-bwd
 bound-r "Bound register"
 bound-r "Bound register"
 "${Rs},${Rd}"
 "${Rs},${Rd}"
 (+ Rd R_BOUND MODE_REGISTER Rs)
 (+ Rd R_BOUND MODE_REGISTER Rs)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ((SI tmpopd) (SI tmpops) (SI newval))
    ((SI tmpopd) (SI tmpops) (SI newval))
    (set tmpops ((.sym BWD -zext) (trunc BWD Rs)))
    (set tmpops ((.sym BWD -zext) (trunc BWD Rs)))
    (set tmpopd Rd)
    (set tmpopd Rd)
    (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
    (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
    (set Rd newval)
    (set Rd newval)
    (setf-move SI newval)))
    (setf-move SI newval)))
)
)
; BOUND.m [Rs],Rd         [ Rd | 100111mm | Rs ]
; BOUND.m [Rs],Rd         [ Rd | 100111mm | Rs ]
; BOUND.m [Rs+],Rd        [ Rd | 110111mm | Rs ]
; BOUND.m [Rs+],Rd        [ Rd | 110111mm | Rs ]
(dni-cmt-bwd-attr
(dni-cmt-bwd-attr
 bound-m "Bound memory"
 bound-m "Bound memory"
 (MACH-PRE-V32)
 (MACH-PRE-V32)
 "[${Rs}${inc}],${Rd}"
 "[${Rs}${inc}],${Rd}"
 (+ Rd INDIR_BOUND Rs)
 (+ Rd INDIR_BOUND Rs)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ((SI tmpopd) (SI tmpops) (SI newval))
    ((SI tmpopd) (SI tmpops) (SI newval))
    (set tmpops ((.sym BWD -zext) (cris-get-mem BWD Rs)))
    (set tmpops ((.sym BWD -zext) (cris-get-mem BWD Rs)))
    (set tmpopd Rd)
    (set tmpopd Rd)
    (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
    (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
    (if (andif prefix-set (not inc))
    (if (andif prefix-set (not inc))
        (set Rs newval)
        (set Rs newval)
        (set Rd newval))
        (set Rd newval))
    (setf-move SI newval)))
    (setf-move SI newval)))
)
)
; (BOUND.m [PC+],Rd        [ Rd | 110111mm | 1111 ])
; (BOUND.m [PC+],Rd        [ Rd | 110111mm | 1111 ])
(dni-c-QI
(dni-c-QI
 bound-cb "Bound constant byte"
 bound-cb "Bound constant byte"
 "bound.b [PC+],${Rd}"
 "bound.b [PC+],${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_BOUND SIZE_BYTE (f-source 15) uconst8)
 (+ Rd MODE_AUTOINCREMENT INDIR_BOUND SIZE_BYTE (f-source 15) uconst8)
 (sequence
 (sequence
   ((SI tmpopd) (SI tmpops) (SI newval))
   ((SI tmpopd) (SI tmpops) (SI newval))
   (set tmpops (zext SI (trunc QI uconst8)))
   (set tmpops (zext SI (trunc QI uconst8)))
    (set tmpopd Rd)
    (set tmpopd Rd)
    (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
    (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
    (set Rd newval)
    (set Rd newval)
    (setf-move SI newval))
    (setf-move SI newval))
)
)
(dni-c-HI
(dni-c-HI
 bound-cw "Bound constant word"
 bound-cw "Bound constant word"
 "bound.w [PC+],${Rd}"
 "bound.w [PC+],${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_BOUND SIZE_WORD (f-source 15) uconst16)
 (+ Rd MODE_AUTOINCREMENT INDIR_BOUND SIZE_WORD (f-source 15) uconst16)
 (sequence
 (sequence
   ((SI tmpopd) (SI tmpops) (SI newval))
   ((SI tmpopd) (SI tmpops) (SI newval))
   (set tmpops (zext SI uconst16))
   (set tmpops (zext SI uconst16))
    (set tmpopd Rd)
    (set tmpopd Rd)
    (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
    (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
    (set Rd newval)
    (set Rd newval)
    (setf-move SI newval))
    (setf-move SI newval))
)
)
(dni-c-SI
(dni-c-SI
 bound-cd "Bound constant dword"
 bound-cd "Bound constant dword"
 "bound.d [PC+],${Rd}"
 "bound.d [PC+],${Rd}"
 (+ Rd MODE_AUTOINCREMENT INDIR_BOUND SIZE_DWORD (f-source 15) const32)
 (+ Rd MODE_AUTOINCREMENT INDIR_BOUND SIZE_DWORD (f-source 15) const32)
 (sequence
 (sequence
   ((SI tmpopd) (SI tmpops) (SI newval))
   ((SI tmpopd) (SI tmpops) (SI newval))
   (set tmpops const32)
   (set tmpops const32)
    (set tmpopd Rd)
    (set tmpopd Rd)
    (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
    (set newval (if SI (ltu tmpops tmpopd) tmpops tmpopd))
    (set Rd newval)
    (set Rd newval)
    (setf-move SI newval))
    (setf-move SI newval))
)
)
; Scc     Rd              [ cc | 01010011 | Rd ]
; Scc     Rd              [ cc | 01010011 | Rd ]
(dni-cdt
(dni-cdt
 scc "scc"
 scc "scc"
 "s${cc} ${Rd-sfield}"
 "s${cc} ${Rd-sfield}"
 (+ cc MODE_REGISTER RFIX_SCC SIZE_FIXED Rd-sfield)
 (+ cc MODE_REGISTER RFIX_SCC SIZE_FIXED Rd-sfield)
 (sequence
 (sequence
   ((BI truthval))
   ((BI truthval))
   (set truthval (cris-condition cc))
   (set truthval (cris-condition cc))
   (set Rd-sfield (zext SI truthval))
   (set Rd-sfield (zext SI truthval))
   (reset-x-p))
   (reset-x-p))
)
)
; LZ      Rs,Rd           [ Rd | 01110011 | Rs ]
; LZ      Rs,Rd           [ Rd | 01110011 | Rs ]
(dni-cdt-attr
(dni-cdt-attr
 lz "lz"
 lz "lz"
 (MACH-V3-UP)
 (MACH-V3-UP)
 "lz ${Rs},${Rd}"
 "lz ${Rs},${Rd}"
 (+ Rd MODE_REGISTER RFIX_LZ SIZE_FIXED Rs)
 (+ Rd MODE_REGISTER RFIX_LZ SIZE_FIXED Rs)
 (sequence
 (sequence
   ((SI tmpd) (SI tmp))
   ((SI tmpd) (SI tmp))
   (set tmp Rs)
   (set tmp Rs)
   (set tmpd 0)
   (set tmpd 0)
   (.splice
   (.splice
    sequence
    sequence
    ()
    ()
    (.unsplice
    (.unsplice
     (.map
     (.map
      (.pmacro (n)
      (.pmacro (n)
               (if (ge tmp 0)
               (if (ge tmp 0)
                   (sequence
                   (sequence
                     ()
                     ()
                     (set tmp (sll tmp 1))
                     (set tmp (sll tmp 1))
                     (set tmpd (add tmpd 1)))))
                     (set tmpd (add tmpd 1)))))
      (.iota 32))))
      (.iota 32))))
   (set Rd tmpd)
   (set Rd tmpd)
   (setf-move SI tmpd))
   (setf-move SI tmpd))
)
)
; ADDOQ   o,Rs,ACR        [ Rs | 0001 | o ]
; ADDOQ   o,Rs,ACR        [ Rs | 0001 | o ]
(dni-cdt
(dni-cdt
 addoq "addoq"
 addoq "addoq"
 "addoq $o,$Rs,ACR"
 "addoq $o,$Rs,ACR"
 (+ Rs-dfield MODE_QUICK_IMMEDIATE QHI_ADDOQ o)
 (+ Rs-dfield MODE_QUICK_IMMEDIATE QHI_ADDOQ o)
 (sequence
 (sequence
   ()
   ()
   (set prefixreg (add SI Rs-dfield o))
   (set prefixreg (add SI Rs-dfield o))
   (set prefix-set 1))
   (set prefix-set 1))
)
)
; (BDAPQ   o,PC        [ 1111 | 0001 | o ])
; (BDAPQ   o,PC        [ 1111 | 0001 | o ])
; This [PC+I] prefix is used in trampolines.
; This [PC+I] prefix is used in trampolines.
(dni-cdt-attr
(dni-cdt-attr
 bdapqpc "bdapq pc operand"
 bdapqpc "bdapq pc operand"
 (MACH-PC UNCOND-CTI)
 (MACH-PC UNCOND-CTI)
 "bdapq $o,PC"
 "bdapq $o,PC"
 (+ (f-dest 15) MODE_QUICK_IMMEDIATE QHI_BDAP o)
 (+ (f-dest 15) MODE_QUICK_IMMEDIATE QHI_BDAP o)
 (sequence
 (sequence
   ()
   ()
   (set prefixreg (add SI (add SI pc 2) o))
   (set prefixreg (add SI (add SI pc 2) o))
   (set prefix-set 1)
   (set prefix-set 1)
   ; When this *rare* instruction is seen, we're may be about to write
   ; When this *rare* instruction is seen, we're may be about to write
   ; into code to be executed soon, *probably* covering addresses decoded
   ; into code to be executed soon, *probably* covering addresses decoded
   ; and executed before.  If the simulator does not implement snooping
   ; and executed before.  If the simulator does not implement snooping
   ; and automatic decoder flush, it will execute old code.  This call
   ; and automatic decoder flush, it will execute old code.  This call
   ; is a kludge for such simulators, asking it to abandon such cached
   ; is a kludge for such simulators, asking it to abandon such cached
   ; information.  Anyway, it is hopefully enough to make CGEN-sim not
   ; information.  Anyway, it is hopefully enough to make CGEN-sim not
   ; hork on gcc trampolines.
   ; hork on gcc trampolines.
   ; We mark this insn as UNCOND-CTI so this insn will end a simulator
   ; We mark this insn as UNCOND-CTI so this insn will end a simulator
   ; basic block (the atomic unit of translation).
   ; basic block (the atomic unit of translation).
   (c-call VOID "cris_flush_simulator_decode_cache" pc))
   (c-call VOID "cris_flush_simulator_decode_cache" pc))
)
)
; (BDAP.D  [PC+],PC   [ 1111 | 11010110 | 1111 ]
; (BDAP.D  [PC+],PC   [ 1111 | 11010110 | 1111 ]
; This [PC+I] prefix is used for DSO-local jumps in PIC code, together with
; This [PC+I] prefix is used for DSO-local jumps in PIC code, together with
; move-m-pcplus-p0: "move [pc=pc+N],p0"
; move-m-pcplus-p0: "move [pc=pc+N],p0"
(dni-c-SI-attr
(dni-c-SI-attr
 bdap-32-pc "bdap.d [PC+],PC"
 bdap-32-pc "bdap.d [PC+],PC"
 (MACH-PC)
 (MACH-PC)
 "bdap ${sconst32},PC"
 "bdap ${sconst32},PC"
 (+ (f-dest 15) MODE_AUTOINCREMENT INDIR_BDAP_M SIZE_DWORD (f-source 15) const32)
 (+ (f-dest 15) MODE_AUTOINCREMENT INDIR_BDAP_M SIZE_DWORD (f-source 15) const32)
 (sequence
 (sequence
   ((SI newpc) (SI oldpc) (SI offs))
   ((SI newpc) (SI oldpc) (SI offs))
   (set offs const32)
   (set offs const32)
   (set oldpc (add SI pc 6))
   (set oldpc (add SI pc 6))
   (set newpc (add SI oldpc offs))
   (set newpc (add SI oldpc offs))
   (set prefixreg newpc)
   (set prefixreg newpc)
   (set prefix-set 1))
   (set prefix-set 1))
)
)
; (MOVE    [PC+],P0        [ 0000 | 11100011 | 1111 ])
; (MOVE    [PC+],P0        [ 0000 | 11100011 | 1111 ])
; This insn is used for DSO-local jumps in PIC code.  See bdap-32-pc.
; This insn is used for DSO-local jumps in PIC code.  See bdap-32-pc.
(dni ; Must not use dni-cmt-* because we force MODE_AUTOINCREMENT.
(dni ; Must not use dni-cmt-* because we force MODE_AUTOINCREMENT.
 move-m-pcplus-p0 "move [PC+],P0"
 move-m-pcplus-p0 "move [PC+],P0"
 (MACH-PC)
 (MACH-PC)
 "move [PC+],P0"
 "move [PC+],P0"
 (+ (f-dest 0) MODE_AUTOINCREMENT INFIX_MOVE_M_S SIZE_FIXED (f-source 15))
 (+ (f-dest 0) MODE_AUTOINCREMENT INFIX_MOVE_M_S SIZE_FIXED (f-source 15))
 (if prefix-set
 (if prefix-set
     (sequence
     (sequence
       ((QI dummy))
       ((QI dummy))
       ; We model the memory read, but throw the result away, as the
       ; We model the memory read, but throw the result away, as the
       ; destination register is read-only.  We need to assign the result of
       ; destination register is read-only.  We need to assign the result of
       ; cris-get-mem though, as CGEN-FIXME: invalid C code will otherwise
       ; cris-get-mem though, as CGEN-FIXME: invalid C code will otherwise
       ; be generated.
       ; be generated.
       (set dummy (cris-get-mem QI pc))
       (set dummy (cris-get-mem QI pc))
       (reset-x-p))
       (reset-x-p))
     (error "move [PC+],P0 without prefix is not implemented"))
     (error "move [PC+],P0 without prefix is not implemented"))
 (cris-mem-timing)
 (cris-mem-timing)
)
)
; This insn is used in Linux in the form "move [$sp=$sp+16],$p8"; it's
; This insn is used in Linux in the form "move [$sp=$sp+16],$p8"; it's
; similar to move-m-pcplus-p0 above.  The same comments apply here.
; similar to move-m-pcplus-p0 above.  The same comments apply here.
(dni
(dni
 move-m-spplus-p8 "move [SP+],P8"
 move-m-spplus-p8 "move [SP+],P8"
 (MACH-PC)
 (MACH-PC)
 "move [SP+],P8"
 "move [SP+],P8"
 (+ (f-dest 8) MODE_AUTOINCREMENT INFIX_MOVE_M_S SIZE_FIXED (f-source 14))
 (+ (f-dest 8) MODE_AUTOINCREMENT INFIX_MOVE_M_S SIZE_FIXED (f-source 14))
 (if prefix-set
 (if prefix-set
     (sequence
     (sequence
       ((SI dummy))
       ((SI dummy))
       (set dummy (cris-get-mem SI sp))
       (set dummy (cris-get-mem SI sp))
       (reset-x-p))
       (reset-x-p))
     (error "move [SP+],P8 without prefix is not implemented"))
     (error "move [SP+],P8 without prefix is not implemented"))
 (cris-mem-timing)
 (cris-mem-timing)
)
)
; ADDO.m  [Rs],Rd,ACR    [ Rd | 100101mm | Rs ]
; ADDO.m  [Rs],Rd,ACR    [ Rd | 100101mm | Rs ]
; ADDO.m  [Rs+],Rd,ACR   [ Rd | 110101mm | Rs ]
; ADDO.m  [Rs+],Rd,ACR   [ Rd | 110101mm | Rs ]
(dni-cmt-bwd
(dni-cmt-bwd
 addo-m "addo.m memory"
 addo-m "addo.m memory"
 "[${Rs}${inc}],$Rd,ACR"
 "[${Rs}${inc}],$Rd,ACR"
 (+ Rd INDIR_ADDO Rs)
 (+ Rd INDIR_ADDO Rs)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ((BWD tmps))
    ((BWD tmps))
    (set tmps (cris-get-mem BWD Rs))
    (set tmps (cris-get-mem BWD Rs))
    (set prefixreg (add SI Rd ((.sym BWD -ext) tmps)))
    (set prefixreg (add SI Rd ((.sym BWD -ext) tmps)))
    (set prefix-set 1)))
    (set prefix-set 1)))
)
)
; (ADDO.m  [PC+],Rd,ACR   [ Rd | 110101mm | 1111 ]
; (ADDO.m  [PC+],Rd,ACR   [ Rd | 110101mm | 1111 ]
(dni-c-QI
(dni-c-QI
 addo-cb "addo.b const"
 addo-cb "addo.b const"
 "addo.b [PC+],$Rd,ACR"
 "addo.b [PC+],$Rd,ACR"
 (+ Rd MODE_AUTOINCREMENT INDIR_ADDO SIZE_BYTE (f-source 15) sconst8)
 (+ Rd MODE_AUTOINCREMENT INDIR_ADDO SIZE_BYTE (f-source 15) sconst8)
 (sequence
 (sequence
   ()
   ()
   (set prefixreg (add SI Rd (ext SI (trunc QI sconst8))))
   (set prefixreg (add SI Rd (ext SI (trunc QI sconst8))))
   (set prefix-set 1))
   (set prefix-set 1))
)
)
(dni-c-HI
(dni-c-HI
 addo-cw "addo.w const"
 addo-cw "addo.w const"
 "addo.w [PC+],$Rd,ACR"
 "addo.w [PC+],$Rd,ACR"
 (+ Rd MODE_AUTOINCREMENT INDIR_ADDO SIZE_WORD (f-source 15) sconst16)
 (+ Rd MODE_AUTOINCREMENT INDIR_ADDO SIZE_WORD (f-source 15) sconst16)
 (sequence
 (sequence
   ()
   ()
   (set prefixreg (add SI Rd (ext SI (trunc HI sconst16))))
   (set prefixreg (add SI Rd (ext SI (trunc HI sconst16))))
   (set prefix-set 1))
   (set prefix-set 1))
)
)
(dni-c-SI
(dni-c-SI
 addo-cd "addo.d const"
 addo-cd "addo.d const"
 "addo.d [PC+],$Rd,ACR"
 "addo.d [PC+],$Rd,ACR"
 (+ Rd MODE_AUTOINCREMENT INDIR_ADDO SIZE_DWORD (f-source 15) const32)
 (+ Rd MODE_AUTOINCREMENT INDIR_ADDO SIZE_DWORD (f-source 15) const32)
 (sequence
 (sequence
   ()
   ()
   (set prefixreg (add SI Rd const32))
   (set prefixreg (add SI Rd const32))
   (set prefix-set 1))
   (set prefix-set 1))
)
)
;         DIP    []   | 0  0  0  0| 1  m| 0  1  0  1| 1  1| Source    |
;         DIP    []   | 0  0  0  0| 1  m| 0  1  0  1| 1  1| Source    |
(dni-cmt-attr
(dni-cmt-attr
 dip-m "dip mem"
 dip-m "dip mem"
 (MACH-PRE-V32)
 (MACH-PRE-V32)
 "dip [${Rs}${inc}]"
 "dip [${Rs}${inc}]"
 (+ (f-dest 0) INFIX_DIP SIZE_FIXED Rs)
 (+ (f-dest 0) INFIX_DIP SIZE_FIXED Rs)
 (sequence
 (sequence
   ((SI tmps))
   ((SI tmps))
   (set tmps (cris-get-mem SI Rs))
   (set tmps (cris-get-mem SI Rs))
   (set prefixreg tmps)
   (set prefixreg tmps)
   (set prefix-set 1))
   (set prefix-set 1))
)
)
;         (DIP    []   | 0  0  0  0| 1  m| 0  1  0  1| 1  1| Source    |    )
;         (DIP    []   | 0  0  0  0| 1  m| 0  1  0  1| 1  1| Source    |    )
(dni-c-SI-attr
(dni-c-SI-attr
 dip-c "dip [PC+]"
 dip-c "dip [PC+]"
 (MACH-PC)
 (MACH-PC)
 "dip [PC+]"
 "dip [PC+]"
 (+ (f-dest 0) MODE_AUTOINCREMENT INFIX_DIP SIZE_FIXED (f-source 15) const32)
 (+ (f-dest 0) MODE_AUTOINCREMENT INFIX_DIP SIZE_FIXED (f-source 15) const32)
 (sequence
 (sequence
   ()
   ()
   (set prefixreg const32)
   (set prefixreg const32)
   (set prefix-set 1))
   (set prefix-set 1))
)
)
; ADDI    Rs.m,Rd,ACR     [ Rs | 010101mm | Rd ]
; ADDI    Rs.m,Rd,ACR     [ Rs | 010101mm | Rd ]
; a.k.a. biap
; a.k.a. biap
(dni-cdt-bwd
(dni-cdt-bwd
 addi-acr "addi prefix"
 addi-acr "addi prefix"
 "${Rs-dfield}.m,${Rd-sfield},ACR"
 "${Rs-dfield}.m,${Rd-sfield},ACR"
 (+ Rd-sfield MODE_REGISTER R_ADDI_ACR Rs-dfield)
 (+ Rd-sfield MODE_REGISTER R_ADDI_ACR Rs-dfield)
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ()
    ()
    (set prefixreg (add SI Rd-sfield (mul Rs-dfield (.sym BWD -size))))
    (set prefixreg (add SI Rd-sfield (mul Rs-dfield (.sym BWD -size))))
    (set prefix-set 1)))
    (set prefix-set 1)))
)
)
(dni-cdt-bwd-attr
(dni-cdt-bwd-attr
 biap-pc "biap.m ${Rs-dfield},PC"
 biap-pc "biap.m ${Rs-dfield},PC"
 (MACH-PC)
 (MACH-PC)
 "${Rs-dfield}.m,PC"
 "${Rs-dfield}.m,PC"
 (+ Rs-dfield MODE_REGISTER R_ADDI_ACR (f-source 15))
 (+ Rs-dfield MODE_REGISTER R_ADDI_ACR (f-source 15))
 (.pmacro
 (.pmacro
  (BWD)
  (BWD)
  (sequence
  (sequence
    ()
    ()
    (set prefixreg (add SI (add SI pc 4) (mul Rs-dfield (.sym BWD -size))))
    (set prefixreg (add SI (add SI pc 4) (mul Rs-dfield (.sym BWD -size))))
    (set prefix-set 1)))
    (set prefix-set 1)))
)
)
; FIDXI    [Rs]            [ 0000 | 11010011 | Rs ]
; FIDXI    [Rs]            [ 0000 | 11010011 | Rs ]
(dni-cdt-attr
(dni-cdt-attr
 fidxi "fidxi [Rs]"
 fidxi "fidxi [Rs]"
 (MACH-V32)
 (MACH-V32)
 "fidxi [$Rs]"
 "fidxi [$Rs]"
 (+ (f-dest 0) MODE_AUTOINCREMENT INFIX_FIDXI SIZE_FIXED Rs)
 (+ (f-dest 0) MODE_AUTOINCREMENT INFIX_FIDXI SIZE_FIXED Rs)
 (set pc (c-call USI "@cpu@_fidxi_handler" pc Rs))
 (set pc (c-call USI "@cpu@_fidxi_handler" pc Rs))
)
)
; FTAGI    [Rs]            [ 0001 | 11010011 | Rs ]
; FTAGI    [Rs]            [ 0001 | 11010011 | Rs ]
(dni-cdt-attr
(dni-cdt-attr
 ftagi "ftagi [Rs]"
 ftagi "ftagi [Rs]"
 (MACH-V32)
 (MACH-V32)
 "fidxi [$Rs]"
 "fidxi [$Rs]"
 (+ (f-dest 1) MODE_AUTOINCREMENT INFIX_FTAGI SIZE_FIXED Rs)
 (+ (f-dest 1) MODE_AUTOINCREMENT INFIX_FTAGI SIZE_FIXED Rs)
 (set pc (c-call USI "@cpu@_ftagi_handler" pc Rs))
 (set pc (c-call USI "@cpu@_ftagi_handler" pc Rs))
)
)
; FIDXD    [Rs]            [ 0000 | 10101011 | Rs ]
; FIDXD    [Rs]            [ 0000 | 10101011 | Rs ]
(dni-cdt-attr
(dni-cdt-attr
 fidxd "fidxd [Rs]"
 fidxd "fidxd [Rs]"
 (MACH-V32)
 (MACH-V32)
 "fidxd [$Rs]"
 "fidxd [$Rs]"
 (+ (f-dest 0) MODE_INDIRECT INFIX_FIDXD SIZE_FIXED Rs)
 (+ (f-dest 0) MODE_INDIRECT INFIX_FIDXD SIZE_FIXED Rs)
 (set pc (c-call USI "@cpu@_fidxd_handler" pc Rs))
 (set pc (c-call USI "@cpu@_fidxd_handler" pc Rs))
)
)
; FTAGD    [Rs]            [ 0001 | 10101011 | Rs ]
; FTAGD    [Rs]            [ 0001 | 10101011 | Rs ]
(dni-cdt-attr
(dni-cdt-attr
 ftagd "ftagd [Rs]"
 ftagd "ftagd [Rs]"
 (MACH-V32)
 (MACH-V32)
 "ftagd [$Rs]"
 "ftagd [$Rs]"
 (+ (f-dest 1) MODE_INDIRECT INFIX_FTAGD SIZE_FIXED Rs)
 (+ (f-dest 1) MODE_INDIRECT INFIX_FTAGD SIZE_FIXED Rs)
 (set pc (c-call USI "@cpu@_ftagd_handler" pc Rs))
 (set pc (c-call USI "@cpu@_ftagd_handler" pc Rs))
)
)
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.