12a6b7db3Sskrll; IQ2000/IQ10 Common CPU description. -*- Scheme -*-
2b578a859Schristos; Copyright 2001, 2002, 2007, 2009 Free Software Foundation, Inc.
32a6b7db3Sskrll;
42a6b7db3Sskrll; Contributed by Red Hat Inc; developed under contract from Fujitsu.
52a6b7db3Sskrll;
62a6b7db3Sskrll; This file is part of the GNU Binutils.
72a6b7db3Sskrll;
82a6b7db3Sskrll; This program is free software; you can redistribute it and/or modify
92a6b7db3Sskrll; it under the terms of the GNU General Public License as published by
102a6b7db3Sskrll; the Free Software Foundation; either version 3 of the License, or
112a6b7db3Sskrll; (at your option) any later version.
122a6b7db3Sskrll;
132a6b7db3Sskrll; This program is distributed in the hope that it will be useful,
142a6b7db3Sskrll; but WITHOUT ANY WARRANTY; without even the implied warranty of
152a6b7db3Sskrll; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
162a6b7db3Sskrll; GNU General Public License for more details.
172a6b7db3Sskrll;
182a6b7db3Sskrll; You should have received a copy of the GNU General Public License
192a6b7db3Sskrll; along with this program; if not, write to the Free Software
202a6b7db3Sskrll; Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
212a6b7db3Sskrll; MA 02110-1301, USA.
222a6b7db3Sskrll
232a6b7db3Sskrll(include "simplify.inc")
242a6b7db3Sskrll
252a6b7db3Sskrll(define-arch
262a6b7db3Sskrll  (name iq2000)
272a6b7db3Sskrll  (comment "IQ2000 architecture")
282a6b7db3Sskrll  (insn-lsb0? #t)
292a6b7db3Sskrll  (machs iq2000 iq10)
302a6b7db3Sskrll  (isas iq2000)
312a6b7db3Sskrll)
322a6b7db3Sskrll
332a6b7db3Sskrll(define-isa
342a6b7db3Sskrll  (name iq2000)
352a6b7db3Sskrll  (comment "Basic IQ2000 instruction set")
362a6b7db3Sskrll  (default-insn-word-bitsize 32)
372a6b7db3Sskrll  (default-insn-bitsize 32)
382a6b7db3Sskrll  (base-insn-bitsize 32)
392a6b7db3Sskrll  (decode-assist (31 30 29 28 27 26))
402a6b7db3Sskrll)
412a6b7db3Sskrll
422a6b7db3Sskrll(define-cpu
432a6b7db3Sskrll  (name iq2000bf)
442a6b7db3Sskrll  (comment "IQ2000 family")
452a6b7db3Sskrll  (endian big)
462a6b7db3Sskrll  (word-bitsize 32)
472a6b7db3Sskrll  (file-transform "")
482a6b7db3Sskrll)
492a6b7db3Sskrll
502a6b7db3Sskrll(define-cpu
512a6b7db3Sskrll  (name iq10bf)
522a6b7db3Sskrll  (comment "IQ10 coprocessor family")
532a6b7db3Sskrll  (endian big)
542a6b7db3Sskrll  (word-bitsize 32)
552a6b7db3Sskrll  (file-transform "")
562a6b7db3Sskrll
572a6b7db3Sskrll)
582a6b7db3Sskrll
592a6b7db3Sskrll(define-mach
602a6b7db3Sskrll  (name iq2000)
612a6b7db3Sskrll  (comment "IQ2000 packet processing engine")
622a6b7db3Sskrll  (cpu iq2000bf)
632a6b7db3Sskrll  (isas iq2000)
642a6b7db3Sskrll)
652a6b7db3Sskrll
662a6b7db3Sskrll(define-mach
672a6b7db3Sskrll  (name iq10)
682a6b7db3Sskrll  (comment "IQ10 coprocessor")
692a6b7db3Sskrll  (cpu iq10bf)
702a6b7db3Sskrll  (isas iq2000)
712a6b7db3Sskrll)
722a6b7db3Sskrll
732a6b7db3Sskrll(define-model
742a6b7db3Sskrll  (name iq2000)
752a6b7db3Sskrll  (comment "IQ2000 microprocessor")
762a6b7db3Sskrll  (mach iq2000)
772a6b7db3Sskrll  (unit u-exec "Execution Unit" ()
782a6b7db3Sskrll	1 1 ; issue done
792a6b7db3Sskrll	() () () ())
802a6b7db3Sskrll)
812a6b7db3Sskrll
822a6b7db3Sskrll(define-model
832a6b7db3Sskrll  (name iq10)
842a6b7db3Sskrll  (comment "IQ10 coprocessor")
852a6b7db3Sskrll  (mach iq10)
862a6b7db3Sskrll  (unit u-exec "Execution Unit" ()
872a6b7db3Sskrll	1 1 ; issue done
882a6b7db3Sskrll	() () () ())
892a6b7db3Sskrll)
902a6b7db3Sskrll
912a6b7db3Sskrll; Macros to simplify MACH attribute specification.
922a6b7db3Sskrll
932a6b7db3Sskrll(define-pmacro MACH2000 (MACH iq2000))
942a6b7db3Sskrll(define-pmacro MACH10 (MACH iq10))
952a6b7db3Sskrll
962a6b7db3Sskrll
972a6b7db3Sskrll; Hardware elements.
982a6b7db3Sskrll
992a6b7db3Sskrll(define-hardware
1002a6b7db3Sskrll  (name h-pc)
1012a6b7db3Sskrll  (comment "program counter")
1022a6b7db3Sskrll  (attrs PC PROFILE (ISA iq2000))
1032a6b7db3Sskrll  (type pc)
1042a6b7db3Sskrll  (get () (c-call USI "get_h_pc"))
1052a6b7db3Sskrll  (set (newval) (c-call VOID "set_h_pc" newval))
1062a6b7db3Sskrll)
1072a6b7db3Sskrll; FIXME: it would be nice if the hardwired zero in R0 could be
1082a6b7db3Sskrll; specified as a virtual hardware element, with one less register in
1092a6b7db3Sskrll; the register file proper.
1102a6b7db3Sskrll
1112a6b7db3Sskrll(define-keyword
1122a6b7db3Sskrll  (name gr-names)
1132a6b7db3Sskrll  (print-name h-gr)
1142a6b7db3Sskrll  (values (r0 0)   (%0 0)   (r1 1)   (%1 1)   (r2 2)   (%2 2)   (r3 3)   (%3 3)
1152a6b7db3Sskrll          (r4 4)   (%4 4)   (r5 5)   (%5 5)   (r6 6)   (%6 6)   (r7 7)   (%7 7)
1162a6b7db3Sskrll          (r8 8)   (%8 8)   (r9 9)   (%9 9)   (r10 10) (%10 10) (r11 11) (%11 11)
1172a6b7db3Sskrll          (r12 12) (%12 12) (r13 13) (%13 13) (r14 14) (%14 14) (r15 15) (%15 15)
1182a6b7db3Sskrll          (r16 16) (%16 16) (r17 17) (%17 17) (r18 18) (%18 18) (r19 19) (%19 19)
1192a6b7db3Sskrll          (r20 20) (%20 20) (r21 21) (%21 21) (r22 22) (%22 22) (r23 23) (%23 23)
1202a6b7db3Sskrll          (r24 24) (%24 24) (r25 25) (%25 25) (r26 26) (%26 26) (r27 27) (%27 27)
1212a6b7db3Sskrll          (r28 28) (%28 28) (r29 29) (%29 29) (r30 30) (%30 30) (r31 31) (%31 31))
1222a6b7db3Sskrll)
1232a6b7db3Sskrll
1242a6b7db3Sskrll(define-hardware
1252a6b7db3Sskrll  (name h-gr)
1262a6b7db3Sskrll  (comment "General purpose registers")
1272a6b7db3Sskrll;  (attrs (ISA iq2000) CACHE-ADDR)
1282a6b7db3Sskrll  (type register SI (32))
1292a6b7db3Sskrll  (indices extern-keyword gr-names)
1302a6b7db3Sskrll  (get (idx)
1312a6b7db3Sskrll       (cond SI
1322a6b7db3Sskrll	     ((eq idx 0) (const 0))
1332a6b7db3Sskrll	     (else (raw-reg h-gr idx))))
1342a6b7db3Sskrll  (set (idx newval)
1352a6b7db3Sskrll       (cond VOID
1362a6b7db3Sskrll	     ((eq idx 0) (nop))
1372a6b7db3Sskrll	     (else (set (raw-reg h-gr idx) newval))))
1382a6b7db3Sskrll)
1392a6b7db3Sskrll
1402a6b7db3Sskrll
1412a6b7db3Sskrll; Instruction fields.
1422a6b7db3Sskrll
1432a6b7db3Sskrll(dnf f-opcode   "opcode field"                  ()  31  6)
1442a6b7db3Sskrll(dnf f-rs       "register field Rs"             ()  25  5)
1452a6b7db3Sskrll(dnf f-rt       "register field Rt"             ()  20  5)
1462a6b7db3Sskrll(dnf f-rd       "register field Rd"             ()  15  5)
1472a6b7db3Sskrll(dnf f-shamt    "shift amount field"            ()  10  5)
1482a6b7db3Sskrll(dnf f-cp-op    "coprocessor op field"		()  10  3)
1492a6b7db3Sskrll(dnf f-cp-op-10 "coprocessor op field for CAM"  ()  10  5)
1502a6b7db3Sskrll(dnf f-cp-grp   "coprocessor group field"	()   7  2)
1512a6b7db3Sskrll(dnf f-func     "function field"                ()   5  6)
1522a6b7db3Sskrll(dnf f-imm      "immediate field"               ()  15 16)
1532a6b7db3Sskrll
1542a6b7db3Sskrll(define-multi-ifield
1552a6b7db3Sskrll  (name f-rd-rs)
1562a6b7db3Sskrll  (comment "register Rd implied from Rs")
1572a6b7db3Sskrll  (attrs)
1582a6b7db3Sskrll  (mode UINT)
1592a6b7db3Sskrll  (subfields f-rd f-rs)
1602a6b7db3Sskrll  (insert (sequence ()
1612a6b7db3Sskrll		    (set (ifield f-rd) (ifield f-rd-rs))
1622a6b7db3Sskrll		    (set (ifield f-rs) (ifield f-rd-rs))
1632a6b7db3Sskrll		     ))
1642a6b7db3Sskrll  (extract (sequence ()
1652a6b7db3Sskrll                     (set (ifield f-rd-rs) (ifield f-rs))
1662a6b7db3Sskrll                     ))
1672a6b7db3Sskrll)
1682a6b7db3Sskrll
1692a6b7db3Sskrll(define-multi-ifield
1702a6b7db3Sskrll  (name f-rd-rt)
1712a6b7db3Sskrll  (comment "register Rd implied from Rt")
1722a6b7db3Sskrll  (attrs)
1732a6b7db3Sskrll  (mode UINT)
1742a6b7db3Sskrll  (subfields f-rd f-rt)
1752a6b7db3Sskrll  (insert (sequence ()
1762a6b7db3Sskrll		    (set (ifield f-rd) (ifield f-rd-rt))
1772a6b7db3Sskrll		    (set (ifield f-rt) (ifield f-rd-rt))
1782a6b7db3Sskrll		     ))
1792a6b7db3Sskrll  (extract (sequence ()
1802a6b7db3Sskrll                     (set (ifield f-rd-rt) (ifield f-rt))
1812a6b7db3Sskrll                     ))
1822a6b7db3Sskrll)
1832a6b7db3Sskrll
1842a6b7db3Sskrll(define-multi-ifield
1852a6b7db3Sskrll  (name f-rt-rs)
1862a6b7db3Sskrll  (comment "register Rt implied from Rs")
1872a6b7db3Sskrll  (attrs)
1882a6b7db3Sskrll  (mode UINT)
1892a6b7db3Sskrll  (subfields f-rt f-rs)
1902a6b7db3Sskrll  (insert (sequence ()
1912a6b7db3Sskrll		    (set (ifield f-rt) (ifield f-rt-rs))
1922a6b7db3Sskrll		    (set (ifield f-rs) (ifield f-rt-rs))
1932a6b7db3Sskrll		     ))
1942a6b7db3Sskrll  (extract (sequence ()
1952a6b7db3Sskrll                     (set (ifield f-rd-rs) (ifield f-rs))
1962a6b7db3Sskrll                     ))
1972a6b7db3Sskrll)
1982a6b7db3Sskrll
1992a6b7db3Sskrll(df  f-jtarg "jump target field"               (ABS-ADDR) 15 16 UINT
2002a6b7db3Sskrll     ((value pc) (srl USI (and USI value #x03FFFF) 2))
2012a6b7db3Sskrll     ((value pc) (or USI (and USI pc #xF0000000) (sll USI value 2))))
2022a6b7db3Sskrll
2032a6b7db3Sskrll(df  f-jtargq10 "iq10 jump target field"       (ABS-ADDR) 20 21 UINT
2042a6b7db3Sskrll     ((value pc) (srl SI (and SI value #x7FFFFF) 2))
2052a6b7db3Sskrll     ((value pc) (or SI (and SI pc #xF0000000) (sll SI value 2))))
2062a6b7db3Sskrll
2072a6b7db3Sskrll(df  f-offset "pc offset field"                (PCREL-ADDR) 15 16 INT
2082a6b7db3Sskrll     ; Actually, this is relative to the address of the delay slot.
2092a6b7db3Sskrll     ((value pc) (sra SI (sub SI value pc) 2))
210*f7172901Schristos     ((value pc) (add SI (mul SI value 4) (add pc 4))))
2112a6b7db3Sskrll
2122a6b7db3Sskrll; Instruction fields that scarcely appear in instructions.
2132a6b7db3Sskrll
2142a6b7db3Sskrll(dnf f-count   "count field"        ()   15  7)
2152a6b7db3Sskrll(dnf f-bytecount "byte count field" ()    7  8)
2162a6b7db3Sskrll(dnf f-index   "index field"        ()    8  9)
2172a6b7db3Sskrll(dnf f-mask    "mask field"         ()    9  4)
2182a6b7db3Sskrll(dnf f-maskq10 "iq10 mask field"    ()   10  5)
2192a6b7db3Sskrll(dnf f-maskl   "mask left field"    ()    4  5)
2202a6b7db3Sskrll(dnf f-excode  "execcode field"     ()   25 20)
2212a6b7db3Sskrll(dnf f-rsrvd   "reserved field"     ()   25 10)
2222a6b7db3Sskrll(dnf f-10-11   "bits 10:0"          ()   10 11)
2232a6b7db3Sskrll(dnf f-24-19   "bits 24:6"          ()   24 19)
2242a6b7db3Sskrll(dnf f-5       "bit 5"              ()    5  1)
2252a6b7db3Sskrll(dnf f-10      "bit 10"             ()   10  1)
2262a6b7db3Sskrll(dnf f-25      "bit 25"             ()   25  1)
2272a6b7db3Sskrll(dnf f-cam-z   "cam global mask z"  ()    5  3)
2282a6b7db3Sskrll(dnf f-cam-y   "cam operation y"    ()    2  3)
2292a6b7db3Sskrll(dnf f-cm-3func "CM 3 bit fn field" ()    5  3)
2302a6b7db3Sskrll(dnf f-cm-4func "CM 4 bit fn field" ()    5  4)
2312a6b7db3Sskrll(dnf f-cm-3z   "CM 3Z field"        ()    1  2)
2322a6b7db3Sskrll(dnf f-cm-4z   "CM 4Z field"        ()    2  3)
2332a6b7db3Sskrll
2342a6b7db3Sskrll
2352a6b7db3Sskrll; Enumerations.
2362a6b7db3Sskrll
2372a6b7db3Sskrll(define-normal-insn-enum
2382a6b7db3Sskrll  opcodes "primary opcodes" () OP_ f-opcode
2392a6b7db3Sskrll  (("SPECIAL" 0) ("REGIMM" 1) ("J"     2) ("JAL"    3) ("BEQ"    4) ("BNE"   5) ("BLEZ"   6) ("BGTZ"    7)
2402a6b7db3Sskrll   ("ADDI"    8) ("ADDIU"  9) ("SLTI" 10) ("SLTIU" 11) ("ANDI"  12) ("ORI"  13) ("XORI"  14) ("LUI"    15)
2412a6b7db3Sskrll   ("COP0"   16) ("COP1"  17) ("COP2" 18) ("COP3"  19) ("BEQL"  20) ("BNEL" 21) ("BLEZL" 22) ("BGTZL"  23)
2422a6b7db3Sskrll   ("BMB0"   24) ("BMB1"  25) ("BMB2" 26) ("BMB3"  27) ("BBI"   28) ("BBV"  29) ("BBIN"  30) ("BBVN"   31)
2432a6b7db3Sskrll   ("LB"     32) ("LH"    33)             ("LW"    35) ("LBU"   36) ("LHU"  37)              ("RAM"    39)
2442a6b7db3Sskrll   ("SB"     40) ("SH"    41)             ("SW"    43) ("ANDOI" 44) ("BMB"  45)              ("ORUI"   47)
2452a6b7db3Sskrll   ("LDW"    48)
2462a6b7db3Sskrll   ("SDW"    56)                                                                             ("ANDOUI" 63))
2472a6b7db3Sskrll)
2482a6b7db3Sskrll
2492a6b7db3Sskrll(define-normal-insn-enum
2502a6b7db3Sskrll  q10_opcodes "iq10-only primary opcodes" () OP10_ f-opcode
2512a6b7db3Sskrll  (("BMB" 6) ("ORUI" 15) ("BMBL" 22) ("ANDOUI" 47) ("BBIL" 60) ("BBVL" 61) ("BBINL" 62) ("BBVNL" 63))
2522a6b7db3Sskrll)
2532a6b7db3Sskrll
2542a6b7db3Sskrll(define-normal-insn-enum
2552a6b7db3Sskrll  regimm-functions "branch sub-opcodes" () FUNC_ f-rt
2562a6b7db3Sskrll  (("BLTZ"    0) ("BGEZ"    1) ("BLTZL"    2) ("BGEZL"    3) ("BLEZ"    4) ("BGTZ"    5) ("BLEZL"    6) ("BGTZL"    7)
2572a6b7db3Sskrll   ("BRI"     8) ("BRV"     9)                               ("BCTX"   12)
2582a6b7db3Sskrll   ("BLTZAL" 16) ("BGEZAL" 17) ("BLTZALL" 18) ("BGEZALL" 19) ("BLEZAL" 20) ("BGTZAL" 21) ("BLEZALL" 22) ("BGTZALL" 23))
2592a6b7db3Sskrll)
2602a6b7db3Sskrll
2612a6b7db3Sskrll(define-normal-insn-enum
2622a6b7db3Sskrll  functions "function sub-opcodes" () FUNC_ f-func
2632a6b7db3Sskrll  (("SLL"  0) ("SLMV"   1) ("SRL"  2) ("SRA"   3) ("SLLV"     4) ("SRMV"   5) ("SRLV"   6) ("SRAV" 7)
2642a6b7db3Sskrll   ("JR"   8) ("JALR"   9) ("JCR" 10)             ("SYSCALL" 12) ("BREAK" 13) ("SLEEP" 14)
2652a6b7db3Sskrll   ("ADD" 32) ("ADDU"  33) ("SUB" 34) ("SUBU" 35) ("AND"     36) ("OR"    37) ("XOR"   38) ("NOR" 39)
2662a6b7db3Sskrll              ("ADO16" 41) ("SLT" 42) ("SLTU" 43)                ("MRGB"  45))
2672a6b7db3Sskrll)
2682a6b7db3Sskrll
2692a6b7db3Sskrll; iq10 special function sub-opcodes
2702a6b7db3Sskrll(define-normal-insn-enum
2712a6b7db3Sskrll  q10s_functions "iq10-only special function sub-opcodes" () FUNC10_ f-func
2722a6b7db3Sskrll  (("YIELD" 14) ("CNT1S" 46))
2732a6b7db3Sskrll)
2742a6b7db3Sskrll
2752a6b7db3Sskrll; coprocessor opcodes in concert with f-cp-grp
2762a6b7db3Sskrll(define-normal-insn-enum
2772a6b7db3Sskrll  cop_functions "iq10 function sub-opcodes" () FUNC10_ f-func
2782a6b7db3Sskrll  (("CFC"    0) ("LOCK"    1) ("CTC"     2) ("UNLK"    3) ("SWRD"    4) ("SWRDL"   5) ("SWWR"    6) ("SWWRU"  7)
2792a6b7db3Sskrll   ("RBA"    8) ("RBAL"    9) ("RBAR"   10)               ("DWRD"   12) ("DWRDL"  13)
2802a6b7db3Sskrll   ("WBA"   16) ("WBAU"   17) ("WBAC"   18)               ("CRC32"  20) ("CRC32B" 21)
2812a6b7db3Sskrll   ("MCID"  32) ("DBD"    33) ("DBA"    34) ("DPWT"   35) ("AVAIL"  36) ("FREE"   37) ("CHKHDR" 38) ("TSTOD" 39)
2822a6b7db3Sskrll   ("PKRLA" 40) ("PKRLAU" 41) ("PKRLAH" 42) ("PKRLAC" 43) ("CMPHDR" 44)
2832a6b7db3Sskrll
2842a6b7db3Sskrll   ("CM64RS"  0) ("CM64RD"  1)                                ("CM64RI"    4) ("CM64CLR"    5)
2852a6b7db3Sskrll   ("CM64SS"  8) ("CM64SD"  9)                                ("CM64SI"   12)
2862a6b7db3Sskrll   ("CM64RA" 16)                                              ("CM64RIA2" 20) ("CM128RIA2" 21)
2872a6b7db3Sskrll   ("CM64SA" 24)                                              ("CM64SIA2" 28) ("CM128SIA2" 29)
2882a6b7db3Sskrll   ("CM32RS" 32) ("CM32RD" 33) ("CM32XOR" 34) ("CM32ANDN" 35) ("CM32RI"   36)                  ("CM128VSA" 38)
2892a6b7db3Sskrll   ("CM32SS" 40) ("CM32SD" 41) ("CM32OR"  42) ("CM32AND"  43) ("CM32SI"   44)
2902a6b7db3Sskrll   ("CM32RA" 48)
2912a6b7db3Sskrll   ("CM32SA" 56) )
2922a6b7db3Sskrll)
2932a6b7db3Sskrll
2942a6b7db3Sskrll; coprocessor opcodes in concert with f-cp-grp
2952a6b7db3Sskrll(define-normal-insn-enum
2962a6b7db3Sskrll  cop_cm128_4functions "iq10 function sub-opcodes" () FUNC10_ f-cm-4func
2972a6b7db3Sskrll  (("CM128RIA3" 4) ("CM128SIA3" 6))
2982a6b7db3Sskrll)
2992a6b7db3Sskrll
3002a6b7db3Sskrll(define-normal-insn-enum
3012a6b7db3Sskrll  cop_cm128_3functions "iq10 function sub-opcodes" () FUNC10_ f-cm-3func
3022a6b7db3Sskrll  (("CM128RIA4" 6) ("CM128SIA4" 7))
3032a6b7db3Sskrll)
3042a6b7db3Sskrll
3052a6b7db3Sskrll(define-normal-insn-enum
3062a6b7db3Sskrll   cop2_functions "iq10 coprocessor sub-opcodes" () FUNC10_ f-cp-op
3072a6b7db3Sskrll   (("PKRLI" 0) ("PKRLIU" 1) ("PKRLIH" 2) ("PKRLIC" 3) ("RBIR" 1) ("RBI" 2) ("RBIL" 3) ("WBIC" 5) ("WBI" 6) ("WBIU" 7))
3082a6b7db3Sskrll)
3092a6b7db3Sskrll
3102a6b7db3Sskrll(define-normal-insn-enum
3112a6b7db3Sskrll   cop3_cam_functions "iq10 coprocessor cam sub-opcodes" () FUNC10_ f-cp-op-10
3122a6b7db3Sskrll   (("CAM36" 16) ("CAM72" 17) ("CAM144" 18) ("CAM288" 19))
3132a6b7db3Sskrll)
3142a6b7db3Sskrll
3152a6b7db3Sskrll
3162a6b7db3Sskrll; Attributes.
3172a6b7db3Sskrll
3182a6b7db3Sskrll(define-attr
3192a6b7db3Sskrll  (for insn)
3202a6b7db3Sskrll  (type boolean)
3212a6b7db3Sskrll  (name YIELD-INSN)
3222a6b7db3Sskrll  (comment "insn generates a context yield")
3232a6b7db3Sskrll)
3242a6b7db3Sskrll
3252a6b7db3Sskrll(define-attr
3262a6b7db3Sskrll  (for insn)
3272a6b7db3Sskrll  (type boolean)
3282a6b7db3Sskrll  (name LOAD-DELAY)
3292a6b7db3Sskrll  (comment "insn has a load delay")
3302a6b7db3Sskrll)
3312a6b7db3Sskrll
3322a6b7db3Sskrll(define-attr
3332a6b7db3Sskrll  (for insn)
3342a6b7db3Sskrll  (type boolean)
3352a6b7db3Sskrll  (name EVEN-REG-NUM)
3362a6b7db3Sskrll  (comment "insn requires an even numbered register in rt(2000) or rd(10)")
3372a6b7db3Sskrll)
3382a6b7db3Sskrll
3392a6b7db3Sskrll(define-attr
3402a6b7db3Sskrll  (for insn)
3412a6b7db3Sskrll  (type boolean)
3422a6b7db3Sskrll  (name UNSUPPORTED)
3432a6b7db3Sskrll  (comment "insn is unsupported")
3442a6b7db3Sskrll)
3452a6b7db3Sskrll
3462a6b7db3Sskrll(define-pmacro (define-reg-use-attr regfield)
3472a6b7db3Sskrll  (define-attr
3482a6b7db3Sskrll    (for insn)
3492a6b7db3Sskrll    (type boolean)
3502a6b7db3Sskrll    (name (.sym USES- (.upcase regfield)))
3512a6b7db3Sskrll    (comment ("insn accesses register operand " regfield))))
3522a6b7db3Sskrll
3532a6b7db3Sskrll(define-reg-use-attr "rd")
3542a6b7db3Sskrll(define-reg-use-attr "rs")
3552a6b7db3Sskrll(define-reg-use-attr "rt")
3562a6b7db3Sskrll(define-reg-use-attr "r31")
3572a6b7db3Sskrll
3582a6b7db3Sskrll
3592a6b7db3Sskrll; Operands.
3602a6b7db3Sskrll
3612a6b7db3Sskrll(dnop rs       "register Rs"             () h-gr    f-rs)
3622a6b7db3Sskrll(dnop rt       "register Rt"             () h-gr    f-rt)
3632a6b7db3Sskrll(dnop rd       "register Rd"             () h-gr    f-rd)
3642a6b7db3Sskrll(dnop rd-rs    "register Rd from Rs"     () h-gr    f-rd-rs)
3652a6b7db3Sskrll(dnop rd-rt    "register Rd from Rt"     () h-gr    f-rd-rt)
3662a6b7db3Sskrll(dnop rt-rs    "register Rt from Rs"     () h-gr    f-rt-rs)
3672a6b7db3Sskrll(dnop shamt    "shift amount"            () h-uint  f-shamt)
3682a6b7db3Sskrll(define-operand (name imm) (comment "immediate") (attrs)
3692a6b7db3Sskrll   (type h-uint) (index f-imm) (handlers (parse "imm")))
3702a6b7db3Sskrll(dnop offset   "pc-relative offset"      () h-iaddr f-offset)
3712a6b7db3Sskrll(dnop baseoff  "base register offset"    () h-iaddr f-imm)
3722a6b7db3Sskrll(dnop jmptarg  "jump target"             () h-iaddr f-jtarg)
3732a6b7db3Sskrll(dnop mask     "mask"                    () h-uint  f-mask)
3742a6b7db3Sskrll(dnop maskq10  "iq10 mask"               () h-uint  f-maskq10)
3752a6b7db3Sskrll(dnop maskl    "mask left"               () h-uint  f-maskl)
3762a6b7db3Sskrll(dnop count    "count"                   () h-uint  f-count)
3772a6b7db3Sskrll(dnop _index   "index"                   () h-uint  f-index)
3782a6b7db3Sskrll(dnop execode  "execcode"                () h-uint  f-excode)
3792a6b7db3Sskrll(dnop bytecount "byte count"             () h-uint  f-bytecount)
3802a6b7db3Sskrll(dnop cam-y     "cam global opn y"       () h-uint  f-cam-y)
3812a6b7db3Sskrll(dnop cam-z     "cam global mask z"      () h-uint  f-cam-z)
3822a6b7db3Sskrll(dnop cm-3func  "CM 3 bit fn field"      () h-uint  f-cm-3func)
3832a6b7db3Sskrll(dnop cm-4func  "CM 4 bit fn field"      () h-uint  f-cm-4func)
3842a6b7db3Sskrll(dnop cm-3z     "CM 3 bit Z field"       () h-uint  f-cm-3z)
3852a6b7db3Sskrll(dnop cm-4z     "CM 4 bit Z field"       () h-uint  f-cm-4z)
3862a6b7db3Sskrll
3872a6b7db3Sskrll; Aliases for the rs and rt operands. This just makes the load/store
3882a6b7db3Sskrll; insns easier to compare with the instruction set documentation.
3892a6b7db3Sskrll
3902a6b7db3Sskrll(dnop base    "base register"                  () h-gr   f-rs)
3912a6b7db3Sskrll(dnop maskr   "mask right"                     () h-uint f-rs)
3922a6b7db3Sskrll(dnop bitnum  "bit number"                     () h-uint f-rt)
3932a6b7db3Sskrll
3942a6b7db3Sskrll; For high(foo).
3952a6b7db3Sskrll(define-operand
3962a6b7db3Sskrll  (name hi16)
3972a6b7db3Sskrll  (comment "high 16 bit immediate")
3982a6b7db3Sskrll  (attrs)
3992a6b7db3Sskrll  (type h-uint)
4002a6b7db3Sskrll  (index f-imm)
4012a6b7db3Sskrll  (handlers (parse "hi16"))
4022a6b7db3Sskrll)
4032a6b7db3Sskrll
4042a6b7db3Sskrll; For low(foo).
4052a6b7db3Sskrll(define-operand
4062a6b7db3Sskrll  (name lo16)
4072a6b7db3Sskrll  (comment "16 bit signed immediate, for low")
4082a6b7db3Sskrll  (attrs)
4092a6b7db3Sskrll  (type h-uint)
4102a6b7db3Sskrll  (index f-imm)
4112a6b7db3Sskrll  (handlers (parse "lo16"))
4122a6b7db3Sskrll)
4132a6b7db3Sskrll
4142a6b7db3Sskrll; For negated imm.
4152a6b7db3Sskrll(define-operand
4162a6b7db3Sskrll  (name mlo16)
4172a6b7db3Sskrll  (comment "negated 16 bit signed immediate")
4182a6b7db3Sskrll  (attrs)
4192a6b7db3Sskrll  (type h-uint)
4202a6b7db3Sskrll  (index f-imm)
4212a6b7db3Sskrll  (handlers (parse "mlo16"))
4222a6b7db3Sskrll)
4232a6b7db3Sskrll
4242a6b7db3Sskrll; For iq10 jmps
4252a6b7db3Sskrll; In the future, we'll want the j & jal to use the 21 bit target, with
4262a6b7db3Sskrll; the upper five bits shifted up.  For now, don't use this.
4272a6b7db3Sskrll(define-operand
4282a6b7db3Sskrll  (name jmptargq10)
4292a6b7db3Sskrll  (comment "iq10 21-bit jump offset")
4302a6b7db3Sskrll  (attrs)
4312a6b7db3Sskrll  (type h-iaddr)
4322a6b7db3Sskrll  (index f-jtargq10)
4332a6b7db3Sskrll  (handlers (parse "jtargq10"))
4342a6b7db3Sskrll)
4352a6b7db3Sskrll
4362a6b7db3Sskrll
4372a6b7db3Sskrll; Instructions.
4382a6b7db3Sskrll
4392a6b7db3Sskrll; A pmacro for use in semantic bodies of unimplemented insns.
4402a6b7db3Sskrll(define-pmacro (unimp mnemonic) (nop))
4412a6b7db3Sskrll
4422a6b7db3Sskrll(define-pmacro (bitset? value bit-num)
4432a6b7db3Sskrll  (and value (sll 1 bit-num)))
4442a6b7db3Sskrll
4452a6b7db3Sskrll(define-pmacro (bitclear? value bit-num)
4462a6b7db3Sskrll  (not (bitset? value bit-num)))
4472a6b7db3Sskrll
4482a6b7db3Sskrll; Arithmetic/logic instructions.
4492a6b7db3Sskrll
4502a6b7db3Sskrll(dni add2 "add registers" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
4512a6b7db3Sskrll     "add ${rd-rs},$rt"
4522a6b7db3Sskrll     (+ OP_SPECIAL rt rd-rs (f-shamt 0) FUNC_ADD)
4532a6b7db3Sskrll     (set rd-rs (add rt rd-rs))
4542a6b7db3Sskrll     ())
4552a6b7db3Sskrll
4562a6b7db3Sskrll(dni add "add registers" (USES-RD USES-RS USES-RT)
4572a6b7db3Sskrll     "add $rd,$rs,$rt"
4582a6b7db3Sskrll     (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_ADD)
4592a6b7db3Sskrll     (set rd (add rs rt))
4602a6b7db3Sskrll     ())
4612a6b7db3Sskrll
4622a6b7db3Sskrll
4632a6b7db3Sskrll(dni addi2 "add immediate" (ALIAS NO-DIS USES-RS USES-RT)
4642a6b7db3Sskrll     "addi ${rt-rs},$lo16"
4652a6b7db3Sskrll     (+ OP_ADDI rt-rs lo16)
4662a6b7db3Sskrll     (set rt-rs (add rt-rs (ext SI (trunc HI lo16))))
4672a6b7db3Sskrll     ())
4682a6b7db3Sskrll
4692a6b7db3Sskrll(dni addi "add immediate" (USES-RS USES-RT)
4702a6b7db3Sskrll     "addi $rt,$rs,$lo16"
4712a6b7db3Sskrll     (+ OP_ADDI rs rt lo16)
4722a6b7db3Sskrll     (set rt (add rs (ext SI (trunc HI lo16))))
4732a6b7db3Sskrll     ())
4742a6b7db3Sskrll
4752a6b7db3Sskrll(dni addiu2 "add immediate unsigned" (ALIAS NO-DIS USES-RS USES-RT)
4762a6b7db3Sskrll     "addiu ${rt-rs},$lo16"
4772a6b7db3Sskrll     (+ OP_ADDIU rt-rs lo16)
4782a6b7db3Sskrll     (set rt-rs (add rt-rs (ext SI (trunc HI lo16))))
4792a6b7db3Sskrll     ())
4802a6b7db3Sskrll
4812a6b7db3Sskrll(dni addiu "add immediate unsigned" (USES-RS USES-RT)
4822a6b7db3Sskrll     "addiu $rt,$rs,$lo16"
4832a6b7db3Sskrll     (+ OP_ADDIU rs rt lo16)
4842a6b7db3Sskrll     (set rt (add rs (ext SI (trunc HI lo16))))
4852a6b7db3Sskrll     ())
4862a6b7db3Sskrll
4872a6b7db3Sskrll(dni addu2 "add unsigned" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
4882a6b7db3Sskrll     "addu ${rd-rs},$rt"
4892a6b7db3Sskrll     (+ OP_SPECIAL rd-rs rt (f-shamt 0) FUNC_ADDU)
4902a6b7db3Sskrll     (set rd-rs (add rd-rs rt))
4912a6b7db3Sskrll     ())
4922a6b7db3Sskrll
4932a6b7db3Sskrll(dni addu "add unsigned" (USES-RD USES-RS USES-RT)
4942a6b7db3Sskrll     "addu $rd,$rs,$rt"
4952a6b7db3Sskrll     (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_ADDU)
4962a6b7db3Sskrll     (set rd (add rs rt))
4972a6b7db3Sskrll     ())
4982a6b7db3Sskrll
4992a6b7db3Sskrll(dni ado162 "add 16, ones complement" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
5002a6b7db3Sskrll     "ado16 ${rd-rs},$rt"
5012a6b7db3Sskrll     (+ OP_SPECIAL rd-rs rt (f-shamt 0) FUNC_ADO16)
5022a6b7db3Sskrll     (sequence ((HI high) (HI low))
5032a6b7db3Sskrll	       (set low (add HI (and HI rd-rs #xFFFF) (and HI rt #xFFFF)))
5042a6b7db3Sskrll	       (set high (add HI (srl rd-rs 16) (srl rt 16)))
5052a6b7db3Sskrll	       (set rd-rs (or SI (sll SI high 16) low)))
5062a6b7db3Sskrll     ())
5072a6b7db3Sskrll
5082a6b7db3Sskrll(dni ado16 "add 16, ones complement" (USES-RD USES-RS USES-RT)
5092a6b7db3Sskrll     "ado16 $rd,$rs,$rt"
5102a6b7db3Sskrll     (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_ADO16)
5112a6b7db3Sskrll     (sequence ((HI high) (HI low))
5122a6b7db3Sskrll	       (set low (add HI (and HI rs #xFFFF) (and HI rt #xFFFF)))
5132a6b7db3Sskrll	       (set high (add HI (srl rs 16) (srl rt 16)))
5142a6b7db3Sskrll	       (set rd (or SI (sll SI high 16) low)))
5152a6b7db3Sskrll     ())
5162a6b7db3Sskrll
5172a6b7db3Sskrll(dni and2 "and register" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
5182a6b7db3Sskrll     "and ${rd-rs},$rt"
5192a6b7db3Sskrll     (+ OP_SPECIAL rd-rs rt (f-shamt 0) FUNC_AND)
5202a6b7db3Sskrll     (set rd-rs (and rd-rs rt))
5212a6b7db3Sskrll     ())
5222a6b7db3Sskrll
5232a6b7db3Sskrll(dni and "and register" (USES-RD USES-RS USES-RT)
5242a6b7db3Sskrll     "and $rd,$rs,$rt"
5252a6b7db3Sskrll     (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_AND)
5262a6b7db3Sskrll     (set rd (and rs rt))
5272a6b7db3Sskrll     ())
5282a6b7db3Sskrll
5292a6b7db3Sskrll(dni andi2 "and immediate" (ALIAS NO-DIS USES-RS USES-RT)
5302a6b7db3Sskrll     "andi ${rt-rs},$lo16"
5312a6b7db3Sskrll     (+ OP_ANDI rt-rs lo16)
5322a6b7db3Sskrll     (set rt-rs (and rt-rs (zext SI lo16)))
5332a6b7db3Sskrll     ())
5342a6b7db3Sskrll
5352a6b7db3Sskrll(dni andi "and immediate" (USES-RS USES-RT)
5362a6b7db3Sskrll     "andi $rt,$rs,$lo16"
5372a6b7db3Sskrll     (+ OP_ANDI rs rt lo16)
5382a6b7db3Sskrll     (set rt (and rs (zext SI lo16)))
5392a6b7db3Sskrll     ())
5402a6b7db3Sskrll
5412a6b7db3Sskrll(dni andoi2 "and ones immediate" (ALIAS NO-DIS USES-RS USES-RT)
5422a6b7db3Sskrll     "andoi ${rt-rs},$lo16"
5432a6b7db3Sskrll     (+ OP_ANDOI rt-rs lo16)
5442a6b7db3Sskrll     (set rt-rs (and rt-rs (or #xFFFF0000 (ext SI (trunc HI lo16)))))
5452a6b7db3Sskrll     ())
5462a6b7db3Sskrll
5472a6b7db3Sskrll(dni andoi "and ones immediate" (USES-RS USES-RT)
5482a6b7db3Sskrll     "andoi $rt,$rs,$lo16"
5492a6b7db3Sskrll     (+ OP_ANDOI rs rt lo16)
5502a6b7db3Sskrll     (set rt (and rs (or #xFFFF0000 (ext SI (trunc HI lo16)))))
5512a6b7db3Sskrll     ())
5522a6b7db3Sskrll
5532a6b7db3Sskrll(dni nor2 "nor" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
5542a6b7db3Sskrll     "nor ${rd-rs},$rt"
5552a6b7db3Sskrll     (+ OP_SPECIAL rd-rs rt (f-shamt 0) FUNC_NOR)
5562a6b7db3Sskrll     (set rd-rs (inv (or rd-rs rt)))
5572a6b7db3Sskrll     ())
5582a6b7db3Sskrll
5592a6b7db3Sskrll(dni nor "nor" (USES-RD USES-RS USES-RT)
5602a6b7db3Sskrll     "nor $rd,$rs,$rt"
5612a6b7db3Sskrll     (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_NOR)
5622a6b7db3Sskrll     (set rd (inv (or rs rt)))
5632a6b7db3Sskrll     ())
5642a6b7db3Sskrll
5652a6b7db3Sskrll(dni or2 "or" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
5662a6b7db3Sskrll     "or ${rd-rs},$rt"
5672a6b7db3Sskrll     (+ OP_SPECIAL rd-rs rt (f-shamt 0) FUNC_OR)
5682a6b7db3Sskrll     (set rd-rs (or rd-rs rt))
5692a6b7db3Sskrll     ())
5702a6b7db3Sskrll
5712a6b7db3Sskrll(dni or "or" (USES-RD USES-RS USES-RT)
5722a6b7db3Sskrll     "or $rd,$rs,$rt"
5732a6b7db3Sskrll     (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_OR)
5742a6b7db3Sskrll     (set rd (or rs rt))
5752a6b7db3Sskrll     ())
5762a6b7db3Sskrll
5772a6b7db3Sskrll(dni ori2 "or immediate" (ALIAS NO-DIS USES-RS USES-RT)
5782a6b7db3Sskrll     "ori ${rt-rs},$lo16"
5792a6b7db3Sskrll     (+ OP_ORI rt-rs lo16)
5802a6b7db3Sskrll     (set rt-rs (or rt-rs (zext SI lo16)))
5812a6b7db3Sskrll     ())
5822a6b7db3Sskrll
5832a6b7db3Sskrll(dni ori "or immediate" (USES-RS USES-RT)
5842a6b7db3Sskrll     "ori $rt,$rs,$lo16"
5852a6b7db3Sskrll     (+ OP_ORI rs rt lo16)
5862a6b7db3Sskrll     (set rt (or rs (zext SI lo16)))
5872a6b7db3Sskrll     ())
5882a6b7db3Sskrll
5892a6b7db3Sskrll(dni ram "rotate and mask" (USES-RD USES-RT)
5902a6b7db3Sskrll     "ram $rd,$rt,$shamt,$maskl,$maskr"
5912a6b7db3Sskrll     (+ OP_RAM maskr rt rd shamt (f-5 0) maskl)
5922a6b7db3Sskrll     (sequence ()
5932a6b7db3Sskrll	       (set rd (ror rt shamt))
5942a6b7db3Sskrll	       (set rd (and rd (srl #xFFFFFFFF maskl)))
5952a6b7db3Sskrll	       (set rd (and rd (sll #xFFFFFFFF maskr))))
5962a6b7db3Sskrll     ())
5972a6b7db3Sskrll
5982a6b7db3Sskrll(dni sll "shift left logical" (USES-RD USES-RT)
5992a6b7db3Sskrll     "sll $rd,$rt,$shamt"
6002a6b7db3Sskrll     (+ OP_SPECIAL (f-rs 0) rt rd shamt (f-func 0))
6012a6b7db3Sskrll     (set rd (sll rt shamt))
6022a6b7db3Sskrll     ())
6032a6b7db3Sskrll
6042a6b7db3Sskrll(dni sllv2 "shift left logical variable" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
6052a6b7db3Sskrll     "sllv ${rd-rt},$rs"
6062a6b7db3Sskrll     (+ OP_SPECIAL rs rd-rt (f-shamt 0) FUNC_SLLV)
6072a6b7db3Sskrll     (set rd-rt (sll rd-rt (and rs #x1F)))
6082a6b7db3Sskrll     ())
6092a6b7db3Sskrll
6102a6b7db3Sskrll(dni sllv "shift left logical variable" (USES-RD USES-RS USES-RT)
6112a6b7db3Sskrll     "sllv $rd,$rt,$rs"
6122a6b7db3Sskrll     (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_SLLV)
6132a6b7db3Sskrll     (set rd (sll rt (and rs #x1F)))
6142a6b7db3Sskrll     ())
6152a6b7db3Sskrll
6162a6b7db3Sskrll(dni slmv2 "shift left and mask variable" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
6172a6b7db3Sskrll     "slmv ${rd-rt},$rs,$shamt"
6182a6b7db3Sskrll     (+ OP_SPECIAL rs rd-rt shamt FUNC_SLMV)
6192a6b7db3Sskrll     (set rd-rt (and (sll rd-rt shamt) (srl #xFFFFFFFF rs)))
6202a6b7db3Sskrll     ())
6212a6b7db3Sskrll
6222a6b7db3Sskrll(dni slmv "shift left and mask variable" (USES-RD USES-RS USES-RT)
6232a6b7db3Sskrll     "slmv $rd,$rt,$rs,$shamt"
6242a6b7db3Sskrll     (+ OP_SPECIAL rs rt rd shamt FUNC_SLMV)
6252a6b7db3Sskrll     (set rd (and (sll rt shamt) (srl #xFFFFFFFF rs)))
6262a6b7db3Sskrll     ())
6272a6b7db3Sskrll
6282a6b7db3Sskrll(dni slt2 "set if less than" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
6292a6b7db3Sskrll     "slt ${rd-rs},$rt"
6302a6b7db3Sskrll     (+ OP_SPECIAL rt rd-rs (f-shamt 0) FUNC_SLT)
6312a6b7db3Sskrll     (if (lt rd-rs rt)
6322a6b7db3Sskrll	 (set rd-rs 1)
6332a6b7db3Sskrll	 (set rd-rs 0))
6342a6b7db3Sskrll     ())
6352a6b7db3Sskrll
6362a6b7db3Sskrll(dni slt "set if less than" (USES-RD USES-RS USES-RT)
6372a6b7db3Sskrll     "slt $rd,$rs,$rt"
6382a6b7db3Sskrll     (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_SLT)
6392a6b7db3Sskrll     (if (lt rs rt)
6402a6b7db3Sskrll	 (set rd 1)
6412a6b7db3Sskrll	 (set rd 0))
6422a6b7db3Sskrll     ())
6432a6b7db3Sskrll
6442a6b7db3Sskrll(dni slti2 "set if less than immediate" (ALIAS NO-DIS USES-RS USES-RT)
6452a6b7db3Sskrll     "slti ${rt-rs},$imm"
6462a6b7db3Sskrll     (+ OP_SLTI rt-rs imm)
6472a6b7db3Sskrll     (if (lt rt-rs (ext SI (trunc HI imm)))
6482a6b7db3Sskrll	 (set rt-rs 1)
6492a6b7db3Sskrll	 (set rt-rs 0))
6502a6b7db3Sskrll     ())
6512a6b7db3Sskrll
6522a6b7db3Sskrll(dni slti "set if less than immediate" (USES-RS USES-RT)
6532a6b7db3Sskrll     "slti $rt,$rs,$imm"
6542a6b7db3Sskrll     (+ OP_SLTI rs rt imm)
6552a6b7db3Sskrll     (if (lt rs (ext SI (trunc HI imm)))
6562a6b7db3Sskrll	 (set rt 1)
6572a6b7db3Sskrll	 (set rt 0))
6582a6b7db3Sskrll     ())
6592a6b7db3Sskrll
6602a6b7db3Sskrll(dni sltiu2 "set if less than immediate unsigned" (ALIAS NO-DIS USES-RS USES-RT)
6612a6b7db3Sskrll     "sltiu ${rt-rs},$imm"
6622a6b7db3Sskrll     (+ OP_SLTIU rt-rs imm)
6632a6b7db3Sskrll     (if (ltu rt-rs (ext SI (trunc HI imm)))
6642a6b7db3Sskrll	 (set rt-rs 1)
6652a6b7db3Sskrll	 (set rt-rs 0))
6662a6b7db3Sskrll     ())
6672a6b7db3Sskrll
6682a6b7db3Sskrll(dni sltiu "set if less than immediate unsigned" (USES-RS USES-RT)
6692a6b7db3Sskrll     "sltiu $rt,$rs,$imm"
6702a6b7db3Sskrll     (+ OP_SLTIU rs rt imm)
6712a6b7db3Sskrll     (if (ltu rs (ext SI (trunc HI imm)))
6722a6b7db3Sskrll	 (set rt 1)
6732a6b7db3Sskrll	 (set rt 0))
6742a6b7db3Sskrll     ())
6752a6b7db3Sskrll
6762a6b7db3Sskrll(dni sltu2 "set if less than unsigned" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
6772a6b7db3Sskrll     "sltu ${rd-rs},$rt"
6782a6b7db3Sskrll     (+ OP_SPECIAL rd-rs rt (f-shamt 0) FUNC_SLTU)
6792a6b7db3Sskrll     (if (ltu rd-rs rt)
6802a6b7db3Sskrll	 (set rd-rs 1)
6812a6b7db3Sskrll	 (set rd-rs 0))
6822a6b7db3Sskrll     ())
6832a6b7db3Sskrll
6842a6b7db3Sskrll(dni sltu "set if less than unsigned" (USES-RD USES-RS USES-RT)
6852a6b7db3Sskrll     "sltu $rd,$rs,$rt"
6862a6b7db3Sskrll     (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_SLTU)
6872a6b7db3Sskrll     (if (ltu rs rt)
6882a6b7db3Sskrll	 (set rd 1)
6892a6b7db3Sskrll	 (set rd 0))
6902a6b7db3Sskrll     ())
6912a6b7db3Sskrll
6922a6b7db3Sskrll(dni sra2 "shift right arithmetic" (ALIAS NO-DIS USES-RD USES-RT)
6932a6b7db3Sskrll     "sra ${rd-rt},$shamt"
6942a6b7db3Sskrll     (+ OP_SPECIAL (f-rs 0) rd-rt shamt FUNC_SRA)
6952a6b7db3Sskrll     (set rd-rt (sra rd-rt shamt))
6962a6b7db3Sskrll     ())
6972a6b7db3Sskrll
6982a6b7db3Sskrll(dni sra "shift right arithmetic" (USES-RD USES-RT)
6992a6b7db3Sskrll     "sra $rd,$rt,$shamt"
7002a6b7db3Sskrll     (+ OP_SPECIAL (f-rs 0) rt rd shamt FUNC_SRA)
7012a6b7db3Sskrll     (set rd (sra rt shamt))
7022a6b7db3Sskrll     ())
7032a6b7db3Sskrll
7042a6b7db3Sskrll(dni srav2 "shift right arithmetic variable" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
7052a6b7db3Sskrll     "srav ${rd-rt},$rs"
7062a6b7db3Sskrll     (+ OP_SPECIAL rs rd-rt (f-shamt 0) FUNC_SRAV)
7072a6b7db3Sskrll     (set rd-rt (sra rd-rt (and rs #x1F)))
7082a6b7db3Sskrll     ())
7092a6b7db3Sskrll
7102a6b7db3Sskrll(dni srav "shift right arithmetic variable" (USES-RD USES-RS USES-RT)
7112a6b7db3Sskrll     "srav $rd,$rt,$rs"
7122a6b7db3Sskrll     (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_SRAV)
7132a6b7db3Sskrll     (set rd (sra rt (and rs #x1F)))
7142a6b7db3Sskrll     ())
7152a6b7db3Sskrll
7162a6b7db3Sskrll(dni srl "shift right logical" (USES-RD USES-RT)
7172a6b7db3Sskrll     "srl $rd,$rt,$shamt"
7182a6b7db3Sskrll     (+ OP_SPECIAL (f-rs 0) rt rd shamt FUNC_SRL)
7192a6b7db3Sskrll     (set rd (srl rt shamt))
7202a6b7db3Sskrll     ())
7212a6b7db3Sskrll
7222a6b7db3Sskrll(dni srlv2 "shift right logical variable" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
7232a6b7db3Sskrll     "srlv ${rd-rt},$rs"
7242a6b7db3Sskrll     (+ OP_SPECIAL rs rd-rt (f-shamt 0) FUNC_SRLV)
7252a6b7db3Sskrll     (set rd-rt (srl rd-rt (and rs #x1F)))
7262a6b7db3Sskrll     ())
7272a6b7db3Sskrll
7282a6b7db3Sskrll(dni srlv "shift right logical variable" (USES-RD USES-RS USES-RT)
7292a6b7db3Sskrll     "srlv $rd,$rt,$rs"
7302a6b7db3Sskrll     (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_SRLV)
7312a6b7db3Sskrll     (set rd (srl rt (and rs #x1F)))
7322a6b7db3Sskrll     ())
7332a6b7db3Sskrll
7342a6b7db3Sskrll(dni srmv2 "shift right and mask variable" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
7352a6b7db3Sskrll     "srmv ${rd-rt},$rs,$shamt"
7362a6b7db3Sskrll     (+ OP_SPECIAL rs rd-rt shamt FUNC_SRMV)
7372a6b7db3Sskrll     (set rd-rt (and (srl rd-rt shamt) (sll #xFFFFFFFF rs)))
7382a6b7db3Sskrll     ())
7392a6b7db3Sskrll
7402a6b7db3Sskrll(dni srmv "shift right and mask variable" (USES-RD USES-RS USES-RT)
7412a6b7db3Sskrll     "srmv $rd,$rt,$rs,$shamt"
7422a6b7db3Sskrll     (+ OP_SPECIAL rs rt rd shamt FUNC_SRMV)
7432a6b7db3Sskrll     (set rd (and (srl rt shamt) (sll #xFFFFFFFF rs)))
7442a6b7db3Sskrll     ())
7452a6b7db3Sskrll
7462a6b7db3Sskrll(dni sub2 "subtract" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
7472a6b7db3Sskrll     "sub ${rd-rs},$rt"
7482a6b7db3Sskrll     (+ OP_SPECIAL rt rd-rs (f-shamt 0) FUNC_SUB)
7492a6b7db3Sskrll     (set rd-rs (sub rd-rs rt))
7502a6b7db3Sskrll     ())
7512a6b7db3Sskrll
7522a6b7db3Sskrll(dni sub "subtract" (USES-RD USES-RS USES-RT)
7532a6b7db3Sskrll     "sub $rd,$rs,$rt"
7542a6b7db3Sskrll     (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_SUB)
7552a6b7db3Sskrll     (set rd (sub rs rt))
7562a6b7db3Sskrll     ())
7572a6b7db3Sskrll
7582a6b7db3Sskrll(dni subu2 "subtract unsigned" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
7592a6b7db3Sskrll     "subu ${rd-rs},$rt"
7602a6b7db3Sskrll     (+ OP_SPECIAL rt rd-rs (f-shamt 0) FUNC_SUBU)
7612a6b7db3Sskrll     (set rd-rs (sub rd-rs rt))
7622a6b7db3Sskrll     ())
7632a6b7db3Sskrll
7642a6b7db3Sskrll(dni subu "subtract unsigned" (USES-RD USES-RS USES-RT)
7652a6b7db3Sskrll     "subu $rd,$rs,$rt"
7662a6b7db3Sskrll     (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_SUBU)
7672a6b7db3Sskrll     (set rd (sub rs rt))
7682a6b7db3Sskrll     ())
7692a6b7db3Sskrll
7702a6b7db3Sskrll(dni xor2 "exclusive or" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
7712a6b7db3Sskrll     "xor ${rd-rs},$rt"
7722a6b7db3Sskrll     (+ OP_SPECIAL rt rd-rs (f-shamt 0) FUNC_XOR)
7732a6b7db3Sskrll     (set rd-rs (xor rd-rs rt))
7742a6b7db3Sskrll     ())
7752a6b7db3Sskrll
7762a6b7db3Sskrll(dni xor "exclusive or" (USES-RD USES-RS USES-RT)
7772a6b7db3Sskrll     "xor $rd,$rs,$rt"
7782a6b7db3Sskrll     (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_XOR)
7792a6b7db3Sskrll     (set rd (xor rs rt))
7802a6b7db3Sskrll     ())
7812a6b7db3Sskrll
7822a6b7db3Sskrll(dni xori2 "exclusive or immediate" (ALIAS NO-DIS USES-RS USES-RT)
7832a6b7db3Sskrll     "xori ${rt-rs},$lo16"
7842a6b7db3Sskrll     (+ OP_XORI rt-rs lo16)
7852a6b7db3Sskrll     (set rt-rs (xor rt-rs (zext SI lo16)))
7862a6b7db3Sskrll     ())
7872a6b7db3Sskrll
7882a6b7db3Sskrll(dni xori "exclusive or immediate" (USES-RS USES-RT)
7892a6b7db3Sskrll     "xori $rt,$rs,$lo16"
7902a6b7db3Sskrll     (+ OP_XORI rs rt lo16)
7912a6b7db3Sskrll     (set rt (xor rs (zext SI lo16)))
7922a6b7db3Sskrll     ())
7932a6b7db3Sskrll
7942a6b7db3Sskrll
7952a6b7db3Sskrll; Branch instructions.
7962a6b7db3Sskrll
7972a6b7db3Sskrll(dni bbi "branch bit immediate" (USES-RS)
7982a6b7db3Sskrll     "bbi $rs($bitnum),$offset"
7992a6b7db3Sskrll     (+ OP_BBI rs bitnum offset)
8002a6b7db3Sskrll     (if (bitset? rs bitnum)
8012a6b7db3Sskrll	 (delay 1 (set pc offset)))
8022a6b7db3Sskrll     ())
8032a6b7db3Sskrll
8042a6b7db3Sskrll(dni bbin "branch bit immediate negated" (USES-RS)
8052a6b7db3Sskrll     "bbin $rs($bitnum),$offset"
8062a6b7db3Sskrll     (+ OP_BBIN rs bitnum offset)
8072a6b7db3Sskrll     (if (bitclear? rs bitnum)
8082a6b7db3Sskrll	 (delay 1 (set pc offset)))
8092a6b7db3Sskrll     ())
8102a6b7db3Sskrll
8112a6b7db3Sskrll(dni bbv "branch bit variable" (USES-RS USES-RT)
8122a6b7db3Sskrll     "bbv $rs,$rt,$offset"
8132a6b7db3Sskrll     (+ OP_BBV rs rt offset)
8142a6b7db3Sskrll     (if (bitset? rs (and rt #x1F))
8152a6b7db3Sskrll	 (delay 1 (set pc offset)))
8162a6b7db3Sskrll     ())
8172a6b7db3Sskrll
8182a6b7db3Sskrll(dni bbvn "branch bit variable negated" (USES-RS USES-RT)
8192a6b7db3Sskrll     "bbvn $rs,$rt,$offset"
8202a6b7db3Sskrll     (+ OP_BBVN rs rt offset)
8212a6b7db3Sskrll     (if (bitclear? rs (and rt #x1F))
8222a6b7db3Sskrll	 (delay 1 (set pc offset)))
8232a6b7db3Sskrll     ())
8242a6b7db3Sskrll
8252a6b7db3Sskrll(dni beq "branch if equal" (USES-RS USES-RT)
8262a6b7db3Sskrll     "beq $rs,$rt,$offset"
8272a6b7db3Sskrll     (+ OP_BEQ rs rt offset)
8282a6b7db3Sskrll     (if (eq rs rt)
8292a6b7db3Sskrll	 (delay 1 (set pc offset)))
8302a6b7db3Sskrll     ())
8312a6b7db3Sskrll
8322a6b7db3Sskrll(dni beql "branch if equal likely" (USES-RS USES-RT)
8332a6b7db3Sskrll     "beql $rs,$rt,$offset"
8342a6b7db3Sskrll     (+ OP_BEQL rs rt offset)
8352a6b7db3Sskrll     (if (eq rs rt)
8362a6b7db3Sskrll	 (delay 1 (set pc offset))
8372a6b7db3Sskrll	 (skip 1))
8382a6b7db3Sskrll     ())
8392a6b7db3Sskrll
8402a6b7db3Sskrll(dni bgez "branch if greater than or equal to zero" (USES-RS)
8412a6b7db3Sskrll     "bgez $rs,$offset"
8422a6b7db3Sskrll     (+ OP_REGIMM rs FUNC_BGEZ offset)
8432a6b7db3Sskrll     (if (ge rs 0)
8442a6b7db3Sskrll	 (delay 1 (set pc offset)))
8452a6b7db3Sskrll     ())
8462a6b7db3Sskrll
8472a6b7db3Sskrll(dni bgezal "branch if greater than or equal to zero and link" (USES-RS USES-R31)
8482a6b7db3Sskrll     "bgezal $rs,$offset"
8492a6b7db3Sskrll     (+ OP_REGIMM rs FUNC_BGEZAL offset)
8502a6b7db3Sskrll     (if (ge rs 0)
8512a6b7db3Sskrll	 (sequence ()
8522a6b7db3Sskrll		   (set (reg h-gr 31) (add pc 8))
8532a6b7db3Sskrll		   (delay 1 (set pc offset))))
8542a6b7db3Sskrll     ())
8552a6b7db3Sskrll
8562a6b7db3Sskrll(dni bgezall
8572a6b7db3Sskrll     "branch if greater than equal to zero and link likely" (USES-RS USES-R31)
8582a6b7db3Sskrll     "bgezall $rs,$offset"
8592a6b7db3Sskrll     (+ OP_REGIMM rs FUNC_BGEZALL offset)
8602a6b7db3Sskrll     (if (ge rs 0)
8612a6b7db3Sskrll	 (sequence ()
8622a6b7db3Sskrll		   (set (reg h-gr 31) (add pc 8))
8632a6b7db3Sskrll		   (delay 1 (set pc offset)))
8642a6b7db3Sskrll	 (skip 1))
8652a6b7db3Sskrll     ())
8662a6b7db3Sskrll
8672a6b7db3Sskrll(dni bgezl "branch if greater or equal to zero likely" (USES-RS)
8682a6b7db3Sskrll     "bgezl $rs,$offset"
8692a6b7db3Sskrll     (+ OP_REGIMM rs FUNC_BGEZL offset)
8702a6b7db3Sskrll     (if (ge rs 0)
8712a6b7db3Sskrll	 (delay 1 (set pc offset))
8722a6b7db3Sskrll	 (skip 1))
8732a6b7db3Sskrll     ())
8742a6b7db3Sskrll
8752a6b7db3Sskrll(dni bltz "branch if less than zero" (USES-RS)
8762a6b7db3Sskrll     "bltz $rs,$offset"
8772a6b7db3Sskrll     (+ OP_REGIMM rs FUNC_BLTZ offset)
8782a6b7db3Sskrll     (if (lt rs 0)
8792a6b7db3Sskrll	 (delay 1 (set pc offset)))
8802a6b7db3Sskrll     ())
8812a6b7db3Sskrll
8822a6b7db3Sskrll(dni bltzl "branch if less than zero likely" (USES-RS)
8832a6b7db3Sskrll     "bltzl $rs,$offset"
8842a6b7db3Sskrll     (+ OP_REGIMM rs FUNC_BLTZL offset)
8852a6b7db3Sskrll     (if (lt rs 0)
8862a6b7db3Sskrll	 (delay 1 (set pc offset))
8872a6b7db3Sskrll	 (skip 1))
8882a6b7db3Sskrll     ())
8892a6b7db3Sskrll
8902a6b7db3Sskrll(dni bltzal "branch if less than zero and link" (USES-RS USES-R31)
8912a6b7db3Sskrll     "bltzal $rs,$offset"
8922a6b7db3Sskrll     (+ OP_REGIMM rs FUNC_BLTZAL offset)
8932a6b7db3Sskrll     (if (lt rs 0)
8942a6b7db3Sskrll	 (sequence ()
8952a6b7db3Sskrll		   (set (reg h-gr 31) (add pc 8))
8962a6b7db3Sskrll		   (delay 1 (set pc offset))))
8972a6b7db3Sskrll     ())
8982a6b7db3Sskrll
8992a6b7db3Sskrll(dni bltzall "branch if less than zero and link likely" (USES-RS USES-R31)
9002a6b7db3Sskrll     "bltzall $rs,$offset"
9012a6b7db3Sskrll     (+ OP_REGIMM rs FUNC_BLTZALL offset)
9022a6b7db3Sskrll     (if (lt rs 0)
9032a6b7db3Sskrll	 (sequence ()
9042a6b7db3Sskrll		   (set (reg h-gr 31) (add pc 8))
9052a6b7db3Sskrll		   (delay 1 (set pc offset)))
9062a6b7db3Sskrll	 (skip 1))
9072a6b7db3Sskrll     ())
9082a6b7db3Sskrll
9092a6b7db3Sskrll(dni bmb0 "branch if matching byte-lane 0" (USES-RS USES-RT)
9102a6b7db3Sskrll     "bmb0 $rs,$rt,$offset"
9112a6b7db3Sskrll     (+ OP_BMB0 rs rt offset)
9122a6b7db3Sskrll     (if (eq (and rs #xFF) (and rt #xFF))
9132a6b7db3Sskrll	 (delay 1 (set pc offset)))
9142a6b7db3Sskrll     ())
9152a6b7db3Sskrll
9162a6b7db3Sskrll(dni bmb1 "branch if matching byte-lane 1" (USES-RS USES-RT)
9172a6b7db3Sskrll     "bmb1 $rs,$rt,$offset"
9182a6b7db3Sskrll     (+ OP_BMB1 rs rt offset)
9192a6b7db3Sskrll     (if (eq (and rs #xFF00) (and rt #xFF00))
9202a6b7db3Sskrll	 (delay 1 (set pc offset)))
9212a6b7db3Sskrll     ())
9222a6b7db3Sskrll
9232a6b7db3Sskrll(dni bmb2 "branch if matching byte-lane 2" (USES-RS USES-RT)
9242a6b7db3Sskrll     "bmb2 $rs,$rt,$offset"
9252a6b7db3Sskrll     (+ OP_BMB2 rs rt offset)
9262a6b7db3Sskrll     (if (eq (and rs #xFF0000) (and rt #xFF0000))
9272a6b7db3Sskrll	 (delay 1 (set pc offset)))
9282a6b7db3Sskrll     ())
9292a6b7db3Sskrll
9302a6b7db3Sskrll(dni bmb3 "branch if matching byte-lane 3" (USES-RS USES-RT)
9312a6b7db3Sskrll     "bmb3 $rs,$rt,$offset"
9322a6b7db3Sskrll     (+ OP_BMB3 rs rt offset)
9332a6b7db3Sskrll     (if (eq (and rs #xFF000000) (and rt #xFF000000))
9342a6b7db3Sskrll	 (delay 1 (set pc offset)))
9352a6b7db3Sskrll     ())
9362a6b7db3Sskrll
9372a6b7db3Sskrll(dni bne "branch if not equal" (USES-RS USES-RT)
9382a6b7db3Sskrll     "bne $rs,$rt,$offset"
9392a6b7db3Sskrll     (+ OP_BNE rs rt offset)
9402a6b7db3Sskrll     (if (ne rs rt)
9412a6b7db3Sskrll	 (delay 1 (set pc offset)))
9422a6b7db3Sskrll     ())
9432a6b7db3Sskrll
9442a6b7db3Sskrll(dni bnel "branch if not equal likely" (USES-RS USES-RT)
9452a6b7db3Sskrll     "bnel $rs,$rt,$offset"
9462a6b7db3Sskrll     (+ OP_BNEL rs rt offset)
9472a6b7db3Sskrll     (if (ne rs rt)
9482a6b7db3Sskrll	 (delay 1 (set pc offset))
9492a6b7db3Sskrll	 (skip 1))
9502a6b7db3Sskrll     ())
9512a6b7db3Sskrll
9522a6b7db3Sskrll
9532a6b7db3Sskrll
9542a6b7db3Sskrll
9552a6b7db3Sskrll; Jump instructions.
9562a6b7db3Sskrll; Might as well jump!
9572a6b7db3Sskrll
9582a6b7db3Sskrll(dni jalr "jump and link register" (USES-RD USES-RS)
9592a6b7db3Sskrll     "jalr $rd,$rs"
9602a6b7db3Sskrll     (+ OP_SPECIAL rs (f-rt 0) rd (f-shamt 0) FUNC_JALR)
9612a6b7db3Sskrll     (delay 1
9622a6b7db3Sskrll	    (sequence ()
9632a6b7db3Sskrll		      (set rd (add pc 8))
9642a6b7db3Sskrll		      (set pc rs)))
9652a6b7db3Sskrll     ())
9662a6b7db3Sskrll
9672a6b7db3Sskrll(dni jr "jump register" (USES-RS)
9682a6b7db3Sskrll     "jr $rs"
9692a6b7db3Sskrll     (+ OP_SPECIAL rs (f-rt 0) (f-rd 0) (f-shamt 0) FUNC_JR)
9702a6b7db3Sskrll     (delay 1 (set pc rs))
9712a6b7db3Sskrll     ())
9722a6b7db3Sskrll
9732a6b7db3Sskrll
9742a6b7db3Sskrll; Load instructions.
9752a6b7db3Sskrll
9762a6b7db3Sskrll(dni lb "load byte" (LOAD-DELAY USES-RS USES-RT)
9772a6b7db3Sskrll     "lb $rt,$lo16($base)"
9782a6b7db3Sskrll     (+ OP_LB base rt lo16)
9792a6b7db3Sskrll     (set rt (ext WI (mem QI (add base (ext SI (trunc HI lo16))))))
9802a6b7db3Sskrll;     (sequence ((SI addr) (SI word))
9812a6b7db3Sskrll;	       (set addr (add base lo16))
9822a6b7db3Sskrll;	       (set word (mem SI (and addr (inv 3))))
9832a6b7db3Sskrll;	       (set word (srl word (sll (and addr 2) 3)))
9842a6b7db3Sskrll;	       (set rt (ext SI word)))
9852a6b7db3Sskrll     ())
9862a6b7db3Sskrll
9872a6b7db3Sskrll(dni lbu "load byte unsigned" (LOAD-DELAY USES-RS USES-RT)
9882a6b7db3Sskrll     "lbu $rt,$lo16($base)"
9892a6b7db3Sskrll     (+ OP_LBU base rt lo16)
9902a6b7db3Sskrll     (set rt (zext WI (mem QI (add base (ext SI (trunc HI lo16))))))
9912a6b7db3Sskrll;     (sequence ((SI addr) (SI word))
9922a6b7db3Sskrll;	       (set addr (add base lo16))
9932a6b7db3Sskrll;	       (set word (mem SI (and addr (inv 3))))
9942a6b7db3Sskrll;	       (set rt (srl word (sll (and addr 2) 3))))
9952a6b7db3Sskrll     ())
9962a6b7db3Sskrll
9972a6b7db3Sskrll(dni lh "load half word" (LOAD-DELAY USES-RS USES-RT)
9982a6b7db3Sskrll     "lh $rt,$lo16($base)"
9992a6b7db3Sskrll     (+ OP_LH base rt lo16)
10002a6b7db3Sskrll     (set rt (ext WI (mem HI (add base (ext SI (trunc HI lo16))))))
10012a6b7db3Sskrll;     (sequence ((SI addr) (HI word))
10022a6b7db3Sskrll;	       (set addr (add base lo16))
10032a6b7db3Sskrll;	       (set word (mem SI (and addr (inv 3))))
10042a6b7db3Sskrll;	       (set word (srl word (sll (and addr 1) 4)))
10052a6b7db3Sskrll;	       (set rt (ext SI word)))
10062a6b7db3Sskrll     ())
10072a6b7db3Sskrll
10082a6b7db3Sskrll(dni lhu "load half word unsigned" (LOAD-DELAY USES-RS USES-RT)
10092a6b7db3Sskrll     "lhu $rt,$lo16($base)"
10102a6b7db3Sskrll     (+ OP_LHU base rt lo16)
10112a6b7db3Sskrll     (set rt (zext WI (mem HI (add base (ext SI (trunc HI lo16))))))
10122a6b7db3Sskrll;     (sequence ((SI addr) (SI word))
10132a6b7db3Sskrll;	       (set addr (add base lo16))
10142a6b7db3Sskrll;	       (set word (mem SI (and addr (inv 3))))
10152a6b7db3Sskrll;	       (set rt (srl word (sll (and addr 1) 4))))
10162a6b7db3Sskrll     ())
10172a6b7db3Sskrll
10182a6b7db3Sskrll(dni lui "load upper immediate" (USES-RT)
10192a6b7db3Sskrll     "lui $rt,$hi16"
10202a6b7db3Sskrll     (+ OP_LUI (f-rs 0) rt hi16)
10212a6b7db3Sskrll     (set rt (sll hi16 16))
10222a6b7db3Sskrll     ())
10232a6b7db3Sskrll
10242a6b7db3Sskrll(dni lw "load word" (LOAD-DELAY USES-RS USES-RT)
10252a6b7db3Sskrll    "lw $rt,$lo16($base)"
10262a6b7db3Sskrll    (+ OP_LW base rt lo16)
10272a6b7db3Sskrll    (set rt (mem SI (add base (ext SI (trunc HI lo16)))))
10282a6b7db3Sskrll    ())
10292a6b7db3Sskrll
10302a6b7db3Sskrll
10312a6b7db3Sskrll; Store instructions.
10322a6b7db3Sskrll
10332a6b7db3Sskrll(dni sb "store byte" (USES-RS USES-RT)
10342a6b7db3Sskrll     "sb $rt,$lo16($base)"
10352a6b7db3Sskrll     (+ OP_SB base rt lo16)
10362a6b7db3Sskrll     (set (mem QI (add base (ext SI (trunc HI lo16)))) (and QI rt #xFF))
10372a6b7db3Sskrll     ())
10382a6b7db3Sskrll
10392a6b7db3Sskrll(dni sh "store half word" (USES-RS USES-RT)
10402a6b7db3Sskrll     "sh $rt,$lo16($base)"
10412a6b7db3Sskrll     (+ OP_SH base rt lo16)
10422a6b7db3Sskrll     (set (mem HI (add base (ext SI (trunc HI lo16)))) (and HI rt #xFFFF))
10432a6b7db3Sskrll     ())
10442a6b7db3Sskrll
10452a6b7db3Sskrll(dni sw "store word" (USES-RS USES-RT)
10462a6b7db3Sskrll     "sw $rt,$lo16($base)"
10472a6b7db3Sskrll     (+ OP_SW base rt lo16)
10482a6b7db3Sskrll     (set (mem SI (add base (ext SI (trunc HI lo16)))) rt)
10492a6b7db3Sskrll     ())
10502a6b7db3Sskrll
10512a6b7db3Sskrll
10522a6b7db3Sskrll; Special instructions for simulation/debugging
10532a6b7db3Sskrll(dni break "breakpoint" ()
10542a6b7db3Sskrll     "break"
10552a6b7db3Sskrll     (+ OP_SPECIAL (f-rs 0) (f-rt 0) (f-rd 0) (f-shamt 0) FUNC_BREAK)
10562a6b7db3Sskrll     (c-call VOID "do_break" pc)
10572a6b7db3Sskrll     ())
10582a6b7db3Sskrll
10592a6b7db3Sskrll(dni syscall "system call" (YIELD-INSN)
10602a6b7db3Sskrll     "syscall"
10612a6b7db3Sskrll     (+ OP_SPECIAL execode (f-func 12))
10622a6b7db3Sskrll     (c-call VOID "do_syscall")
10632a6b7db3Sskrll     ())
10642a6b7db3Sskrll
10652a6b7db3Sskrll; Macro instructions, common to iq10 & iq2000
10662a6b7db3Sskrll
10672a6b7db3Sskrll(dnmi nop "nop" ()
10682a6b7db3Sskrll      "nop"
10692a6b7db3Sskrll      (emit sll (rd 0) (rt 0) (shamt 0))
10702a6b7db3Sskrll)
10712a6b7db3Sskrll
10722a6b7db3Sskrll(dnmi li "load immediate" (USES-RS NO-DIS)
10732a6b7db3Sskrll      "li $rs,$imm"
10742a6b7db3Sskrll      (emit ori (rt 0) rs imm)
10752a6b7db3Sskrll)
10762a6b7db3Sskrll
10772a6b7db3Sskrll(dnmi move "move" (USES-RD USES-RT NO-DIS)
10782a6b7db3Sskrll      "move $rd,$rt"
10792a6b7db3Sskrll      (emit or rd (rs 0) rt)
10802a6b7db3Sskrll)
10812a6b7db3Sskrll
10822a6b7db3Sskrll(dnmi lb-base-0 "load byte - implied base 0" (USES-RT NO-DIS)
10832a6b7db3Sskrll      "lb $rt,$lo16"
10842a6b7db3Sskrll      (emit lb rt lo16 (base 0))
10852a6b7db3Sskrll)
10862a6b7db3Sskrll
10872a6b7db3Sskrll(dnmi lbu-base-0 "load byte unsigned - implied base 0" (USES-RT NO-DIS)
10882a6b7db3Sskrll      "lbu $rt,$lo16"
10892a6b7db3Sskrll      (emit lbu rt lo16 (base 0))
10902a6b7db3Sskrll)
10912a6b7db3Sskrll
10922a6b7db3Sskrll(dnmi lh-base-0 "load half - implied base 0" (USES-RT NO-DIS)
10932a6b7db3Sskrll      "lh $rt,$lo16"
10942a6b7db3Sskrll      (emit lh rt lo16 (base 0))
10952a6b7db3Sskrll)
10962a6b7db3Sskrll
10972a6b7db3Sskrll(dnmi lw-base-0 "load word - implied base 0" (USES-RT NO-DIS)
10982a6b7db3Sskrll      "lw $rt,$lo16"
10992a6b7db3Sskrll      (emit lw rt lo16 (base 0))
11002a6b7db3Sskrll)
11012a6b7db3Sskrll
11022a6b7db3Sskrll(dnmi m-add "add immediate" (USES-RS USES-RT NO-DIS)
11032a6b7db3Sskrll      "add $rt,$rs,$lo16"
11042a6b7db3Sskrll      (emit addi rt rs lo16))
11052a6b7db3Sskrll
11062a6b7db3Sskrll(dnmi m-addu "add immediate unsigned" (USES-RS USES-RT NO-DIS)
11072a6b7db3Sskrll      "addu $rt,$rs,$lo16"
11082a6b7db3Sskrll      (emit addiu rt rs lo16)
11092a6b7db3Sskrll)
11102a6b7db3Sskrll
11112a6b7db3Sskrll(dnmi m-and "and immediate" (USES-RS USES-RT NO-DIS)
11122a6b7db3Sskrll      "and $rt,$rs,$lo16"
11132a6b7db3Sskrll      (emit andi rt rs lo16)
11142a6b7db3Sskrll)
11152a6b7db3Sskrll
11162a6b7db3Sskrll(dnmi m-j "jump register" (USES-RS NO-DIS)
11172a6b7db3Sskrll      "j $rs"
11182a6b7db3Sskrll      (emit jr rs)
11192a6b7db3Sskrll)
11202a6b7db3Sskrll
11212a6b7db3Sskrll(dnmi m-or "or immediate" (USES-RS USES-RT NO-DIS)
11222a6b7db3Sskrll      "or $rt,$rs,$lo16"
11232a6b7db3Sskrll      (emit ori rt rs lo16)
11242a6b7db3Sskrll)
11252a6b7db3Sskrll
11262a6b7db3Sskrll(dnmi m-sll "shift left logical" (USES-RD USES-RT USES-RS NO-DIS)
11272a6b7db3Sskrll      "sll $rd,$rt,$rs"
11282a6b7db3Sskrll      (emit sllv rd rt rs)
11292a6b7db3Sskrll)
11302a6b7db3Sskrll
11312a6b7db3Sskrll(dnmi m-slt "slt immediate" (USES-RS USES-RT NO-DIS)
11322a6b7db3Sskrll      "slt $rt,$rs,$imm"
11332a6b7db3Sskrll      (emit slti rt rs imm)
11342a6b7db3Sskrll)
11352a6b7db3Sskrll
11362a6b7db3Sskrll(dnmi m-sltu "sltu immediate" (USES-RS USES-RT NO-DIS)
11372a6b7db3Sskrll      "sltu $rt,$rs,$imm"
11382a6b7db3Sskrll      (emit sltiu rt rs imm)
11392a6b7db3Sskrll)
11402a6b7db3Sskrll
11412a6b7db3Sskrll(dnmi m-sra "shift right arithmetic" (USES-RD USES-RT USES-RS NO-DIS)
11422a6b7db3Sskrll      "sra $rd,$rt,$rs"
11432a6b7db3Sskrll      (emit srav rd rt rs)
11442a6b7db3Sskrll)
11452a6b7db3Sskrll
11462a6b7db3Sskrll(dnmi m-srl "shift right logical" (USES-RD USES-RT USES-RS NO-DIS)
11472a6b7db3Sskrll      "srl $rd,$rt,$rs"
11482a6b7db3Sskrll      (emit srlv rd rt rs)
11492a6b7db3Sskrll)
11502a6b7db3Sskrll
11512a6b7db3Sskrll(dnmi not "not" (USES-RD USES-RT NO-DIS)
11522a6b7db3Sskrll      "not $rd,$rt"
11532a6b7db3Sskrll      (emit nor rd (rs 0) rt)
11542a6b7db3Sskrll)
11552a6b7db3Sskrll
11562a6b7db3Sskrll(dnmi subi "sub immediate" (USES-RS USES-RT NO-DIS)
11572a6b7db3Sskrll      "subi $rt,$rs,$mlo16"
11582a6b7db3Sskrll      (emit addiu rt rs mlo16)
11592a6b7db3Sskrll)
11602a6b7db3Sskrll
11612a6b7db3Sskrll(dnmi m-sub "subtract immediate" (USES-RS USES-RT NO-DIS)
11622a6b7db3Sskrll      "sub $rt,$rs,$mlo16"
11632a6b7db3Sskrll      (emit addiu rt rs mlo16)
11642a6b7db3Sskrll)
11652a6b7db3Sskrll
11662a6b7db3Sskrll(dnmi m-subu "subtract unsigned" (USES-RS USES-RT NO-DIS)
11672a6b7db3Sskrll      "subu $rt,$rs,$mlo16"
11682a6b7db3Sskrll      (emit addiu rt rs mlo16)
11692a6b7db3Sskrll)
11702a6b7db3Sskrll
11712a6b7db3Sskrll(dnmi sb-base-0 "store byte - implied base 0" (USES-RT NO-DIS)
11722a6b7db3Sskrll      "sb $rt,$lo16"
11732a6b7db3Sskrll      (emit sb rt lo16 (base 0))
11742a6b7db3Sskrll)
11752a6b7db3Sskrll
11762a6b7db3Sskrll(dnmi sh-base-0 "store half - implied base 0" (USES-RT NO-DIS)
11772a6b7db3Sskrll      "sh $rt,$lo16"
11782a6b7db3Sskrll      (emit sh rt lo16 (base 0))
11792a6b7db3Sskrll)
11802a6b7db3Sskrll
11812a6b7db3Sskrll(dnmi sw-base-0 "store word - implied base 0" (USES-RT NO-DIS)
11822a6b7db3Sskrll      "sw $rt,$lo16"
11832a6b7db3Sskrll      (emit sw rt lo16 (base 0))
11842a6b7db3Sskrll)
11852a6b7db3Sskrll
11862a6b7db3Sskrll(dnmi m-xor "xor immediate" (USES-RS USES-RT NO-DIS)
11872a6b7db3Sskrll      "xor $rt,$rs,$lo16"
11882a6b7db3Sskrll      (emit xori rt rs lo16)
11892a6b7db3Sskrll)
11902a6b7db3Sskrll
11912a6b7db3Sskrll
11922a6b7db3Sskrll(if (keep-mach? (iq2000))
11932a6b7db3Sskrll(include "iq2000m.cpu"))
11942a6b7db3Sskrll
11952a6b7db3Sskrll(if (keep-mach? (iq10))
11962a6b7db3Sskrll(include "iq10.cpu"))
1197