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-8-1 "resv-8-1" ((MACH ORBIS-MACHS) RESERVED) 8 1)
65 (dnf f-resv-7-4 "resv-7-4" ((MACH ORBIS-MACHS) RESERVED) 7 4)
66 (dnf f-resv-5-2 "resv-5-2" ((MACH ORBIS-MACHS) RESERVED) 5 2)
68 (dnf f-imm16-25-5 "imm16-25-5" ((MACH ORBIS-MACHS)) 25 5)
69 (dnf f-imm16-10-11 "imm16-10-11" ((MACH ORBIS-MACHS)) 10 11)
71 ; PC relative, 26-bit (2 shifted to right)
74 ((MACH ORBIS-MACHS) PCREL-ADDR)
78 ((value pc) (sra IAI (sub IAI value pc) (const 2)))
79 ((value pc) (add IAI (mul IAI value (const 4)) pc))
82 ; PC relative, 21-bit, 13 shifted to right, aligned.
83 ; Note that the alignment means that we can't simplify relocations in the
84 ; same way as we do for pc-relative, so we use ABS-ADDR instead of PCREL-ADDR.
87 ((MACH ORBIS-MACHS) ABS-ADDR)
92 (sub IAI (sra IAI value (const 13)) (sra IAI pc (const 13))))
94 (mul IAI (add IAI value (sra IAI pc (const 13))) (const 8192)))
98 (dnf f-uimm16 "uimm16" ((MACH ORBIS-MACHS)) 15 16)
99 (df f-simm16 "simm16" ((MACH ORBIS-MACHS) SIGN-OPT) 15 16 INT #f #f)
100 (dnf f-uimm6 "uimm6" ((MACH ORBIS-MACHS)) 5 6) ;; shroti
103 (name f-uimm16-split)
104 (comment "16-bit split unsigned immediate")
105 (attrs (MACH ORBIS-MACHS))
107 (subfields f-imm16-25-5 f-imm16-10-11)
109 (set (ifield f-imm16-25-5)
110 (and (srl (ifield f-uimm16-split)
113 (set (ifield f-imm16-10-11)
114 (and (ifield f-uimm16-split)
117 (set (ifield f-uimm16-split)
119 (or (sll (ifield f-imm16-25-5)
121 (ifield f-imm16-10-11)))))
125 (name f-simm16-split)
126 (comment "16-bit split signed immediate")
127 (attrs (MACH ORBIS-MACHS) SIGN-OPT)
129 (subfields f-imm16-25-5 f-imm16-10-11)
131 (set (ifield f-imm16-25-5)
132 (and (sra (ifield f-simm16-split)
135 (set (ifield f-imm16-10-11)
136 (and (ifield f-simm16-split)
139 (set (ifield f-simm16-split)
141 (or (sll (ifield f-imm16-25-5)
143 (ifield f-imm16-10-11)))))
148 ; insn-opcode: bits 31-26
149 (define-normal-insn-enum
150 insn-opcode "insn main opcode enums" ((MACH ORBIS-MACHS)) OPC_ f-opcode
158 ("SYSTRAPSYNCS" #x08)
202 (define-normal-insn-enum insn-opcode-systrapsyncs
203 "systrapsync insn opcode enums" ((MACH ORBIS-MACHS))
204 OPC_SYSTRAPSYNCS_ f-op-25-5
213 (define-normal-insn-enum insn-opcode-movehimacrc
214 "movhi/macrc insn opcode enums" ((MACH ORBIS-MACHS))
215 OPC_MOVHIMACRC_ f-op-16-1
221 (define-normal-insn-enum insn-opcode-mac
222 "multiply/accumulate insn opcode enums" ((MACH ORBIS-MACHS))
231 (define-normal-insn-enum insn-opcode-shorts
232 "shift/rotate insn opcode enums" ((MACH ORBIS-MACHS))
241 (define-normal-insn-enum insn-opcode-extbhs
242 "extend byte/half opcode enums" ((MACH ORBIS-MACHS))
251 (define-normal-insn-enum insn-opcode-extws
252 "extend word opcode enums" ((MACH ORBIS-MACHS))
259 (define-normal-insn-enum insn-opcode-alu-regreg
260 "alu reg/reg insn opcode enums" ((MACH ORBIS-MACHS))
261 OPC_ALU_REGREG_ f-op-3-4
282 (define-normal-insn-enum insn-opcode-setflag
283 "setflag insn opcode enums" ((MACH ORBIS-MACHS))
299 ; Instruction operands.
301 (dnop sys-sr "supervision register" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-sr f-nil)
302 (dnop sys-esr0 "exception supervision register 0" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-esr0 f-nil)
303 (dnop sys-epcr0 "exception PC register 0" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-epcr0 f-nil)
305 (dnop sys-sr-lee "SR little endian enable bit" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-sr-lee f-nil)
306 (dnop sys-sr-f "SR flag bit" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-sr-f f-nil)
307 (dnop sys-sr-cy "SR carry bit" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-sr-cy f-nil)
308 (dnop sys-sr-ov "SR overflow bit" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-sr-ov f-nil)
309 (dnop sys-sr-ove "SR overflow exception enable bit" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-sr-ove f-nil)
310 (dnop sys-cpucfgr-ob64s "CPUCFGR ORBIS64 supported bit" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-cpucfgr-ob64s f-nil)
311 (dnop sys-cpucfgr-nd "CPUCFGR no delay bit" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-cpucfgr-nd f-nil)
312 (dnop sys-fpcsr-rm "floating point round mode" ((MACH ORBIS-MACHS) SEM-ONLY) h-sys-fpcsr-rm f-nil)
314 (dnop mac-machi "MAC HI result register" ((MACH ORBIS-MACHS) SEM-ONLY) h-mac-machi f-nil)
315 (dnop mac-maclo "MAC LO result register" ((MACH ORBIS-MACHS) SEM-ONLY) h-mac-maclo f-nil)
317 (dnop atomic-reserve "atomic reserve flag" ((MACH ORBIS-MACHS) SEM-ONLY) h-atomic-reserve f-nil)
318 (dnop atomic-address "atomic address" ((MACH ORBIS-MACHS) SEM-ONLY) h-atomic-address f-nil)
320 (dnop uimm6 "uimm6" ((MACH ORBIS-MACHS)) h-uimm6 f-uimm6)
322 (dnop rD "destination register" ((MACH ORBIS-MACHS)) h-gpr f-r1)
323 (dnop rA "source register A" ((MACH ORBIS-MACHS)) h-gpr f-r2)
324 (dnop rB "source register B" ((MACH ORBIS-MACHS)) h-gpr f-r3)
328 (comment "pc-rel 26 bit")
329 (attrs (MACH ORBIS-MACHS))
332 (handlers (parse "disp26"))
337 (comment "pc-rel 21 bit")
338 (attrs (MACH ORBIS-MACHS))
341 (handlers (parse "disp21"))
346 (comment "16-bit signed immediate")
347 (attrs (MACH ORBIS-MACHS) SIGN-OPT)
350 (handlers (parse "simm16"))
355 (comment "16-bit unsigned immediate")
356 (attrs (MACH ORBIS-MACHS))
359 (handlers (parse "uimm16"))
364 (comment "split 16-bit signed immediate")
365 (attrs (MACH ORBIS-MACHS) SIGN-OPT)
367 (index f-simm16-split)
368 (handlers (parse "simm16_split"))
373 (comment "split 16-bit unsigned immediate")
374 (attrs (MACH ORBIS-MACHS))
376 (index f-uimm16-split)
377 (handlers (parse "uimm16_split"))
382 ; Branch releated instructions
384 (define-pmacro (cti-link-return)
385 (set IAI (reg h-gpr 9) (add pc (if sys-cpucfgr-nd 4 8)))
387 (define-pmacro (cti-transfer-control condition target)
388 ;; this mess is necessary because we're
389 ;; skipping the delay slot, but it's
390 ;; actually the start of the next basic
394 (delay 1 (set IAI pc target))
396 (delay 1 (set IAI pc (add pc 4))))
416 (.splice (MACH ORBIS-MACHS) DELAYED-CTI NOT-IN-DELAY-SLOT (.unsplice cti-attrs))
427 "jump (pc-relative iaddr)"
428 (!COND-CTI UNCOND-CTI)
432 (cti-transfer-control 1 disp26)
436 (dni l-adrp "load pc-relative page address"
438 "l.adrp $rD,${disp21}"
439 (+ OPC_ADRP rD disp21)
446 "jump and link (pc-relative iaddr)"
447 (!COND-CTI UNCOND-CTI)
453 (cti-transfer-control 1 disp26)
460 "jump register (absolute iaddr)"
461 (!COND-CTI UNCOND-CTI)
463 (+ OPC_JR (f-resv-25-10 0) rB (f-resv-10-11 0))
465 (cti-transfer-control 1 rB)
471 "jump register and link (absolute iaddr)"
472 (!COND-CTI UNCOND-CTI)
474 (+ OPC_JALR (f-resv-25-10 0) rB (f-resv-10-11 0) )
478 (cti-transfer-control 1 rB)
485 "branch if condition bit not set (pc relative iaddr)"
486 (COND-CTI !UNCOND-CTI)
490 (cti-transfer-control (not sys-sr-f) disp26)
496 "branch if condition bit set (pc relative iaddr)"
497 (COND-CTI !UNCOND-CTI)
501 (cti-transfer-control sys-sr-f disp26)
505 (dni l-trap "trap (exception)"
506 ((MACH ORBIS-MACHS) NOT-IN-DELAY-SLOT)
508 (+ OPC_SYSTRAPSYNCS OPC_SYSTRAPSYNCS_TRAP (f-resv-20-5 0) uimm16)
509 ; Do exception entry handling in C function, PC set based on SR state
510 (raise-exception EXCEPT-TRAP)
515 (dni l-sys "syscall (exception)"
516 ; This function may not be in delay slot
517 ((MACH ORBIS-MACHS) NOT-IN-DELAY-SLOT)
520 (+ OPC_SYSTRAPSYNCS OPC_SYSTRAPSYNCS_SYSCALL (f-resv-20-5 0) uimm16)
521 ; Do exception entry handling in C function, PC set based on SR state
522 (raise-exception EXCEPT-SYSCALL)
526 (dni l-msync "memory sync"
529 (+ OPC_SYSTRAPSYNCS OPC_SYSTRAPSYNCS_MSYNC (f-resv-20-21 0))
534 (dni l-psync "pipeline sync"
537 (+ OPC_SYSTRAPSYNCS OPC_SYSTRAPSYNCS_PSYNC (f-resv-20-21 0))
542 (dni l-csync "context sync"
545 (+ OPC_SYSTRAPSYNCS OPC_SYSTRAPSYNCS_CSYNC (f-resv-20-21 0))
550 (dni l-rfe "return from exception"
551 ; This function may not be in delay slot
552 ((MACH ORBIS-MACHS) NOT-IN-DELAY-SLOT FORCED-CTI)
555 (+ OPC_RFE (f-resv-25-26 0))
556 (c-call VOID "@cpu@_rfe")
563 ; l.nop with immediate must be first so it handles all l.nops in sim
564 (dni l-nop-imm "nop uimm16"
567 (+ OPC_NOP (f-op-25-2 #x1) (f-resv-23-8 0) uimm16)
568 (c-call VOID "@cpu@_nop" (zext UWI uimm16))
572 (if (application-is? SIMULATOR)
578 (+ OPC_NOP (f-op-25-2 #x1) (f-resv-23-8 0) uimm16)
585 (dni l-movhi "movhi reg/uimm16"
587 "l.movhi $rD,$uimm16"
588 (+ OPC_MOVHIMACRC rD (f-resv-20-4 0) OPC_MOVHIMACRC_MOVHI uimm16)
589 (set UWI rD (sll UWI (zext UWI uimm16) (const 16)))
593 (dni l-macrc "macrc reg"
596 (+ OPC_MOVHIMACRC rD (f-resv-20-4 0) OPC_MOVHIMACRC_MACRC (f-uimm16 0))
598 (set UWI rD mac-maclo)
599 (set UWI mac-maclo 0)
600 (set UWI mac-machi 0)
606 ; System releated instructions
610 "l.mfspr $rD,$rA,${uimm16}"
611 (+ OPC_MFSPR rD rA uimm16)
612 (set UWI rD (c-call UWI "@cpu@_mfspr" (or rA (zext UWI uimm16))))
618 "l.mtspr $rA,$rB,${uimm16-split}"
619 (+ OPC_MTSPR rA rB uimm16-split )
620 (c-call VOID "@cpu@_mtspr" (or rA (zext WI uimm16-split)) rB)
626 (define-pmacro (load-store-addr base offset size)
627 (c-call AI "@cpu@_make_load_store_addr" base (ext SI offset) size))
629 (dni l-lwz "l.lwz reg/simm16(reg)"
631 "l.lwz $rD,${simm16}($rA)"
632 (+ OPC_LWZ rD rA simm16)
633 (set UWI rD (zext UWI (mem USI (load-store-addr rA simm16 4))))
638 (dni l-lws "l.lws reg/simm16(reg)"
640 "l.lws $rD,${simm16}($rA)"
641 (+ OPC_LWS rD rA simm16)
642 (set WI rD (ext WI (mem SI (load-store-addr rA simm16 4))))
646 (dni l-lwa "l.lwa reg/simm16(reg)"
648 "l.lwa $rD,${simm16}($rA)"
649 (+ OPC_LWA rD rA simm16)
651 (set UWI rD (zext UWI (mem USI (load-store-addr rA simm16 4))))
652 (set atomic-reserve (const 1))
653 (set atomic-address (load-store-addr rA simm16 4))
658 (dni l-lbz "l.lbz reg/simm16(reg)"
660 "l.lbz $rD,${simm16}($rA)"
661 (+ OPC_LBZ rD rA simm16)
662 (set UWI rD (zext UWI (mem UQI (load-store-addr rA simm16 1))))
666 (dni l-lbs "l.lbs reg/simm16(reg)"
668 "l.lbs $rD,${simm16}($rA)"
669 (+ OPC_LBS rD rA simm16)
670 (set WI rD (ext WI (mem QI (load-store-addr rA simm16 1))))
674 (dni l-lhz "l.lhz reg/simm16(reg)"
676 "l.lhz $rD,${simm16}($rA)"
677 (+ OPC_LHZ rD simm16 rA)
678 (set UWI rD (zext UWI (mem UHI (load-store-addr rA simm16 2))))
682 (dni l-lhs "l.lhs reg/simm16(reg)"
684 "l.lhs $rD,${simm16}($rA)"
685 (+ OPC_LHS rD rA simm16)
686 (set WI rD (ext WI (mem HI (load-store-addr rA simm16 2))))
693 (define-pmacro (store-insn mnemonic opc-op mode size)
695 (dni (.sym l- mnemonic)
696 (.str "l." mnemonic " simm16(reg)/reg")
698 (.str "l." mnemonic " ${simm16-split}($rA),$rB")
699 (+ opc-op rA rB simm16-split)
700 (sequence ((SI addr))
701 (set addr (load-store-addr rA simm16-split size))
702 (set mode (mem mode addr) (trunc mode rB))
703 (if (eq (and addr #xffffffc) atomic-address)
704 (set atomic-reserve (const 0))
712 (store-insn sw OPC_SW USI 4)
713 (store-insn sb OPC_SB UQI 1)
714 (store-insn sh OPC_SH UHI 2)
716 (dni l-swa "l.swa simm16(reg)/reg"
718 "l.swa ${simm16-split}($rA),$rB"
719 (+ OPC_SWA rA rB simm16)
720 (sequence ((SI addr))
721 (set addr (load-store-addr rA simm16-split 4))
722 (set sys-sr-f (and atomic-reserve (eq addr atomic-address)))
724 (set USI (mem USI addr) (trunc USI rB))
726 (set atomic-reserve (const 0))
732 ; Shift and rotate instructions
734 (define-pmacro (shift-insn mnemonic)
736 (dni (.sym l- mnemonic)
737 (.str "l." mnemonic " reg/reg/reg")
739 (.str "l." mnemonic " $rD,$rA,$rB")
740 (+ OPC_ALU rD rA rB (f-resv-10-3 0) (.sym OPC_SHROTS_ (.upcase mnemonic)) (f-resv-5-2 0)
741 OPC_ALU_REGREG_SHROT )
742 (set UWI rD (mnemonic rA rB))
745 (dni (.sym l- mnemonic "i")
746 (.str "l." mnemonic " reg/reg/uimm6")
748 (.str "l." mnemonic "i $rD,$rA,${uimm6}")
749 (+ OPC_SHROTI rD rA (f-resv-15-8 0) (.sym OPC_SHROTS_ (.upcase mnemonic)) uimm6)
750 (set rD (mnemonic rA uimm6))
765 (define-pmacro (alu-insn mnemonic)
767 (dni (.sym l- mnemonic)
768 (.str "l." mnemonic " reg/reg/reg")
770 (.str "l." mnemonic " $rD,$rA,$rB")
771 (+ OPC_ALU rD rA rB (f-resv-10-7 0) (.sym OPC_ALU_REGREG_ (.upcase mnemonic)))
772 (set rD (mnemonic rA rB))
782 (define-pmacro (alu-carry-insn mnemonic)
784 (dni (.sym l- mnemonic)
785 (.str "l." mnemonic " reg/reg/reg")
787 (.str "l." mnemonic " $rD,$rA,$rB")
788 (+ OPC_ALU rD rA rB (f-resv-10-7 #x00) (.sym OPC_ALU_REGREG_ (.upcase mnemonic)))
791 (set BI sys-sr-cy ((.sym mnemonic "c-cflag") WI rA rB 0))
792 (set BI sys-sr-ov ((.sym mnemonic "c-oflag") WI rA rB 0))
793 (set rD (mnemonic WI rA rB))
795 (if (andif sys-sr-ov sys-sr-ove)
796 (raise-exception EXCEPT-RANGE))
806 (dni (l-addc) "l.addc reg/reg/reg"
808 ("l.addc $rD,$rA,$rB")
809 (+ OPC_ALU rD rA rB (f-resv-10-7 #x00) OPC_ALU_REGREG_ADDC)
811 (sequence ((BI tmp-sys-sr-cy))
812 (set BI tmp-sys-sr-cy sys-sr-cy)
813 (set BI sys-sr-cy (addc-cflag WI rA rB tmp-sys-sr-cy))
814 (set BI sys-sr-ov (addc-oflag WI rA rB tmp-sys-sr-cy))
815 (set rD (addc WI rA rB tmp-sys-sr-cy))
817 (if (andif sys-sr-ov sys-sr-ove)
818 (raise-exception EXCEPT-RANGE))
823 (dni (l-mul) "l.mul reg/reg/reg"
825 ("l.mul $rD,$rA,$rB")
826 (+ OPC_ALU rD rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_MUL)
829 (set BI sys-sr-ov (mul-o2flag WI rA rB))
830 (set rD (mul WI rA rB))
832 (if (andif sys-sr-ov sys-sr-ove)
833 (raise-exception EXCEPT-RANGE))
838 (dni (l-muld) "l.muld reg/reg"
841 (+ OPC_ALU (f-resv-25-5 0) rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_MULD)
842 (sequence ((DI result))
843 (set DI result (mul DI (ext DI rA) (ext DI rB)))
844 (set SI mac-machi (subword SI result 0))
845 (set SI mac-maclo (subword SI result 1))
850 (dni (l-mulu) "l.mulu reg/reg/reg"
852 ("l.mulu $rD,$rA,$rB")
853 (+ OPC_ALU rD rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_MULU)
856 (set BI sys-sr-cy (mul-o1flag UWI rA rB))
857 (set rD (mul UWI rA rB))
859 (if (andif sys-sr-cy sys-sr-ove)
860 (raise-exception EXCEPT-RANGE))
865 (dni (l-muldu) "l.muld reg/reg"
868 (+ OPC_ALU (f-resv-25-5 0) rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_MULDU)
869 (sequence ((DI result))
870 (set DI result (mul DI (zext DI rA) (zext DI rB)))
871 (set SI mac-machi (subword SI result 0))
872 (set SI mac-maclo (subword SI result 1))
877 (dni l-div "divide (signed)"
880 (+ OPC_ALU rD rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_DIV)
884 (set WI rD (div WI rA rB))
889 (raise-exception EXCEPT-RANGE))
895 (dni l-divu "divide (unsigned)"
898 (+ OPC_ALU rD rA rB (f-resv-10-7 #x30) OPC_ALU_REGREG_DIVU)
902 (set rD (udiv UWI rA rB))
907 (raise-exception EXCEPT-RANGE))
913 (dni l-ff1 "find first '1'"
916 (+ OPC_ALU rD rA rB (f-resv-10-7 #x00) OPC_ALU_REGREG_FFL1)
917 (set rD (c-call UWI "@cpu@_ff1" rA))
921 (dni l-fl1 "find last '1'"
924 (+ OPC_ALU rD rA rB (f-resv-10-7 #x10) OPC_ALU_REGREG_FFL1)
925 (set rD (c-call UWI "@cpu@_fl1" rA))
930 (define-pmacro (alu-insn-simm mnemonic)
932 (dni (.sym l- mnemonic "i")
933 (.str "l." mnemonic " reg/reg/simm16")
935 (.str "l." mnemonic "i $rD,$rA,$simm16")
936 (+ (.sym OPC_ (.upcase mnemonic) "I") rD rA simm16)
937 (set rD (mnemonic rA (ext WI simm16)))
943 (define-pmacro (alu-insn-uimm mnemonic)
945 (dni (.sym l- mnemonic "i")
946 (.str "l." mnemonic " reg/reg/uimm16")
948 (.str "l." mnemonic "i $rD,$rA,$uimm16")
949 (+ (.sym OPC_ (.upcase mnemonic) "I") rD rA uimm16)
950 (set rD (mnemonic rA (zext UWI uimm16)))
960 (define-pmacro (alu-carry-insn-simm mnemonic)
962 (dni (.sym l- mnemonic "i")
963 (.str "l." mnemonic "i reg/reg/simm16")
965 (.str "l." mnemonic "i $rD,$rA,$simm16")
966 (+ (.sym OPC_ (.upcase mnemonic) "I") rD rA simm16)
969 (set BI sys-sr-cy ((.sym mnemonic "c-cflag") WI rA (ext WI simm16) 0))
970 (set BI sys-sr-ov ((.sym mnemonic "c-oflag") WI rA (ext WI simm16) 0))
971 (set rD (mnemonic WI rA (ext WI simm16)))
973 (if (andif sys-sr-ov sys-sr-ove)
974 (raise-exception EXCEPT-RANGE))
981 (alu-carry-insn-simm add)
984 ("l.addic reg/reg/simm16")
986 ("l.addic $rD,$rA,$simm16")
987 (+ OPC_ADDIC rD rA simm16)
989 (sequence ((BI tmp-sys-sr-cy))
990 (set BI tmp-sys-sr-cy sys-sr-cy)
991 (set BI sys-sr-cy (addc-cflag WI rA (ext WI simm16) tmp-sys-sr-cy))
992 (set BI sys-sr-ov (addc-oflag WI rA (ext WI simm16) tmp-sys-sr-cy))
993 (set WI rD (addc WI rA (ext WI simm16) tmp-sys-sr-cy))
995 (if (andif sys-sr-ov sys-sr-ove)
996 (raise-exception EXCEPT-RANGE))
1002 "l.muli reg/reg/simm16"
1003 ((MACH ORBIS-MACHS))
1004 ("l.muli $rD,$rA,$simm16")
1005 (+ OPC_MULI rD rA simm16)
1008 (set sys-sr-ov (mul-o2flag WI rA (ext WI simm16)))
1009 (set rD (mul WI rA (ext WI simm16)))
1011 (if (andif sys-sr-ov sys-sr-ove)
1012 (raise-exception EXCEPT-RANGE))
1017 (define-pmacro (extbh-insn mnemonic extop extmode truncmode)
1019 (dni (.sym l- mnemonic)
1020 (.str "l." mnemonic " reg/reg")
1021 ((MACH ORBIS-MACHS))
1022 (.str "l." mnemonic " $rD,$rA")
1023 (+ OPC_ALU rD rA (f-resv-15-6 0) (.sym OPC_EXTBHS_ (.upcase mnemonic)) (f-resv-5-2 0) OPC_ALU_REGREG_EXTBH)
1024 (set rD (extop extmode (trunc truncmode rA)))
1030 (extbh-insn exths ext WI HI)
1031 (extbh-insn extbs ext WI QI)
1032 (extbh-insn exthz zext UWI UHI)
1033 (extbh-insn extbz zext UWI UQI)
1035 (define-pmacro (extw-insn mnemonic extop extmode truncmode)
1037 (dni (.sym l- mnemonic)
1038 (.str "l." mnemonic " reg/reg")
1039 ((MACH ORBIS-MACHS))
1040 (.str "l." mnemonic " $rD,$rA")
1041 (+ OPC_ALU rD rA (f-resv-15-6 0) (.sym OPC_EXTWS_ (.upcase mnemonic)) (f-resv-5-2 0) OPC_ALU_REGREG_EXTW)
1042 (set rD (extop extmode (trunc truncmode rA)))
1048 (extw-insn extws ext WI SI)
1049 (extw-insn extwz zext USI USI)
1052 "l.cmov reg/reg/reg"
1053 ((MACH ORBIS-MACHS))
1054 "l.cmov $rD,$rA,$rB"
1055 (+ OPC_ALU rD rA rB (f-resv-10-1 0) (f-op-9-2 0) (f-resv-7-4 0) OPC_ALU_REGREG_CMOV)
1063 ; Compare instructions
1066 (define-pmacro (sf-insn op)
1068 (dni (.sym l- "sf" op "s") ; l-sfgts
1069 (.str "l.sf" op "s reg/reg") ; "l.sfgts reg/reg"
1070 ((MACH ORBIS-MACHS))
1071 (.str "l.sf" op "s $rA,$rB") ; "l.sfgts $rA,$rB"
1072 (+ 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))
1073 (set sys-sr-f (op WI rA rB)) ; (set sys-sr-f (gt WI rA rB))
1076 (dni (.sym l- "sf" op "si") ; l-sfgtsi
1077 (.str "l.sf" op "si reg/simm16") ; "l.sfgtsi reg/simm16"
1078 ((MACH ORBIS-MACHS))
1079 (.str "l.sf" op "si $rA,$simm16") ; "l.sfgtsi $rA,$simm16"
1080 (+ OPC_SFI (.sym "OPC_SF_" (.upcase op) "S") rA simm16) ; (+ OPC_SFI OPC_SF_GTS rA simm16)
1081 (set sys-sr-f (op WI rA (ext WI simm16))) ; (set sys-sr-f (gt WI rA (ext WI simm16)))
1084 (dni (.sym l- "sf" op "u") ; l-sfgtu
1085 (.str "l.sf" op "u reg/reg") ; "l.sfgtu reg/reg"
1086 ((MACH ORBIS-MACHS))
1087 (.str "l.sf" op "u $rA,$rB") ; "l.sfgtu $rA,$rB"
1088 (+ 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))
1089 (set sys-sr-f ((.sym op "u") WI rA rB)) ; (set sys-sr-f (gtu WI rA rB))
1092 ; immediate is sign extended even for unsigned compare
1093 (dni (.sym l- "sf" op "ui") ; l-sfgtui
1094 (.str "l.sf" op "ui reg/simm16") ; "l.sfgtui reg/uimm16"
1095 ((MACH ORBIS-MACHS))
1096 (.str "l.sf" op "ui $rA,$simm16") ; "l.sfgtui $rA,$simm16"
1097 (+ OPC_SFI (.sym "OPC_SF_" (.upcase op) "U") rA simm16) ; (+ OPC_SFI OPC_SF_GTU rA simm16)
1098 (set sys-sr-f ((.sym op "u") WI rA (ext WI simm16))) ; (set sys-sr-f (gtu WI rA (ext WI simm16)))
1110 (define-pmacro (sf-insn-eq op)
1112 (dni (.sym l- "sf" op)
1113 (.str "l." op " reg/reg")
1114 ((MACH ORBIS-MACHS))
1115 (.str "l.sf" op " $rA,$rB")
1116 (+ OPC_SF (.sym "OPC_SF_" (.upcase op)) rA rB (f-resv-10-11 0))
1117 (set sys-sr-f (op WI rA rB))
1120 (dni (.sym l- "sf" op "i")
1121 (.str "l.sf" op "i reg/simm16")
1122 ((MACH ORBIS-MACHS))
1123 (.str "l.sf" op "i $rA,$simm16")
1124 (+ OPC_SFI (.sym "OPC_SF_" (.upcase op)) rA simm16)
1125 (set sys-sr-f (op WI rA (ext WI simm16)))
1136 ((MACH ORBIS-MACHS))
1138 (+ OPC_MAC (f-op-25-5 0) rA rB (f-resv-10-7 0) OPC_MAC_MAC)
1140 (sequence ((DI prod) (DI mac) (DI result))
1141 (set DI prod (mul DI (ext DI rA) (ext DI rB)))
1142 (set DI mac (join DI SI mac-machi mac-maclo))
1143 (set DI result (add prod mac))
1144 (set SI mac-machi (subword SI result 0))
1145 (set SI mac-maclo (subword SI result 1))
1146 (set BI sys-sr-ov (addc-oflag prod mac 0))
1148 (if (andif sys-sr-ov sys-sr-ove)
1149 (raise-exception EXCEPT-RANGE))
1156 ((MACH ORBIS-MACHS))
1157 "l.maci $rA,${simm16}"
1158 (+ OPC_MACI (f-resv-25-5 0) rA simm16)
1160 (sequence ((DI prod) (DI mac) (DI result))
1161 (set DI prod (mul DI (ext DI rA) (ext DI simm16)))
1162 (set DI mac (join DI SI mac-machi mac-maclo))
1163 (set DI result (add mac prod))
1164 (set SI mac-machi (subword SI result 0))
1165 (set SI mac-maclo (subword SI result 1))
1166 (set BI sys-sr-ov (addc-oflag prod mac 0))
1168 (if (andif sys-sr-ov sys-sr-ove)
1169 (raise-exception EXCEPT-RANGE))
1176 ((MACH ORBIS-MACHS))
1178 (+ OPC_MAC (f-op-25-5 0) rA rB (f-resv-10-7 0) OPC_MAC_MACU)
1180 (sequence ((DI prod) (DI mac) (DI result))
1181 (set DI prod (mul DI (zext DI rA) (zext DI rB)))
1182 (set DI mac (join DI SI mac-machi mac-maclo))
1183 (set DI result (add prod mac))
1184 (set SI mac-machi (subword SI result 0))
1185 (set SI mac-maclo (subword SI result 1))
1186 (set BI sys-sr-cy (addc-cflag prod mac 0))
1188 (if (andif sys-sr-cy sys-sr-ove)
1189 (raise-exception EXCEPT-RANGE))
1196 ((MACH ORBIS-MACHS))
1198 (+ OPC_MAC (f-op-25-5 0) rA rB (f-resv-10-7 0) OPC_MAC_MSB)
1200 (sequence ((DI prod) (DI mac) (DI result))
1201 (set DI prod (mul DI (ext DI rA) (ext DI rB)))
1202 (set DI mac (join DI SI mac-machi mac-maclo))
1203 (set DI result (sub mac prod))
1204 (set SI mac-machi (subword SI result 0))
1205 (set SI mac-maclo (subword SI result 1))
1206 (set BI sys-sr-ov (subc-oflag mac result 0))
1208 (if (andif sys-sr-ov sys-sr-ove)
1209 (raise-exception EXCEPT-RANGE))
1216 ((MACH ORBIS-MACHS))
1218 (+ OPC_MAC (f-op-25-5 0) rA rB (f-resv-10-7 0) OPC_MAC_MSBU)
1220 (sequence ((DI prod) (DI mac) (DI result))
1221 (set DI prod (mul DI (zext DI rA) (zext DI rB)))
1222 (set DI mac (join DI SI mac-machi mac-maclo))
1223 (set DI result (sub mac prod))
1224 (set SI mac-machi (subword SI result 0))
1225 (set SI mac-maclo (subword SI result 1))
1226 (set BI sys-sr-cy (subc-cflag mac result 0))
1228 (if (andif sys-sr-cy sys-sr-ove)
1229 (raise-exception EXCEPT-RANGE))
1234 (define-pmacro (cust-insn cust-num)
1236 (dni (.sym l- "cust" cust-num)
1237 (.str "l.cust" cust-num)
1238 ((MACH ORBIS-MACHS))
1239 (.str "l.cust" cust-num)
1240 (+ (.sym OPC_CUST cust-num) (f-resv-25-26 0))