1 ; OpenRISC Basic Instruction Set 32-bit (ORBIS) -*- Scheme -*-
2 ; Copyright 2000-2014 Free Software Foundation, Inc.
3 ; Contributed for OR32 by Johan Rydberg, jrydberg@opencores.org
4 ; Modified by Julius Baxter, juliusbaxter@gmail.com
5 ; Modified by Peter Gavin, pgavin@gmail.com
7 ; This program is free software; you can redistribute it and/or modify
8 ; it under the terms of the GNU General Public License as published by
9 ; the Free Software Foundation; either version 3 of the License, or
10 ; (at your option) any later version.
12 ; This program is distributed in the hope that it will be useful,
13 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ; GNU General Public License for more details.
17 ; You should have received a copy of the GNU General Public License
18 ; along with this program; if not, see <http://www.gnu.org/licenses/>
22 ; Hardware for immediate operands
23 (dnh h-simm16 "16-bit signed immediate" ((MACH ORBIS-MACHS)) (immediate (INT 16)) () () ())
24 (dnh h-uimm16 "16-bit unsigned immediate" () (immediate (UINT 16)) () () ())
25 (dnh h-uimm6 "6-bit unsigned immediate" () (immediate (UINT 6)) () () ())
27 ; Hardware for the (internal) atomic registers
28 (dsh h-atomic-reserve "atomic reserve flag" () (register BI))
29 (dsh h-atomic-address "atomic reserve address" () (register SI))
31 ; Instruction classes.
32 (dnf f-opcode "insn opcode" ((MACH ORBIS-MACHS)) 31 6)
35 (dnf f-r1 "r1" ((MACH ORBIS-MACHS)) 25 5)
36 (dnf f-r2 "r2" ((MACH ORBIS-MACHS)) 20 5)
37 (dnf f-r3 "r3" ((MACH ORBIS-MACHS)) 15 5)
40 (dnf f-op-25-2 "op-25-2" ((MACH ORBIS-MACHS)) 25 2) ;; nop
41 (dnf f-op-25-5 "op-25-5" ((MACH ORBIS-MACHS)) 25 5) ;; sys, trap, *sync, sf*
42 (dnf f-op-16-1 "op-16-1" ((MACH ORBIS-MACHS)) 16 1) ;; movhi,macrc
43 (dnf f-op-7-4 "op-7-4" ((MACH ORBIS-MACHS)) 7 4)
44 (dnf f-op-3-4 "op-3-4" ((MACH ORBIS-MACHS)) 3 4)
45 (dnf f-op-9-2 "op-9-2" ((MACH ORBIS-MACHS)) 9 2) ;; alu ops upper opcode
46 (dnf f-op-9-4 "op-9-4" ((MACH ORBIS-MACHS)) 9 4) ;;
47 (dnf f-op-7-8 "op-7-8" ((MACH ORBIS-MACHS)) 7 8)
48 (dnf f-op-7-2 "op-7-2" ((MACH ORBIS-MACHS)) 7 2) ;; alu lower upper opc,shroti
51 (dnf f-resv-25-26 "resv-25-26" ((MACH ORBIS-MACHS) RESERVED) 25 26)
52 (dnf f-resv-25-10 "resv-25-10" ((MACH ORBIS-MACHS) RESERVED) 25 10)
53 (dnf f-resv-25-5 "resv-25-5" ((MACH ORBIS-MACHS) RESERVED) 25 5)
54 (dnf f-resv-23-8 "resv-23-8" ((MACH ORBIS-MACHS) RESERVED) 23 8)
55 (dnf f-resv-20-21 "resv-20-21" ((MACH ORBIS-MACHS) RESERVED) 20 21)
56 (dnf f-resv-20-5 "resv-20-5" ((MACH ORBIS-MACHS) RESERVED) 20 5)
57 (dnf f-resv-20-4 "resv-20-4" ((MACH ORBIS-MACHS) RESERVED) 20 4)
58 (dnf f-resv-15-8 "resv-15-8" ((MACH ORBIS-MACHS) RESERVED) 15 8)
59 (dnf f-resv-15-6 "resv-15-6" ((MACH ORBIS-MACHS) RESERVED) 15 6)
60 (dnf f-resv-10-11 "resv-10-11" ((MACH ORBIS-MACHS) RESERVED) 10 11)
61 (dnf f-resv-10-7 "resv-10-7" ((MACH ORBIS-MACHS) RESERVED) 10 7)
62 (dnf f-resv-10-3 "resv-10-3" ((MACH ORBIS-MACHS) RESERVED) 10 3)
63 (dnf f-resv-10-1 "resv-10-1" ((MACH ORBIS-MACHS) RESERVED) 10 1)
64 (dnf f-resv-7-4 "resv-7-4" ((MACH ORBIS-MACHS) RESERVED) 7 4)
65 (dnf f-resv-5-2 "resv-5-2" ((MACH ORBIS-MACHS) RESERVED) 5 2)
67 (dnf f-imm16-25-5 "imm16-25-5" ((MACH ORBIS-MACHS)) 25 5)
68 (dnf f-imm16-10-11 "imm16-10-11" ((MACH ORBIS-MACHS)) 10 11)
70 ; PC relative, 26-bit (2 shifted to right)
73 ((MACH ORBIS-MACHS) PCREL-ADDR)
77 ((value pc) (sra IAI (sub IAI value pc) (const 2)))
78 ((value pc) (add IAI (sll IAI value (const 2)) pc))
81 ; PC relative, 21-bit, 13 shifted to right, aligned.
82 ; Note that the alignment means that we can't simplify relocations in the
83 ; same way as we do for pc-relative, so we use ABS-ADDR instead of PCREL-ADDR.
86 ((MACH ORBIS-MACHS) ABS-ADDR)
91 (sub IAI (sra IAI value (const 13)) (sra IAI pc (const 13))))
93 (sll IAI (add IAI value (sra IAI pc (const 13))) (const 13)))
97 (dnf f-uimm16 "uimm16" ((MACH ORBIS-MACHS)) 15 16)
98 (df f-simm16 "simm16" ((MACH ORBIS-MACHS) SIGN-OPT) 15 16 INT #f #f)
99 (dnf f-uimm6 "uimm6" ((MACH ORBIS-MACHS)) 5 6) ;; shroti
102 (name f-uimm16-split)
103 (comment "16-bit split unsigned immediate")
104 (attrs (MACH ORBIS-MACHS))
106 (subfields f-imm16-25-5 f-imm16-10-11)
108 (set (ifield f-imm16-25-5)
109 (and (srl (ifield f-uimm16-split)
112 (set (ifield f-imm16-10-11)
113 (and (ifield f-uimm16-split)
116 (set (ifield f-uimm16-split)
118 (or (sll (ifield f-imm16-25-5)
120 (ifield f-imm16-10-11)))))
124 (name f-simm16-split)
125 (comment "16-bit split signed immediate")
126 (attrs (MACH ORBIS-MACHS) SIGN-OPT)
128 (subfields f-imm16-25-5 f-imm16-10-11)
130 (set (ifield f-imm16-25-5)
131 (and (sra (ifield f-simm16-split)
134 (set (ifield f-imm16-10-11)
135 (and (ifield f-simm16-split)
138 (set (ifield f-simm16-split)
140 (or (sll (ifield f-imm16-25-5)
142 (ifield f-imm16-10-11)))))
147 ; insn-opcode: bits 31-26
148 (define-normal-insn-enum
149 insn-opcode "insn main opcode enums" ((MACH ORBIS-MACHS)) OPC_ f-opcode
157 ("SYSTRAPSYNCS" #x08)
201 (define-normal-insn-enum insn-opcode-systrapsyncs
202 "systrapsync insn opcode enums" ((MACH ORBIS-MACHS))
203 OPC_SYSTRAPSYNCS_ f-op-25-5
212 (define-normal-insn-enum insn-opcode-movehimacrc
213 "movhi/macrc insn opcode enums" ((MACH ORBIS-MACHS))
214 OPC_MOVHIMACRC_ f-op-16-1
220 (define-normal-insn-enum insn-opcode-mac
221 "multiply/accumulate insn opcode enums" ((MACH ORBIS-MACHS))
230 (define-normal-insn-enum insn-opcode-shorts
231 "shift/rotate insn opcode enums" ((MACH ORBIS-MACHS))
240 (define-normal-insn-enum insn-opcode-extbhs
241 "extend byte/half opcode enums" ((MACH ORBIS-MACHS))
250 (define-normal-insn-enum insn-opcode-extws
251 "extend word opcode enums" ((MACH ORBIS-MACHS))
258 (define-normal-insn-enum insn-opcode-alu-regreg
259 "alu reg/reg insn opcode enums" ((MACH ORBIS-MACHS))
260 OPC_ALU_REGREG_ f-op-3-4
281 (define-normal-insn-enum insn-opcode-setflag
282 "setflag insn opcode enums" ((MACH ORBIS-MACHS))
298 ; Instruction operands.
300 (dnop sys-sr "supervision register" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-sr f-nil)
301 (dnop sys-esr0 "exception supervision register 0" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-esr0 f-nil)
302 (dnop sys-epcr0 "exception PC register 0" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-epcr0 f-nil)
304 (dnop sys-sr-lee "SR little endian enable bit" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-sr-lee f-nil)
305 (dnop sys-sr-f "SR flag bit" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-sr-f f-nil)
306 (dnop sys-sr-cy "SR carry bit" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-sr-cy f-nil)
307 (dnop sys-sr-ov "SR overflow bit" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-sr-ov f-nil)
308 (dnop sys-sr-ove "SR overflow exception enable bit" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-sr-ove f-nil)
309 (dnop sys-cpucfgr-ob64s "CPUCFGR ORBIS64 supported bit" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-cpucfgr-ob64s f-nil)
310 (dnop sys-cpucfgr-nd "CPUCFGR no delay bit" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-cpucfgr-nd f-nil)
311 (dnop sys-fpcsr-rm "floating point round mode" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-fpcsr-rm f-nil)
313 (dnop mac-machi "MAC HI result register" ((MACH ORBIS-MACHS) SEM-ONLY) h-mac-machi f-nil)
314 (dnop mac-maclo "MAC LO result register" ((MACH ORBIS-MACHS) SEM-ONLY) h-mac-maclo f-nil)
316 (dnop atomic-reserve "atomic reserve flag" ((MACH ORBIS-MACHS) SEM-ONLY) h-atomic-reserve f-nil)
317 (dnop atomic-address "atomic address" ((MACH ORBIS-MACHS) SEM-ONLY) h-atomic-address f-nil)
319 (dnop uimm6 "uimm6" ((MACH ORBIS-MACHS)) h-uimm6 f-uimm6)
321 (dnop rD "destination register" ((MACH ORBIS-MACHS)) h-gpr f-r1)
322 (dnop rA "source register A" ((MACH ORBIS-MACHS)) h-gpr f-r2)
323 (dnop rB "source register B" ((MACH ORBIS-MACHS)) h-gpr f-r3)
327 (comment "pc-rel 26 bit")
328 (attrs (MACH ORBIS-MACHS))
331 (handlers (parse "disp26"))
336 (comment "pc-rel 21 bit")
337 (attrs (MACH ORBIS-MACHS))
340 (handlers (parse "disp21"))
345 (comment "16-bit signed immediate")
346 (attrs (MACH ORBIS-MACHS) SIGN-OPT)
349 (handlers (parse "simm16"))
354 (comment "16-bit unsigned immediate")
355 (attrs (MACH ORBIS-MACHS))
358 (handlers (parse "uimm16"))
363 (comment "split 16-bit signed immediate")
364 (attrs (MACH ORBIS-MACHS) SIGN-OPT)
366 (index f-simm16-split)
367 (handlers (parse "simm16_split"))
372 (comment "split 16-bit unsigned immediate")
373 (attrs (MACH ORBIS-MACHS))
375 (index f-uimm16-split)
376 (handlers (parse "uimm16_split"))
381 ; Branch releated instructions
383 (define-pmacro (cti-link-return)
384 (set IAI (reg h-gpr 9) (add pc (if sys-cpucfgr-nd 4 8)))
386 (define-pmacro (cti-transfer-control condition target)
387 ;; this mess is necessary because we're
388 ;; skipping the delay slot, but it's
389 ;; actually the start of the next basic
393 (delay 1 (set IAI pc target))
395 (delay 1 (set IAI pc (add pc 4))))
415 (.splice (MACH ORBIS-MACHS) DELAYED-CTI NOT-IN-DELAY-SLOT (.unsplice cti-attrs))
426 "jump (pc-relative iaddr)"
427 (!COND-CTI UNCOND-CTI)
431 (cti-transfer-control 1 disp26)
435 (dni l-adrp "adrp reg/disp21"
437 "l.adrp $rD,${disp21}"
438 (+ OPC_ADRP rD disp21)
445 "jump and link (pc-relative iaddr)"
446 (!COND-CTI UNCOND-CTI)
452 (cti-transfer-control 1 disp26)
459 "jump register (absolute iaddr)"
460 (!COND-CTI UNCOND-CTI)
462 (+ OPC_JR (f-resv-25-10 0) rB (f-resv-10-11 0))
464 (cti-transfer-control 1 rB)
470 "jump register and link (absolute iaddr)"
471 (!COND-CTI UNCOND-CTI)
473 (+ OPC_JALR (f-resv-25-10 0) rB (f-resv-10-11 0) )
477 (cti-transfer-control 1 rB)
484 "branch if condition bit not set (pc relative iaddr)"
485 (COND-CTI !UNCOND-CTI)
489 (cti-transfer-control (not sys-sr-f) disp26)
495 "branch if condition bit set (pc relative iaddr)"
496 (COND-CTI !UNCOND-CTI)
500 (cti-transfer-control sys-sr-f disp26)
504 (dni l-trap "trap (exception)"
505 ((MACH ORBIS-MACHS) NOT-IN-DELAY-SLOT)
507 (+ OPC_SYSTRAPSYNCS OPC_SYSTRAPSYNCS_TRAP (f-resv-20-5 0) uimm16)
508 ; Do exception entry handling in C function, PC set based on SR state
509 (raise-exception EXCEPT-TRAP)
514 (dni l-sys "syscall (exception)"
515 ; This function may not be in delay slot
516 ((MACH ORBIS-MACHS) NOT-IN-DELAY-SLOT)
519 (+ OPC_SYSTRAPSYNCS OPC_SYSTRAPSYNCS_SYSCALL (f-resv-20-5 0) uimm16)
520 ; Do exception entry handling in C function, PC set based on SR state
521 (raise-exception EXCEPT-SYSCALL)
525 (dni l-msync "memory sync"
528 (+ OPC_SYSTRAPSYNCS OPC_SYSTRAPSYNCS_MSYNC (f-resv-20-21 0))
533 (dni l-psync "pipeline sync"
536 (+ OPC_SYSTRAPSYNCS OPC_SYSTRAPSYNCS_PSYNC (f-resv-20-21 0))
541 (dni l-csync "context sync"
544 (+ OPC_SYSTRAPSYNCS OPC_SYSTRAPSYNCS_CSYNC (f-resv-20-21 0))
549 (dni l-rfe "return from exception"
550 ; This function may not be in delay slot
551 ((MACH ORBIS-MACHS) NOT-IN-DELAY-SLOT FORCED-CTI)
554 (+ OPC_RFE (f-resv-25-26 0))
555 (c-call VOID "@cpu@_rfe")
562 ; l.nop with immediate must be first so it handles all l.nops in sim
563 (dni l-nop-imm "nop uimm16"
566 (+ OPC_NOP (f-op-25-2 #x1) (f-resv-23-8 0) uimm16)
567 (c-call VOID "@cpu@_nop" (zext UWI uimm16))
571 (if (application-is? SIMULATOR)
577 (+ OPC_NOP (f-op-25-2 #x1) (f-resv-23-8 0) uimm16)
584 (dni l-movhi "movhi reg/uimm16"
586 "l.movhi $rD,$uimm16"
587 (+ OPC_MOVHIMACRC rD (f-resv-20-4 0) OPC_MOVHIMACRC_MOVHI uimm16)
588 (set UWI rD (sll UWI (zext UWI uimm16) (const 16)))
592 (dni l-macrc "macrc reg"
595 (+ OPC_MOVHIMACRC rD (f-resv-20-4 0) OPC_MOVHIMACRC_MACRC (f-uimm16 0))
597 (set UWI rD mac-maclo)
598 (set UWI mac-maclo 0)
599 (set UWI mac-machi 0)
605 ; System releated instructions
609 "l.mfspr $rD,$rA,${uimm16}"
610 (+ OPC_MFSPR rD rA uimm16)
611 (set UWI rD (c-call UWI "@cpu@_mfspr" (or rA (zext UWI uimm16))))
617 "l.mtspr $rA,$rB,${uimm16-split}"
618 (+ OPC_MTSPR rA rB uimm16-split )
619 (c-call VOID "@cpu@_mtspr" (or rA (zext WI uimm16-split)) rB)
625 (define-pmacro (load-store-addr base offset size)
626 (c-call AI "@cpu@_make_load_store_addr" base (ext SI offset) size))
628 (dni l-lwz "l.lwz reg/simm16(reg)"
630 "l.lwz $rD,${simm16}($rA)"
631 (+ OPC_LWZ rD rA simm16)
632 (set UWI rD (zext UWI (mem USI (load-store-addr rA simm16 4))))
637 (dni l-lws "l.lws reg/simm16(reg)"
639 "l.lws $rD,${simm16}($rA)"
640 (+ OPC_LWS rD rA simm16)
641 (set WI rD (ext WI (mem SI (load-store-addr rA simm16 4))))
645 (dni l-lwa "l.lwa reg/simm16(reg)"
647 "l.lwa $rD,${simm16}($rA)"
648 (+ OPC_LWA rD rA simm16)
650 (set UWI rD (zext UWI (mem USI (load-store-addr rA simm16 4))))
651 (set atomic-reserve (const 1))
652 (set atomic-address (load-store-addr rA simm16 4))
657 (dni l-lbz "l.lbz reg/simm16(reg)"
659 "l.lbz $rD,${simm16}($rA)"
660 (+ OPC_LBZ rD rA simm16)
661 (set UWI rD (zext UWI (mem UQI (load-store-addr rA simm16 1))))
665 (dni l-lbs "l.lbs reg/simm16(reg)"
667 "l.lbs $rD,${simm16}($rA)"
668 (+ OPC_LBS rD rA simm16)
669 (set WI rD (ext WI (mem QI (load-store-addr rA simm16 1))))
673 (dni l-lhz "l.lhz reg/simm16(reg)"
675 "l.lhz $rD,${simm16}($rA)"
676 (+ OPC_LHZ rD simm16 rA)
677 (set UWI rD (zext UWI (mem UHI (load-store-addr rA simm16 2))))
681 (dni l-lhs "l.lhs reg/simm16(reg)"
683 "l.lhs $rD,${simm16}($rA)"
684 (+ OPC_LHS rD rA simm16)
685 (set WI rD (ext WI (mem HI (load-store-addr rA simm16 2))))
692 (define-pmacro (store-insn mnemonic opc-op mode size)
694 (dni (.sym l- mnemonic)
695 (.str "l." mnemonic " simm16(reg)/reg")
697 (.str "l." mnemonic " ${simm16-split}($rA),$rB")
698 (+ opc-op rA rB simm16-split)
699 (sequence ((SI addr))
700 (set addr (load-store-addr rA simm16-split size))
701 (set mode (mem mode addr) (trunc mode rB))
702 (if (eq (and addr #xffffffc) atomic-address)
703 (set atomic-reserve (const 0))
711 (store-insn sw OPC_SW USI 4)
712 (store-insn sb OPC_SB UQI 1)
713 (store-insn sh OPC_SH UHI 2)
715 (dni l-swa "l.swa simm16(reg)/reg"
717 "l.swa ${simm16-split}($rA),$rB"
718 (+ OPC_SWA rA rB simm16)
719 (sequence ((SI addr) (BI flag))
720 (set addr (load-store-addr rA simm16-split 4))
721 (set sys-sr-f (and atomic-reserve (eq addr atomic-address)))
723 (set USI (mem USI addr) (trunc USI rB))
725 (set atomic-reserve (const 0))
731 ; Shift and rotate instructions
733 (define-pmacro (shift-insn mnemonic)
735 (dni (.sym l- mnemonic)
736 (.str "l." mnemonic " reg/reg/reg")
738 (.str "l." mnemonic " $rD,$rA,$rB")
739 (+ OPC_ALU rD rA rB (f-resv-10-3 0) (.sym OPC_SHROTS_ (.upcase mnemonic)) (f-resv-5-2 0)
740 OPC_ALU_REGREG_SHROT )
741 (set UWI rD (mnemonic rA rB))
744 (dni (.sym l- mnemonic "i")
745 (.str "l." mnemonic " reg/reg/uimm6")
747 (.str "l." mnemonic "i $rD,$rA,${uimm6}")
748 (+ OPC_SHROTI rD rA (f-resv-15-8 0) (.sym OPC_SHROTS_ (.upcase mnemonic)) uimm6)
749 (set rD (mnemonic rA uimm6))
764 (define-pmacro (alu-insn mnemonic)
766 (dni (.sym l- mnemonic)
767 (.str "l." mnemonic " reg/reg/reg")
769 (.str "l." mnemonic " $rD,$rA,$rB")
770 (+ OPC_ALU rD rA rB (f-resv-10-7 0) (.sym OPC_ALU_REGREG_ (.upcase mnemonic)))
771 (set rD (mnemonic rA rB))
781 (define-pmacro (alu-carry-insn mnemonic)
783 (dni (.sym l- mnemonic)
784 (.str "l." mnemonic " reg/reg/reg")
786 (.str "l." mnemonic " $rD,$rA,$rB")
787 (+ OPC_ALU rD rA rB (f-resv-10-7 #x00) (.sym OPC_ALU_REGREG_ (.upcase mnemonic)))
790 (set BI sys-sr-cy ((.sym mnemonic "c-cflag") WI rA rB 0))
791 (set BI sys-sr-ov ((.sym mnemonic "c-oflag") WI rA rB 0))
792 (set rD (mnemonic WI rA rB))
794 (if (andif sys-sr-ov sys-sr-ove)
795 (raise-exception EXCEPT-RANGE))
805 (dni (l-addc) "l.addc reg/reg/reg"
807 ("l.addc $rD,$rA,$rB")
808 (+ OPC_ALU rD rA rB (f-resv-10-7 #x00) OPC_ALU_REGREG_ADDC)
810 (sequence ((BI tmp-sys-sr-cy))
811 (set BI tmp-sys-sr-cy sys-sr-cy)
812 (set BI sys-sr-cy (addc-cflag WI rA rB tmp-sys-sr-cy))
813 (set BI sys-sr-ov (addc-oflag WI rA rB tmp-sys-sr-cy))
814 (set rD (addc WI rA rB tmp-sys-sr-cy))
816 (if (andif sys-sr-ov sys-sr-ove)
817 (raise-exception EXCEPT-RANGE))
822 (dni (l-mul) "l.mul reg/reg/reg"
824 ("l.mul $rD,$rA,$rB")
825 (+ OPC_ALU rD rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_MUL)
828 (set BI sys-sr-ov (mul-o2flag WI rA rB))
829 (set rD (mul WI rA rB))
831 (if (andif sys-sr-ov sys-sr-ove)
832 (raise-exception EXCEPT-RANGE))
837 (dni (l-muld) "l.muld reg/reg"
840 (+ OPC_ALU (f-resv-25-5 0) rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_MULD)
841 (sequence ((DI result))
842 (set DI result (mul DI (ext DI rA) (ext DI rB)))
843 (set SI mac-machi (subword SI result 0))
844 (set SI mac-maclo (subword SI result 1))
849 (dni (l-mulu) "l.mulu reg/reg/reg"
851 ("l.mulu $rD,$rA,$rB")
852 (+ OPC_ALU rD rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_MULU)
855 (set BI sys-sr-cy (mul-o1flag UWI rA rB))
856 (set rD (mul UWI rA rB))
858 (if (andif sys-sr-cy sys-sr-ove)
859 (raise-exception EXCEPT-RANGE))
864 (dni (l-muldu) "l.muld reg/reg"
867 (+ OPC_ALU (f-resv-25-5 0) rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_MULDU)
868 (sequence ((DI result))
869 (set DI result (mul DI (zext DI rA) (zext DI rB)))
870 (set SI mac-machi (subword SI result 0))
871 (set SI mac-maclo (subword SI result 1))
876 (dni l-div "divide (signed)"
879 (+ OPC_ALU rD rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_DIV)
883 (set WI rD (div WI rA rB))
888 (raise-exception EXCEPT-RANGE))
894 (dni l-divu "divide (unsigned)"
897 (+ OPC_ALU rD rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_DIVU)
901 (set rD (udiv UWI rA rB))
906 (raise-exception EXCEPT-RANGE))
912 (dni l-ff1 "find first '1'"
915 (+ OPC_ALU rD rA rB (f-resv-10-7 #x00) OPC_ALU_REGREG_FFL1)
916 (set rD (c-call UWI "@cpu@_ff1" rA))
920 (dni l-fl1 "find last '1'"
923 (+ OPC_ALU rD rA rB (f-resv-10-7 #x10) OPC_ALU_REGREG_FFL1)
924 (set rD (c-call UWI "@cpu@_fl1" rA))
929 (define-pmacro (alu-insn-simm mnemonic)
931 (dni (.sym l- mnemonic "i")
932 (.str "l." mnemonic " reg/reg/simm16")
934 (.str "l." mnemonic "i $rD,$rA,$simm16")
935 (+ (.sym OPC_ (.upcase mnemonic) "I") rD rA simm16)
936 (set rD (mnemonic rA (ext WI simm16)))
942 (define-pmacro (alu-insn-uimm mnemonic)
944 (dni (.sym l- mnemonic "i")
945 (.str "l." mnemonic " reg/reg/uimm16")
947 (.str "l." mnemonic "i $rD,$rA,$uimm16")
948 (+ (.sym OPC_ (.upcase mnemonic) "I") rD rA uimm16)
949 (set rD (mnemonic rA (zext UWI uimm16)))
959 (define-pmacro (alu-carry-insn-simm mnemonic)
961 (dni (.sym l- mnemonic "i")
962 (.str "l." mnemonic "i reg/reg/simm16")
964 (.str "l." mnemonic "i $rD,$rA,$simm16")
965 (+ (.sym OPC_ (.upcase mnemonic) "I") rD rA simm16)
968 (set BI sys-sr-cy ((.sym mnemonic "c-cflag") WI rA (ext WI simm16) 0))
969 (set BI sys-sr-ov ((.sym mnemonic "c-oflag") WI rA (ext WI simm16) 0))
970 (set rD (mnemonic WI rA (ext WI simm16)))
972 (if (andif sys-sr-ov sys-sr-ove)
973 (raise-exception EXCEPT-RANGE))
980 (alu-carry-insn-simm add)
983 ("l.addic reg/reg/simm16")
985 ("l.addic $rD,$rA,$simm16")
986 (+ OPC_ADDIC rD rA simm16)
988 (sequence ((BI tmp-sys-sr-cy))
989 (set BI tmp-sys-sr-cy sys-sr-cy)
990 (set BI sys-sr-cy (addc-cflag WI rA (ext WI simm16) tmp-sys-sr-cy))
991 (set BI sys-sr-ov (addc-oflag WI rA (ext WI simm16) tmp-sys-sr-cy))
992 (set WI rD (addc WI rA (ext WI simm16) tmp-sys-sr-cy))
994 (if (andif sys-sr-ov sys-sr-ove)
995 (raise-exception EXCEPT-RANGE))
1001 "l.muli reg/reg/simm16"
1002 ((MACH ORBIS-MACHS))
1003 ("l.muli $rD,$rA,$simm16")
1004 (+ OPC_MULI rD rA simm16)
1007 (set sys-sr-ov (mul-o2flag WI rA (ext WI simm16)))
1008 (set rD (mul WI rA (ext WI simm16)))
1010 (if (andif sys-sr-ov sys-sr-ove)
1011 (raise-exception EXCEPT-RANGE))
1016 (define-pmacro (extbh-insn mnemonic extop extmode truncmode)
1018 (dni (.sym l- mnemonic)
1019 (.str "l." mnemonic " reg/reg")
1020 ((MACH ORBIS-MACHS))
1021 (.str "l." mnemonic " $rD,$rA")
1022 (+ OPC_ALU rD rA (f-resv-15-6 0) (.sym OPC_EXTBHS_ (.upcase mnemonic)) (f-resv-5-2 0) OPC_ALU_REGREG_EXTBH)
1023 (set rD (extop extmode (trunc truncmode rA)))
1029 (extbh-insn exths ext WI HI)
1030 (extbh-insn extbs ext WI QI)
1031 (extbh-insn exthz zext UWI UHI)
1032 (extbh-insn extbz zext UWI UQI)
1034 (define-pmacro (extw-insn mnemonic extop extmode truncmode)
1036 (dni (.sym l- mnemonic)
1037 (.str "l." mnemonic " reg/reg")
1038 ((MACH ORBIS-MACHS))
1039 (.str "l." mnemonic " $rD,$rA")
1040 (+ OPC_ALU rD rA (f-resv-15-6 0) (.sym OPC_EXTWS_ (.upcase mnemonic)) (f-resv-5-2 0) OPC_ALU_REGREG_EXTW)
1041 (set rD (extop extmode (trunc truncmode rA)))
1047 (extw-insn extws ext WI SI)
1048 (extw-insn extwz zext USI USI)
1051 "l.cmov reg/reg/reg"
1052 ((MACH ORBIS-MACHS))
1053 "l.cmov $rD,$rA,$rB"
1054 (+ OPC_ALU rD rA rB (f-resv-10-1 0) (f-op-9-2 0) (f-resv-7-4 0) OPC_ALU_REGREG_CMOV)
1062 ; Compare instructions
1065 (define-pmacro (sf-insn op)
1067 (dni (.sym l- "sf" op "s") ; l-sfgts
1068 (.str "l.sf" op "s reg/reg") ; "l.sfgts reg/reg"
1069 ((MACH ORBIS-MACHS))
1070 (.str "l.sf" op "s $rA,$rB") ; "l.sfgts $rA,$rB"
1071 (+ OPC_SF (.sym "OPC_SF_" (.upcase op) "S") rA rB (f-resv-10-11 0)) ; (+ OPC_SF OPC_SF_GTS rA rB (f-resv-10-11 0))
1072 (set sys-sr-f (op WI rA rB)) ; (set sys-sr-f (gt WI rA rB))
1075 (dni (.sym l- "sf" op "si") ; l-sfgtsi
1076 (.str "l.sf" op "si reg/simm16") ; "l.sfgtsi reg/simm16"
1077 ((MACH ORBIS-MACHS))
1078 (.str "l.sf" op "si $rA,$simm16") ; "l.sfgtsi $rA,$simm16"
1079 (+ OPC_SFI (.sym "OPC_SF_" (.upcase op) "S") rA simm16) ; (+ OPC_SFI OPC_SF_GTS rA simm16)
1080 (set sys-sr-f (op WI rA (ext WI simm16))) ; (set sys-sr-f (gt WI rA (ext WI simm16)))
1083 (dni (.sym l- "sf" op "u") ; l-sfgtu
1084 (.str "l.sf" op "u reg/reg") ; "l.sfgtu reg/reg"
1085 ((MACH ORBIS-MACHS))
1086 (.str "l.sf" op "u $rA,$rB") ; "l.sfgtu $rA,$rB"
1087 (+ OPC_SF (.sym "OPC_SF_" (.upcase op) "U") rA rB (f-resv-10-11 0)) ; (+ OPC_SF OPC_SF_GTU rA rB (f-resv-10-11 0))
1088 (set sys-sr-f ((.sym op "u") WI rA rB)) ; (set sys-sr-f (gtu WI rA rB))
1091 ; immediate is sign extended even for unsigned compare
1092 (dni (.sym l- "sf" op "ui") ; l-sfgtui
1093 (.str "l.sf" op "ui reg/simm16") ; "l.sfgtui reg/uimm16"
1094 ((MACH ORBIS-MACHS))
1095 (.str "l.sf" op "ui $rA,$simm16") ; "l.sfgtui $rA,$simm16"
1096 (+ OPC_SFI (.sym "OPC_SF_" (.upcase op) "U") rA simm16) ; (+ OPC_SFI OPC_SF_GTU rA simm16)
1097 (set sys-sr-f ((.sym op "u") WI rA (ext WI simm16))) ; (set sys-sr-f (gtu WI rA (ext WI simm16)))
1109 (define-pmacro (sf-insn-eq op)
1111 (dni (.sym l- "sf" op)
1112 (.str "l." op " reg/reg")
1113 ((MACH ORBIS-MACHS))
1114 (.str "l.sf" op " $rA,$rB")
1115 (+ OPC_SF (.sym "OPC_SF_" (.upcase op)) rA rB (f-resv-10-11 0))
1116 (set sys-sr-f (op WI rA rB))
1119 (dni (.sym l- "sf" op "i")
1120 (.str "l.sf" op "i reg/simm16")
1121 ((MACH ORBIS-MACHS))
1122 (.str "l.sf" op "i $rA,$simm16")
1123 (+ OPC_SFI (.sym "OPC_SF_" (.upcase op)) rA simm16)
1124 (set sys-sr-f (op WI rA (ext WI simm16)))
1135 ((MACH ORBIS-MACHS))
1137 (+ OPC_MAC (f-op-25-5 0) rA rB (f-resv-10-7 0) OPC_MAC_MAC)
1139 (sequence ((DI prod) (DI mac) (DI result))
1140 (set DI prod (mul DI (ext DI rA) (ext DI rB)))
1141 (set DI mac (join DI SI mac-machi mac-maclo))
1142 (set DI result (add prod mac))
1143 (set SI mac-machi (subword SI result 0))
1144 (set SI mac-maclo (subword SI result 1))
1145 (set BI sys-sr-ov (addc-oflag prod mac 0))
1147 (if (andif sys-sr-ov sys-sr-ove)
1148 (raise-exception EXCEPT-RANGE))
1155 ((MACH ORBIS-MACHS))
1156 "l.maci $rA,${simm16}"
1157 (+ OPC_MACI (f-resv-25-5 0) rA simm16)
1159 (sequence ((DI prod) (DI mac) (DI result))
1160 (set DI prod (mul DI (ext DI rA) (ext DI simm16)))
1161 (set DI mac (join DI SI mac-machi mac-maclo))
1162 (set DI result (add mac prod))
1163 (set SI mac-machi (subword SI result 0))
1164 (set SI mac-maclo (subword SI result 1))
1165 (set BI sys-sr-ov (addc-oflag prod mac 0))
1167 (if (andif sys-sr-ov sys-sr-ove)
1168 (raise-exception EXCEPT-RANGE))
1175 ((MACH ORBIS-MACHS))
1177 (+ OPC_MAC (f-op-25-5 0) rA rB (f-resv-10-7 0) OPC_MAC_MACU)
1179 (sequence ((DI prod) (DI mac) (DI result))
1180 (set DI prod (mul DI (zext DI rA) (zext DI rB)))
1181 (set DI mac (join DI SI mac-machi mac-maclo))
1182 (set DI result (add prod mac))
1183 (set SI mac-machi (subword SI result 0))
1184 (set SI mac-maclo (subword SI result 1))
1185 (set BI sys-sr-cy (addc-cflag prod mac 0))
1187 (if (andif sys-sr-cy sys-sr-ove)
1188 (raise-exception EXCEPT-RANGE))
1195 ((MACH ORBIS-MACHS))
1197 (+ OPC_MAC (f-op-25-5 0) rA rB (f-resv-10-7 0) OPC_MAC_MSB)
1199 (sequence ((DI prod) (DI mac) (DI result))
1200 (set DI prod (mul DI (ext DI rA) (ext DI rB)))
1201 (set DI mac (join DI SI mac-machi mac-maclo))
1202 (set DI result (sub mac prod))
1203 (set SI mac-machi (subword SI result 0))
1204 (set SI mac-maclo (subword SI result 1))
1205 (set BI sys-sr-ov (subc-oflag mac result 0))
1207 (if (andif sys-sr-ov sys-sr-ove)
1208 (raise-exception EXCEPT-RANGE))
1215 ((MACH ORBIS-MACHS))
1217 (+ OPC_MAC (f-op-25-5 0) rA rB (f-resv-10-7 0) OPC_MAC_MSBU)
1219 (sequence ((DI prod) (DI mac) (DI result))
1220 (set DI prod (mul DI (zext DI rA) (zext DI rB)))
1221 (set DI mac (join DI SI mac-machi mac-maclo))
1222 (set DI result (sub mac prod))
1223 (set SI mac-machi (subword SI result 0))
1224 (set SI mac-maclo (subword SI result 1))
1225 (set BI sys-sr-cy (subc-cflag mac result 0))
1227 (if (andif sys-sr-cy sys-sr-ove)
1228 (raise-exception EXCEPT-RANGE))
1233 (define-pmacro (cust-insn cust-num)
1235 (dni (.sym l- "cust" cust-num)
1236 (.str "l.cust" cust-num)
1237 ((MACH ORBIS-MACHS))
1238 (.str "l.cust" cust-num)
1239 (+ (.sym OPC_CUST cust-num) (f-resv-25-26 0))