; SuperH SHmedia instruction set description.  -*- Scheme -*-
; Copyright (C) 2000, 2001, 2006 Red Hat, Inc.
; Copyright (C) 2002 SuperH Ltd
; This file is part of CGEN.
; See file COPYING.CGEN for details.

; dshmf -- define-normal-sh-media-field

(define-pmacro (dshmf xname xcomment ignored xstart xlength)
  (dnf xname xcomment ((ISA media)) xstart xlength))

; dshmop -- define-normal-sh-media-operand

(define-pmacro (dshmop xname xcomment ignored xhardware xfield)
  (dnop xname xcomment ((ISA media)) xhardware xfield))

; dnshmi -- define-normal-sh-media-insn

(define-pmacro (dshmi xname xcomment xattrs xsyntax xformat xsemantics xtiming)
  (define-insn
    (name xname)
    (comment xcomment)
    (.splice attrs (.unsplice xattrs) (ISA media))
    (syntax xsyntax)
    (format xformat)
    (semantics xsemantics)
    (.splice timing (.unsplice xtiming))))


; Saturation functions.
; Force a value `i' into words `n' bits wide.
; See SuperH (SH) 64 bit RISC Series / SH-5 CPU Core, Volume 2,
; page 11 for details.  (page number refers to 05-CC-10002 V1.0).

; saturate -- signed saturatation function

(define-pmacro (saturate mode n i)
  (if mode (lt i (neg DI (sll DI 1 (sub n 1))))
      (neg (sll mode 1 (sub n 1)))
      (if mode (lt i (sll DI 1 (sub n 1)))
	  i
 	  (sub mode (sll mode 1 (sub n 1)) 1))))

; usaturate -- unsigned saturation function

(define-pmacro (usaturate mode n i)
  (if mode (lt i (const DI 0))
      (const mode 0)
      (if mode (lt i (sll DI 1 n))
	  i
	  (sub mode (sll mode 1 n) 1))))


; Ifields.

(dshmf f-op          "Opcode"                       ()   0  6)
(dshmf f-ext         "Extension opcode"             ()  12  4)
(dshmf f-rsvd        "Reserved"		    (RESERVED)  28  4)

(dshmf f-left        "Left register"                ()   6  6)
(dshmf f-right       "Right register"               ()  16  6)
(dshmf f-dest        "Destination register"         ()  22  6)

(define-multi-ifield
  (name f-left-right)
  (comment "Left and right matched register pair")
  (attrs (ISA media))
  (mode UINT)
  (subfields f-left f-right)
  (insert (sequence ()
		    (set (ifield f-left)
			 (and (ifield f-left-right) 63))
		    (set (ifield f-right)
			 (and (ifield f-left-right) 63))))
  (extract (set (ifield f-left-right) (ifield f-left)))
)

(dshmf f-tra         "Target register"              ()  25  3)
(dshmf f-trb         "Target register"              ()   9  3)
(dshmf f-likely      "Likely bit"                   ()  22  1)
(dshmf f-6-3           "Three unused bits at bit 25"  ()   6  3)
(dshmf f-23-2        "Two unused bits at bit 25"    ()  23  2)

(df f-imm6   "Immediate value (6 bits)"      ((ISA media)) 16 6 INT #f #f)
(df f-imm10  "Immediate value (10 bits)"     ((ISA media)) 12 10 INT #f #f)
(df f-imm16  "Immediate value (16 bits)"     ((ISA media))  6 16 INT #f #f)

(dshmf f-uimm6       "Immediate value (6 bits)"     ()  16  6)
(dshmf f-uimm16      "Immediate value (16 bits)"    ()   6 16)

; Various displacement fields.
; The 10 bit field, for example, has different scaling for displacements.

(df f-disp6	     "Displacement (6 bits)"        ((ISA media)) 16 6 INT #f #f)

(df f-disp6x32       "Displacement (6 bits)"        ((ISA media)) 16 6 INT
    ((value pc) (sra SI value 5))
    ((value pc) (sll SI value 5)))

(df f-disp10         "Displacement (10 bits)"       ((ISA media)) 12 10 INT #f #f)

(df f-disp10x8       "Displacement (10 bits)"       ((ISA media)) 12 10 INT
    ((value pc) (sra SI value 3))
    ((value pc) (sll SI value 3)))

(df f-disp10x4       "Displacement (10 bits)"       ((ISA media)) 12 10 INT
    ((value pc) (sra SI value 2))
    ((value pc) (sll SI value 2)))

(df f-disp10x2       "Displacement (10 bits)"       ((ISA media)) 12 10 INT
    ((value pc) (sra SI value 1))
    ((value pc) (sll SI value 1)))

(df f-disp16         "Displacement (16 bits)"       ((ISA media) PCREL-ADDR)  6 16 INT
    ((value pc) (sra DI value 2))
    ((value pc) (add DI (sll DI value 2) pc)))


; Operands.

(dshmop rm        "Left general purpose reg"            ()  h-gr    f-left)
(dshmop rn        "Right general purpose reg"           ()  h-gr    f-right)
(dshmop rd        "Destination general purpose reg"     ()  h-gr    f-dest)

(dshmop frg       "Left single precision register"      ()  h-fr    f-left)
(dshmop frh       "Right single precision register"     ()  h-fr    f-right)
(dshmop frf       "Destination single precision reg"    ()  h-fr    f-dest)
(dshmop frgh      "Single precision register pair"      ()  h-fr    f-left-right)

(dshmop fpf       "Pair of single precision registers"  ()  h-fp    f-dest)

(dshmop fvg       "Left single precision vector"        ()  h-fv    f-left)
(dshmop fvh       "Right single precision vector"       ()  h-fv    f-right)
(dshmop fvf       "Destination single precision vector" ()  h-fv    f-dest)
(dshmop mtrxg     "Left single precision matrix"        ()  h-fmtx  f-left)

(dshmop drg       "Left double precision register"      ()  h-dr    f-left)
(dshmop drh       "Right double precision register"     ()  h-dr    f-right)
(dshmop drf       "Destination double precision reg"    ()  h-dr    f-dest)
(dshmop drgh      "Double precision register pair"      ()  h-dr    f-left-right)

(dshmop fpscr     "Floating point status register"      ()  h-fpscr f-nil)
(dshmop crj       "Control register j"                  ()  h-cr    f-dest)
(dshmop crk       "Control register k"			()  h-cr    f-left)

(dshmop tra       "Target register a"                   ()  h-tr    f-tra)
(dshmop trb       "Target register b"                   ()  h-tr    f-trb)

(dshmop disp6     "Displacement (6 bits)"		()  h-sint  f-disp6)
(dshmop disp6x32  "Displacement (6 bits, scale 32)"     ()  h-sint  f-disp6x32)
(dshmop disp10    "Displacement (10 bits)"              ()  h-sint  f-disp10)
(dshmop disp10x2  "Displacement (10 bits, scale 2)"     ()  h-sint  f-disp10x2)
(dshmop disp10x4  "Displacement (10 bits, scale 4)"     ()  h-sint  f-disp10x4)
(dshmop disp10x8  "Displacement (10 bits, scale 8)"     ()  h-sint  f-disp10x8)
(dshmop disp16    "Displacement (16 bits)"              ()  h-sint  f-disp16)

(dshmop imm6      "Immediate (6 bits)"                  ()  h-sint  f-imm6)
(dshmop imm10     "Immediate (10 bits)"                 ()  h-sint  f-imm10)
(dshmop imm16     "Immediate (16 bits)"                 ()  h-sint  f-imm16)
(dshmop uimm6     "Immediate (6 bits)"                  ()  h-uint  f-uimm6)
(dshmop uimm16    "Unsigned immediate (16 bits)"        ()  h-uint  f-uimm16)

; FIXME: provide these parse/print functions in `sh-media.opc'.

(define-operand (name likely) (comment "Likely branch?") (attrs (ISA media))
  (type h-uint) (index f-likely) (handlers (parse "likely") (print "likely")))


; Instructions.

(dshmi add "Add"
       ()
       "add $rm, $rn, $rd"
       (+ (f-op 0) rm (f-ext 9) rn rd (f-rsvd 0))
       (set rd (add rm rn))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi addl "Add long"
       ()
       "add.l $rm, $rn, $rd"
       (+ (f-op 0) rm (f-ext 8) rn rd (f-rsvd 0))
       (set rd (add (subword SI rm 1) (subword SI rn 1)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi addi "Add immediate"
       ()
       "addi $rm, $disp10, $rd"
       (+ (f-op 52) rm disp10 rd (f-rsvd 0))
       (set rd (add rm (ext DI disp10)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi addil "Add immediate long"
       ()
       "addi.l $rm, $disp10, $rd"
       (+ (f-op 53) rm disp10 rd (f-rsvd 0))
       (set rd (ext DI (add (ext SI disp10) (subword SI rm 1))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi addzl "Add zero extended long"
       ()
       "addz.l $rm, $rn, $rd"
       (+ (f-op 0) rm (f-ext 12) rn rd (f-rsvd 0))
       (set rd (zext DI (add (subword SI rm 1) (subword SI rn 1))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi alloco "Allocate operand cache block"
       ()
       "alloco $rm, $disp6x32"
       (+ (f-op 56) rm (f-ext 4) disp6x32 (f-dest 63) (f-rsvd 0))
       (sequence ()
		 (set rm rm) ; for now to allow profiling
		 (unimp "alloco"))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi and "AND"
       ()
       "and $rm, $rn, $rd"
       (+ (f-op 1) rm (f-ext 11) rn rd (f-rsvd 0))
       (set rd (and rm rn))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi andc "AND complement"
       ()
       "andc $rm, $rn, $rd"
       (+ (f-op 1) rm (f-ext 15) rn rd (f-rsvd 0))
       (set rd (and rm (inv rn)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi andi "AND immediate"
       ()
       "andi $rm, $disp10, $rd"
       (+ (f-op 54) rm disp10 rd (f-rsvd 0))
       (set rd (and rm (ext DI disp10)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi beq "Branch if equal"
       ()
       "beq$likely $rm, $rn, $tra"
       (+ (f-op 25) rm (f-ext 1) rn likely (f-23-2 0) tra (f-rsvd 0))
       (sequence ()
		 (save-branch-optimization likely)
		 (if (eq rm rn)
		     (set pc tra)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-cond-branch (in targetreg tra)))))

(dshmi beqi "Branch if equal immediate"
       ()
       "beqi$likely $rm, $imm6, $tra"
       (+ (f-op 57) rm (f-ext 1) imm6 likely (f-23-2 0) tra (f-rsvd 0))
       (sequence ()
		 (save-branch-optimization likely)
		 (if (eq rm (ext DI imm6))
		     (set pc tra)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec)
			  (unit u-cond-branch (in targetreg tra)))))

(dshmi bge "Branch if greater than or equal"
       ()
       "bge$likely $rm, $rn, $tra"
       (+ (f-op 25) rm (f-ext 3) rn likely (f-23-2 0) tra (f-rsvd 0))
       (sequence ()
		 (save-branch-optimization likely)
		 (if (ge rm rn)
		     (set pc tra)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-cond-branch (in targetreg tra)))))

(dshmi bgeu "Branch if greater than or equal (unsigned comparison)"
       ()
       "bgeu$likely $rm, $rn, $tra"
       (+ (f-op 25) rm (f-ext 11) rn likely (f-23-2 0) tra (f-rsvd 0))
       (sequence ()
		 (save-branch-optimization likely)
		 (if (geu rm rn)
		     (set pc tra)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-cond-branch (in targetreg tra)))))

(dshmi bgt "Branch greater than"
       ()
       "bgt$likely $rm, $rn, $tra"
       (+ (f-op 25) rm (f-ext 7) rn likely (f-23-2 0) tra (f-rsvd 0))
       (sequence ()
		 (save-branch-optimization likely)
		 (if (gt rm rn)
		     (set pc tra)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-cond-branch (in targetreg tra)))))

(dshmi bgtu "Branch greater than (unsigned comparison)"
       ()
       "bgtu$likely $rm, $rn, $tra"
       (+ (f-op 25) rm (f-ext 15) rn likely (f-23-2 0) tra (f-rsvd 0))
       (sequence ()
		 (save-branch-optimization likely)
		 (if (gtu rm rn)
		     (set pc tra)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-cond-branch (in targetreg tra)))))

(dshmi blink "Branch and link"
       ()
       "blink $trb, $rd"
       (+ (f-op 17) (f-6-3 0) trb (f-ext 1) (f-right 63) rd (f-rsvd 0))
       (sequence ()
		 (set rd (or (add pc 4) 1))
		 (set pc trb)
		 (if (eq (index-of rd) 63)
		     (cg-profile-jump pc trb) ; rd==r63 is used for local branches and returns
		     (cg-profile pc trb)))
       (sh5-media-models ((unit u-blink (in targetreg trb)))))

(dshmi bne "Branch if not equal"
       ()
       "bne$likely $rm, $rn, $tra"
       (+ (f-op 25) rm (f-ext 5) rn likely (f-23-2 0) tra (f-rsvd 0))
       (sequence ()
		 (save-branch-optimization likely)
		 (if (ne rm rn)
		     (set pc tra)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-cond-branch (in targetreg tra)))))

(dshmi bnei "Branch if not equal immediate"
       ()
       "bnei$likely $rm, $imm6, $tra"
       (+ (f-op 57) rm (f-ext 5) rn likely (f-23-2 0) tra (f-rsvd 0))
       (sequence ()
		 (save-branch-optimization likely)
		 (if (ne rm (ext DI imm6))
		     (set pc tra)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec)
			  (unit u-cond-branch (in targetreg tra)))))

(dshmi brk "Breakpoint instruction"
       ()
       "brk"
       (+ (f-op 27) (f-left 63) (f-ext 5) (f-right 63) (f-dest 63) (f-rsvd 0))
       (c-call "sh64_break" pc)
       (sh5-media-models ((unit u-exec (cycles 10)))))

(define-pmacro (-byterev-step)
  (sequence ()
    (set result (or (sll result 8) (and source 255)))
    (set source (srl source 8)))
)

(dshmi byterev "Byte reverse"
       ()
       "byterev $rm, $rd"
       (+ (f-op 0) rm (f-ext 15) (f-right 63) rd (f-rsvd 0))
       (sequence ((DI source) (DI result))
		 (set source rm)
		 (set result 0)
		 (-byterev-step)
		 (-byterev-step)
		 (-byterev-step)
		 (-byterev-step)
		 (-byterev-step)
		 (-byterev-step)
		 (-byterev-step)
		 (-byterev-step)
		 (set rd result))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi cmpeq "Compare equal"
       ()
       "cmpeq $rm, $rn, $rd"
       (+ (f-op 0) rm (f-ext 1) rn rd (f-rsvd 0))
       (set rd (if DI (eq rm rn) 1 0))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi cmpgt "Compare greater than"
       ()
       "cmpgt $rm, $rn, $rd"
       (+ (f-op 0) rm (f-ext 3) rn rd (f-rsvd 0))
       (set rd (if DI (gt rm rn) 1 0))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi cmpgtu "Compare greater than (unsigned comparison)"
       ()
       "cmpgtu $rm,$rn, $rd"
       (+ (f-op 0) rm (f-ext 7) rn rd (f-rsvd 0))
       (set rd (if DI (gtu rm rn) 1 0))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi cmveq "Conditional move if equal to zero"
       ()
       "cmveq $rm, $rn, $rd"
       (+ (f-op 8) rm (f-ext 1) rn rd (f-rsvd 0))
       (if (eq rm 0)
	   (set rd rn))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi cmvne "Conditional move if not equal to zero"
       ()
       "cmvne $rm, $rn, $rd"
       (+ (f-op 8) rm (f-ext 5) rn rd (f-rsvd 0))
       (if (ne rm 0)
	   (set rd rn))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi fabsd "Floating point absolute (double)"
       ()
       "fabs.d $drgh, $drf"
       (+ (f-op 6) drgh (f-ext 1) drf (f-rsvd 0))
       (set drf (c-call DF "sh64_fabsd" drgh))
       (sh5-media-models ((unit u-use-dr (in usereg drgh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg drf) (cycles 7))
			  (unit u-set-dr (out loadreg drf) (cycles 4))
			  (unit u-set-fp (out loadreg drf) (cycles 4))
			  (unit u-set-fv (out loadreg drf) (cycles 7))
			  (unit u-set-mtrx (out loadreg drf) (cycles 7)))))

(dshmi fabss "Floating point absolute (single)"
       ()
       "fabs.s $frgh, $frf"
       (+ (f-op 6) frgh (f-ext 0) frf (f-rsvd 0))
       (set frf (c-call SF "sh64_fabss" frgh))
       (sh5-media-models ((unit u-use-fr (in usereg frgh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg frf) (cycles 4))
			  (unit u-set-dr (out loadreg frf) (cycles 7))
			  (unit u-set-fp (out loadreg frf) (cycles 7))
			  (unit u-set-fv (out loadreg frf) (cycles 7))
			  (unit u-set-mtrx (out loadreg frf) (cycles 7)))))

(dshmi faddd "Floating point add (double)"
       ()
       "fadd.d $drg, $drh, $drf"
       (+ (f-op 13) drg (f-ext 1) drh drf (f-rsvd 0))
       (set drf (c-call DF "sh64_faddd" drg drh))
       (sh5-media-models ((unit u-use-dr (in usereg drg))
			  (unit u-use-dr (in usereg drh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg drf) (cycles 7))
			  (unit u-set-dr (out loadreg drf) (cycles 6))
			  (unit u-set-fp (out loadreg drf) (cycles 6))
			  (unit u-set-fv (out loadreg drf) (cycles 7))
			  (unit u-set-mtrx (out loadreg drf) (cycles 7)))))

(dshmi fadds "Floating point add (single)"
       ()
       "fadd.s $frg, $frh, $frf"
       (+ (f-op 13) frg (f-ext 0) frh frf (f-rsvd 0))
       (set frf (c-call SF "sh64_fadds" frg frh))
       (sh5-media-models ((unit u-use-fr (in usereg frg))
			  (unit u-use-fr (in usereg frh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg frf) (cycles 6))
			  (unit u-set-dr (out loadreg frf) (cycles 7))
			  (unit u-set-fp (out loadreg frf) (cycles 7))
			  (unit u-set-fv (out loadreg frf) (cycles 7))
			  (unit u-set-mtrx (out loadreg frf) (cycles 7)))))

(dshmi fcmpeqd "Floating point compare if equal (double)"
       ()
       "fcmpeq.d $drg, $drh, $rd"
       (+ (f-op 12) drg (f-ext 9) drh rd (f-rsvd 0))
       (set rd (zext DI (c-call BI "sh64_fcmpeqd" drg drh)))
       (sh5-media-models ((unit u-fpu (cycles 1))
			  (unit u-set-gr (cycles 3) (out loadreg rd)))))

(dshmi fcmpeqs "Floating point compare if equal (single)"
       ()
       "fcmpeq.s $frg, $frh, $rd"
       (+ (f-op 12) frg (f-ext 8) frh rd (f-rsvd 0))
       (set rd (zext DI (c-call BI "sh64_fcmpeqs" frg frh)))
       (sh5-media-models ((unit u-fpu (cycles 1))
			  (unit u-set-gr (cycles 3) (out loadreg rd)))))

(dshmi fcmpged "Floating compare compare if greater than or equal (double)"
       ()
       "fcmpge.d $drg, $drh, $rd"
       (+ (f-op 12) drg (f-ext 15) drh rd (f-rsvd 0))
       (set rd (zext DI (c-call BI "sh64_fcmpged" drg drh)))
       (sh5-media-models ((unit u-fpu (cycles 1))
			  (unit u-set-gr (cycles 3) (out loadreg rd)))))

(dshmi fcmpges "Floating point compare if greater than or equal (single)"
       ()
       "fcmpge.s $frg, $frh, $rd"
       (+ (f-op 12) frg (f-ext 14) frh rd (f-rsvd 0))
       (set rd (zext DI (c-call BI "sh64_fcmpges" frg frh)))
       (sh5-media-models ((unit u-fpu (cycles 1))
			  (unit u-set-gr (cycles 3) (out loadreg rd)))))

(dshmi fcmpgtd "Floating point compare if greater than (double)"
       ()
       "fcmpgt.d $drg, $drh, $rd"
       (+ (f-op 12) drg (f-ext 13) drh rd (f-rsvd 0))
       (set rd (zext DI (c-call BI "sh64_fcmpgtd" drg drh)))
       (sh5-media-models ((unit u-fpu (cycles 1))
			  (unit u-set-gr (cycles 3) (out loadreg rd)))))

(dshmi fcmpgts "Floating point compare if greater than (single)"
       ()
       "fcmpgt.s $frg, $frh, $rd"
       (+ (f-op 12) frg (f-ext 12) frh rd (f-rsvd 0))
       (set rd (zext DI (c-call BI "sh64_fcmpgts" frg frh)))
       (sh5-media-models ((unit u-fpu (cycles 1))
			  (unit u-set-gr (cycles 3) (out loadreg rd)))))

(dshmi fcmpund "Floating point unordered comparison (double)"
       ()
       "fcmpun.d $drg, $drh, $rd"
       (+ (f-op 12) drg (f-ext 11) drh rd (f-rsvd 0))
       (set rd (zext DI (c-call BI "sh64_fcmpund" drg drh)))
       (sh5-media-models ((unit u-fpu (cycles 1))
			  (unit u-set-gr (cycles 3) (out loadreg rd)))))

(dshmi fcmpuns "Floating point unordered comparison (single)"
       ()
       "fcmpun.s $frg, $frh, $rd"
       (+ (f-op 12) frg (f-ext 10) frh rd (f-rsvd 0))
       (set rd (zext DI (c-call BI "sh64_fcmpuns" frg frh)))
       (sh5-media-models ((unit u-fpu (cycles 1))
			  (unit u-set-gr (cycles 3) (out loadreg rd)))))

(dshmi fcnvds "Floating point coversion (double to single)"
       ()
       "fcnv.ds $drgh, $frf"
       (+ (f-op 14) drgh (f-ext 7) frf (f-rsvd 0))
       (set frf (c-call SF "sh64_fcnvds" drgh))
       (sh5-media-models ((unit u-use-dr (in usereg drgh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg frf) (cycles 6))
			  (unit u-set-dr (out loadreg frf) (cycles 7))
			  (unit u-set-fp (out loadreg frf) (cycles 7))
			  (unit u-set-fv (out loadreg frf) (cycles 7))
			  (unit u-set-mtrx (out loadreg frf) (cycles 7)))))

(dshmi fcnvsd "Floating point conversion (single to double)"
       ()
       "fcnv.sd $frgh, $drf"
       (+ (f-op 14) frgh (f-ext 6) drf (f-rsvd 0))
       (set drf (c-call DF "sh64_fcnvsd" frgh))
       (sh5-media-models ((unit u-use-fr (in usereg frgh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg drf) (cycles 7))
			  (unit u-set-dr (out loadreg drf) (cycles 6))
			  (unit u-set-fp (out loadreg drf) (cycles 6))
			  (unit u-set-fv (out loadreg drf) (cycles 7))
			  (unit u-set-mtrx (out loadreg drf) (cycles 7)))))

(dshmi fdivd "Floating point divide (double)"
       ()
       "fdiv.d $drg, $drh, $drf"
       (+ (f-op 13) drg (f-ext 5) drh drf (f-rsvd 0))
       (set drf (c-call DF "sh64_fdivd" drg drh))
       (sh5-media-models ((unit u-use-dr (in usereg drg))
			  (unit u-use-dr (in usereg drh))
			  (unit u-fdivd (out loadreg drf))
			  (unit u-set-fr (out loadreg drf) (cycles 36))
			  (unit u-set-dr (out loadreg drf) (cycles 35))
			  (unit u-set-fp (out loadreg drf) (cycles 35))
			  (unit u-set-fv (out loadreg drf) (cycles 36))
			  (unit u-set-mtrx (out loadreg drf) (cycles 36)))))

(dshmi fdivs "Floating point divide (single)"
       ()
       "fdiv.s $frg, $frh, $frf"
       (+ (f-op 13) frg (f-ext 4) frh frf (f-rsvd 0))
       (set frf (c-call SF "sh64_fdivs" frg frh))
       (sh5-media-models ((unit u-use-fr (in usereg frg))
			  (unit u-use-fr (in usereg frh))
			  (unit u-fdiv (out loadreg frf))
			  (unit u-set-fr (out loadreg frf) (cycles 19))
			  (unit u-set-dr (out loadreg frf) (cycles 20))
			  (unit u-set-fp (out loadreg frf) (cycles 20))
			  (unit u-set-fv (out loadreg frf) (cycles 20))
			  (unit u-set-mtrx (out loadreg frf) (cycles 20)))))

(dshmi fgetscr "Floating point get from FPSCR"
       ()
       "fgetscr $frf"
       (+ (f-op 7) (f-left 63) (f-ext 2) (f-right 63) frf (f-rsvd 0))
       (set frf (subword SF fpscr 0))
       (sh5-media-models ((unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg frf) (cycles 6))
			  (unit u-set-dr (out loadreg frf) (cycles 7))
			  (unit u-set-fp (out loadreg frf) (cycles 7))
			  (unit u-set-fv (out loadreg frf) (cycles 7))
			  (unit u-set-mtrx (out loadreg frf) (cycles 7)))))

(dshmi fiprs "Floating point inner product (single)"
       ()
       "fipr.s $fvg, $fvh, $frf"
       (+ (f-op 5) fvg (f-ext 6) fvh frf (f-rsvd 0))
       (sequence ()
		 (set fvg fvg) ; to allow profiling
		 (set fvh fvh) ; to allow profiling
		 (set frf (c-call SF "sh64_fiprs" (index-of fvg) (index-of fvh))))
       (sh5-media-models ((unit u-use-fv (in usereg fvg))
			  (unit u-use-fv (in usereg fvh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg frf) (cycles 6))
			  (unit u-set-dr (out loadreg frf) (cycles 7))
			  (unit u-set-fp (out loadreg frf) (cycles 7))
			  (unit u-set-fv (out loadreg frf) (cycles 7))
			  (unit u-set-mtrx (out loadreg frf) (cycles 7)))))

(dshmi fldd "Floating point load (double)"
       ()
       "fld.d $rm, $disp10x8, $drf"
       (+ (f-op 39) rm disp10x8 drf (f-rsvd 0))
       (set drf (mem DF (add rm disp10x8)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-fr (out loadreg drf) (cycles 6))
			  (unit u-load-dr (out loadreg drf) (cycles 3))
			  (unit u-load-fp (out loadreg drf) (cycles 3))
			  (unit u-load-fv (out loadreg drf) (cycles 6))
			  (unit u-load-mtrx (out loadreg drf) (cycles 6)))))

(dshmi fldp "Floating point load (pair of singles)"
       ()
       "fld.p $rm, $disp10x8, $fpf"
       (+ (f-op 38) rm disp10x8 fpf (f-rsvd 0))
       (sequence ()
		 (set fpf fpf) ; to allow profiling
		 (c-call VOID "sh64_fldp" pc rm disp10x8 (index-of fpf)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-fr (out loadreg fpf) (cycles 6))
			  (unit u-load-dr (out loadreg fpf) (cycles 3))
			  (unit u-load-fp (out loadreg fpf) (cycles 3))
			  (unit u-load-fv (out loadreg fpf) (cycles 6))
			  (unit u-load-mtrx (out loadreg fpf) (cycles 6)))))

(dshmi flds "Floating point load (single)"
       ()
       "fld.s $rm, $disp10x4, $frf"
       (+ (f-op 37) rm disp10x4 frf (f-rsvd 0))
       (set frf (mem SF (add rm disp10x4)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-fr (out loadreg frf) (cycles 3))
			  (unit u-load-dr (out loadreg frf) (cycles 6))
			  (unit u-load-fp (out loadreg frf) (cycles 6))
			  (unit u-load-fv (out loadreg frf) (cycles 6))
			  (unit u-load-mtrx (out loadreg frf) (cycles 6)))))

(dshmi fldxd "Floating point extended load (double)"
       ()
       "fldx.d $rm, $rn, $drf"
       (+ (f-op 7) rm (f-ext 9) rn frf (f-rsvd 0))
       (set drf (mem DF (add rm rn)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-fr (out loadreg drf) (cycles 6))
			  (unit u-load-dr (out loadreg drf) (cycles 3))
			  (unit u-load-fp (out loadreg drf) (cycles 3))
			  (unit u-load-fv (out loadreg drf) (cycles 6))
			  (unit u-load-mtrx (out loadreg drf) (cycles 6)))))

(dshmi fldxp "Floating point extended load (pair of singles)"
       ()
       "fldx.p $rm, $rn, $fpf"
       (+ (f-op 7) rm (f-ext 13) rn fpf (f-rsvd 0))
       (sequence ()
		 (set fpf fpf) ; Allows profiling
		 (c-call VOID "sh64_fldp" pc rm rn (index-of fpf)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-fr (out loadreg fpf) (cycles 6))
			  (unit u-load-dr (out loadreg fpf) (cycles 3))
			  (unit u-load-fp (out loadreg fpf) (cycles 3))
			  (unit u-load-fv (out loadreg fpf) (cycles 6))
			  (unit u-load-mtrx (out loadreg fpf) (cycles 6)))))

(dshmi fldxs "Floating point extended load (single)"
       ()
       "fldx.s $rm, $rn, $frf"
       (+ (f-op 7) rm (f-ext 8) rn frf (f-rsvd 0))
       (set frf (mem SF (add rm rn)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-fr (out loadreg frf) (cycles 3))
			  (unit u-load-dr (out loadreg frf) (cycles 6))
			  (unit u-load-fp (out loadreg frf) (cycles 6))
			  (unit u-load-fv (out loadreg frf) (cycles 6))
			  (unit u-load-mtrx (out loadreg frf) (cycles 6)))))

(dshmi floatld "Floating point conversion (long to double)"
       ()
       "float.ld $frgh, $drf"
       (+ (f-op 14) frgh (f-ext 14) drf (f-rsvd 0))
       (set drf (c-call DF "sh64_floatld" frgh))
       (sh5-media-models ((unit u-use-fr (in usereg frgh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg drf) (cycles 7))
			  (unit u-set-dr (out loadreg drf) (cycles 6))
			  (unit u-set-fp (out loadreg drf) (cycles 6))
			  (unit u-set-fv (out loadreg drf) (cycles 7))
			  (unit u-set-mtrx (out loadreg drf) (cycles 7)))))

(dshmi floatls "Floating point conversion (long to single)"
       ()
       "float.ls $frgh, $frf"
       (+ (f-op 14) frgh (f-ext 12) frf (f-rsvd 0))
       (set frf (c-call SF "sh64_floatls" frgh))
       (sh5-media-models ((unit u-use-fr (in usereg frgh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg frf) (cycles 6))
			  (unit u-set-dr (out loadreg frf) (cycles 7))
			  (unit u-set-fp (out loadreg frf) (cycles 7))
			  (unit u-set-fv (out loadreg frf) (cycles 7))
			  (unit u-set-mtrx (out loadreg frf) (cycles 7)))))

(dshmi floatqd "Floating point conversion (quad to double)"
       ()
       "float.qd $drgh, $drf"
       (+ (f-op 14) drgh (f-ext 13) drf (f-rsvd 0))
       (set drf (c-call DF "sh64_floatqd" drgh))
       (sh5-media-models ((unit u-use-dr (in usereg drgh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg drf) (cycles 7))
			  (unit u-set-dr (out loadreg drf) (cycles 6))
			  (unit u-set-fp (out loadreg drf) (cycles 6))
			  (unit u-set-fv (out loadreg drf) (cycles 7))
			  (unit u-set-mtrx (out loadreg drf) (cycles 7)))))

(dshmi floatqs "Floating point conversion (quad to single)"
       ()
       "float.qs $drgh, $frf"
       (+ (f-op 14) drgh (f-ext 15) frf (f-rsvd 0))
       (set frf (c-call SF "sh64_floatqs" drgh))
       (sh5-media-models ((unit u-use-dr (in usereg drgh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg frf) (cycles 6))
			  (unit u-set-dr (out loadreg frf) (cycles 7))
			  (unit u-set-fp (out loadreg frf) (cycles 7))
			  (unit u-set-fv (out loadreg frf) (cycles 7))
			  (unit u-set-mtrx (out loadreg frf) (cycles 7)))))

(dshmi fmacs "Floating point multiply and accumulate (single)"
       ()
       "fmac.s $frg, $frh, $frf"
       (+ (f-op 13) frg (f-ext 14) frh frf (f-rsvd 0))
       (set frf (c-call SF "sh64_fadds" frf (c-call SF "sh64_fmuls" frg frh)))
       (sh5-media-models ((unit u-use-fr (in usereg frg))
			  (unit u-use-fr (in usereg frh))
			  (unit u-use-fr (in usereg frf))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg frf) (cycles 6))
			  (unit u-set-dr (out loadreg frf) (cycles 7))
			  (unit u-set-fp (out loadreg frf) (cycles 7))
			  (unit u-set-fv (out loadreg frf) (cycles 7))
			  (unit u-set-mtrx (out loadreg frf) (cycles 7)))))

(dshmi fmovd "Floating point move double"
       ()
       "fmov.d $drgh, $drf"
       (+ (f-op 14) drgh (f-ext 1) drf (f-rsvd 0))
       (set drf drgh)
       (sh5-media-models ((unit u-use-dr (in usereg drgh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg drf) (cycles 7))
			  (unit u-set-dr (out loadreg drf) (cycles 4))
			  (unit u-set-fp (out loadreg drf) (cycles 4))
			  (unit u-set-fv (out loadreg drf) (cycles 7))
			  (unit u-set-mtrx (out loadreg drf) (cycles 7)))))

(dshmi fmovdq "Floating point move (double to quad integer)"
       ()
       "fmov.dq $drgh, $rd"
       (+ (f-op 12) drgh (f-ext 1) rd (f-rsvd 0))
       (set rd (subword DI drgh 0))
       (sh5-media-models ((unit u-fpu (cycles 1))
			  (unit u-set-gr (cycles 3) (out loadreg rd)))))

(dshmi fmovls "Floating point move (lower to single)"
       ()
       "fmov.ls $rm, $frf"
       (+ (f-op 7) rm (f-ext 0) (f-right 63) frf (f-rsvd 0))
       (set frf (subword SF (subword SI rm 1) 0))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg frf) (cycles 4))
			  (unit u-set-dr (out loadreg frf) (cycles 7))
			  (unit u-set-fp (out loadreg frf) (cycles 7))
			  (unit u-set-fv (out loadreg frf) (cycles 7))
			  (unit u-set-mtrx (out loadreg frf) (cycles 7)))))

(dshmi fmovqd "Floating point move (quad to double)"
       ()
       "fmov.qd $rm, $drf"
       (+ (f-op 7) rm (f-ext 1) (f-right 63) frf (f-rsvd 0))
       (set drf (subword DF rm 0))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg drf) (cycles 7))
			  (unit u-set-dr (out loadreg drf) (cycles 4))
			  (unit u-set-fp (out loadreg drf) (cycles 4))
			  (unit u-set-fv (out loadreg drf) (cycles 7))
			  (unit u-set-mtrx (out loadreg drf) (cycles 7)))))

(dshmi fmovs "Floating point move (single)"
       ()
       "fmov.s $frgh, $frf"
       (+ (f-op 14) frgh (f-ext 0) frf (f-rsvd 0))
       (set frf frgh)
       (sh5-media-models ((unit u-use-fr (in usereg frgh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg frf) (cycles 4))
			  (unit u-set-dr (out loadreg frf) (cycles 7))
			  (unit u-set-fp (out loadreg frf) (cycles 7))
			  (unit u-set-fv (out loadreg frf) (cycles 7))
			  (unit u-set-mtrx (out loadreg frf) (cycles 7)))))

(dshmi fmovsl "Floating point move (single to lower)"
       ()
       "fmov.sl $frgh, $rd"
       (+ (f-op 12) frgh (f-ext 0) rd (f-rsvd 0))
       (set rd (ext DI (subword SI frgh 1)))
       (sh5-media-models ((unit u-use-fr (in usereg frgh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-gr (cycles 3) (out loadreg rd)))))

(dshmi fmuld "Floating point multiply (double)"
       ()
       "fmul.d $drg, $drh, $drf"
       (+ (f-op 13) drg (f-ext 7) drh drf (f-rsvd 0))
       (set drf (c-call DF "sh64_fmuld" drg drh))
       (sh5-media-models ((unit u-use-dr (in usereg drg))
			  (unit u-use-dr (in usereg drh))
			  (unit u-fpu (cycles 4))
			  (unit u-set-fr (out loadreg drf) (cycles 10))
			  (unit u-set-dr (out loadreg drf) (cycles 9))
			  (unit u-set-fp (out loadreg drf) (cycles 9))
			  (unit u-set-fv (out loadreg drf) (cycles 10))
			  (unit u-set-mtrx (out loadreg drf) (cycles 10)))))

(dshmi fmuls "Floating point multiply (single)"
       ()
       "fmul.s $frg, $frh, $frf"
       (+ (f-op 13) frg (f-ext 6) frh frf (f-rsvd 0))
       (set frf (c-call SF "sh64_fmuls" frg frh))
       (sh5-media-models ((unit u-use-fr (in usereg frg))
			  (unit u-use-fr (in usereg frh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg frf) (cycles 6))
			  (unit u-set-dr (out loadreg frf) (cycles 7))
			  (unit u-set-fp (out loadreg frf) (cycles 7))
			  (unit u-set-fv (out loadreg frf) (cycles 7))
			  (unit u-set-mtrx (out loadreg frf) (cycles 7)))))

(dshmi fnegd "Floating point negate (double)"
       ()
       "fneg.d $drgh, $drf"
       (+ (f-op 6) drgh (f-ext 3) drf (f-rsvd 0))
       (set drf (c-call DF "sh64_fnegd" drgh))
       (sh5-media-models ((unit u-use-dr (in usereg drgh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg drf) (cycles 7))
			  (unit u-set-dr (out loadreg drf) (cycles 4))
			  (unit u-set-fp (out loadreg drf) (cycles 4))
			  (unit u-set-fv (out loadreg drf) (cycles 7))
			  (unit u-set-mtrx (out loadreg drf) (cycles 7)))))

(dshmi fnegs "Floating point negate (single)"
       ()
       "fneg.s $frgh, $frf"
       (+ (f-op 6) frgh (f-ext 2) frf (f-rsvd 0))
       (set frf (c-call SF "sh64_fnegs" frgh))
       (sh5-media-models ((unit u-use-fr (in usereg frgh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg frf) (cycles 4))
			  (unit u-set-dr (out loadreg frf) (cycles 7))
			  (unit u-set-fp (out loadreg frf) (cycles 7))
			  (unit u-set-fv (out loadreg frf) (cycles 7))
			  (unit u-set-mtrx (out loadreg frf) (cycles 7)))))

(dshmi fputscr "Floating point put to FPSCR"
       ()
       "fputscr $frgh"
       (+ (f-op 12) frgh (f-ext 2) (f-dest 63) (f-rsvd 0))
       (set fpscr (subword SI frgh 0))
       (sh5-media-models ((unit u-exec (cycles 8)))))

(dshmi fsqrtd "Floating point square root (double)"
       ()
       "fsqrt.d $drgh, $drf"
       (+ (f-op 14) drgh (f-ext 5) drf (f-rsvd 0))
       (set drf (c-call DF "sh64_fsqrtd" drgh))
       (sh5-media-models ((unit u-use-dr (in usereg drgh))
			  (unit u-fsqrtd (out loadreg drf))
			  (unit u-set-fr (out loadreg drf) (cycles 36))
			  (unit u-set-dr (out loadreg drf) (cycles 35))
			  (unit u-set-fp (out loadreg drf) (cycles 35))
			  (unit u-set-fv (out loadreg drf) (cycles 36))
			  (unit u-set-mtrx (out loadreg drf) (cycles 36)))))

(dshmi fsqrts "Floating point squart root (single)"
       ()
       "fsqrt.s $frgh, $frf"
       (+ (f-op 14) frgh (f-ext 4) frf (f-rsvd 0))
       (set frf (c-call SF "sh64_fsqrts" frgh))
       (sh5-media-models ((unit u-use-fr (in usereg frgh))
			  (unit u-fsqrt (out loadreg frf))
			  (unit u-set-fr (out loadreg frf) (cycles 19))
			  (unit u-set-dr (out loadreg frf) (cycles 20))
			  (unit u-set-fp (out loadreg frf) (cycles 20))
			  (unit u-set-fv (out loadreg frf) (cycles 20))
			  (unit u-set-mtrx (out loadreg frf) (cycles 20)))))

(dshmi fstd "Floating point store (double)"
       ()
       "fst.d $rm, $disp10x8, $drf"
       (+ (f-op 47) rm disp10x8 drf (f-rsvd 0))
       (set (mem DF (add rm disp10x8)) drf)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-dr (in usereg drf))
			  (unit u-exec))))

(dshmi fstp "Floating point store (pair of singles)"
       ()
       "fst.p $rm, $disp10x8, $fpf"
       (+ (f-op 46) rm disp10x8 fpf (f-rsvd 0))
       (sequence ()
		 (set fpf fpf) ; Allows profiling
		 (c-call VOID "sh64_fstp" pc rm disp10x8 (index-of fpf)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-fp (in usereg fpf))
			  (unit u-exec))))

(dshmi fsts "Floating point store (single)"
       ()
       "fst.s $rm, $disp10x4, $frf"
       (+ (f-op 45) rm disp10x4 frf (f-rsvd 0))
       (set (mem SF (add rm disp10x4)) frf)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-fr (in usereg frf))
			  (unit u-exec))))

(dshmi fstxd "Floating point extended store (double)"
       ()
       "fstx.d $rm, $rn, $drf"
       (+ (f-op 15) rm (f-ext 9) rn drf (f-rsvd 0))
       (set (mem DF (add rm rn)) drf)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-use-dr (in usereg drf))
			  (unit u-exec))))

(dshmi fstxp "Floating point extended store (pair of singles)"
       ()
       "fstx.p $rm, $rn, $fpf"
       (+ (f-op 15) rm (f-ext 13) rn fpf (f-rsvd 0))
       (sequence ()
		 (set fpf fpf) ; Allows profiling
		 (c-call VOID "sh64_fstp" pc rm rn (index-of fpf)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-use-fp (in usereg fpf))
			  (unit u-exec))))

(dshmi fstxs "Floating point extended store (single)"
       ()
       "fstx.s $rm, $rn, $frf"
       (+ (f-op 15) rm (f-ext 8) rn frf (f-rsvd 0))
       (set (mem SF (add rm rn)) frf)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-use-fr (in usereg frf))
			  (unit u-exec))))

(dshmi fsubd "Floating point subtract (double)"
       ()
       "fsub.d $drg, $drh, $drf"
       (+ (f-op 13) frg (f-ext 3) frh frf (f-rsvd 0))
       (set drf (c-call DF "sh64_fsubd" drg drh))
       (sh5-media-models ((unit u-use-dr (in usereg drg))
			  (unit u-use-dr (in usereg drh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg drf) (cycles 7))
			  (unit u-set-dr (out loadreg drf) (cycles 6))
			  (unit u-set-fp (out loadreg drf) (cycles 6))
			  (unit u-set-fv (out loadreg drf) (cycles 7))
			  (unit u-set-mtrx (out loadreg drf) (cycles 7)))))

(dshmi fsubs "Floating point subtract (single)"
       ()
       "fsub.s $frg, $frh, $frf"
       (+ (f-op 13) frg (f-ext 2) frh frf (f-rsvd 0))
       (set frf (c-call SF "sh64_fsubs" frg frh))
       (sh5-media-models ((unit u-use-fr (in usereg frg))
			  (unit u-use-fr (in usereg frh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg frf) (cycles 6))
			  (unit u-set-dr (out loadreg frf) (cycles 7))
			  (unit u-set-fp (out loadreg frf) (cycles 7))
			  (unit u-set-fv (out loadreg frf) (cycles 7))
			  (unit u-set-mtrx (out loadreg frf) (cycles 7)))))

(dshmi ftrcdl "Floating point conversion (double to long)"
       ()
       "ftrc.dl $drgh, $frf"
       (+ (f-op 14) drgh (f-ext 11) frf (f-rsvd 0))
       (set frf (c-call SF "sh64_ftrcdl" drgh))
       (sh5-media-models ((unit u-use-dr (in usereg drgh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg frf) (cycles 6))
			  (unit u-set-dr (out loadreg frf) (cycles 7))
			  (unit u-set-fp (out loadreg frf) (cycles 7))
			  (unit u-set-fv (out loadreg frf) (cycles 7))
			  (unit u-set-mtrx (out loadreg frf) (cycles 7)))))

(dshmi ftrcsl "Floating point conversion (single to long)"
       ()
       "ftrc.sl $frgh, $frf"
       (+ (f-op 14) frgh (f-ext 8) frf (f-rsvd 0))
       (set frf (c-call SF "sh64_ftrcsl" frgh))
       (sh5-media-models ((unit u-use-fr (in usereg frgh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg frf) (cycles 6))
			  (unit u-set-dr (out loadreg frf) (cycles 7))
			  (unit u-set-fp (out loadreg frf) (cycles 7))
			  (unit u-set-fv (out loadreg frf) (cycles 7))
			  (unit u-set-mtrx (out loadreg frf) (cycles 7)))))

(dshmi ftrcdq "Floating point conversion (double to quad)"
       ()
       "ftrc.dq $drgh, $drf"
       (+ (f-op 14) drgh (f-ext 9) frf (f-rsvd 0))
       (set drf (c-call DF "sh64_ftrcdq" drgh))
       (sh5-media-models ((unit u-use-dr (in usereg drgh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg drf) (cycles 7))
			  (unit u-set-dr (out loadreg drf) (cycles 6))
			  (unit u-set-fp (out loadreg drf) (cycles 6))
			  (unit u-set-fv (out loadreg drf) (cycles 7))
			  (unit u-set-mtrx (out loadreg drf) (cycles 7)))))

(dshmi ftrcsq "Floating point conversion (single to quad)"
       ()
       "ftrc.sq $frgh, $drf"
       (+ (f-op 14) frgh (f-ext 10) drf (f-rsvd 0))
       (set drf (c-call DF "sh64_ftrcsq" frgh))
       (sh5-media-models ((unit u-use-fr (in usereg frgh))
			  (unit u-fpu (cycles 1))
			  (unit u-set-fr (out loadreg drf) (cycles 7))
			  (unit u-set-dr (out loadreg drf) (cycles 6))
			  (unit u-set-fp (out loadreg drf) (cycles 6))
			  (unit u-set-fv (out loadreg drf) (cycles 7))
			  (unit u-set-mtrx (out loadreg drf) (cycles 7)))))

(dshmi ftrvs "Floating point matrix multiply"
       ()
       "ftrv.s $mtrxg, $fvh, $fvf"
       (+ (f-op 5) mtrxg (f-ext 14) fvh fvf (f-rsvd 0))
       (sequence ()
		 (set mtrxg mtrxg) ; to allow profiling
		 (set fvh fvh) ; to allow profiling
		 (set fvf fvf) ; to allow profiling
		 (c-call "sh64_ftrvs" (index-of mtrxg) (index-of fvh) (index-of fvf)))
       (sh5-media-models ((unit u-use-mtrx (in usereg mtrxg))
			  (unit u-use-fv (in usereg fvh))
			  (unit u-fpu (cycles 4))
			  (unit u-ftrvs (out loadreg fvf)))))

(dshmi getcfg "Get configuration register"
       ()
       "getcfg $rm, $disp6, $rd"
       (+ (f-op 48) rm (f-ext 15) disp6 rd (f-rsvd 0))
       (sequence ((SI address))
		 (set address (add rm disp6))
		 (save-cfg-address address)
		 (set rd (mem SI address)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-getcfg))))

(dshmi getcon "Get control register"
       ()
       "getcon $crk, $rd"
       (+ (f-op 9) crk (f-ext 15) (f-right 63) rd (f-rsvd 0))
       (set rd crk)
       (sh5-media-models ((unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(dshmi gettr "Get target register"
       ()
       "gettr $trb, $rd"
       (+ (f-op 17) (f-6-3 0) trb (f-ext 5) (f-right 63) rd (f-rsvd 0))
       (set rd trb)
       (sh5-media-models ((unit u-use-tr (in usereg trb))
			  (unit u-exec))))

(dshmi icbi "Invalidate instruction cache block"
       ()
       "icbi $rm, $disp6x32"
       (+ (f-op 56) rm (f-ext 5) disp6x32 (f-dest 63) (f-rsvd 0))
       (sequence ()
		 (set rm rm) ; for now to allow profiling
		 (unimp "icbi"))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi ldb "Load byte"
       ()
       "ld.b $rm, $disp10, $rd"
       (+ (f-op 32) rm disp10 rd (f-rsvd 0))
       (set rd (ext DI (mem QI (add rm (ext DI disp10)))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-gr (out loadreg rd)))))

(dshmi ldl "Load long word"
       ()
       "ld.l $rm, $disp10x4, $rd"
       (+ (f-op 34) rm disp10x4 rd (f-rsvd 0))
       (set rd (ext DI (mem SI (add rm (ext DI disp10x4)))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-gr (out loadreg rd)))))

(dshmi ldq "Load quad word"
       ()
       "ld.q $rm, $disp10x8, $rd"
       (+ (f-op 35) rm disp10x8 rd (f-rsvd 0))
       (set rd (mem DI (add rm (ext DI disp10x8))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-gr (out loadreg rd)))))

(dshmi ldub "Load unsigned byte"
       ()
       "ld.ub $rm, $disp10, $rd"
       (+ (f-op 36) rm disp10 rd (f-rsvd 0))
       (set rd (zext DI (mem QI (add rm (ext DI disp10)))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-gr (out loadreg rd)))))

(dshmi lduw "Load unsigned word"
       ()
       "ld.uw $rm, $disp10x2, $rd"
       (+ (f-op 44) rm disp10 rd (f-rsvd 0))
       (set rd (zext DI (mem HI (add rm (ext DI disp10x2)))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-gr (out loadreg rd)))))

(dshmi ldw "Load word"
       ()
       "ld.w $rm, $disp10x2, $rd"
       (+ (f-op 33) rm disp10 rd (f-rsvd 0))
       (set rd (ext DI (mem HI (add rm (ext DI disp10x2)))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-gr (out loadreg rd)))))

(define-pmacro (-ldhi-byte)
  (if (and bytecount 1)
      (set val (add (sll val 8) (zext DI (mem QI addr))))))

(define-pmacro (-ldhi-word)
  (if (and bytecount 2)
      (set val (add (sll val 16) (zext DI (mem HI (and addr -4)))))))

(define-pmacro (-ldhi-long)
  (if (and bytecount 4)
      (set val (add (sll val 32) (zext DI (mem SI (and addr -8)))))))

(dshmi ldhil "Load high part (long word)"
       ()
       "ldhi.l $rm, $disp6, $rd"
       (+ (f-op 48) rm (f-ext 6) disp6 rd (f-rsvd 0))
       (sequence ((DI addr) (QI bytecount) (SI val))
		 (set addr (add rm disp6))
		 (set bytecount (add (and addr 3) 1))
		 (set val 0)
		 (if (and bytecount 4)
		     (set rd (ext DI (mem SI (and addr -4))))
		     (if endian
			 (sequence () ; Big endian.
				   (-ldhi-word)
				   (-ldhi-byte)
				   (set rd (ext DI val)))
			 (sequence () ; Little endian.
				   (-ldhi-byte)
				   (-ldhi-word)
				   (set rd
					(ext DI
					 (sll SI val
					      (sub 32 (mul 8 bytecount)))))))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-gr (out loadreg rd)))))

(dshmi ldhiq "Load high part (quad word)"
       ()
       "ldhi.q $rm, $disp6, $rd"
       (+ (f-op 48) rm (f-ext 7) disp6 rd (f-rsvd 0))
       (sequence ((DI addr) (QI bytecount) (DI val))
		 (set addr (add rm disp6))
		 (set bytecount (add (and addr 7) 1))
		 (set val 0)
		 (if (and bytecount 8)
		     (set rd (mem DI (and addr -8)))
		     (if endian
			 (sequence () ; Big endian.
				   (-ldhi-long)
				   (-ldhi-word)
				   (-ldhi-byte)
				   (set rd val))
			 (sequence () ; Little endian.
				   (-ldhi-byte)
				   (-ldhi-word)
				   (-ldhi-long)
				   (set rd
					(sll val
					     (sub 64 (mul 8 bytecount))))))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-gr (out loadreg rd)))))

(define-pmacro (-ldlo-byte)
  (if (and bytecount 1)
      (set val (add (sll val 8) (zext DI (mem QI addr))))))

(define-pmacro (-ldlo-word)
  (if (and bytecount 2)
      (set val (add (sll val 16) (zext DI (mem HI (and (add addr 1) -2)))))))

(define-pmacro (-ldlo-long)
  (if (and bytecount 4)
      (set val (add (sll val 32) (zext DI (mem SI (and (add addr 3) -4)))))))

(dshmi ldlol "Load low part (long word)"
       ()
       "ldlo.l $rm, $disp6, $rd"
       (+ (f-op 48) rm (f-ext 2) disp6 rd (f-rsvd 0))
       (sequence ((DI addr) (QI bytecount) (SI val))
		 (set addr (add rm disp6))
		 (set bytecount (sub 4 (and addr 3)))
		 (set val 0)
		 (if (and bytecount 4)
		     (set rd (ext DI (mem SI addr)))
		     (if endian
			 (sequence () ; Big endian.
				   (-ldlo-byte)
				   (-ldlo-word)
				   (set rd
					(ext DI
					 (sll SI val
					      (sub 32 (mul 8 bytecount))))))
			 (sequence () ; Little endian.
				   (-ldlo-word)
				   (-ldlo-byte)
				   (set rd (ext DI val))))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-gr (out loadreg rd)))))

(dshmi ldloq "Load low part (quad word)"
       ()
       "ldlo.q $rm, $disp6, $rd"
       (+ (f-op 48) rm (f-ext 3) disp6 rd (f-rsvd 0))
       (sequence ((DI addr) (QI bytecount) (DI val))
		 (set addr (add rm disp6))
		 (set bytecount (sub 8 (and addr 7)))
		 (set val 0)
		 (if (and bytecount 8)
		     (set rd (mem DI addr))
		     (if endian
			 (sequence () ; Big endian.
				   (-ldlo-byte)
				   (-ldlo-word)
				   (-ldlo-long)
				   (set rd
					(sll val (sub 64 (mul 8 bytecount)))))
			 (sequence () ; Little endian.
				   (-ldlo-long)
				   (-ldlo-word)
				   (-ldlo-byte)
				   (set rd val)))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-gr (out loadreg rd)))))

(dshmi ldxb "Load byte (extended displacement)"
       ()
       "ldx.b $rm, $rn, $rd"
       (+ (f-op 16) rm (f-ext 0) rn rd (f-rsvd 0))
       (set rd (ext DI (mem QI (add rm rn))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-gr (out loadreg rd)))))

(dshmi ldxl "Load long word (extended displacement)"
       ()
       "ldx.l $rm, $rn, $rd"
       (+ (f-op 16) rm (f-ext 2) rn rd (f-rsvd 0))
       (set rd (ext DI (mem SI (add rm rn))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-gr (out loadreg rd)))))

(dshmi ldxq "Load quad word (extended displacement)"
       ()
       "ldx.q $rm, $rn, $rd"
       (+ (f-op 16) rm (f-ext 3) rn rd (f-rsvd 0))
       (set rd (mem DI (add rm rn)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-gr (out loadreg rd)))))

(dshmi ldxub "Load unsigned byte (extended displacement)"
       ()
       "ldx.ub $rm, $rn, $rd"
       (+ (f-op 16) rm (f-ext 4) rn rd (f-rsvd 0))
       (set rd (zext DI (mem UQI (add rm rn))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-gr (out loadreg rd)))))

(dshmi ldxuw "Load unsigned word (extended displacement)"
       ()
       "ldx.uw $rm, $rn, $rd"
       (+ (f-op 16) rm (f-ext 5) rn rd (f-rsvd 0))
       (set rd (zext DI (mem UHI (add rm rn))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-gr (out loadreg rd)))))

(dshmi ldxw "Load word (extended displacement)"
       ()
       "ldx.w $rm, $rn, $rd"
       (+ (f-op 16) rm (f-ext 1) rn rd (f-rsvd 0))
       (set rd (ext DI (mem HI (add rm rn))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-memory-access)
			  (unit u-load-gr (out loadreg rd)))))


; Macros to facilitate multimedia instructions.

(define-pmacro (slice-byte expr)
  (sequence ((QI result7) (QI result6) (QI result5) (QI result4)
	     (QI result3) (QI result2) (QI result1) (QI result0))
	    (set result0 (expr (subword QI rm 7) (subword QI rn 7)))
	    (set result1 (expr (subword QI rm 6) (subword QI rn 6)))
	    (set result2 (expr (subword QI rm 5) (subword QI rn 5)))
	    (set result3 (expr (subword QI rm 4) (subword QI rn 4)))
	    (set result4 (expr (subword QI rm 3) (subword QI rn 3)))
	    (set result5 (expr (subword QI rm 2) (subword QI rn 2)))
	    (set result6 (expr (subword QI rm 1) (subword QI rn 1)))
	    (set result7 (expr (subword QI rm 0) (subword QI rn 0)))
	    (set rd (-join-qi result7 result6 result5 result4 result3 result2
			   result1 result0))))

(define-pmacro (slice-word expr)
  (sequence ((HI result3) (HI result2) (HI result1) (HI result0))
	    (set result0 (expr (subword HI rm 3) (subword HI rn 3)))
	    (set result1 (expr (subword HI rm 2) (subword HI rn 2)))
	    (set result2 (expr (subword HI rm 1) (subword HI rn 1)))
	    (set result3 (expr (subword HI rm 0) (subword HI rn 0)))
	    (set rd (-join-hi result3 result2 result1 result0))))

(define-pmacro (slice-word-unop expr)
  (sequence ((HI result3) (HI result2) (HI result1) (HI result0))
	    (set result0 (expr (subword HI rm 3)))
	    (set result1 (expr (subword HI rm 2)))
	    (set result2 (expr (subword HI rm 1)))
	    (set result3 (expr (subword HI rm 0)))
	    (set rd (-join-hi result3 result2 result1 result0))))

(define-pmacro (slice-long expr)
  (sequence ((SI result1) (SI result0))
	    (set result0 (expr (subword SI rm 1) (subword SI rn 1)))
	    (set result1 (expr (subword SI rm 0) (subword SI rn 0)))
	    (set rd (-join-si result1 result0))))

(define-pmacro (slice-long-unop expr)
  (sequence ((SI result1) (SI result0))
	    (set result0 (expr (subword SI rm 1)))
	    (set result1 (expr (subword SI rm 0)))
	    (set rd (-join-si result1 result0))))

; Multimedia instructions.

(dshmi mabsl "Multimedia absolute value (long word)"
       ()
       "mabs.l $rm, $rd"
       (+ (f-op 10) rm (f-ext 10) (f-right 63) rd (f-rsvd 0))
       (slice-long-unop abs)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(dshmi mabsw "Multimedia absolute value (word)"
       ()
       "mabs.w $rm, $rd"
       (+ (f-op 10) rm (f-ext 9) (f-right 63) rd (f-rsvd 0))
       (slice-word-unop abs)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(dshmi maddl "Multimedia add (long word)"
       ()
       "madd.l $rm, $rn, $rd"
       (+ (f-op 2) rm (f-ext 2) rn rd (f-rsvd 0))
       (slice-long add)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi maddw "Multimedia add (word)"
       ()
       "madd.w $rm, $rn, $rd"
       (+ (f-op 2) rm (f-ext 1) rn rd (f-rsvd 0))
       (slice-word add)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(define-pmacro (-maddsl arg1 arg2) (saturate SI 32 (add (ext DI arg1)
							(ext DI arg2))))
(dshmi maddsl "Multimedia add (saturating, long word)"
       ()
       "madds.l $rm, $rn, $rd"
       (+ (f-op 2) rm (f-ext 6) rn rd (f-rsvd 0))
       (slice-long -maddsl)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(define-pmacro (-maddsub arg1 arg2) (usaturate QI 8 (add (zext DI arg1)
							 (zext DI arg2))))
(dshmi maddsub "Multimedia add (saturating, unsigned byte)"
       ()
       "madds.ub $rm, $rn, $rd"
       (+ (f-op 2) rm (f-ext 4) rn rd (f-rsvd 0))
       (slice-byte -maddsub)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(define-pmacro (-maddsw arg1 arg2) (saturate HI 16 (add (ext DI arg1)
							(ext DI arg2))))
(dshmi maddsw "Multimedia add (saturating, word)"
       ()
       "madds.w $rm, $rn, $rd"
       (+ (f-op 2) rm (f-ext 5) rn rd (f-rsvd 0))
       (slice-word -maddsw)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(define-pmacro (-mcmpeq mode arg1 arg2)
  (if mode (eq arg1 arg2) (inv mode 0) (const mode 0)))

(define-pmacro (-mcmpeqb arg1 arg2) (-mcmpeq QI arg1 arg2))
(dshmi mcmpeqb "Multimedia compare equal (byte)"
       ()
       "mcmpeq.b $rm, $rn, $rd"
       (+ (f-op 10) rm (f-ext 0) rn rd (f-rsvd 0))
       (slice-byte -mcmpeqb)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(define-pmacro (-mcmpeql arg1 arg2) (-mcmpeq SI arg1 arg2))
(dshmi mcmpeql "Multimedia compare equal (long word)"
       ()
       "mcmpeq.l $rm, $rn, $rd"
       (+ (f-op 10) rm (f-ext 2) rn rd (f-rsvd 0))
       (slice-long -mcmpeql)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(define-pmacro (-mcmpeqw arg1 arg2) (-mcmpeq HI arg1 arg2))
(dshmi mcmpeqw "Multimedia compare equal (word)"
       ()
       "mcmpeq.w $rm, $rn, $rd"
       (+ (f-op 10) rm (f-ext 1) rn rd (f-rsvd 0))
       (slice-word -mcmpeqw)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(define-pmacro (-mcmpgt mode arg1 arg2)
  (if mode (gt arg1 arg2) (inv mode 0) (const mode 0)))
(define-pmacro (-mcmpgtu mode arg1 arg2)
  (if mode (gtu arg1 arg2) (inv mode 0) (const mode 0)))

(define-pmacro (-mcmpgtl arg1 arg2) (-mcmpgt SI arg1 arg2))
(dshmi mcmpgtl "Multimedia compare greater than (long word)"
       ()
       "mcmpgt.l $rm, $rn, $rd"
       (+ (f-op 10) rm (f-ext 6) rn rd (f-rsvd 0))
       (slice-long -mcmpgtl)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(define-pmacro (-mcmpgtub arg1 arg2) (-mcmpgtu QI arg1 arg2))
(dshmi mcmpgtub "Multimediate compare unsigned greater than (byte)"
       ()
       "mcmpgt.ub $rm, $rn, $rd"
       (+ (f-op 10) rm (f-ext 4) rn rd (f-rsvd 0))
       (slice-byte -mcmpgtub)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(define-pmacro (-mcmpgtw arg1 arg2) (-mcmpgt HI arg1 arg2))
(dshmi mcmpgtw "Multimedia compare greater than (word)"
       ()
       "mcmpgt.w $rm, $rn, $rd"
       (+ (f-op 10) rm (f-ext 5) rn rd (f-rsvd 0))
       (slice-word -mcmpgtw)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(dshmi mcmv "Multimedia conditional move"
       ()
       "mcmv $rm, $rn, $rd"
       (+ (f-op 18) rm (f-ext 3) rn rd (f-rsvd 0))
       (set rd (or (and rm rn) (and rd (inv rn))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi mcnvslw "Multimedia convert/saturate (long to word)"
       ()
       "mcnvs.lw $rm, $rn, $rd"
       (+ (f-op 19) rm (f-ext 13) rn rd (f-rsvd 0))
       (sequence ((HI result3) (HI result2) (HI result1) (HI result0))
		 (set result0 (saturate HI 16 (subword SI rm 1)))
		 (set result1 (saturate HI 16 (subword SI rm 0)))
		 (set result2 (saturate HI 16 (subword SI rn 1)))
		 (set result3 (saturate HI 16 (subword SI rn 0)))
		 (set rd (-join-hi result3 result2 result1 result0)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(dshmi mcnvswb "Multimedia convert/saturate (word to byte)"
       ()
       "mcnvs.wb $rm, $rn, $rd"
       (+ (f-op 19) rm (f-ext 8) rn rd (f-rsvd 0))
       (sequence ((QI result7) (QI result6) (QI result5) (QI result4) 
		  (QI result3) (QI result2) (QI result1) (QI result0))
		 (set result0 (saturate QI 8 (subword HI rm 3)))
		 (set result1 (saturate QI 8 (subword HI rm 2)))
		 (set result2 (saturate QI 8 (subword HI rm 1)))
		 (set result3 (saturate QI 8 (subword HI rm 0)))
		 (set result4 (saturate QI 8 (subword HI rn 3)))
		 (set result5 (saturate QI 8 (subword HI rn 2)))
		 (set result6 (saturate QI 8 (subword HI rn 1)))
		 (set result7 (saturate QI 8 (subword HI rn 0)))
		 (set rd (-join-qi result7 result6 result5 result4
				 result3 result2 result1 result0)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(dshmi mcnvswub "Multimedia convert/saturate (word to unsigned byte)"
       ()
       "mcnvs.wub $rm, $rn, $rd"
       (+ (f-op 19) rm (f-ext 12) rn rd (f-rsvd 0))
       (sequence ((QI result7) (QI result6) (QI result5) (QI result4)
			       (QI result3) (QI result2) (QI result1) (QI result0))
		 (set result0 (usaturate QI 8 (subword HI rm 3)))
		 (set result1 (usaturate QI 8 (subword HI rm 2)))
		 (set result2 (usaturate QI 8 (subword HI rm 1)))
		 (set result3 (usaturate QI 8 (subword HI rm 0)))
		 (set result4 (usaturate QI 8 (subword HI rn 3)))
		 (set result5 (usaturate QI 8 (subword HI rn 2)))
		 (set result6 (usaturate QI 8 (subword HI rn 1)))
		 (set result7 (usaturate QI 8 (subword HI rn 0)))
		 (set rd (-join-qi result7 result6 result5 result4 result3
				 result2 result1 result0)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

; mexter -- generate an mexterN instruction, where:
;   op = primary opcode
;   extop = extended opcode

(define-pmacro (make-mextr n op extop)
  (dshmi (.sym mextr n)
	 (.str "Multimedia extract 64-bit slice (from byte " n ")")
	 ()
	 (.str "mextr" n " $rm, $rn, $rd")
	 (+ (f-op op) rm (f-ext extop) rn rd (f-rsvd 0))
	 (sequence ((QI count) (DI mask) (DI rhs))
		   (set count (mul QI 8 n))
		   (set mask (sll DI (inv 0) count))
		   (set rhs (srl (and rm mask) count))
		   (set count (mul QI 8 (sub QI 8 n)))
		   (set mask (srl DI (inv 0) count))
		   (set rd (or DI rhs (sll DI (and rn mask) count))))
	 (sh5-media-models ((unit u-use-gr (in usereg rm))
			    (unit u-use-gr (in usereg rn))
			    (unit u-exec)))))

(make-mextr 1 10  7)
(make-mextr 2 10 11)
(make-mextr 3 10 15)
(make-mextr 4 11  3)
(make-mextr 5 11  7)
(make-mextr 6 11 11)
(make-mextr 7 11 15)

(dshmi mmacfxwl "Multimedia fractional multiply (word to long)"
       ()
       "mmacfx.wl $rm, $rn, $rd"
       (+ (f-op 18) rm (f-ext 1) rn rd (f-rsvd 0))
       (sequence ((SI temp) (SI result1) (SI result0))
		 (set result0 (subword SI rd 1))
		 (set result1 (subword SI rd 0))
		 (set temp (mul (zext SI (subword HI rm 3)) (zext SI (subword HI rn 3))))
		 (set temp (saturate SI 32 (sll DI temp 1)))
		 (set result0 (saturate SI 32 (add (ext DI result0)
						   (ext DI temp))))
		 (set temp (mul (zext SI (subword HI rm 2)) (zext SI (subword HI rn 2))))
		 (set temp (saturate SI 32 (sll DI temp 1)))
		 (set result1 (saturate SI 32 (add (ext DI result1)
						   (ext DI temp))))
		 (set rd (-join-si result1 result0)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi mmacnfx.wl "Multimedia fractional multiple (word to long)"
       ()
       "mmacnfx.wl $rm, $rn, $rd"
       (+ (f-op 18) rn (f-ext 5) rn rd (f-rsvd 0))
       (sequence ((SI temp) (SI result1) (SI result0))
		 (set result0 (subword SI rd 1))
		 (set result1 (subword SI rd 0))
		 (set temp (mul (zext SI (subword HI rm 3)) (zext SI (subword HI rn 3))))
		 (set temp (saturate SI 32 (sll DI temp 1)))
		 (set result0 (saturate SI 32 (sub (ext DI result0)
						   (ext DI temp))))
		 (set temp (mul (zext SI (subword HI rm 2)) (zext SI (subword HI rn 2))))
		 (set temp (saturate SI 32 (sll DI temp 1)))
		 (set result1 (saturate SI 32 (sub (ext DI result1)
						   (ext DI temp))))
		 (set rd (-join-si result1 result0)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi mmull "Multimedia multiply (long word)"
       ()
       "mmul.l $rm, $rn, $rd"
       (+ (f-op 19) rm (f-ext 2) rn rd (f-rsvd 0))
       (slice-long mul)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec (cycles 2))
			  (unit u-set-gr (cycles 4) (out loadreg rd)))))

(dshmi mmulw "Multimedia multiply (word)"
       ()
       "mmul.w $rm, $rn, $rd"
       (+ (f-op 19) rm (f-ext 1) rn rd (f-rsvd 0))
       (slice-word mul)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 3) (out loadreg rd)))))

(dshmi mmulfxl "Multimedia fractional multiply (long word)"
       ()
       "mmulfx.l $rm, $rn, $rd"
       (+ (f-op 19) rm (f-ext 6) rn rd (f-rsvd 0))
       (sequence ((DI temp) (SI result0) (SI result1))
		 (set temp (mul (zext DI (subword SI rm 1)) (zext DI (subword SI rn 1))))
		 (set result0 (saturate SI 32 (sra temp 31)))
		 (set temp (mul (zext DI (subword SI rm 0)) (zext DI (subword SI rn 0))))
		 (set result1 (saturate SI 32 (sra temp 31)))
		 (set rd (-join-si result1 result0)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec (cycles 2))
			  (unit u-set-gr (cycles 4) (out loadreg rd)))))

(dshmi mmulfxw "Multimedia fractional multiply (word)"
       ()
       "mmulfx.w $rm, $rn, $rd"
       (+ (f-op 19) rm (f-ext 5) rn rd (f-rsvd 0))
       (sequence ((SI temp) (HI result0) (HI result1) (HI result2) (HI result3))
		 (set temp (mul (zext SI (subword HI rm 3)) (zext SI (subword HI rn 3))))
		 (set result0 (saturate HI 16 (sra temp 15)))
		 (set temp (mul (zext SI (subword HI rm 2)) (zext SI (subword HI rn 2))))
		 (set result1 (saturate HI 16 (sra temp 15)))
		 (set temp (mul (zext SI (subword HI rm 1)) (zext SI (subword HI rn 1))))
		 (set result2 (saturate HI 16 (sra temp 15)))
		 (set temp (mul (zext SI (subword HI rm 0)) (zext SI (subword HI rn 0))))
		 (set result3 (saturate HI 16 (sra temp 15)))
		 (set rd (-join-hi result3 result2 result1 result0)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 3) (out loadreg rd)))))

(dshmi mmulfxrpw "Multimedia fractional multiply round positive (word op)"
       ()
       "mmulfxrp.w $rm, $rn, $rd"
       (+ (f-op 19) rm (f-ext 9) rn rd (f-rsvd 0))
       (sequence ((SI temp) (HI result0) (HI result1) (HI result2) (HI result3) (HI c))
		 (set c (sll 1 14))
		 (set temp (mul (zext SI (subword HI rm 3)) (zext SI (subword HI rn 3))))
		 (set result0 (saturate HI 16 (sra (add temp c) 15)))
		 (set temp (mul (zext SI (subword HI rm 2)) (zext SI (subword HI rn 2))))
		 (set result1 (saturate HI 16 (sra (add temp c) 15)))
		 (set temp (mul (zext SI (subword HI rm 1)) (zext SI (subword HI rn 1))))
		 (set result2 (saturate HI 16 (sra (add temp c) 15)))
		 (set temp (mul (zext SI (subword HI rm 0)) (zext SI (subword HI rn 0))))
		 (set result3 (saturate HI 16 (sra (add temp c) 15)))
		 (set rd (-join-hi result3 result2 result1 result0)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 3) (out loadreg rd)))))

(dshmi mmulhiwl "Multimedia multiply higher halves (word to long)"
       ()
       "mmulhi.wl $rm, $rn, $rd"
       (+ (f-op 19) rm (f-ext 14) rn rd (f-rsvd 0))
       (sequence ((SI result1) (SI result0))
		 (set result0 (mul (zext SI (subword HI rm 1)) (zext SI (subword HI rn 1))))
		 (set result1 (mul (zext SI (subword HI rm 0)) (zext SI (subword HI rn 0))))
		 (set rd (-join-si result1 result0)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 3) (out loadreg rd)))))

(dshmi mmullowl "Multimedia multiply lower halves (word to long)"
       ()
       "mmullo.wl $rm, $rn, $rd"
       (+ (f-op 19) rm (f-ext 10) rn rd (f-rsvd 0))
       (sequence ((SI result1) (SI result0))
		 (set result0 (mul (zext SI (subword HI rm 3)) (zext SI (subword HI rn 3))))
		 (set result1 (mul (zext SI (subword HI rm 2)) (zext SI (subword HI rn 2))))
		 (set rd (-join-si result1 result0)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 3) (out loadreg rd)))))

(dshmi mmulsumwq "Multimedia multiply and accumulate (word to quad)"
       ()
       "mmulsum.wq $rm, $rn, $rd"
       (+ (f-op 18) rm (f-ext 9) rn rd (f-rsvd 0))
       (sequence ((DI acc))
		 (set acc (mul SI (zext SI (subword HI rm 0)) (zext SI (subword HI rn 0))))
		 (set acc (add acc (mul SI (zext SI (subword HI rm 1)) (zext SI (subword HI rn 1)))))
		 (set acc (add acc (mul SI (zext SI (subword HI rm 2)) (zext SI (subword HI rn 2)))))
		 (set acc (add acc (mul SI (zext SI (subword HI rm 3)) (zext SI (subword HI rn 3)))))
		 (set rd (add rd acc)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi movi "Move immediate"
       ()
       "movi $imm16, $rd"
       (+ (f-op 51) imm16 rd (f-rsvd 0))
       (set rd (ext DI imm16))
       ())

(dshmi mpermw "Multimedia permutate word"
       ()
       "mperm.w $rm, $rn, $rd"
       (+ (f-op 10) rm (f-ext 13) rn rd (f-rsvd 0))
       (sequence ((QI control) (HI result3) (HI result2) (HI result1) (HI result0))
		 (set control (and QI rn #xff))
		 (set result0 (subword HI rm (sub 3 (and control 3))))
		 (set result1 (subword HI rm (sub 3 (and (srl control 2) 3))))
		 (set result2 (subword HI rm (sub 3 (and (srl control 4) 3))))
		 (set result3 (subword HI rm (sub 3 (and (srl control 6) 3))))
		 (set rd (-join-hi result3 result2 result1 result0)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi msadubq "Multimedia absolute difference (byte)"
       ()
       "msad.ubq $rm, $rn, $rd"
       (+ (f-op 18) rm (f-ext 0) rn rd (f-rsvd 0))
       (sequence ((DI acc))
		 (set acc (abs DI (sub (subword QI rm 0) (subword QI rn 0))))
		 (set acc (add DI acc (abs (sub (subword QI rm 1) (subword QI rn 1)))))
		 (set acc (add DI acc (abs (sub (subword QI rm 2) (subword QI rn 2)))))
		 (set acc (add DI acc (abs (sub (subword QI rm 3) (subword QI rn 3)))))
		 (set acc (add DI acc (abs (sub (subword QI rm 4) (subword QI rn 4)))))
		 (set acc (add DI acc (abs (sub (subword QI rm 5) (subword QI rn 5)))))
		 (set acc (add DI acc (abs (sub (subword QI rm 6) (subword QI rn 6)))))
		 (set acc (add DI acc (abs (sub (subword QI rm 7) (subword QI rn 7)))))
		 (set rd (add rd acc)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(define-pmacro (-mshaldsl arg) (saturate SI 32 (sll DI arg (and rn 31))))
(dshmi mshaldsl "Multimedia saturating arithmetic left shift (long word)"
       ()
       "mshalds.l $rm, $rn, $rd"
       (+ (f-op 3) rm (f-ext 6) rn rd (f-rsvd 0))
       (slice-long-unop -mshaldsl)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(define-pmacro (-mshaldsw arg) (saturate HI 16 (sll DI arg (and rn 15))))
(dshmi mshaldsw "Multimedia saturating arithmetic left shift (word)"
       ()
       "mshalds.w $rm, $rn, $rd"
       (+ (f-op 3) rm (f-ext 5) rn rd (f-rsvd 0))
       (slice-word-unop -mshaldsw)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(define-pmacro (-mshardl arg) (sra arg (and rn 31)))
(dshmi mshardl "Multimedia arithmetic right shift (long)"
       ()
       "mshard.l $rm, $rn, $rd"
       (+ (f-op 3) rm (f-ext 10) rn rd (f-rsvd 0))
       (slice-long-unop -mshardl)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(define-pmacro (-mshardw arg) (sra arg (and rn 15)))
(dshmi mshardw "Multimedia arithmetic right shift (word)"
       ()
       "mshard.w $rm, $rn, $rd"
       (+ (f-op 3) rm (f-ext 9) rn rd (f-rsvd 0))
       (slice-word-unop -mshardw)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi mshardsq "Multimedia saturating arithmetic right shift (quad word)"
       ()
       "mshards.q $rm, $rn, $rd"
       (+ (f-op 3) rm (f-ext 11) rn rd (f-rsvd 0))
       (set rd (saturate DI 16 (sra rm (and rn 63))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(dshmi mshfhib "Multimedia shuffle higher-half (byte)"
       ()
       "mshfhi.b $rm, $rn, $rd"
       (+ (f-op 11) rm (f-ext 4) rn rd (f-rsvd 0))
       (sequence ((QI result7) (QI result6) (QI result5) (QI result4)
		  (QI result3) (QI result2) (QI result1) (QI result0))
		 (set result0 (subword QI rm 3))
		 (set result1 (subword QI rn 3))
		 (set result2 (subword QI rm 2))
		 (set result3 (subword QI rn 2))
		 (set result4 (subword QI rm 1))
		 (set result5 (subword QI rn 1))
		 (set result6 (subword QI rm 0))
		 (set result7 (subword QI rn 0))
		 (set rd (-join-qi result7 result6 result5 result4 result3
				 result2 result1 result0)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi mshfhil "Multimedia shuffle higher-half (long)"
       ()
       "mshfhi.l $rm, $rn, $rd"
       (+ (f-op 11) rm (f-ext 6) rn rd (f-rsvd 0))
       (sequence ((SI result1) (SI result0))
		 (set result0 (subword SI rm 0))
		 (set result1 (subword SI rn 0))
		 (set rd (-join-si result1 result0)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi mshfhiw "Multimedia shuffle higher-half (word)"
       ()
       "mshfhi.w $rm, $rn, $rd"
       (+ (f-op 11) rm (f-ext 5) rn rd (f-rsvd 0))
       (sequence ((HI result3) (HI result2) (HI result1) (HI result0))
		 (set result0 (subword HI rm 1))
		 (set result1 (subword HI rn 1))
		 (set result2 (subword HI rm 0))
		 (set result3 (subword HI rn 0))
		 (set rd (-join-hi result3 result2 result1 result0)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi mshflob "Multimedia shuffle lower-half (byte)"
       ()
       "mshflo.b $rm, $rn, $rd"
       (+ (f-op 11) rm (f-ext 0) rn rd (f-rsvd 0))
       (sequence ((QI result7) (QI result6) (QI result5) (QI result4)
		  (QI result3) (QI result2) (QI result1) (QI result0))
		 (set result0 (subword QI rm 7))
		 (set result1 (subword QI rn 7))
		 (set result2 (subword QI rm 6))
		 (set result3 (subword QI rn 6))
		 (set result4 (subword QI rm 5))
		 (set result5 (subword QI rn 5))
		 (set result6 (subword QI rm 4))
		 (set result7 (subword QI rn 4))
		 (set rd (-join-qi result7 result6 result5 result4 result3
				 result2 result1 result0)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi mshflol "Multimedia shuffle lower-half (long)"
       ()
       "mshflo.l $rm, $rn, $rd"
       (+ (f-op 11) rm (f-ext 2) rn rd (f-rsvd 0))
       (sequence ((SI result1) (SI result0))
		 (set result0 (subword SI rm 1))
		 (set result1 (subword SI rn 1))
		 (set rd (-join-si result1 result0)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi mshflow "Multimedia shuffle lower-half (word)"
       ()
       "mshflo.w $rm, $rn, $rd"
       (+ (f-op 11) rm (f-ext 1) rn rd (f-rsvd 0))
       (sequence ((HI result3) (HI result2) (HI result1) (HI result0))
		 (set result0 (subword HI rm 3))
		 (set result1 (subword HI rn 3))
		 (set result2 (subword HI rm 2))
		 (set result3 (subword HI rn 2))
		 (set rd (-join-hi result3 result2 result1 result0)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(define-pmacro (-mshlldl arg) (sll arg (and rn 31)))
(dshmi mshlldl "Multimedia logical left shift (long word)"
       ()
       "mshlld.l $rm, $rn, $rd"
       (+ (f-op 3) rm (f-ext 2) rn rd (f-rsvd 0))
       (slice-long-unop -mshlldl)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(define-pmacro (-mshlldw arg) (sll arg (and rn 15)))
(dshmi mshlldw "Multimedia logical left shift (word)"
       ()
       "mshlld.w $rm, $rn, $rd"
       (+ (f-op 3) rm (f-ext 1) rn rd (f-rsvd 0))
       (slice-word-unop -mshlldw)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(define-pmacro (-mshlrdl arg) (srl arg (and rn 31)))
(dshmi mshlrdl "Multimedia logical right shift (long word)"
       ()
       "mshlrd.l $rm, $rn, $rd"
       (+ (f-op 3) rm (f-ext 14) rn rd (f-rsvd 0))
       (slice-long-unop -mshlrdl)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(define-pmacro (-mshlrdw arg) (srl arg (and rn 15)))
(dshmi mshlrdw "Multimedia logical right shift (word)"
       ()
       "mshlrd.w $rm, $rn, $rd"
       (+ (f-op 3) rm (f-ext 13) rn rd (f-rsvd 0))
       (slice-word-unop -mshlrdw)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi msubl "Multimedia subtract (long word)"
       ()
       "msub.l $rm, $rn, $rd"
       (+ (f-op 2) rm (f-ext 10) rn rd (f-rsvd 0))
       (slice-long sub)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi msubw "Multimedia add (word)"
       ()
       "msub.w $rm, $rn, $rd"
       (+ (f-op 2) rm (f-ext 9) rn rd (f-rsvd 0))
       (slice-word sub)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(define-pmacro (-msubsl arg1 arg2) (saturate SI 32 (sub (ext DI arg1)
							(ext DI arg2))))
(dshmi msubsl "Multimedia subtract (saturating long)"
       ()
       "msubs.l $rm, $rn, $rd"
       (+ (f-op 2) rm (f-ext 14) rn rd (f-rsvd 0))
       (slice-long -msubsl)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(define-pmacro (-msubsub arg1 arg2) (usaturate QI 8 (sub (zext DI arg1)
							 (zext DI arg2))))
(dshmi msubsub "Multimedia subtract (saturating byte)"
       ()
       "msubs.ub $rm, $rn, $rd"
       (+ (f-op 2) rm (f-ext 12) rn rd (f-rsvd 0))
       (slice-byte -msubsub)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(define-pmacro (-msubsw arg1 arg2) (saturate HI 16 (sub (ext DI arg1)
							(ext DI arg2))))
(dshmi msubsw "Multimedia subtract (saturating word)"
       ()
       "msubs.w $rm, $rn, $rd"
       (+ (f-op 2) rm (f-ext 13) rn rd (f-rsvd 0))
       (slice-byte -msubsw)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 2) (out loadreg rd)))))

(dshmi mulsl "Multiply signed long"
       ()
       "muls.l $rm, $rn, $rd"
       (+ (f-op 1) rm (f-ext 14) rn rd (f-rsvd 0))
       (set rd (mul (ext DI (subword SI rm 1)) (ext DI (subword SI rn 1))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 3) (out loadreg rd)))))

(dshmi mulul "Multiply unsigned long"
       ()
       "mulu.l $rm, $rn, $rd"
       (+ (f-op 0) rm (f-ext 14) rn rd (f-rsvd 0))
       (set rd (mul (zext DI (subword SI rm 1)) (zext DI (subword SI rn 1))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-set-gr (cycles 3) (out loadreg rd)))))

(dshmi nop "No operation"
       ()
       "nop"
       (+ (f-op 27) (f-left 63) (f-ext 0) (f-right 63) (f-dest 63) (f-rsvd 0))
       (nop)
       ())

(dshmi nsb "Number of consecutive sign bits"
       ()
       "nsb $rm, $rd"
       (+ (f-op 0) rm (f-ext 13) (f-right 63) rd (f-rsvd 0))
       ; Semantics requires a loop construct, so punt to C.
       (set rd (c-call DI "sh64_nsb" rm))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi ocbi "Invalidate operand cache block"
       ()
       "ocbi $rm, $disp6x32"
       (+ (f-op 56) rm (f-ext 9) disp6x32 (f-dest 63) (f-rsvd 0))
       (sequence ()
		 (set rm rm) ; for now to allow profiling
		 (unimp "ocbi"))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi ocbp "Purge operand cache block"
       ()
       "ocbp $rm, $disp6x32"
       (+ (f-op 56) rm (f-ext 8) disp6x32 (f-dest 63) (f-rsvd 0))
       (sequence ()
		 (set rm rm) ; for now to allow profiling
		 (unimp "ocbp"))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi ocbwb "Write-back operand cache block"
       ()
       "ocbwb $rm, $disp6x32"
       (+ (f-op 56) rm (f-ext 12) disp6x32 (f-dest 63) (f-rsvd 0))
       (sequence ()
		 (set rm rm) ; for now to allow profiling
		 (unimp "ocbwb"))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi or "OR"
       ()
       "or $rm, $rn, $rd"
       (+ (f-op 1) rm (f-ext 9) rn rd (f-rsvd 0))
       (set rd (or rm rn))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi ori "OR immediate"
       ()
       "ori $rm, $imm10, $rd"
       (+ (f-op 55) rm imm10 rd (f-rsvd 0))
       (set rd (or rm (ext DI imm10)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi prefi "Prefetch instruction"
       ()
       "prefi $rm, $disp6x32"
       (+ (f-op 56) rm (f-ext 1) disp6x32 (f-right 63) (f-rsvd 0))
       (sequence ()
		 (set rm rm) ; for now to allow profiling
		 (unimp "prefi"))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi pta "Prepare target register for SHmedia target"
       ()
       "pta$likely $disp16, $tra"
       (+ (f-op 58) disp16 likely (f-23-2 0) tra (f-rsvd 0))
       (sequence ()
		 (save-branch-prediction (index-of tra) likely)
		 (set tra (add disp16 1)))
       (sh5-media-models ((unit u-exec)
			  (unit u-pt (out targetreg tra)))))

(dshmi ptabs "Prepare target register with absolute value from register"
       ()
       "ptabs$likely $rn, $tra"
       (+ (f-op 26) (f-left 63) (f-ext 1) rn likely (f-23-2 0) tra (f-rsvd 0))
       (sequence ()
		 (save-branch-prediction (index-of tra) likely)
		 (set tra rn))
       (sh5-media-models ((unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-pt (out targetreg tra)))))

(dshmi ptb "Prepare target register for SHcompact target"
       ()
       "ptb$likely $disp16, $tra"
       (+ (f-op 59) disp16 likely (f-23-2 0) tra (f-rsvd 0))
       (sequence ()
		 (save-branch-prediction (index-of tra) likely)
		 (set tra disp16))
       (sh5-media-models ((unit u-exec)
			  (unit u-pt (out targetreg tra)))))

(dshmi ptrel "Prepare target register with relative value from register"
       ()
       "ptrel$likely $rn, $tra"
       (+ (f-op 26) (f-left 63) (f-ext 5) rn likely (f-23-2 0) tra (f-rsvd 0))
       (sequence ()
		 (save-branch-prediction (index-of tra) likely)
		 (set tra (add pc rn)))
       (sh5-media-models ((unit u-use-gr (in usereg rn))
			  (unit u-exec)
			  (unit u-pt (out targetreg tra)))))

(dshmi putcfg "Put configuration register"
       ()
       "putcfg $rm, $disp6, $rd"
       (+ (f-op 56) rm (f-ext 15) disp6 rd (f-rsvd 0))
       (sequence ((SI address))
		 (set address (add rm disp6))
		 (save-cfg-address address)
		 (set (mem SI address) rd))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-putcfg))))

(dshmi putcon "Put control register"
       ()
       "putcon $rm, $crj"
       (+ (f-op 27) rm (f-ext 15) (f-right 63) crj (f-rsvd 0))
       (set crj rm)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec (cycles 5)))))

(dshmi rte "Return from exception"
       ()
       "rte"
       (+ (f-op 27) (f-left 63) (f-ext 3) (f-right 63) (f-dest 63) (f-rsvd 0))
       (unimp "rte")
       (sh5-media-models ((unit u-exec (cycles 8)))))

(dshmi shard "Arithmetic right shift"
       ()
       "shard $rm, $rn, $rd"
       (+ (f-op 1) rm (f-ext 7) rn rd (f-rsvd 0))
       (set rd (sra rm (and rn 63)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi shardl "Arithmetic right shift (long word)"
       ()
       "shard.l $rm, $rn, $rd"
       (+ (f-op 1) rm (f-ext 6) rn rd (f-rsvd 0))
       (set rd (ext DI (sra (subword SI rm 1) (and rn 63))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi shari "Arithmetic right shift (immediate count)"
       ()
       "shari $rm, $uimm6, $rd"
       (+ (f-op 49) rm (f-ext 7) uimm6 rd (f-rsvd 0))
       (set rd (sra rm uimm6))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi sharil "Arithmetic right shift (long word, immediate count)"
       ()
       "shari.l $rm, $uimm6, $rd"
       (+ (f-op 49) rm (f-ext 6) uimm6 rd (f-rsvd 0))
       (set rd (ext DI (sra (subword SI rm 1) (and uimm6 63))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi shlld "Logical left shift"
       ()
       "shlld $rm, $rn, $rd"
       (+ (f-op 1) rm (f-ext 1) rn rd (f-rsvd 0))
       (set rd (sll rm (and rn 63)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi shlldl "Logical left shift (long word)"
       ()
       "shlld.l $rm, $rn, $rd"
       (+ (f-op 1) rm (f-ext 0) rn rd (f-rsvd 0))
       (set rd (ext DI (sll (subword SI rm 1) (and rn 63))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi shlli "Logical left shift (immediate count)"
       ()
       "shlli $rm, $uimm6, $rd"
       (+ (f-op 49) rm (f-ext 1) uimm6 rd (f-rsvd 0))
       (set rd (sll rm uimm6))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi shllil "Logical left shift (long word, immediate count)"
       ()
       "shlli.l $rm, $uimm6, $rd"
       (+ (f-op 49) rm (f-ext 0) uimm6 rd (f-rsvd 0))
       (set rd (ext DI (sll (subword SI rm 1) (and uimm6 63))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi shlrd "Logical right shift"
       ()
       "shlrd $rm, $rn, $rd"
       (+ (f-op 1) rm (f-ext 3) rn rd (f-rsvd 0))
       (set rd (srl rm (and rn 63)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi shlrdl "Logical right shift (long word)"
       ()
       "shlrd.l $rm, $rn, $rd"
       (+ (f-op 1) rm (f-ext 2) rn rd (f-rsvd 0))
       (set rd (ext DI (srl (subword SI rm 1) (and rn 63))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi shlri "Logical right shift (immediate count)"
       ()
       "shlri $rm, $uimm6, $rd"
       (+ (f-op 49) rm (f-ext 3) uimm6 rd (f-rsvd 0))
       (set rd (srl rm uimm6))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi shlril "Logical right shift (long word, immediate count)"
       ()
       "shlri.l $rm, $uimm6, $rd"
       (+ (f-op 49) rm (f-ext 2) uimm6 rd (f-rsvd 0))
       (set rd (ext DI (srl (subword SI rm 1) (and uimm6 63))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi shori "Shift-or immediate"
       ()
       "shori $uimm16, $rd"
       (+ (f-op 50) uimm16 rd (f-rsvd 0))
       (set rd (or (sll rd 16) (zext DI uimm16)))
       (sh5-media-models ((unit u-use-gr (in usereg rd))
			  (unit u-exec))))

(dshmi sleep "Sleep"
       ()
       "sleep"
       (+ (f-op 27) (f-left 63) (f-ext 7) (f-right 63) (f-dest 63) (f-rsvd 0))
       (unimp "sleep")
       ())

(dshmi stb "Store byte"
       ()
       "st.b $rm, $disp10, $rd"
       (+ (f-op 40) rm disp10 rd (f-rsvd 0))
       (set (mem UQI (add rm (ext DI disp10))) (and QI rd #xff))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi stl "Store long word"
       ()
       "st.l $rm, $disp10x4, $rd"
       (+ (f-op 42) rm disp10x4 rd (f-rsvd 0))
       (set (mem SI (add rm (ext DI disp10x4))) (and SI rd #xffffffff))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi stq "Store quad word"
       ()
       "st.q $rm, $disp10x8, $rd"
       (+ (f-op 43) rm disp10x8 rd (f-rsvd 0))
       (set (mem DI (add rm (ext DI disp10x8))) rd)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi stw "Store word"
       ()
       "st.w $rm, $disp10x2, $rd"
       (+ (f-op 41) rm disp10x2 rd (f-rsvd 0))
       (set (mem HI (add rm (ext DI disp10x2))) (and HI rd #xffff))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(define-pmacro (-sthi-byte)
  (if (and bytecount 1)
      (sequence ()
		(set (mem UQI addr) (and QI val #xff))
		(set val (srl val 8)))))

(define-pmacro (-sthi-word)
  (if (and bytecount 2)
      (sequence ()
		(set (mem HI (and addr -4)) (and HI val #xffff))
		(set val (srl val 16)))))

(define-pmacro (-sthi-long)
  (if (and bytecount 4)
      (sequence ()
		(set (mem SI (and addr -8)) (and SI val #xffffffff))
		(set val (srl val 32)))))

(dshmi sthil "Store high part (long word)"
      ()
       "sthi.l $rm, $disp6, $rd"
       (+ (f-op 56) rm (f-ext 6) disp6 rd (f-rsvd 0))
       (sequence ((DI addr) (QI bytecount) (DI val))
		 (set addr (add rm disp6))
		 (set bytecount (add (and addr 3) 1))
		 (if (and bytecount 4)
		     (set (mem SI (and addr -4)) rd)
		     (if endian
			 (sequence ()
				   ; Big endian.
				   (set val rd)
				   (-sthi-byte)
				   (-sthi-word))
			 (sequence ()
				   (set val (srl rd (sub 32 (mul 8 bytecount))))
				   (-sthi-word)
				   (-sthi-byte)))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi sthiq "Store high part (quad word)"
       ()
       "sthi.q $rm, $disp6, $rd"
       (+ (f-op 56) rm (f-ext 7) disp6 rd (f-rsvd 0))
       (sequence ((DI addr) (QI bytecount) (DI val))
		 (set addr (add rm disp6))
		 (set bytecount (add (and addr 7) 1))
		 (if (and bytecount 8)
		     (set (mem DI (and addr -8)) rd)
		     (if endian
			 (sequence ()
				   (set val rd)
				   (-sthi-byte)
				   (-sthi-word)
				   (-sthi-long))
			 (sequence ()
				   (set val (srl rd (sub 64 (mul 8 bytecount))))
				   (-sthi-long)
				   (-sthi-word)
				   (-sthi-byte)))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(define-pmacro (-stlo-byte)
  (if (and bytecount 1)
      (sequence ()
		(set (mem UQI addr) (and QI val #xff))
		(set val (srl val 8)))))

(define-pmacro (-stlo-word)
  (if (and bytecount 2)
      (sequence ()
		(set (mem UHI (and (add addr 1) -2)) (and HI val #xffff))
		(set val (srl val 16)))))

(define-pmacro (-stlo-long)
  (if (and bytecount 4)
      (sequence ()
		(set (mem USI (and (add addr  3) -4)) (and SI val #xffffffff))
		(set val (srl val 32)))))

(dshmi stlol "Store low part (long word)"
       ()
       "stlo.l $rm, $disp6, $rd"
       (+ (f-op 56) rm (f-ext 2) disp6 rd (f-rsvd 0))
       (sequence ((DI addr) (QI bytecount) (DI val))
		 (set addr (add rm disp6))
		 (set bytecount (sub 4 (and addr 3)))
		 (if (and bytecount 4)
		     (set (mem USI addr) rd)
		     (if endian
			 (sequence ()
				   (set val (srl rd (sub 32 (mul 8 bytecount))))
				   (-stlo-word)
				   (-stlo-byte))
			 (sequence ()
				   (set val rd)
				   (-stlo-byte)
				   (-stlo-word)))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi stloq "Store low part (quad word)"
       ()
       "stlo.q $rm, $disp6, $rd"
       (+ (f-op 56) rm (f-ext 3) disp6 rd (f-rsvd 0))
       (sequence ((DI addr) (QI bytecount) (DI val))
		 (set addr (add rm disp6))
		 (set bytecount (sub 8 (and addr 7)))
		 (if (and bytecount 8)
		     (set (mem UDI addr) rd)
		     (if endian
			 (sequence ()
				   (set val (srl rd (sub 64 (mul 8 bytecount))))
				   (-stlo-long)
				   (-stlo-word)
				   (-stlo-byte))
			 (sequence ()
				   (set val rd)
				   (-stlo-byte)
				   (-stlo-word)
				   (-stlo-long)))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))

(dshmi stxb "Store byte (extended displacement)"
       ()
       "stx.b $rm, $rn, $rd"
       (+ (f-op 24) rm (f-ext 0) rn rd (f-rsvd 0))
       (set (mem UQI (add rm rn)) (subword QI rd 7))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi stxl "Store long (extended displacement)"
       ()
       "stx.l $rm, $rn, $rd"
       (+ (f-op 24) rm (f-ext 2) rn rd (f-rsvd 0))
       (set (mem SI (add rm rn)) (subword SI rd 1))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi stxq "Store quad word (extended displacement)"
       ()
       "stx.q $rm, $rn, $rd"
       (+ (f-op 24) rm (f-ext 3) rn rd (f-rsvd 0))
       (set (mem DI (add rm rn)) rd)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi stxw "Store word (extended displacement)"
       ()
       "stx.w $rm, $rn, $rd"
       (+ (f-op 24) rm (f-ext 1) rn rd (f-rsvd 0))
       (set (mem HI (add rm rn)) (subword HI rd 3))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi sub "Subtract"
       ()
       "sub $rm, $rn, $rd"
       (+ (f-op 0) rm (f-ext 11) rn rd (f-rsvd 0))
       (set rd (sub rm rn))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi subl "Subtract long"
       ()
       "sub.l $rm, $rn, $rd"
       (+ (f-op 0) rm (f-ext 10) rn rd (f-rsvd 0))
       (set rd (ext DI (sub (subword SI rm 1) (subword SI rn 1))))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi swapq "Swap quad words"
       ()
       "swap.q $rm, $rn, $rd"
       (+ (f-op 8) rm (f-ext 3) rn rd (f-rsvd 0))
       (sequence ((DI addr) (DI temp))
		 (set addr (add rm rn))
		 (set temp (mem DI addr))
		 (set (mem DI addr) rd)
		 (set rd temp))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi synci "Synchronise instruction fetch"
       ()
       "synci"
       (+ (f-op 27) (f-left 63) (f-ext 2) (f-right 63) (f-dest 63) (f-rsvd 0))
       (unimp "synci")
       ())

(dshmi synco "Synchronise data operations"
       ()
       "synco"
       (+ (f-op 27) (f-left 63) (f-ext 6) (f-right 63) (f-dest 63) (f-rsvd 0))
       (unimp "synco")
       ())

(dshmi trapa "Trap"
       ()
       "trapa $rm"
       (+ (f-op 27) rm (f-ext 1) (f-right 63) (f-dest 63) (f-rsvd 0))
       (c-call "sh64_trapa" rm pc)
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec (cycles 10)))))

(dshmi xor "Exclusive OR"
       ()
       "xor $rm, $rn, $rd"
       (+ (f-op 1) rm (f-ext 13) rn rd (f-rsvd 0))
       (set rd (xor rm rn))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-use-gr (in usereg rn))
			  (unit u-exec))))

(dshmi xori "Exclusive OR immediate"
       ()
       "xori $rm, $imm6, $rd"
       (+ (f-op 49) rm (f-ext 13) rn rd (f-rsvd 0))
       (set rd (xor rm (ext DI imm6)))
       (sh5-media-models ((unit u-use-gr (in usereg rm))
			  (unit u-exec))))
