1 ; IQ2000/IQ10 Common CPU description. -*- Scheme -*-
2 ; Copyright 2001, 2002, 2007, 2009 Free Software Foundation, Inc.
4 ; Contributed by Red Hat Inc; developed under contract from Fujitsu.
6 ; This file is part of the GNU Binutils.
8 ; This program is free software; you can redistribute it and/or modify
9 ; it under the terms of the GNU General Public License as published by
10 ; the Free Software Foundation; either version 3 of the License, or
11 ; (at your option) any later version.
13 ; This program is distributed in the hope that it will be useful,
14 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ; GNU General Public License for more details.
18 ; You should have received a copy of the GNU General Public License
19 ; along with this program; if not, write to the Free Software
20 ; Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23 (include "simplify.inc")
27 (comment "IQ2000 architecture")
35 (comment "Basic IQ2000 instruction set")
36 (default-insn-word-bitsize 32)
37 (default-insn-bitsize 32)
38 (base-insn-bitsize 32)
39 (decode-assist (31 30 29 28 27 26))
44 (comment "IQ2000 family")
52 (comment "IQ10 coprocessor family")
61 (comment "IQ2000 packet processing engine")
68 (comment "IQ10 coprocessor")
75 (comment "IQ2000 microprocessor")
77 (unit u-exec "Execution Unit" ()
84 (comment "IQ10 coprocessor")
86 (unit u-exec "Execution Unit" ()
91 ; Macros to simplify MACH attribute specification.
93 (define-pmacro MACH2000 (MACH iq2000))
94 (define-pmacro MACH10 (MACH iq10))
101 (comment "program counter")
102 (attrs PC PROFILE (ISA iq2000))
104 (get () (c-call USI "get_h_pc"))
105 (set (newval) (c-call VOID "set_h_pc" newval))
107 ; FIXME: it would be nice if the hardwired zero in R0 could be
108 ; specified as a virtual hardware element, with one less register in
109 ; the register file proper.
114 (values (r0 0) (%0 0) (r1 1) (%1 1) (r2 2) (%2 2) (r3 3) (%3 3)
115 (r4 4) (%4 4) (r5 5) (%5 5) (r6 6) (%6 6) (r7 7) (%7 7)
116 (r8 8) (%8 8) (r9 9) (%9 9) (r10 10) (%10 10) (r11 11) (%11 11)
117 (r12 12) (%12 12) (r13 13) (%13 13) (r14 14) (%14 14) (r15 15) (%15 15)
118 (r16 16) (%16 16) (r17 17) (%17 17) (r18 18) (%18 18) (r19 19) (%19 19)
119 (r20 20) (%20 20) (r21 21) (%21 21) (r22 22) (%22 22) (r23 23) (%23 23)
120 (r24 24) (%24 24) (r25 25) (%25 25) (r26 26) (%26 26) (r27 27) (%27 27)
121 (r28 28) (%28 28) (r29 29) (%29 29) (r30 30) (%30 30) (r31 31) (%31 31))
126 (comment "General purpose registers")
127 ; (attrs (ISA iq2000) CACHE-ADDR)
128 (type register SI (32))
129 (indices extern-keyword gr-names)
132 ((eq idx 0) (const 0))
133 (else (raw-reg h-gr idx))))
137 (else (set (raw-reg h-gr idx) newval))))
141 ; Instruction fields.
143 (dnf f-opcode "opcode field" () 31 6)
144 (dnf f-rs "register field Rs" () 25 5)
145 (dnf f-rt "register field Rt" () 20 5)
146 (dnf f-rd "register field Rd" () 15 5)
147 (dnf f-shamt "shift amount field" () 10 5)
148 (dnf f-cp-op "coprocessor op field" () 10 3)
149 (dnf f-cp-op-10 "coprocessor op field for CAM" () 10 5)
150 (dnf f-cp-grp "coprocessor group field" () 7 2)
151 (dnf f-func "function field" () 5 6)
152 (dnf f-imm "immediate field" () 15 16)
156 (comment "register Rd implied from Rs")
159 (subfields f-rd f-rs)
161 (set (ifield f-rd) (ifield f-rd-rs))
162 (set (ifield f-rs) (ifield f-rd-rs))
164 (extract (sequence ()
165 (set (ifield f-rd-rs) (ifield f-rs))
171 (comment "register Rd implied from Rt")
174 (subfields f-rd f-rt)
176 (set (ifield f-rd) (ifield f-rd-rt))
177 (set (ifield f-rt) (ifield f-rd-rt))
179 (extract (sequence ()
180 (set (ifield f-rd-rt) (ifield f-rt))
186 (comment "register Rt implied from Rs")
189 (subfields f-rt f-rs)
191 (set (ifield f-rt) (ifield f-rt-rs))
192 (set (ifield f-rs) (ifield f-rt-rs))
194 (extract (sequence ()
195 (set (ifield f-rd-rs) (ifield f-rs))
199 (df f-jtarg "jump target field" (ABS-ADDR) 15 16 UINT
200 ((value pc) (srl USI (and USI value #x03FFFF) 2))
201 ((value pc) (or USI (and USI pc #xF0000000) (sll USI value 2))))
203 (df f-jtargq10 "iq10 jump target field" (ABS-ADDR) 20 21 UINT
204 ((value pc) (srl SI (and SI value #x7FFFFF) 2))
205 ((value pc) (or SI (and SI pc #xF0000000) (sll SI value 2))))
207 (df f-offset "pc offset field" (PCREL-ADDR) 15 16 INT
208 ; Actually, this is relative to the address of the delay slot.
209 ((value pc) (sra SI (sub SI value pc) 2))
210 ((value pc) (add SI (sll SI value 2) (add pc 4))))
212 ; Instruction fields that scarcely appear in instructions.
214 (dnf f-count "count field" () 15 7)
215 (dnf f-bytecount "byte count field" () 7 8)
216 (dnf f-index "index field" () 8 9)
217 (dnf f-mask "mask field" () 9 4)
218 (dnf f-maskq10 "iq10 mask field" () 10 5)
219 (dnf f-maskl "mask left field" () 4 5)
220 (dnf f-excode "execcode field" () 25 20)
221 (dnf f-rsrvd "reserved field" () 25 10)
222 (dnf f-10-11 "bits 10:0" () 10 11)
223 (dnf f-24-19 "bits 24:6" () 24 19)
224 (dnf f-5 "bit 5" () 5 1)
225 (dnf f-10 "bit 10" () 10 1)
226 (dnf f-25 "bit 25" () 25 1)
227 (dnf f-cam-z "cam global mask z" () 5 3)
228 (dnf f-cam-y "cam operation y" () 2 3)
229 (dnf f-cm-3func "CM 3 bit fn field" () 5 3)
230 (dnf f-cm-4func "CM 4 bit fn field" () 5 4)
231 (dnf f-cm-3z "CM 3Z field" () 1 2)
232 (dnf f-cm-4z "CM 4Z field" () 2 3)
237 (define-normal-insn-enum
238 opcodes "primary opcodes" () OP_ f-opcode
239 (("SPECIAL" 0) ("REGIMM" 1) ("J" 2) ("JAL" 3) ("BEQ" 4) ("BNE" 5) ("BLEZ" 6) ("BGTZ" 7)
240 ("ADDI" 8) ("ADDIU" 9) ("SLTI" 10) ("SLTIU" 11) ("ANDI" 12) ("ORI" 13) ("XORI" 14) ("LUI" 15)
241 ("COP0" 16) ("COP1" 17) ("COP2" 18) ("COP3" 19) ("BEQL" 20) ("BNEL" 21) ("BLEZL" 22) ("BGTZL" 23)
242 ("BMB0" 24) ("BMB1" 25) ("BMB2" 26) ("BMB3" 27) ("BBI" 28) ("BBV" 29) ("BBIN" 30) ("BBVN" 31)
243 ("LB" 32) ("LH" 33) ("LW" 35) ("LBU" 36) ("LHU" 37) ("RAM" 39)
244 ("SB" 40) ("SH" 41) ("SW" 43) ("ANDOI" 44) ("BMB" 45) ("ORUI" 47)
246 ("SDW" 56) ("ANDOUI" 63))
249 (define-normal-insn-enum
250 q10_opcodes "iq10-only primary opcodes" () OP10_ f-opcode
251 (("BMB" 6) ("ORUI" 15) ("BMBL" 22) ("ANDOUI" 47) ("BBIL" 60) ("BBVL" 61) ("BBINL" 62) ("BBVNL" 63))
254 (define-normal-insn-enum
255 regimm-functions "branch sub-opcodes" () FUNC_ f-rt
256 (("BLTZ" 0) ("BGEZ" 1) ("BLTZL" 2) ("BGEZL" 3) ("BLEZ" 4) ("BGTZ" 5) ("BLEZL" 6) ("BGTZL" 7)
257 ("BRI" 8) ("BRV" 9) ("BCTX" 12)
258 ("BLTZAL" 16) ("BGEZAL" 17) ("BLTZALL" 18) ("BGEZALL" 19) ("BLEZAL" 20) ("BGTZAL" 21) ("BLEZALL" 22) ("BGTZALL" 23))
261 (define-normal-insn-enum
262 functions "function sub-opcodes" () FUNC_ f-func
263 (("SLL" 0) ("SLMV" 1) ("SRL" 2) ("SRA" 3) ("SLLV" 4) ("SRMV" 5) ("SRLV" 6) ("SRAV" 7)
264 ("JR" 8) ("JALR" 9) ("JCR" 10) ("SYSCALL" 12) ("BREAK" 13) ("SLEEP" 14)
265 ("ADD" 32) ("ADDU" 33) ("SUB" 34) ("SUBU" 35) ("AND" 36) ("OR" 37) ("XOR" 38) ("NOR" 39)
266 ("ADO16" 41) ("SLT" 42) ("SLTU" 43) ("MRGB" 45))
269 ; iq10 special function sub-opcodes
270 (define-normal-insn-enum
271 q10s_functions "iq10-only special function sub-opcodes" () FUNC10_ f-func
272 (("YIELD" 14) ("CNT1S" 46))
275 ; coprocessor opcodes in concert with f-cp-grp
276 (define-normal-insn-enum
277 cop_functions "iq10 function sub-opcodes" () FUNC10_ f-func
278 (("CFC" 0) ("LOCK" 1) ("CTC" 2) ("UNLK" 3) ("SWRD" 4) ("SWRDL" 5) ("SWWR" 6) ("SWWRU" 7)
279 ("RBA" 8) ("RBAL" 9) ("RBAR" 10) ("DWRD" 12) ("DWRDL" 13)
280 ("WBA" 16) ("WBAU" 17) ("WBAC" 18) ("CRC32" 20) ("CRC32B" 21)
281 ("MCID" 32) ("DBD" 33) ("DBA" 34) ("DPWT" 35) ("AVAIL" 36) ("FREE" 37) ("CHKHDR" 38) ("TSTOD" 39)
282 ("PKRLA" 40) ("PKRLAU" 41) ("PKRLAH" 42) ("PKRLAC" 43) ("CMPHDR" 44)
284 ("CM64RS" 0) ("CM64RD" 1) ("CM64RI" 4) ("CM64CLR" 5)
285 ("CM64SS" 8) ("CM64SD" 9) ("CM64SI" 12)
286 ("CM64RA" 16) ("CM64RIA2" 20) ("CM128RIA2" 21)
287 ("CM64SA" 24) ("CM64SIA2" 28) ("CM128SIA2" 29)
288 ("CM32RS" 32) ("CM32RD" 33) ("CM32XOR" 34) ("CM32ANDN" 35) ("CM32RI" 36) ("CM128VSA" 38)
289 ("CM32SS" 40) ("CM32SD" 41) ("CM32OR" 42) ("CM32AND" 43) ("CM32SI" 44)
294 ; coprocessor opcodes in concert with f-cp-grp
295 (define-normal-insn-enum
296 cop_cm128_4functions "iq10 function sub-opcodes" () FUNC10_ f-cm-4func
297 (("CM128RIA3" 4) ("CM128SIA3" 6))
300 (define-normal-insn-enum
301 cop_cm128_3functions "iq10 function sub-opcodes" () FUNC10_ f-cm-3func
302 (("CM128RIA4" 6) ("CM128SIA4" 7))
305 (define-normal-insn-enum
306 cop2_functions "iq10 coprocessor sub-opcodes" () FUNC10_ f-cp-op
307 (("PKRLI" 0) ("PKRLIU" 1) ("PKRLIH" 2) ("PKRLIC" 3) ("RBIR" 1) ("RBI" 2) ("RBIL" 3) ("WBIC" 5) ("WBI" 6) ("WBIU" 7))
310 (define-normal-insn-enum
311 cop3_cam_functions "iq10 coprocessor cam sub-opcodes" () FUNC10_ f-cp-op-10
312 (("CAM36" 16) ("CAM72" 17) ("CAM144" 18) ("CAM288" 19))
322 (comment "insn generates a context yield")
329 (comment "insn has a load delay")
336 (comment "insn requires an even numbered register in rt(2000) or rd(10)")
343 (comment "insn is unsupported")
346 (define-pmacro (define-reg-use-attr regfield)
350 (name (.sym USES- (.upcase regfield)))
351 (comment ("insn accesses register operand " regfield))))
353 (define-reg-use-attr "rd")
354 (define-reg-use-attr "rs")
355 (define-reg-use-attr "rt")
356 (define-reg-use-attr "r31")
361 (dnop rs "register Rs" () h-gr f-rs)
362 (dnop rt "register Rt" () h-gr f-rt)
363 (dnop rd "register Rd" () h-gr f-rd)
364 (dnop rd-rs "register Rd from Rs" () h-gr f-rd-rs)
365 (dnop rd-rt "register Rd from Rt" () h-gr f-rd-rt)
366 (dnop rt-rs "register Rt from Rs" () h-gr f-rt-rs)
367 (dnop shamt "shift amount" () h-uint f-shamt)
368 (define-operand (name imm) (comment "immediate") (attrs)
369 (type h-uint) (index f-imm) (handlers (parse "imm")))
370 (dnop offset "pc-relative offset" () h-iaddr f-offset)
371 (dnop baseoff "base register offset" () h-iaddr f-imm)
372 (dnop jmptarg "jump target" () h-iaddr f-jtarg)
373 (dnop mask "mask" () h-uint f-mask)
374 (dnop maskq10 "iq10 mask" () h-uint f-maskq10)
375 (dnop maskl "mask left" () h-uint f-maskl)
376 (dnop count "count" () h-uint f-count)
377 (dnop _index "index" () h-uint f-index)
378 (dnop execode "execcode" () h-uint f-excode)
379 (dnop bytecount "byte count" () h-uint f-bytecount)
380 (dnop cam-y "cam global opn y" () h-uint f-cam-y)
381 (dnop cam-z "cam global mask z" () h-uint f-cam-z)
382 (dnop cm-3func "CM 3 bit fn field" () h-uint f-cm-3func)
383 (dnop cm-4func "CM 4 bit fn field" () h-uint f-cm-4func)
384 (dnop cm-3z "CM 3 bit Z field" () h-uint f-cm-3z)
385 (dnop cm-4z "CM 4 bit Z field" () h-uint f-cm-4z)
387 ; Aliases for the rs and rt operands. This just makes the load/store
388 ; insns easier to compare with the instruction set documentation.
390 (dnop base "base register" () h-gr f-rs)
391 (dnop maskr "mask right" () h-uint f-rs)
392 (dnop bitnum "bit number" () h-uint f-rt)
397 (comment "high 16 bit immediate")
401 (handlers (parse "hi16"))
407 (comment "16 bit signed immediate, for low")
411 (handlers (parse "lo16"))
417 (comment "negated 16 bit signed immediate")
421 (handlers (parse "mlo16"))
425 ; In the future, we'll want the j & jal to use the 21 bit target, with
426 ; the upper five bits shifted up. For now, don't use this.
429 (comment "iq10 21-bit jump offset")
433 (handlers (parse "jtargq10"))
439 ; A pmacro for use in semantic bodies of unimplemented insns.
440 (define-pmacro (unimp mnemonic) (nop))
442 (define-pmacro (bitset? value bit-num)
443 (and value (sll 1 bit-num)))
445 (define-pmacro (bitclear? value bit-num)
446 (not (bitset? value bit-num)))
448 ; Arithmetic/logic instructions.
450 (dni add2 "add registers" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
452 (+ OP_SPECIAL rt rd-rs (f-shamt 0) FUNC_ADD)
453 (set rd-rs (add rt rd-rs))
456 (dni add "add registers" (USES-RD USES-RS USES-RT)
458 (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_ADD)
463 (dni addi2 "add immediate" (ALIAS NO-DIS USES-RS USES-RT)
464 "addi ${rt-rs},$lo16"
465 (+ OP_ADDI rt-rs lo16)
466 (set rt-rs (add rt-rs (ext SI (trunc HI lo16))))
469 (dni addi "add immediate" (USES-RS USES-RT)
471 (+ OP_ADDI rs rt lo16)
472 (set rt (add rs (ext SI (trunc HI lo16))))
475 (dni addiu2 "add immediate unsigned" (ALIAS NO-DIS USES-RS USES-RT)
476 "addiu ${rt-rs},$lo16"
477 (+ OP_ADDIU rt-rs lo16)
478 (set rt-rs (add rt-rs (ext SI (trunc HI lo16))))
481 (dni addiu "add immediate unsigned" (USES-RS USES-RT)
482 "addiu $rt,$rs,$lo16"
483 (+ OP_ADDIU rs rt lo16)
484 (set rt (add rs (ext SI (trunc HI lo16))))
487 (dni addu2 "add unsigned" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
489 (+ OP_SPECIAL rd-rs rt (f-shamt 0) FUNC_ADDU)
490 (set rd-rs (add rd-rs rt))
493 (dni addu "add unsigned" (USES-RD USES-RS USES-RT)
495 (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_ADDU)
499 (dni ado162 "add 16, ones complement" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
501 (+ OP_SPECIAL rd-rs rt (f-shamt 0) FUNC_ADO16)
502 (sequence ((HI high) (HI low))
503 (set low (add HI (and HI rd-rs #xFFFF) (and HI rt #xFFFF)))
504 (set high (add HI (srl rd-rs 16) (srl rt 16)))
505 (set rd-rs (or SI (sll SI high 16) low)))
508 (dni ado16 "add 16, ones complement" (USES-RD USES-RS USES-RT)
510 (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_ADO16)
511 (sequence ((HI high) (HI low))
512 (set low (add HI (and HI rs #xFFFF) (and HI rt #xFFFF)))
513 (set high (add HI (srl rs 16) (srl rt 16)))
514 (set rd (or SI (sll SI high 16) low)))
517 (dni and2 "and register" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
519 (+ OP_SPECIAL rd-rs rt (f-shamt 0) FUNC_AND)
520 (set rd-rs (and rd-rs rt))
523 (dni and "and register" (USES-RD USES-RS USES-RT)
525 (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_AND)
529 (dni andi2 "and immediate" (ALIAS NO-DIS USES-RS USES-RT)
530 "andi ${rt-rs},$lo16"
531 (+ OP_ANDI rt-rs lo16)
532 (set rt-rs (and rt-rs (zext SI lo16)))
535 (dni andi "and immediate" (USES-RS USES-RT)
537 (+ OP_ANDI rs rt lo16)
538 (set rt (and rs (zext SI lo16)))
541 (dni andoi2 "and ones immediate" (ALIAS NO-DIS USES-RS USES-RT)
542 "andoi ${rt-rs},$lo16"
543 (+ OP_ANDOI rt-rs lo16)
544 (set rt-rs (and rt-rs (or #xFFFF0000 (ext SI (trunc HI lo16)))))
547 (dni andoi "and ones immediate" (USES-RS USES-RT)
548 "andoi $rt,$rs,$lo16"
549 (+ OP_ANDOI rs rt lo16)
550 (set rt (and rs (or #xFFFF0000 (ext SI (trunc HI lo16)))))
553 (dni nor2 "nor" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
555 (+ OP_SPECIAL rd-rs rt (f-shamt 0) FUNC_NOR)
556 (set rd-rs (inv (or rd-rs rt)))
559 (dni nor "nor" (USES-RD USES-RS USES-RT)
561 (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_NOR)
562 (set rd (inv (or rs rt)))
565 (dni or2 "or" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
567 (+ OP_SPECIAL rd-rs rt (f-shamt 0) FUNC_OR)
568 (set rd-rs (or rd-rs rt))
571 (dni or "or" (USES-RD USES-RS USES-RT)
573 (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_OR)
577 (dni ori2 "or immediate" (ALIAS NO-DIS USES-RS USES-RT)
579 (+ OP_ORI rt-rs lo16)
580 (set rt-rs (or rt-rs (zext SI lo16)))
583 (dni ori "or immediate" (USES-RS USES-RT)
585 (+ OP_ORI rs rt lo16)
586 (set rt (or rs (zext SI lo16)))
589 (dni ram "rotate and mask" (USES-RD USES-RT)
590 "ram $rd,$rt,$shamt,$maskl,$maskr"
591 (+ OP_RAM maskr rt rd shamt (f-5 0) maskl)
593 (set rd (ror rt shamt))
594 (set rd (and rd (srl #xFFFFFFFF maskl)))
595 (set rd (and rd (sll #xFFFFFFFF maskr))))
598 (dni sll "shift left logical" (USES-RD USES-RT)
600 (+ OP_SPECIAL (f-rs 0) rt rd shamt (f-func 0))
601 (set rd (sll rt shamt))
604 (dni sllv2 "shift left logical variable" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
606 (+ OP_SPECIAL rs rd-rt (f-shamt 0) FUNC_SLLV)
607 (set rd-rt (sll rd-rt (and rs #x1F)))
610 (dni sllv "shift left logical variable" (USES-RD USES-RS USES-RT)
612 (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_SLLV)
613 (set rd (sll rt (and rs #x1F)))
616 (dni slmv2 "shift left and mask variable" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
617 "slmv ${rd-rt},$rs,$shamt"
618 (+ OP_SPECIAL rs rd-rt shamt FUNC_SLMV)
619 (set rd-rt (and (sll rd-rt shamt) (srl #xFFFFFFFF rs)))
622 (dni slmv "shift left and mask variable" (USES-RD USES-RS USES-RT)
623 "slmv $rd,$rt,$rs,$shamt"
624 (+ OP_SPECIAL rs rt rd shamt FUNC_SLMV)
625 (set rd (and (sll rt shamt) (srl #xFFFFFFFF rs)))
628 (dni slt2 "set if less than" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
630 (+ OP_SPECIAL rt rd-rs (f-shamt 0) FUNC_SLT)
636 (dni slt "set if less than" (USES-RD USES-RS USES-RT)
638 (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_SLT)
644 (dni slti2 "set if less than immediate" (ALIAS NO-DIS USES-RS USES-RT)
646 (+ OP_SLTI rt-rs imm)
647 (if (lt rt-rs (ext SI (trunc HI imm)))
652 (dni slti "set if less than immediate" (USES-RS USES-RT)
654 (+ OP_SLTI rs rt imm)
655 (if (lt rs (ext SI (trunc HI imm)))
660 (dni sltiu2 "set if less than immediate unsigned" (ALIAS NO-DIS USES-RS USES-RT)
661 "sltiu ${rt-rs},$imm"
662 (+ OP_SLTIU rt-rs imm)
663 (if (ltu rt-rs (ext SI (trunc HI imm)))
668 (dni sltiu "set if less than immediate unsigned" (USES-RS USES-RT)
670 (+ OP_SLTIU rs rt imm)
671 (if (ltu rs (ext SI (trunc HI imm)))
676 (dni sltu2 "set if less than unsigned" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
678 (+ OP_SPECIAL rd-rs rt (f-shamt 0) FUNC_SLTU)
684 (dni sltu "set if less than unsigned" (USES-RD USES-RS USES-RT)
686 (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_SLTU)
692 (dni sra2 "shift right arithmetic" (ALIAS NO-DIS USES-RD USES-RT)
693 "sra ${rd-rt},$shamt"
694 (+ OP_SPECIAL (f-rs 0) rd-rt shamt FUNC_SRA)
695 (set rd-rt (sra rd-rt shamt))
698 (dni sra "shift right arithmetic" (USES-RD USES-RT)
700 (+ OP_SPECIAL (f-rs 0) rt rd shamt FUNC_SRA)
701 (set rd (sra rt shamt))
704 (dni srav2 "shift right arithmetic variable" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
706 (+ OP_SPECIAL rs rd-rt (f-shamt 0) FUNC_SRAV)
707 (set rd-rt (sra rd-rt (and rs #x1F)))
710 (dni srav "shift right arithmetic variable" (USES-RD USES-RS USES-RT)
712 (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_SRAV)
713 (set rd (sra rt (and rs #x1F)))
716 (dni srl "shift right logical" (USES-RD USES-RT)
718 (+ OP_SPECIAL (f-rs 0) rt rd shamt FUNC_SRL)
719 (set rd (srl rt shamt))
722 (dni srlv2 "shift right logical variable" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
724 (+ OP_SPECIAL rs rd-rt (f-shamt 0) FUNC_SRLV)
725 (set rd-rt (srl rd-rt (and rs #x1F)))
728 (dni srlv "shift right logical variable" (USES-RD USES-RS USES-RT)
730 (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_SRLV)
731 (set rd (srl rt (and rs #x1F)))
734 (dni srmv2 "shift right and mask variable" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
735 "srmv ${rd-rt},$rs,$shamt"
736 (+ OP_SPECIAL rs rd-rt shamt FUNC_SRMV)
737 (set rd-rt (and (srl rd-rt shamt) (sll #xFFFFFFFF rs)))
740 (dni srmv "shift right and mask variable" (USES-RD USES-RS USES-RT)
741 "srmv $rd,$rt,$rs,$shamt"
742 (+ OP_SPECIAL rs rt rd shamt FUNC_SRMV)
743 (set rd (and (srl rt shamt) (sll #xFFFFFFFF rs)))
746 (dni sub2 "subtract" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
748 (+ OP_SPECIAL rt rd-rs (f-shamt 0) FUNC_SUB)
749 (set rd-rs (sub rd-rs rt))
752 (dni sub "subtract" (USES-RD USES-RS USES-RT)
754 (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_SUB)
758 (dni subu2 "subtract unsigned" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
760 (+ OP_SPECIAL rt rd-rs (f-shamt 0) FUNC_SUBU)
761 (set rd-rs (sub rd-rs rt))
764 (dni subu "subtract unsigned" (USES-RD USES-RS USES-RT)
766 (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_SUBU)
770 (dni xor2 "exclusive or" (ALIAS NO-DIS USES-RD USES-RS USES-RT)
772 (+ OP_SPECIAL rt rd-rs (f-shamt 0) FUNC_XOR)
773 (set rd-rs (xor rd-rs rt))
776 (dni xor "exclusive or" (USES-RD USES-RS USES-RT)
778 (+ OP_SPECIAL rs rt rd (f-shamt 0) FUNC_XOR)
782 (dni xori2 "exclusive or immediate" (ALIAS NO-DIS USES-RS USES-RT)
783 "xori ${rt-rs},$lo16"
784 (+ OP_XORI rt-rs lo16)
785 (set rt-rs (xor rt-rs (zext SI lo16)))
788 (dni xori "exclusive or immediate" (USES-RS USES-RT)
790 (+ OP_XORI rs rt lo16)
791 (set rt (xor rs (zext SI lo16)))
795 ; Branch instructions.
797 (dni bbi "branch bit immediate" (USES-RS)
798 "bbi $rs($bitnum),$offset"
799 (+ OP_BBI rs bitnum offset)
800 (if (bitset? rs bitnum)
801 (delay 1 (set pc offset)))
804 (dni bbin "branch bit immediate negated" (USES-RS)
805 "bbin $rs($bitnum),$offset"
806 (+ OP_BBIN rs bitnum offset)
807 (if (bitclear? rs bitnum)
808 (delay 1 (set pc offset)))
811 (dni bbv "branch bit variable" (USES-RS USES-RT)
812 "bbv $rs,$rt,$offset"
813 (+ OP_BBV rs rt offset)
814 (if (bitset? rs (and rt #x1F))
815 (delay 1 (set pc offset)))
818 (dni bbvn "branch bit variable negated" (USES-RS USES-RT)
819 "bbvn $rs,$rt,$offset"
820 (+ OP_BBVN rs rt offset)
821 (if (bitclear? rs (and rt #x1F))
822 (delay 1 (set pc offset)))
825 (dni beq "branch if equal" (USES-RS USES-RT)
826 "beq $rs,$rt,$offset"
827 (+ OP_BEQ rs rt offset)
829 (delay 1 (set pc offset)))
832 (dni beql "branch if equal likely" (USES-RS USES-RT)
833 "beql $rs,$rt,$offset"
834 (+ OP_BEQL rs rt offset)
836 (delay 1 (set pc offset))
840 (dni bgez "branch if greater than or equal to zero" (USES-RS)
842 (+ OP_REGIMM rs FUNC_BGEZ offset)
844 (delay 1 (set pc offset)))
847 (dni bgezal "branch if greater than or equal to zero and link" (USES-RS USES-R31)
849 (+ OP_REGIMM rs FUNC_BGEZAL offset)
852 (set (reg h-gr 31) (add pc 8))
853 (delay 1 (set pc offset))))
857 "branch if greater than equal to zero and link likely" (USES-RS USES-R31)
858 "bgezall $rs,$offset"
859 (+ OP_REGIMM rs FUNC_BGEZALL offset)
862 (set (reg h-gr 31) (add pc 8))
863 (delay 1 (set pc offset)))
867 (dni bgezl "branch if greater or equal to zero likely" (USES-RS)
869 (+ OP_REGIMM rs FUNC_BGEZL offset)
871 (delay 1 (set pc offset))
875 (dni bltz "branch if less than zero" (USES-RS)
877 (+ OP_REGIMM rs FUNC_BLTZ offset)
879 (delay 1 (set pc offset)))
882 (dni bltzl "branch if less than zero likely" (USES-RS)
884 (+ OP_REGIMM rs FUNC_BLTZL offset)
886 (delay 1 (set pc offset))
890 (dni bltzal "branch if less than zero and link" (USES-RS USES-R31)
892 (+ OP_REGIMM rs FUNC_BLTZAL offset)
895 (set (reg h-gr 31) (add pc 8))
896 (delay 1 (set pc offset))))
899 (dni bltzall "branch if less than zero and link likely" (USES-RS USES-R31)
900 "bltzall $rs,$offset"
901 (+ OP_REGIMM rs FUNC_BLTZALL offset)
904 (set (reg h-gr 31) (add pc 8))
905 (delay 1 (set pc offset)))
909 (dni bmb0 "branch if matching byte-lane 0" (USES-RS USES-RT)
910 "bmb0 $rs,$rt,$offset"
911 (+ OP_BMB0 rs rt offset)
912 (if (eq (and rs #xFF) (and rt #xFF))
913 (delay 1 (set pc offset)))
916 (dni bmb1 "branch if matching byte-lane 1" (USES-RS USES-RT)
917 "bmb1 $rs,$rt,$offset"
918 (+ OP_BMB1 rs rt offset)
919 (if (eq (and rs #xFF00) (and rt #xFF00))
920 (delay 1 (set pc offset)))
923 (dni bmb2 "branch if matching byte-lane 2" (USES-RS USES-RT)
924 "bmb2 $rs,$rt,$offset"
925 (+ OP_BMB2 rs rt offset)
926 (if (eq (and rs #xFF0000) (and rt #xFF0000))
927 (delay 1 (set pc offset)))
930 (dni bmb3 "branch if matching byte-lane 3" (USES-RS USES-RT)
931 "bmb3 $rs,$rt,$offset"
932 (+ OP_BMB3 rs rt offset)
933 (if (eq (and rs #xFF000000) (and rt #xFF000000))
934 (delay 1 (set pc offset)))
937 (dni bne "branch if not equal" (USES-RS USES-RT)
938 "bne $rs,$rt,$offset"
939 (+ OP_BNE rs rt offset)
941 (delay 1 (set pc offset)))
944 (dni bnel "branch if not equal likely" (USES-RS USES-RT)
945 "bnel $rs,$rt,$offset"
946 (+ OP_BNEL rs rt offset)
948 (delay 1 (set pc offset))
956 ; Might as well jump!
958 (dni jalr "jump and link register" (USES-RD USES-RS)
960 (+ OP_SPECIAL rs (f-rt 0) rd (f-shamt 0) FUNC_JALR)
967 (dni jr "jump register" (USES-RS)
969 (+ OP_SPECIAL rs (f-rt 0) (f-rd 0) (f-shamt 0) FUNC_JR)
970 (delay 1 (set pc rs))
976 (dni lb "load byte" (LOAD-DELAY USES-RS USES-RT)
977 "lb $rt,$lo16($base)"
978 (+ OP_LB base rt lo16)
979 (set rt (ext WI (mem QI (add base (ext SI (trunc HI lo16))))))
980 ; (sequence ((SI addr) (SI word))
981 ; (set addr (add base lo16))
982 ; (set word (mem SI (and addr (inv 3))))
983 ; (set word (srl word (sll (and addr 2) 3)))
984 ; (set rt (ext SI word)))
987 (dni lbu "load byte unsigned" (LOAD-DELAY USES-RS USES-RT)
988 "lbu $rt,$lo16($base)"
989 (+ OP_LBU base rt lo16)
990 (set rt (zext WI (mem QI (add base (ext SI (trunc HI lo16))))))
991 ; (sequence ((SI addr) (SI word))
992 ; (set addr (add base lo16))
993 ; (set word (mem SI (and addr (inv 3))))
994 ; (set rt (srl word (sll (and addr 2) 3))))
997 (dni lh "load half word" (LOAD-DELAY USES-RS USES-RT)
998 "lh $rt,$lo16($base)"
999 (+ OP_LH base rt lo16)
1000 (set rt (ext WI (mem HI (add base (ext SI (trunc HI lo16))))))
1001 ; (sequence ((SI addr) (HI word))
1002 ; (set addr (add base lo16))
1003 ; (set word (mem SI (and addr (inv 3))))
1004 ; (set word (srl word (sll (and addr 1) 4)))
1005 ; (set rt (ext SI word)))
1008 (dni lhu "load half word unsigned" (LOAD-DELAY USES-RS USES-RT)
1009 "lhu $rt,$lo16($base)"
1010 (+ OP_LHU base rt lo16)
1011 (set rt (zext WI (mem HI (add base (ext SI (trunc HI lo16))))))
1012 ; (sequence ((SI addr) (SI word))
1013 ; (set addr (add base lo16))
1014 ; (set word (mem SI (and addr (inv 3))))
1015 ; (set rt (srl word (sll (and addr 1) 4))))
1018 (dni lui "load upper immediate" (USES-RT)
1020 (+ OP_LUI (f-rs 0) rt hi16)
1021 (set rt (sll hi16 16))
1024 (dni lw "load word" (LOAD-DELAY USES-RS USES-RT)
1025 "lw $rt,$lo16($base)"
1026 (+ OP_LW base rt lo16)
1027 (set rt (mem SI (add base (ext SI (trunc HI lo16)))))
1031 ; Store instructions.
1033 (dni sb "store byte" (USES-RS USES-RT)
1034 "sb $rt,$lo16($base)"
1035 (+ OP_SB base rt lo16)
1036 (set (mem QI (add base (ext SI (trunc HI lo16)))) (and QI rt #xFF))
1039 (dni sh "store half word" (USES-RS USES-RT)
1040 "sh $rt,$lo16($base)"
1041 (+ OP_SH base rt lo16)
1042 (set (mem HI (add base (ext SI (trunc HI lo16)))) (and HI rt #xFFFF))
1045 (dni sw "store word" (USES-RS USES-RT)
1046 "sw $rt,$lo16($base)"
1047 (+ OP_SW base rt lo16)
1048 (set (mem SI (add base (ext SI (trunc HI lo16)))) rt)
1052 ; Special instructions for simulation/debugging
1053 (dni break "breakpoint" ()
1055 (+ OP_SPECIAL (f-rs 0) (f-rt 0) (f-rd 0) (f-shamt 0) FUNC_BREAK)
1056 (c-call VOID "do_break" pc)
1059 (dni syscall "system call" (YIELD-INSN)
1061 (+ OP_SPECIAL execode (f-func 12))
1062 (c-call VOID "do_syscall")
1065 ; Macro instructions, common to iq10 & iq2000
1069 (emit sll (rd 0) (rt 0) (shamt 0))
1072 (dnmi li "load immediate" (USES-RS NO-DIS)
1074 (emit ori (rt 0) rs imm)
1077 (dnmi move "move" (USES-RD USES-RT NO-DIS)
1079 (emit or rd (rs 0) rt)
1082 (dnmi lb-base-0 "load byte - implied base 0" (USES-RT NO-DIS)
1084 (emit lb rt lo16 (base 0))
1087 (dnmi lbu-base-0 "load byte unsigned - implied base 0" (USES-RT NO-DIS)
1089 (emit lbu rt lo16 (base 0))
1092 (dnmi lh-base-0 "load half - implied base 0" (USES-RT NO-DIS)
1094 (emit lh rt lo16 (base 0))
1097 (dnmi lw-base-0 "load word - implied base 0" (USES-RT NO-DIS)
1099 (emit lw rt lo16 (base 0))
1102 (dnmi m-add "add immediate" (USES-RS USES-RT NO-DIS)
1104 (emit addi rt rs lo16))
1106 (dnmi m-addu "add immediate unsigned" (USES-RS USES-RT NO-DIS)
1107 "addu $rt,$rs,$lo16"
1108 (emit addiu rt rs lo16)
1111 (dnmi m-and "and immediate" (USES-RS USES-RT NO-DIS)
1113 (emit andi rt rs lo16)
1116 (dnmi m-j "jump register" (USES-RS NO-DIS)
1121 (dnmi m-or "or immediate" (USES-RS USES-RT NO-DIS)
1123 (emit ori rt rs lo16)
1126 (dnmi m-sll "shift left logical" (USES-RD USES-RT USES-RS NO-DIS)
1128 (emit sllv rd rt rs)
1131 (dnmi m-slt "slt immediate" (USES-RS USES-RT NO-DIS)
1133 (emit slti rt rs imm)
1136 (dnmi m-sltu "sltu immediate" (USES-RS USES-RT NO-DIS)
1138 (emit sltiu rt rs imm)
1141 (dnmi m-sra "shift right arithmetic" (USES-RD USES-RT USES-RS NO-DIS)
1143 (emit srav rd rt rs)
1146 (dnmi m-srl "shift right logical" (USES-RD USES-RT USES-RS NO-DIS)
1148 (emit srlv rd rt rs)
1151 (dnmi not "not" (USES-RD USES-RT NO-DIS)
1153 (emit nor rd (rs 0) rt)
1156 (dnmi subi "sub immediate" (USES-RS USES-RT NO-DIS)
1157 "subi $rt,$rs,$mlo16"
1158 (emit addiu rt rs mlo16)
1161 (dnmi m-sub "subtract immediate" (USES-RS USES-RT NO-DIS)
1162 "sub $rt,$rs,$mlo16"
1163 (emit addiu rt rs mlo16)
1166 (dnmi m-subu "subtract unsigned" (USES-RS USES-RT NO-DIS)
1167 "subu $rt,$rs,$mlo16"
1168 (emit addiu rt rs mlo16)
1171 (dnmi sb-base-0 "store byte - implied base 0" (USES-RT NO-DIS)
1173 (emit sb rt lo16 (base 0))
1176 (dnmi sh-base-0 "store half - implied base 0" (USES-RT NO-DIS)
1178 (emit sh rt lo16 (base 0))
1181 (dnmi sw-base-0 "store word - implied base 0" (USES-RT NO-DIS)
1183 (emit sw rt lo16 (base 0))
1186 (dnmi m-xor "xor immediate" (USES-RS USES-RT NO-DIS)
1188 (emit xori rt rs lo16)
1192 (if (keep-mach? (iq2000))
1193 (include "iq2000m.cpu"))
1195 (if (keep-mach? (iq10))
1196 (include "iq10.cpu"))