xref: /netbsd-src/external/gpl3/binutils/dist/cpu/m32r.cpu (revision 4f645668ed707e1f969c546666f8c8e45e6f8888)
12a6b7db3Sskrll; Renesas M32R CPU description.  -*- Scheme -*-
22a6b7db3Sskrll;
3be12b8bcSchristos; Copyright 1998, 1999, 2000, 2001, 2003, 2007, 2009
4be12b8bcSchristos; Free Software Foundation, Inc.
52a6b7db3Sskrll;
62a6b7db3Sskrll; Contributed by Red Hat Inc; developed under contract from Mitsubishi
72a6b7db3Sskrll; Electric Corporation.
82a6b7db3Sskrll;
92a6b7db3Sskrll; This file is part of the GNU Binutils.
102a6b7db3Sskrll;
112a6b7db3Sskrll; This program is free software; you can redistribute it and/or modify
122a6b7db3Sskrll; it under the terms of the GNU General Public License as published by
132a6b7db3Sskrll; the Free Software Foundation; either version 3 of the License, or
142a6b7db3Sskrll; (at your option) any later version.
152a6b7db3Sskrll;
162a6b7db3Sskrll; This program is distributed in the hope that it will be useful,
172a6b7db3Sskrll; but WITHOUT ANY WARRANTY; without even the implied warranty of
182a6b7db3Sskrll; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
192a6b7db3Sskrll; GNU General Public License for more details.
202a6b7db3Sskrll;
212a6b7db3Sskrll; You should have received a copy of the GNU General Public License
222a6b7db3Sskrll; along with this program; if not, write to the Free Software
232a6b7db3Sskrll; Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
242a6b7db3Sskrll; MA 02110-1301, USA.
252a6b7db3Sskrll
262a6b7db3Sskrll(include "simplify.inc")
272a6b7db3Sskrll
282a6b7db3Sskrll; FIXME: Delete sign extension of accumulator results.
292a6b7db3Sskrll; Sign extension is done when accumulator is read.
302a6b7db3Sskrll
312a6b7db3Sskrll; define-arch must appear first
322a6b7db3Sskrll
332a6b7db3Sskrll(define-arch
342a6b7db3Sskrll  (name m32r) ; name of cpu family
352a6b7db3Sskrll  (comment "Renesas M32R")
362a6b7db3Sskrll  (default-alignment aligned)
372a6b7db3Sskrll  (insn-lsb0? #f)
382a6b7db3Sskrll  (machs m32r m32rx m32r2)
392a6b7db3Sskrll  (isas m32r)
402a6b7db3Sskrll)
412a6b7db3Sskrll
422a6b7db3Sskrll; Attributes.
432a6b7db3Sskrll
442a6b7db3Sskrll; An attribute to describe which pipeline an insn runs in.
452a6b7db3Sskrll; O_OS is a special attribute for sll, sra, sla, slli, srai, slai.
462a6b7db3Sskrll; These instructions have O attribute for m32rx and OS attribute for m32r2.
472a6b7db3Sskrll
482a6b7db3Sskrll(define-attr
492a6b7db3Sskrll  (for insn)
502a6b7db3Sskrll  (type enum)
512a6b7db3Sskrll  (name PIPE)
522a6b7db3Sskrll  (comment "parallel execution pipeline selection")
532a6b7db3Sskrll  (values NONE O S OS O_OS)
542a6b7db3Sskrll)
552a6b7db3Sskrll
562a6b7db3Sskrll; A derived attribute that says which insns can be executed in parallel
572a6b7db3Sskrll; with others.  This is a required attribute for architectures with
582a6b7db3Sskrll; parallel execution.
592a6b7db3Sskrll
602a6b7db3Sskrll(define-attr
612a6b7db3Sskrll  (for insn)
622a6b7db3Sskrll  (type enum)
632a6b7db3Sskrll  (name PARALLEL)
642a6b7db3Sskrll  (attrs META) ; do not define in any generated file for now
652a6b7db3Sskrll  (values NO YES)
662a6b7db3Sskrll  (default (if (eq-attr (current-insn) PIPE NONE) (symbol NO) (symbol YES)))
672a6b7db3Sskrll)
682a6b7db3Sskrll
692a6b7db3Sskrll; Instruction set parameters.
702a6b7db3Sskrll
712a6b7db3Sskrll(define-isa
722a6b7db3Sskrll  (name m32r)
732a6b7db3Sskrll
742a6b7db3Sskrll  ; This is 32 because 16 bit insns always appear as pairs.
752a6b7db3Sskrll  ; ??? See if this can go away.  It's only used by the disassembler (right?)
762a6b7db3Sskrll  ; to decide how long an unknown insn is.  One value isn't sufficient (e.g. if
772a6b7db3Sskrll  ; on a 16 bit (and not 32 bit) boundary, will only want to advance pc by 16.)
782a6b7db3Sskrll  (default-insn-bitsize 32)
792a6b7db3Sskrll
802a6b7db3Sskrll  ; Number of bytes of insn we can initially fetch.
812a6b7db3Sskrll  ; The M32R is tricky in that insns are either two 16-bit insns
822a6b7db3Sskrll  ; (executed sequentially or in parallel) or one 32-bit insn.
832a6b7db3Sskrll  ; So on one hand the base insn size is 16 bits, but on another it's 32.
842a6b7db3Sskrll  ; 32 is chosen because:
852a6b7db3Sskrll  ; - if the chip were ever bi-endian it is believed that the byte order would
862a6b7db3Sskrll  ;   be based on 32 bit quantities
872a6b7db3Sskrll  ; - 32 bit insns are always aligned on 32 bit boundaries
882a6b7db3Sskrll  ; - the pc will never stop on a 16 bit (and not 32 bit) boundary
892a6b7db3Sskrll  ;   [well actually it can, but there are no branches to such places]
902a6b7db3Sskrll  (base-insn-bitsize 32)
912a6b7db3Sskrll
922a6b7db3Sskrll  ; Used in computing bit numbers.
932a6b7db3Sskrll  (default-insn-word-bitsize 32)
942a6b7db3Sskrll
952a6b7db3Sskrll  ; The m32r fetches 2 insns at a time.
962a6b7db3Sskrll  (liw-insns 2)
972a6b7db3Sskrll
982a6b7db3Sskrll  ; While the m32r can execute insns in parallel, the base mach can't
992a6b7db3Sskrll  ; (other than nop).  The base mach is greatly handicapped by this, but
1002a6b7db3Sskrll  ; we still need to cleanly handle it.
1012a6b7db3Sskrll  (parallel-insns 2)
1022a6b7db3Sskrll
1032a6b7db3Sskrll  ; Initial bitnumbers to decode insns by.
1042a6b7db3Sskrll  (decode-assist (0 1 2 3 8 9 10 11))
1052a6b7db3Sskrll
1062a6b7db3Sskrll  ; Classification of instructions that fit in the various frames.
1072a6b7db3Sskrll  ; wip, not currently used
1082a6b7db3Sskrll  (insn-types (long ; name
1092a6b7db3Sskrll	       31 ; length
1102a6b7db3Sskrll	       (eq-attr (current-insn) LENGTH 31) ; matching insns
1112a6b7db3Sskrll	       (0 1 2 7 8 9 10) ; decode-assist
1122a6b7db3Sskrll	       )
1132a6b7db3Sskrll	      (short
1142a6b7db3Sskrll	       15
1152a6b7db3Sskrll	       (eq-attr (current-insn) LENGTH 15) ; matching insns
1162a6b7db3Sskrll	       (0 1 2 7 8 9 10)
1172a6b7db3Sskrll	       )
1182a6b7db3Sskrll	      )
1192a6b7db3Sskrll
1202a6b7db3Sskrll  ; Instruction framing.
1212a6b7db3Sskrll  ; Each m32r insn is either one 32 bit insn, two 16 bit insns executed
1222a6b7db3Sskrll  ; serially (left->right), or two 16 bit insns executed parallelly.
1232a6b7db3Sskrll  ; wip, not currently used
1242a6b7db3Sskrll  (frame long32 ; name
1252a6b7db3Sskrll	 ((long)) ; list of insns in frame, plus constraint
1262a6b7db3Sskrll	 "$0"   ; assembler
1272a6b7db3Sskrll	 (+ (1 1) (31 $0)) ; value
1282a6b7db3Sskrll	 (sequence () (execute $0)) ; action
1292a6b7db3Sskrll	 )
1302a6b7db3Sskrll  (frame serial2x16
1312a6b7db3Sskrll	 ((short)
1322a6b7db3Sskrll	  (short))
1332a6b7db3Sskrll	 "$0 -> $1"
1342a6b7db3Sskrll	 (+ (1 0) (15 $0) (1 0) (15 $1))
1352a6b7db3Sskrll	 (sequence ()
1362a6b7db3Sskrll		   (execute $0)
1372a6b7db3Sskrll		   (execute $1))
1382a6b7db3Sskrll	 )
1392a6b7db3Sskrll  (frame parallel2x16
1402a6b7db3Sskrll	 ((short (eq-attr (current-insn) PIPE "O,BOTH"))
1412a6b7db3Sskrll	  (short (eq-attr (current-insn) PIPE "S,BOTH")))
1422a6b7db3Sskrll	 "$0 || $1"
1432a6b7db3Sskrll	 (+ (1 0) (15 $0) (1 1) (15 $1))
1442a6b7db3Sskrll	 (parallel ()
1452a6b7db3Sskrll		   (execute $0)
1462a6b7db3Sskrll		   (execute $1))
1472a6b7db3Sskrll	 )
1482a6b7db3Sskrll)
1492a6b7db3Sskrll
1502a6b7db3Sskrll; Cpu family definitions.
1512a6b7db3Sskrll
1522a6b7db3Sskrll; ??? define-cpu-family [and in general "cpu-family"] might be clearer than
1532a6b7db3Sskrll; define-cpu.
1542a6b7db3Sskrll; ??? Have define-arch provide defaults for architecture that define-cpu can
1552a6b7db3Sskrll; then override [reduces duplication in define-cpu].
1562a6b7db3Sskrll; ??? Another way to go is to delete cpu-families entirely and have one mach
1572a6b7db3Sskrll; able to inherit things from another mach (would also need the ability to
1582a6b7db3Sskrll; not only override specific inherited things but also disable some,
1592a6b7db3Sskrll; e.g. if an insn wasn't supported).
1602a6b7db3Sskrll
1612a6b7db3Sskrll(define-cpu
1622a6b7db3Sskrll  ; cpu names must be distinct from the architecture name and machine names.
1632a6b7db3Sskrll  ; The "b" suffix stands for "base" and is the convention.
1642a6b7db3Sskrll  ; The "f" suffix stands for "family" and is the convention.
1652a6b7db3Sskrll  (name m32rbf)
1662a6b7db3Sskrll  (comment "Renesas M32R base family")
1672a6b7db3Sskrll  (endian either)
1682a6b7db3Sskrll  (word-bitsize 32)
1692a6b7db3Sskrll  ; Override isa spec (??? keeps things simpler, though it was more true
1702a6b7db3Sskrll  ; in the early days and not so much now).
1712a6b7db3Sskrll  (parallel-insns 1)
1722a6b7db3Sskrll)
1732a6b7db3Sskrll
1742a6b7db3Sskrll(define-cpu
1752a6b7db3Sskrll  (name m32rxf)
1762a6b7db3Sskrll  (comment "Renesas M32Rx family")
1772a6b7db3Sskrll  (endian either)
1782a6b7db3Sskrll  (word-bitsize 32)
1792a6b7db3Sskrll  ; Generated files have an "x" suffix.
1802a6b7db3Sskrll  (file-transform "x")
1812a6b7db3Sskrll)
1822a6b7db3Sskrll
1832a6b7db3Sskrll(define-cpu
1842a6b7db3Sskrll  (name m32r2f)
1852a6b7db3Sskrll  (comment "Renesas M32R2 family")
1862a6b7db3Sskrll  (endian either)
1872a6b7db3Sskrll  (word-bitsize 32)
1882a6b7db3Sskrll  ; Generated files have an "2" suffix.
1892a6b7db3Sskrll  (file-transform "2")
1902a6b7db3Sskrll)
1912a6b7db3Sskrll
1922a6b7db3Sskrll(define-mach
1932a6b7db3Sskrll  (name m32r)
1942a6b7db3Sskrll  (comment "Generic M32R cpu")
1952a6b7db3Sskrll  (cpu m32rbf)
1962a6b7db3Sskrll)
1972a6b7db3Sskrll
1982a6b7db3Sskrll(define-mach
1992a6b7db3Sskrll  (name m32rx)
2002a6b7db3Sskrll  (comment "M32RX cpu")
2012a6b7db3Sskrll  (cpu m32rxf)
2022a6b7db3Sskrll)
2032a6b7db3Sskrll
2042a6b7db3Sskrll(define-mach
2052a6b7db3Sskrll  (name m32r2)
2062a6b7db3Sskrll  (comment "M32R2 cpu")
2072a6b7db3Sskrll  (cpu m32r2f)
2082a6b7db3Sskrll)
2092a6b7db3Sskrll
2102a6b7db3Sskrll; Model descriptions.
2112a6b7db3Sskrll
2122a6b7db3Sskrll; The meaning of this value is wip but at the moment it's intended to describe
2132a6b7db3Sskrll; the implementation (i.e. what -mtune=foo does in sparc gcc).
2142a6b7db3Sskrll;
2152a6b7db3Sskrll; Notes while wip:
2162a6b7db3Sskrll; - format of pipeline entry:
2172a6b7db3Sskrll;   (pipeline name (stage1-name ...) (stage2-name ...) ...)
2182a6b7db3Sskrll;   The contents of a stage description is wip.
2192a6b7db3Sskrll; - each mach must have at least one model
2202a6b7db3Sskrll; - the default model must be the first one
2212a6b7db3Sskrll;- maybe have `retire' support update total cycle count to handle current
2222a6b7db3Sskrll;  parallel insn cycle counting problems
2232a6b7db3Sskrll
2242a6b7db3Sskrll(define-model
2252a6b7db3Sskrll  (name m32r/d) (comment "m32r/d") (attrs)
2262a6b7db3Sskrll  (mach m32r)
2272a6b7db3Sskrll
2282a6b7db3Sskrll  ;(prefetch)
2292a6b7db3Sskrll  ;(retire)
2302a6b7db3Sskrll
2312a6b7db3Sskrll  (pipeline p-non-mem "" () ((fetch) (decode) (execute) (writeback)))
2322a6b7db3Sskrll  (pipeline p-mem "" () ((fetch) (decode) (execute) (memory) (writeback)))
2332a6b7db3Sskrll
2342a6b7db3Sskrll  ; `state' is a list of variables for recording model state
2352a6b7db3Sskrll  (state
2362a6b7db3Sskrll   ; bit mask of h-gr registers, =1 means value being loaded from memory
2372a6b7db3Sskrll   (h-gr UINT)
2382a6b7db3Sskrll   )
2392a6b7db3Sskrll
2402a6b7db3Sskrll  (unit u-exec "Execution Unit" ()
2412a6b7db3Sskrll	1 1 ; issue done
2422a6b7db3Sskrll	() ; state
2432a6b7db3Sskrll	((sr INT -1) (dr INT -1)) ; inputs
2442a6b7db3Sskrll	((dr INT -1)) ; outputs
2452a6b7db3Sskrll	() ; profile action (default)
2462a6b7db3Sskrll	)
2472a6b7db3Sskrll  (unit u-cmp "Compare Unit" ()
2482a6b7db3Sskrll	1 1 ; issue done
2492a6b7db3Sskrll	() ; state
2502a6b7db3Sskrll	((src1 INT -1) (src2 INT -1)) ; inputs
2512a6b7db3Sskrll	() ; outputs
2522a6b7db3Sskrll	() ; profile action (default)
2532a6b7db3Sskrll	)
2542a6b7db3Sskrll  (unit u-mac "Multiply/Accumulate Unit" ()
2552a6b7db3Sskrll	1 1 ; issue done
2562a6b7db3Sskrll	() ; state
2572a6b7db3Sskrll	((src1 INT -1) (src2 INT -1)) ; inputs
2582a6b7db3Sskrll	() ; outputs
2592a6b7db3Sskrll	() ; profile action (default)
2602a6b7db3Sskrll	)
2612a6b7db3Sskrll  (unit u-cti "Branch Unit" ()
2622a6b7db3Sskrll	1 1 ; issue done
2632a6b7db3Sskrll	() ; state
2642a6b7db3Sskrll	((sr INT -1)) ; inputs
2652a6b7db3Sskrll	((pc)) ; outputs
2662a6b7db3Sskrll	() ; profile action (default)
2672a6b7db3Sskrll	)
2682a6b7db3Sskrll  (unit u-load "Memory Load Unit" ()
2692a6b7db3Sskrll	1 1 ; issue done
2702a6b7db3Sskrll	() ; state
2712a6b7db3Sskrll	((sr INT)
2722a6b7db3Sskrll	 ;(ld-mem AI)
2732a6b7db3Sskrll	 ) ; inputs
2742a6b7db3Sskrll	((dr INT)) ; outputs
2752a6b7db3Sskrll	() ; profile action (default)
2762a6b7db3Sskrll	)
2772a6b7db3Sskrll  (unit u-store "Memory Store Unit" ()
2782a6b7db3Sskrll	1 1 ; issue done
2792a6b7db3Sskrll	() ; state
2802a6b7db3Sskrll	((src1 INT) (src2 INT)) ; inputs
2812a6b7db3Sskrll	() ; ((st-mem AI)) ; outputs
2822a6b7db3Sskrll	() ; profile action (default)
2832a6b7db3Sskrll	)
2842a6b7db3Sskrll)
2852a6b7db3Sskrll
2862a6b7db3Sskrll(define-model
2872a6b7db3Sskrll  (name test) (comment "test") (attrs)
2882a6b7db3Sskrll  (mach m32r)
2892a6b7db3Sskrll  (pipeline all "" () ((fetch) (decode) (execute) (writeback)))
2902a6b7db3Sskrll  (unit u-exec "Execution Unit" ()
2912a6b7db3Sskrll	1 1 ; issue done
2922a6b7db3Sskrll	() () () ())
2932a6b7db3Sskrll)
2942a6b7db3Sskrll
2952a6b7db3Sskrll; Each mach must have at least one model.
2962a6b7db3Sskrll
2972a6b7db3Sskrll(define-model
2982a6b7db3Sskrll  (name m32rx) (comment "m32rx") (attrs)
2992a6b7db3Sskrll  (mach m32rx)
3002a6b7db3Sskrll
3012a6b7db3Sskrll  ; ??? It's 6 stages but I forget the details right now.
3022a6b7db3Sskrll  (pipeline p-o "" () ((fetch) (decode) (execute) (writeback)))
3032a6b7db3Sskrll  (pipeline p-s "" () ((fetch) (decode) (execute) (writeback)))
3042a6b7db3Sskrll  (pipeline p-o-mem "" () ((fetch) (decode) (execute) (memory) (writeback)))
3052a6b7db3Sskrll
3062a6b7db3Sskrll  (unit u-exec "Execution Unit" ()
3072a6b7db3Sskrll	1 1 ; issue done
3082a6b7db3Sskrll	() ; state
3092a6b7db3Sskrll	((sr INT -1) (dr INT -1)) ; inputs
3102a6b7db3Sskrll	((dr INT -1)) ; outputs
3112a6b7db3Sskrll	() ; profile action (default)
3122a6b7db3Sskrll	)
3132a6b7db3Sskrll  (unit u-cmp "Compare Unit" ()
3142a6b7db3Sskrll	1 1 ; issue done
3152a6b7db3Sskrll	() ; state
3162a6b7db3Sskrll	((src1 INT -1) (src2 INT -1)) ; inputs
3172a6b7db3Sskrll	() ; outputs
3182a6b7db3Sskrll	() ; profile action (default)
3192a6b7db3Sskrll	)
3202a6b7db3Sskrll  (unit u-mac "Multiply/Accumulate Unit" ()
3212a6b7db3Sskrll	1 1 ; issue done
3222a6b7db3Sskrll	() ; state
3232a6b7db3Sskrll	((src1 INT -1) (src2 INT -1)) ; inputs
3242a6b7db3Sskrll	() ; outputs
3252a6b7db3Sskrll	() ; profile action (default)
3262a6b7db3Sskrll	)
3272a6b7db3Sskrll  (unit u-cti "Branch Unit" ()
3282a6b7db3Sskrll	1 1 ; issue done
3292a6b7db3Sskrll	() ; state
3302a6b7db3Sskrll	((sr INT -1)) ; inputs
3312a6b7db3Sskrll	((pc)) ; outputs
3322a6b7db3Sskrll	() ; profile action (default)
3332a6b7db3Sskrll	)
3342a6b7db3Sskrll  (unit u-load "Memory Load Unit" ()
3352a6b7db3Sskrll	1 1 ; issue done
3362a6b7db3Sskrll	() ; state
3372a6b7db3Sskrll	((sr INT)) ; inputs
3382a6b7db3Sskrll	((dr INT)) ; outputs
3392a6b7db3Sskrll	() ; profile action (default)
3402a6b7db3Sskrll	)
3412a6b7db3Sskrll  (unit u-store "Memory Store Unit" ()
3422a6b7db3Sskrll	1 1 ; issue done
3432a6b7db3Sskrll	() ; state
3442a6b7db3Sskrll	((src1 INT) (src2 INT)) ; inputs
3452a6b7db3Sskrll	() ; outputs
3462a6b7db3Sskrll	() ; profile action (default)
3472a6b7db3Sskrll	)
3482a6b7db3Sskrll)
3492a6b7db3Sskrll
3502a6b7db3Sskrll(define-model
3512a6b7db3Sskrll  (name m32r2) (comment "m32r2") (attrs)
3522a6b7db3Sskrll  (mach m32r2)
3532a6b7db3Sskrll
3542a6b7db3Sskrll  ; ??? It's 6 stages but I forget the details right now.
3552a6b7db3Sskrll  (pipeline p-o "" () ((fetch) (decode) (execute) (writeback)))
3562a6b7db3Sskrll  (pipeline p-s "" () ((fetch) (decode) (execute) (writeback)))
3572a6b7db3Sskrll  (pipeline p-o-mem "" () ((fetch) (decode) (execute) (memory) (writeback)))
3582a6b7db3Sskrll
3592a6b7db3Sskrll  (unit u-exec "Execution Unit" ()
3602a6b7db3Sskrll	1 1 ; issue done
3612a6b7db3Sskrll	() ; state
3622a6b7db3Sskrll	((sr INT -1) (dr INT -1)) ; inputs
3632a6b7db3Sskrll	((dr INT -1)) ; outputs
3642a6b7db3Sskrll	() ; profile action (default)
3652a6b7db3Sskrll	)
3662a6b7db3Sskrll  (unit u-cmp "Compare Unit" ()
3672a6b7db3Sskrll	1 1 ; issue done
3682a6b7db3Sskrll	() ; state
3692a6b7db3Sskrll	((src1 INT -1) (src2 INT -1)) ; inputs
3702a6b7db3Sskrll	() ; outputs
3712a6b7db3Sskrll	() ; profile action (default)
3722a6b7db3Sskrll	)
3732a6b7db3Sskrll  (unit u-mac "Multiply/Accumulate Unit" ()
3742a6b7db3Sskrll	1 1 ; issue done
3752a6b7db3Sskrll	() ; state
3762a6b7db3Sskrll	((src1 INT -1) (src2 INT -1)) ; inputs
3772a6b7db3Sskrll	() ; outputs
3782a6b7db3Sskrll	() ; profile action (default)
3792a6b7db3Sskrll	)
3802a6b7db3Sskrll  (unit u-cti "Branch Unit" ()
3812a6b7db3Sskrll	1 1 ; issue done
3822a6b7db3Sskrll	() ; state
3832a6b7db3Sskrll	((sr INT -1)) ; inputs
3842a6b7db3Sskrll	((pc)) ; outputs
3852a6b7db3Sskrll	() ; profile action (default)
3862a6b7db3Sskrll	)
3872a6b7db3Sskrll  (unit u-load "Memory Load Unit" ()
3882a6b7db3Sskrll	1 1 ; issue done
3892a6b7db3Sskrll	() ; state
3902a6b7db3Sskrll	((sr INT)) ; inputs
3912a6b7db3Sskrll	((dr INT)) ; outputs
3922a6b7db3Sskrll	() ; profile action (default)
3932a6b7db3Sskrll	)
3942a6b7db3Sskrll  (unit u-store "Memory Store Unit" ()
3952a6b7db3Sskrll	1 1 ; issue done
3962a6b7db3Sskrll	() ; state
3972a6b7db3Sskrll	((src1 INT) (src2 INT)) ; inputs
3982a6b7db3Sskrll	() ; outputs
3992a6b7db3Sskrll	() ; profile action (default)
4002a6b7db3Sskrll	)
4012a6b7db3Sskrll)
4022a6b7db3Sskrll
4032a6b7db3Sskrll; The instruction fetch/execute cycle.
4042a6b7db3Sskrll; This is split into two parts as sometimes more than one instruction is
4052a6b7db3Sskrll; decoded at once.
4062a6b7db3Sskrll; The `const SI' argument to decode/execute is used to distinguish
4072a6b7db3Sskrll; multiple instructions processed at the same time (e.g. m32r).
4082a6b7db3Sskrll;
4092a6b7db3Sskrll; ??? This is wip, and not currently used.
4102a6b7db3Sskrll; ??? Needs to be moved to define-isa.
4112a6b7db3Sskrll
4122a6b7db3Sskrll; This is how to fetch and decode an instruction.
4132a6b7db3Sskrll
4142a6b7db3Sskrll;(define-extract
4152a6b7db3Sskrll;  (sequence VOID
4162a6b7db3Sskrll;	    (if VOID (ne AI (and AI pc (const AI 3)) (const AI 0))
4172a6b7db3Sskrll;		(sequence VOID
4182a6b7db3Sskrll;			  (set-quiet USI (scratch UHI insn1) (ifetch UHI pc))
4192a6b7db3Sskrll;			  (decode VOID pc (and UHI insn1 (const UHI #x7fff))
4202a6b7db3Sskrll;				  (const SI 0)))
4212a6b7db3Sskrll;		(sequence VOID
4222a6b7db3Sskrll;			  (set-quiet USI (scratch USI insn) (ifetch USI pc))
4232a6b7db3Sskrll;			  (if VOID (ne USI (and USI insn (const USI #x80000000))
4242a6b7db3Sskrll;				     (const USI 0))
4252a6b7db3Sskrll;			      (decode VOID pc (srl USI insn (const WI 16)) (const SI 0))
4262a6b7db3Sskrll;			      (sequence VOID
4272a6b7db3Sskrll;					; ??? parallel support
4282a6b7db3Sskrll;					(decode VOID pc (srl USI insn (const WI 16))
4292a6b7db3Sskrll;						(const SI 0))
4302a6b7db3Sskrll;					(decode VOID (add AI pc (const AI 2))
4312a6b7db3Sskrll;						(and USI insn (const WI #x7fff))
4322a6b7db3Sskrll;						(const SI 1))))))
4332a6b7db3Sskrll;	    )
4342a6b7db3Sskrll;)
4352a6b7db3Sskrll
4362a6b7db3Sskrll; This is how to execute a decoded instruction.
4372a6b7db3Sskrll
4382a6b7db3Sskrll;(define-execute
4392a6b7db3Sskrll;  (sequence VOID () ; () is empty option list
4402a6b7db3Sskrll;	     ((AI new_pc))
4412a6b7db3Sskrll;	     (set AI new_pc (execute: AI (const 0)) #:quiet)
4422a6b7db3Sskrll;	     (set AI pc new_pc #:direct)
4432a6b7db3Sskrll;	     )
4442a6b7db3Sskrll;)
4452a6b7db3Sskrll
4462a6b7db3Sskrll; FIXME: It might simplify things to separate the execute process from the
4472a6b7db3Sskrll; one that updates the PC.
4482a6b7db3Sskrll
4492a6b7db3Sskrll; Instruction fields.
4502a6b7db3Sskrll;
4512a6b7db3Sskrll; Attributes:
4522a6b7db3Sskrll; PCREL-ADDR: pc relative value (for reloc and disassembly purposes)
4532a6b7db3Sskrll; ABS-ADDR: absolute address (for reloc and disassembly purposes?)
4542a6b7db3Sskrll; RESERVED: bits are not used to decode insn, must be all 0
4552a6b7db3Sskrll; RELOC: there is a relocation associated with this field (experiment)
4562a6b7db3Sskrll
4572a6b7db3Sskrll(define-attr
4582a6b7db3Sskrll  (for ifield operand)
4592a6b7db3Sskrll  (type boolean)
4602a6b7db3Sskrll  (name RELOC)
4612a6b7db3Sskrll  (comment "there is a reloc associated with this field (experiment)")
4622a6b7db3Sskrll)
4632a6b7db3Sskrll
4642a6b7db3Sskrll(dnf f-op1       "op1"                 () 0 4)
4652a6b7db3Sskrll(dnf f-op2       "op2"                 () 8 4)
4662a6b7db3Sskrll(dnf f-cond      "cond"                () 4 4)
4672a6b7db3Sskrll(dnf f-r1        "r1"                  () 4 4)
4682a6b7db3Sskrll(dnf f-r2        "r2"                  () 12 4)
4692a6b7db3Sskrll(df f-simm8      "simm8"               () 8 8 INT #f #f)
4702a6b7db3Sskrll(df f-simm16     "simm16"              () 16 16 INT #f #f)
4712a6b7db3Sskrll(dnf f-shift-op2 "shift op2"           () 8 3)
4722a6b7db3Sskrll(dnf f-uimm3     "uimm3"               () 5 3)
4732a6b7db3Sskrll(dnf f-uimm4     "uimm4"               () 12 4)
4742a6b7db3Sskrll(dnf f-uimm5     "uimm5"               () 11 5)
4752a6b7db3Sskrll(dnf f-uimm8     "uimm8"               () 8 8)
4762a6b7db3Sskrll(dnf f-uimm16    "uimm16"              () 16 16)
4772a6b7db3Sskrll(dnf f-uimm24    "uimm24"              (ABS-ADDR RELOC) 8 24)
4782a6b7db3Sskrll(dnf f-hi16      "high 16 bits"        (SIGN-OPT) 16 16)
4792a6b7db3Sskrll(df f-disp8      "disp8, slot unknown" (PCREL-ADDR RELOC) 8 8 INT
4802a6b7db3Sskrll    ((value pc) (sra WI (sub WI value (and WI pc (const -4))) (const 2)))
4816f4ced0bSchristos    ((value pc) (add WI (mul WI value (const 4)) (and WI pc (const -4)))))
4822a6b7db3Sskrll(df f-disp16     "disp16"              (PCREL-ADDR RELOC) 16 16 INT
4832a6b7db3Sskrll    ((value pc) (sra WI (sub WI value pc) (const 2)))
4846f4ced0bSchristos    ((value pc) (add WI (mul WI value (const 4)) pc)))
4852a6b7db3Sskrll(df f-disp24     "disp24"              (PCREL-ADDR RELOC) 8 24 INT
4862a6b7db3Sskrll    ((value pc) (sra WI (sub WI value pc) (const 2)))
4876f4ced0bSchristos    ((value pc) (add WI (mul WI value (const 4)) pc)))
4882a6b7db3Sskrll
4892a6b7db3Sskrll(dnf f-op23      "op2.3"               ()  9 3)
4902a6b7db3Sskrll(dnf f-op3       "op3"                 () 14 2)
4912a6b7db3Sskrll(dnf f-acc       "acc"                 ()  8 1)
4922a6b7db3Sskrll(dnf f-accs      "accs"                () 12 2)
4932a6b7db3Sskrll(dnf f-accd      "accd"                ()  4 2)
4942a6b7db3Sskrll(dnf f-bits67    "bits67"              ()  6 2)
4952a6b7db3Sskrll(dnf f-bit4      "bit4"                ()  4 1)
4962a6b7db3Sskrll(dnf f-bit14     "bit14"               () 14 1)
4972a6b7db3Sskrll
4982a6b7db3Sskrll(define-ifield (name f-imm1) (comment "1 bit immediate, 0->1 1->2")
4992a6b7db3Sskrll  (attrs)
5002a6b7db3Sskrll  (start 15) (length 1)
5012a6b7db3Sskrll  (encode (value pc) (sub WI value (const WI 1)))
5022a6b7db3Sskrll  (decode (value pc) (add WI value (const WI 1)))
5032a6b7db3Sskrll)
5042a6b7db3Sskrll
5052a6b7db3Sskrll; Enums.
5062a6b7db3Sskrll
5072a6b7db3Sskrll; insn-op1: bits 0-3
5082a6b7db3Sskrll; FIXME: should use die macro or some such
5092a6b7db3Sskrll(define-normal-insn-enum insn-op1 "insn format enums" () OP1_ f-op1
5102a6b7db3Sskrll  ("0" "1" "2" "3" "4" "5" "6" "7"
5112a6b7db3Sskrll   "8" "9" "10" "11" "12" "13" "14" "15")
5122a6b7db3Sskrll)
5132a6b7db3Sskrll
5142a6b7db3Sskrll; insn-op2: bits 8-11
5152a6b7db3Sskrll; FIXME: should use die macro or some such
5162a6b7db3Sskrll(define-normal-insn-enum insn-op2 "op2 enums" () OP2_ f-op2
5172a6b7db3Sskrll  ("0" "1" "2" "3" "4" "5" "6" "7"
5182a6b7db3Sskrll   "8" "9" "10" "11" "12" "13" "14" "15")
5192a6b7db3Sskrll)
5202a6b7db3Sskrll
5212a6b7db3Sskrll; Hardware pieces.
5222a6b7db3Sskrll; These entries list the elements of the raw hardware.
5232a6b7db3Sskrll; They're also used to provide tables and other elements of the assembly
5242a6b7db3Sskrll; language.
5252a6b7db3Sskrll
5262a6b7db3Sskrll(dnh h-pc "program counter" (PC PROFILE) (pc) () () ())
5272a6b7db3Sskrll
5282a6b7db3Sskrll(dnh h-hi16 "high 16 bits" ()
5292a6b7db3Sskrll     (immediate (UINT 16))
5302a6b7db3Sskrll     () () ()
5312a6b7db3Sskrll)
5322a6b7db3Sskrll
5332a6b7db3Sskrll; These two aren't technically needed.
5342a6b7db3Sskrll; They're here for illustration sake mostly.
5352a6b7db3Sskrll; Plus they cause the value to be stored in the extraction buffers to only
5362a6b7db3Sskrll; be 16 bits wide (vs 32 or 64).  Whoopie ding.  But it's fun.
5372a6b7db3Sskrll(dnh h-slo16 "signed low 16 bits" ()
5382a6b7db3Sskrll     (immediate (INT 16))
5392a6b7db3Sskrll     () () ()
5402a6b7db3Sskrll)
5412a6b7db3Sskrll(dnh h-ulo16 "unsigned low 16 bits" ()
5422a6b7db3Sskrll     (immediate (UINT 16))
5432a6b7db3Sskrll     () () ()
5442a6b7db3Sskrll)
5452a6b7db3Sskrll
5462a6b7db3Sskrll(define-keyword
5472a6b7db3Sskrll  (name gr-names)
5482a6b7db3Sskrll  (print-name h-gr)
5492a6b7db3Sskrll  (prefix "")
5502a6b7db3Sskrll  (values (fp 13) (lr 14) (sp 15)
5512a6b7db3Sskrll	  (r0 0) (r1 1) (r2 2) (r3 3) (r4 4) (r5 5) (r6 6) (r7 7)
5522a6b7db3Sskrll	  (r8 8) (r9 9) (r10 10) (r11 11) (r12 12) (r13 13) (r14 14) (r15 15))
5532a6b7db3Sskrll)
5542a6b7db3Sskrll
5552a6b7db3Sskrll(define-hardware
5562a6b7db3Sskrll  (name h-gr)
5572a6b7db3Sskrll  (comment "general registers")
5582a6b7db3Sskrll  (attrs PROFILE CACHE-ADDR)
5592a6b7db3Sskrll  (type register WI (16))
5602a6b7db3Sskrll  (indices extern-keyword gr-names)
5612a6b7db3Sskrll)
5622a6b7db3Sskrll
5632a6b7db3Sskrll(define-keyword
5642a6b7db3Sskrll  (name cr-names)
5652a6b7db3Sskrll  (print-name h-cr)
5662a6b7db3Sskrll  (prefix "")
5672a6b7db3Sskrll  (values (psw 0)   (cbr 1)   (spi 2)   (spu 3)
5682a6b7db3Sskrll	  (bpc 6)   (bbpsw 8) (bbpc 14) (evb 5)
5692a6b7db3Sskrll	  (cr0 0)   (cr1 1)   (cr2 2)   (cr3 3)
5702a6b7db3Sskrll	  (cr4 4)   (cr5 5)   (cr6 6)   (cr7 7)
5712a6b7db3Sskrll	  (cr8 8)   (cr9 9)   (cr10 10) (cr11 11)
5722a6b7db3Sskrll	  (cr12 12) (cr13 13) (cr14 14) (cr15 15))
5732a6b7db3Sskrll)
5742a6b7db3Sskrll
5752a6b7db3Sskrll(define-hardware
5762a6b7db3Sskrll  (name h-cr)
5772a6b7db3Sskrll  (comment "control registers")
5782a6b7db3Sskrll  (type register UWI (16))
5792a6b7db3Sskrll  (indices extern-keyword cr-names)
5802a6b7db3Sskrll  (get (index) (c-call UWI "@cpu@_h_cr_get_handler" index))
5812a6b7db3Sskrll  (set (index newval) (c-call VOID "@cpu@_h_cr_set_handler" index newval))
5822a6b7db3Sskrll)
5832a6b7db3Sskrll
5842a6b7db3Sskrll; The actual accumulator is only 56 bits.
5852a6b7db3Sskrll; The top 8 bits are sign extended from bit 8 (when counting msb = bit 0).
5862a6b7db3Sskrll; To simplify the accumulator instructions, no attempt is made to keep the
5872a6b7db3Sskrll; top 8 bits properly sign extended (currently there's no point since they
5882a6b7db3Sskrll; all ignore them).  When the value is read it is properly sign extended
5892a6b7db3Sskrll; [in the `get' handler].
5902a6b7db3Sskrll(define-hardware
5912a6b7db3Sskrll  (name h-accum)
5922a6b7db3Sskrll  (comment "accumulator")
5932a6b7db3Sskrll  (type register DI)
5942a6b7db3Sskrll  (get () (c-call DI "@cpu@_h_accum_get_handler"))
5952a6b7db3Sskrll  (set (newval) (c-call VOID "@cpu@_h_accum_set_handler" newval))
5962a6b7db3Sskrll)
5972a6b7db3Sskrll
5982a6b7db3Sskrll; FIXME: Revisit after sanitization can be removed.  Remove h-accum.
5992a6b7db3Sskrll(define-hardware
6002a6b7db3Sskrll  (name h-accums)
6012a6b7db3Sskrll  (comment "accumulators")
6022a6b7db3Sskrll  (attrs (MACH m32rx,m32r2))
6032a6b7db3Sskrll  (type register DI (2))
6042a6b7db3Sskrll  (indices keyword "" ((a0 0) (a1 1)))
6052a6b7db3Sskrll  ; get/set so a0 accesses are redirected to h-accum.
6062a6b7db3Sskrll  ; They're also so reads can properly sign extend the value.
6072a6b7db3Sskrll  ; FIXME: Needn't be a function call.
6082a6b7db3Sskrll  (get (index) (c-call DI "@cpu@_h_accums_get_handler" index))
6092a6b7db3Sskrll  (set (index newval) (c-call VOID "@cpu@_h_accums_set_handler" index newval))
6102a6b7db3Sskrll)
6112a6b7db3Sskrll
6122a6b7db3Sskrll; For condbit operand.  FIXME: Need to allow spec of get/set of operands.
6132a6b7db3Sskrll; Having this separate from h-psw keeps the parts that use it simpler
6142a6b7db3Sskrll; [since they greatly outnumber those that use h-psw].
6152a6b7db3Sskrll(dsh h-cond "condition bit" () (register BI))
6162a6b7db3Sskrll
6172a6b7db3Sskrll; The actual values of psw,bpsw,bbpsw are recorded here to allow access
6182a6b7db3Sskrll; to them as a unit.
6192a6b7db3Sskrll(define-hardware
6202a6b7db3Sskrll  (name h-psw)
6212a6b7db3Sskrll  (comment "psw part of psw")
6222a6b7db3Sskrll  (type register UQI)
6232a6b7db3Sskrll  ; get/set to handle cond bit.
6242a6b7db3Sskrll  ; FIXME: missing: use's and clobber's
6252a6b7db3Sskrll  ; FIXME: remove c-call?
6262a6b7db3Sskrll  (get () (c-call UQI "@cpu@_h_psw_get_handler"))
6272a6b7db3Sskrll  (set (newval) (c-call VOID "@cpu@_h_psw_set_handler" newval))
6282a6b7db3Sskrll)
6292a6b7db3Sskrll(dsh h-bpsw  "backup psw"      () (register UQI))
6302a6b7db3Sskrll(dsh h-bbpsw "backup bpsw"     () (register UQI))
6312a6b7db3Sskrll
6322a6b7db3Sskrll; FIXME: Later make add get/set specs and support SMP.
6332a6b7db3Sskrll(dsh h-lock  "lock"  () (register BI))
6342a6b7db3Sskrll
6352a6b7db3Sskrll; Instruction Operands.
6362a6b7db3Sskrll; These entries provide a layer between the assembler and the raw hardware
6372a6b7db3Sskrll; description, and are used to refer to hardware elements in the semantic
6382a6b7db3Sskrll; code.  Usually there's a bit of over-specification, but in more complicated
6392a6b7db3Sskrll; instruction sets there isn't.
6402a6b7db3Sskrll
641be12b8bcSchristos;; Print some operands take a hash prefix.
642be12b8bcSchristos;; ??? Why don't we also handle one when parsing?
6432a6b7db3Sskrll
644be12b8bcSchristos(define-pmacro (duhpo x-name x-comment x-attrs x-type x-index)
645be12b8bcSchristos  (define-operand (name x-name) (comment x-comment)
646be12b8bcSchristos    (.splice attrs (.unsplice x-attrs))
647be12b8bcSchristos    (type x-type) (index x-index)
648be12b8bcSchristos    (handlers (print "unsigned_with_hash_prefix")))
649be12b8bcSchristos)
650be12b8bcSchristos
651be12b8bcSchristos(define-pmacro (dshpo x-name x-comment x-attrs x-type x-index)
652be12b8bcSchristos  (define-operand (name x-name) (comment x-comment)
653be12b8bcSchristos    (.splice attrs (.unsplice x-attrs))
654be12b8bcSchristos    (type x-type) (index x-index)
655be12b8bcSchristos    (handlers (print "signed_with_hash_prefix")))
6562a6b7db3Sskrll)
6572a6b7db3Sskrll
6582a6b7db3Sskrll; ??? Convention says this should be o-sr, but then the insn definitions
6592a6b7db3Sskrll; should refer to o-sr which is clumsy.  The "o-" could be implicit, but
6602a6b7db3Sskrll; then it should be implicit for all the symbols here, but then there would
6612a6b7db3Sskrll; be confusion between (f-)simm8 and (h-)simm8.
6622a6b7db3Sskrll; So for now the rule is exactly as it appears here.
6632a6b7db3Sskrll
6642a6b7db3Sskrll(dnop sr     "source register"              () h-gr   f-r2)
6652a6b7db3Sskrll(dnop dr     "destination register"         () h-gr   f-r1)
6662a6b7db3Sskrll;; The assembler relies upon the fact that dr and src1 are the same field.
6672a6b7db3Sskrll;; FIXME: Revisit.
6682a6b7db3Sskrll(dnop src1   "source register 1"            () h-gr   f-r1)
6692a6b7db3Sskrll(dnop src2   "source register 2"            () h-gr   f-r2)
6702a6b7db3Sskrll(dnop scr    "source control register"      () h-cr   f-r2)
6712a6b7db3Sskrll(dnop dcr    "destination control register" () h-cr   f-r1)
6722a6b7db3Sskrll
673be12b8bcSchristos(dshpo simm8  "8 bit signed immediate"       () h-sint f-simm8)
674be12b8bcSchristos(dshpo simm16 "16 bit signed immediate"      () h-sint f-simm16)
675be12b8bcSchristos(duhpo uimm3  "3 bit unsigned number"        () h-uint f-uimm3)
676be12b8bcSchristos(duhpo uimm4  "4 bit trap number"            () h-uint f-uimm4)
677be12b8bcSchristos(duhpo uimm5  "5 bit shift count"            () h-uint f-uimm5)
678be12b8bcSchristos(duhpo uimm8  "8 bit unsigned immediate"     () h-uint f-uimm8)
679be12b8bcSchristos(duhpo uimm16 "16 bit unsigned immediate"    () h-uint f-uimm16)
6802a6b7db3Sskrll
681be12b8bcSchristos(duhpo imm1 "1 bit immediate" ((MACH m32rx,m32r2)) h-uint f-imm1)
682be12b8bcSchristos
6832a6b7db3Sskrll(dnop accd   "accumulator destination register" ((MACH m32rx,m32r2)) h-accums f-accd)
6842a6b7db3Sskrll(dnop accs   "accumulator source register"  ((MACH m32rx,m32r2))     h-accums f-accs)
6852a6b7db3Sskrll(dnop acc    "accumulator reg (d)"          ((MACH m32rx,m32r2))     h-accums f-acc)
6862a6b7db3Sskrll
6872a6b7db3Sskrll; slo16,ulo16 are used in both with-hash-prefix/no-hash-prefix cases.
688be12b8bcSchristos; e.g. add3 r3,r3,#1 and ld r3,@(4,r4).  We could use special handlers on
689be12b8bcSchristos; the operands themselves.
6902a6b7db3Sskrll; Instead we create a fake operand `hash'.  The m32r is an illustration port,
6912a6b7db3Sskrll; so we often try out various ways of doing things.
6922a6b7db3Sskrll
6932a6b7db3Sskrll(define-operand (name hash) (comment "# prefix") (attrs)
6942a6b7db3Sskrll  (type h-sint) ; doesn't really matter
6952a6b7db3Sskrll  (index f-nil)
6962a6b7db3Sskrll  (handlers (parse "hash") (print "hash"))
6972a6b7db3Sskrll)
6982a6b7db3Sskrll
6992a6b7db3Sskrll; For high(foo),shigh(foo).
7002a6b7db3Sskrll(define-operand
7012a6b7db3Sskrll  (name hi16)
7022a6b7db3Sskrll  (comment "high 16 bit immediate, sign optional")
7032a6b7db3Sskrll  (attrs)
7042a6b7db3Sskrll  (type h-hi16)
7052a6b7db3Sskrll  (index f-hi16)
7062a6b7db3Sskrll  (handlers (parse "hi16"))
7072a6b7db3Sskrll)
7082a6b7db3Sskrll
7092a6b7db3Sskrll; For low(foo),sda(foo).
7102a6b7db3Sskrll(define-operand
7112a6b7db3Sskrll  (name slo16)
7122a6b7db3Sskrll  (comment "16 bit signed immediate, for low()")
7132a6b7db3Sskrll  (attrs)
7142a6b7db3Sskrll  (type h-slo16)
7152a6b7db3Sskrll  (index f-simm16)
7162a6b7db3Sskrll  (handlers (parse "slo16"))
7172a6b7db3Sskrll)
7182a6b7db3Sskrll
7192a6b7db3Sskrll; For low(foo).
7202a6b7db3Sskrll(define-operand
7212a6b7db3Sskrll  (name ulo16)
7222a6b7db3Sskrll  (comment "16 bit unsigned immediate, for low()")
7232a6b7db3Sskrll  (attrs)
7242a6b7db3Sskrll  (type h-ulo16)
7252a6b7db3Sskrll  (index f-uimm16)
7262a6b7db3Sskrll  (handlers (parse "ulo16"))
7272a6b7db3Sskrll)
7282a6b7db3Sskrll
729be12b8bcSchristos(dnop uimm24 "24 bit address" () h-addr f-uimm24)
7302a6b7db3Sskrll
7312a6b7db3Sskrll(define-operand
7322a6b7db3Sskrll  (name disp8)
7332a6b7db3Sskrll  (comment "8 bit displacement")
7342a6b7db3Sskrll  (attrs RELAX)
7352a6b7db3Sskrll  (type h-iaddr)
7362a6b7db3Sskrll  (index f-disp8)
7372a6b7db3Sskrll  ; ??? Early experiments had insert/extract fields here.
7382a6b7db3Sskrll  ; Moving these to f-disp8 made things cleaner, but may wish to re-introduce
7392a6b7db3Sskrll  ; fields here to handle more complicated cases.
7402a6b7db3Sskrll)
7412a6b7db3Sskrll
7422a6b7db3Sskrll(dnop disp16 "16 bit displacement" () h-iaddr f-disp16)
7432a6b7db3Sskrll(dnop disp24 "24 bit displacement" (RELAX) h-iaddr f-disp24)
7442a6b7db3Sskrll
745*4f645668Schristos; These hardware elements are referred to frequently.
7462a6b7db3Sskrll
7472a6b7db3Sskrll(dnop condbit "condition bit" (SEM-ONLY) h-cond f-nil)
7482a6b7db3Sskrll(dnop accum "accumulator" (SEM-ONLY) h-accum f-nil)
7492a6b7db3Sskrll
7502a6b7db3Sskrll; Instruction definitions.
7512a6b7db3Sskrll;
7522a6b7db3Sskrll; Notes while wip:
7532a6b7db3Sskrll; - dni is a cover macro to the real "this is an instruction" keyword.
7542a6b7db3Sskrll;   The syntax of the real one is yet to be determined.
7552a6b7db3Sskrll;   At the lowest level (i.e. the "real" one) it will probably take a variable
7562a6b7db3Sskrll;   list of arguments where each argument [perhaps after the standard three of
7572a6b7db3Sskrll;   name, comment, attrs] is "(keyword arg-to-keyword)".  This syntax is simple
7582a6b7db3Sskrll;   and yet completely upward extensible.  And given the macro facility, one
7592a6b7db3Sskrll;   needn't code at that low a level so even though it'll be more verbose than
7602a6b7db3Sskrll;   necessary it won't matter.  This same reasoning can be applied to most
7612a6b7db3Sskrll;   types of entries in this file.
7622a6b7db3Sskrll
7632a6b7db3Sskrll; M32R specific instruction attributes:
7642a6b7db3Sskrll
7652a6b7db3Sskrll; FILL-SLOT: Need next insn to begin on 32 bit boundary.
7662a6b7db3Sskrll; (A "slot" as used here is a 32 bit quantity that can either be filled with
7672a6b7db3Sskrll; one 32 bit insn or two 16 bit insns which go in the "left bin" and "right
7682a6b7db3Sskrll; bin" where the left bin is the one with a lower address).
7692a6b7db3Sskrll
7702a6b7db3Sskrll(define-attr
7712a6b7db3Sskrll  (for insn)
7722a6b7db3Sskrll  (type boolean)
7732a6b7db3Sskrll  (name FILL-SLOT)
7742a6b7db3Sskrll  (comment "fill right bin with `nop' if insn is in left bin")
7752a6b7db3Sskrll)
7762a6b7db3Sskrll
7772a6b7db3Sskrll(define-attr
7782a6b7db3Sskrll  (for insn)
7792a6b7db3Sskrll  (type boolean)
7802a6b7db3Sskrll  (name SPECIAL)
7812a6b7db3Sskrll  (comment "non-public m32rx insn")
7822a6b7db3Sskrll)
7832a6b7db3Sskrll
7842a6b7db3Sskrll(define-attr
7852a6b7db3Sskrll  (for insn)
7862a6b7db3Sskrll  (type boolean)
7872a6b7db3Sskrll  (name SPECIAL_M32R)
7882a6b7db3Sskrll  (comment "non-public m32r insn")
7892a6b7db3Sskrll)
7902a6b7db3Sskrll
7912a6b7db3Sskrll(define-attr
7922a6b7db3Sskrll  (for insn)
7932a6b7db3Sskrll  (type boolean)
7942a6b7db3Sskrll  (name SPECIAL_FLOAT)
7952a6b7db3Sskrll  (comment "floating point insn")
7962a6b7db3Sskrll)
7972a6b7db3Sskrll
7982a6b7db3Sskrll; IDOC attribute for instruction documentation.
7992a6b7db3Sskrll
8002a6b7db3Sskrll(define-attr
8012a6b7db3Sskrll  (for insn)
8022a6b7db3Sskrll  (type enum)
8032a6b7db3Sskrll  (name IDOC)
8042a6b7db3Sskrll  (comment "insn kind for documentation")
8052a6b7db3Sskrll  (attrs META)
8062a6b7db3Sskrll  (values
8072a6b7db3Sskrll   (MEM - () "Memory")
8082a6b7db3Sskrll   (ALU - () "ALU")
8092a6b7db3Sskrll   (BR - () "Branch")
8102a6b7db3Sskrll   (ACCUM - () "Accumulator")
8112a6b7db3Sskrll   (MAC - () "Multiply/Accumulate")
8122a6b7db3Sskrll   (MISC - () "Miscellaneous")
8132a6b7db3Sskrll  )
8142a6b7db3Sskrll)
8152a6b7db3Sskrll
8162a6b7db3Sskrll(define-pmacro (bin-op mnemonic op2-op sem-op imm-prefix imm)
8172a6b7db3Sskrll  (begin
8182a6b7db3Sskrll     (dni mnemonic
8192a6b7db3Sskrll	  (.str mnemonic " reg/reg")
8202a6b7db3Sskrll	  ((PIPE OS) (IDOC ALU))
8212a6b7db3Sskrll	  (.str mnemonic " $dr,$sr")
8222a6b7db3Sskrll	  (+ OP1_0 op2-op dr sr)
8232a6b7db3Sskrll	  (set dr (sem-op dr sr))
8242a6b7db3Sskrll	  ()
8252a6b7db3Sskrll     )
8262a6b7db3Sskrll     (dni (.sym mnemonic "3")
8272a6b7db3Sskrll	  (.str mnemonic " reg/" imm)
8282a6b7db3Sskrll	  ((IDOC ALU))
8292a6b7db3Sskrll	  (.str mnemonic "3 $dr,$sr," imm-prefix "$" imm)
8302a6b7db3Sskrll	  (+ OP1_8 op2-op dr sr imm)
8312a6b7db3Sskrll	  (set dr (sem-op sr imm))
8322a6b7db3Sskrll	  ()
8332a6b7db3Sskrll     )
8342a6b7db3Sskrll   )
8352a6b7db3Sskrll)
8362a6b7db3Sskrll(bin-op add OP2_10 add "$hash" slo16)
8372a6b7db3Sskrll; sub isn't present because sub3 doesn't exist.
8382a6b7db3Sskrll(bin-op and OP2_12 and "" uimm16)
8392a6b7db3Sskrll(bin-op or OP2_14 or "$hash" ulo16)
8402a6b7db3Sskrll(bin-op xor OP2_13 xor "" uimm16)
8412a6b7db3Sskrll
8422a6b7db3Sskrll(dni addi "addi"
8432a6b7db3Sskrll     ((PIPE OS) (IDOC ALU))
8442a6b7db3Sskrll     ;#.(string-append "addi " "$dr,$simm8") ; #. experiment
8452a6b7db3Sskrll     "addi $dr,$simm8"
8462a6b7db3Sskrll     (+ OP1_4 dr simm8)
8472a6b7db3Sskrll     (set dr (add dr simm8))
8482a6b7db3Sskrll     ((m32r/d (unit u-exec))
8492a6b7db3Sskrll      (m32rx (unit u-exec))
8502a6b7db3Sskrll      (m32r2 (unit u-exec)))
8512a6b7db3Sskrll)
8522a6b7db3Sskrll
8532a6b7db3Sskrll(dni addv "addv"
8542a6b7db3Sskrll     ((PIPE OS) (IDOC ALU))
8552a6b7db3Sskrll     "addv $dr,$sr"
8562a6b7db3Sskrll     (+ OP1_0 OP2_8 dr sr)
8572a6b7db3Sskrll     (parallel ()
8582a6b7db3Sskrll	       (set dr (add dr sr))
8592a6b7db3Sskrll	       (set condbit (add-oflag dr sr (const 0))))
8602a6b7db3Sskrll     ()
8612a6b7db3Sskrll)
8622a6b7db3Sskrll
8632a6b7db3Sskrll(dni addv3 "addv3"
8642a6b7db3Sskrll     ((IDOC ALU))
8652a6b7db3Sskrll     "addv3 $dr,$sr,$simm16"
8662a6b7db3Sskrll     (+ OP1_8 OP2_8 dr sr simm16)
8672a6b7db3Sskrll     (parallel ()
8682a6b7db3Sskrll	       (set dr (add sr simm16))
8692a6b7db3Sskrll	       (set condbit (add-oflag sr simm16 (const 0))))
8702a6b7db3Sskrll     ()
8712a6b7db3Sskrll)
8722a6b7db3Sskrll
8732a6b7db3Sskrll(dni addx "addx"
8742a6b7db3Sskrll     ((PIPE OS) (IDOC ALU))
8752a6b7db3Sskrll     "addx $dr,$sr"
8762a6b7db3Sskrll     (+ OP1_0 OP2_9 dr sr)
8772a6b7db3Sskrll     (parallel ()
8782a6b7db3Sskrll	       (set dr (addc dr sr condbit))
8792a6b7db3Sskrll	       (set condbit (add-cflag dr sr condbit)))
8802a6b7db3Sskrll     ()
8812a6b7db3Sskrll)
8822a6b7db3Sskrll
8832a6b7db3Sskrll(dni bc8 "bc with 8 bit displacement"
8842a6b7db3Sskrll     (COND-CTI (PIPE O) (IDOC BR))
8852a6b7db3Sskrll     "bc.s $disp8"
8862a6b7db3Sskrll     (+ OP1_7 (f-r1 12) disp8)
8872a6b7db3Sskrll     (if condbit (set pc disp8))
8882a6b7db3Sskrll     ((m32r/d (unit u-cti))
8892a6b7db3Sskrll      (m32rx (unit u-cti))
8902a6b7db3Sskrll      (m32r2 (unit u-cti)))
8912a6b7db3Sskrll)
8922a6b7db3Sskrll
8932a6b7db3Sskrll(dnmi bc8r "relaxable bc8"
8942a6b7db3Sskrll     (COND-CTI RELAXABLE (PIPE O) (IDOC BR))
8952a6b7db3Sskrll     "bc $disp8"
8962a6b7db3Sskrll     (emit bc8 disp8)
8972a6b7db3Sskrll)
8982a6b7db3Sskrll
8992a6b7db3Sskrll(dni bc24 "bc with 24 bit displacement"
9002a6b7db3Sskrll     (COND-CTI (IDOC BR))
9012a6b7db3Sskrll     "bc.l $disp24"
9022a6b7db3Sskrll     (+ OP1_15 (f-r1 12) disp24)
9032a6b7db3Sskrll     (if condbit (set pc disp24))
9042a6b7db3Sskrll     ((m32r/d (unit u-cti))
9052a6b7db3Sskrll      (m32rx (unit u-cti))
9062a6b7db3Sskrll      (m32r2 (unit u-cti)))
9072a6b7db3Sskrll)
9082a6b7db3Sskrll
9092a6b7db3Sskrll(dnmi bc24r "relaxable bc24"
9102a6b7db3Sskrll     (COND-CTI RELAXED (IDOC BR))
9112a6b7db3Sskrll     "bc $disp24"
9122a6b7db3Sskrll     (emit bc24 disp24)
9132a6b7db3Sskrll)
9142a6b7db3Sskrll
9152a6b7db3Sskrll(dni beq "beq"
9162a6b7db3Sskrll     (COND-CTI (IDOC BR))
9172a6b7db3Sskrll     "beq $src1,$src2,$disp16"
9182a6b7db3Sskrll     (+ OP1_11 OP2_0 src1 src2 disp16)
9192a6b7db3Sskrll     (if (eq src1 src2) (set pc disp16))
9202a6b7db3Sskrll     ((m32r/d (unit u-cti) (unit u-cmp (cycles 0)))
9212a6b7db3Sskrll      (m32rx (unit u-cti) (unit u-cmp (cycles 0)))
9222a6b7db3Sskrll      (m32r2 (unit u-cti) (unit u-cmp (cycles 0))))
9232a6b7db3Sskrll)
9242a6b7db3Sskrll
9252a6b7db3Sskrll(define-pmacro (cbranch sym comment op2-op comp-op)
9262a6b7db3Sskrll  (dni sym comment (COND-CTI (IDOC BR))
9272a6b7db3Sskrll	(.str sym " $src2,$disp16")
9282a6b7db3Sskrll	(+ OP1_11 op2-op (f-r1 0) src2 disp16)
9292a6b7db3Sskrll	(if (comp-op src2 (const WI 0)) (set pc disp16))
9302a6b7db3Sskrll	((m32r/d (unit u-cti) (unit u-cmp (cycles 0)))
9312a6b7db3Sskrll	 (m32rx (unit u-cti) (unit u-cmp (cycles 0)))
9322a6b7db3Sskrll	 (m32r2 (unit u-cti) (unit u-cmp (cycles 0))))
9332a6b7db3Sskrll	)
9342a6b7db3Sskrll)
9352a6b7db3Sskrll(cbranch beqz "beqz" OP2_8 eq)
9362a6b7db3Sskrll(cbranch bgez "bgez" OP2_11 ge)
9372a6b7db3Sskrll(cbranch bgtz "bgtz" OP2_13 gt)
9382a6b7db3Sskrll(cbranch blez "blez" OP2_12 le)
9392a6b7db3Sskrll(cbranch bltz "bltz" OP2_10 lt)
9402a6b7db3Sskrll(cbranch bnez "bnez" OP2_9 ne)
9412a6b7db3Sskrll
9422a6b7db3Sskrll(dni bl8 "bl with 8 bit displacement"
9432a6b7db3Sskrll     (UNCOND-CTI FILL-SLOT (PIPE O) (IDOC BR))
9442a6b7db3Sskrll     "bl.s $disp8"
9452a6b7db3Sskrll     (+ OP1_7 (f-r1 14) disp8)
9462a6b7db3Sskrll     (sequence ()
9472a6b7db3Sskrll	       (set (reg h-gr 14)
9482a6b7db3Sskrll		    (add (and pc (const -4)) (const 4)))
9492a6b7db3Sskrll	       (set pc disp8))
9502a6b7db3Sskrll     ((m32r/d (unit u-cti))
9512a6b7db3Sskrll      (m32rx (unit u-cti))
9522a6b7db3Sskrll      (m32r2 (unit u-cti)))
9532a6b7db3Sskrll)
9542a6b7db3Sskrll
9552a6b7db3Sskrll(dnmi bl8r "relaxable bl8"
9562a6b7db3Sskrll     (UNCOND-CTI FILL-SLOT RELAXABLE (PIPE O) (IDOC BR))
9572a6b7db3Sskrll     "bl $disp8"
9582a6b7db3Sskrll     (emit bl8 disp8)
9592a6b7db3Sskrll)
9602a6b7db3Sskrll
9612a6b7db3Sskrll(dni bl24 "bl with 24 bit displacement"
9622a6b7db3Sskrll     (UNCOND-CTI (IDOC BR))
9632a6b7db3Sskrll     "bl.l $disp24"
9642a6b7db3Sskrll     (+ OP1_15 (f-r1 14) disp24)
9652a6b7db3Sskrll     (sequence ()
9662a6b7db3Sskrll	       (set (reg h-gr 14) (add pc (const 4)))
9672a6b7db3Sskrll	       (set pc disp24))
9682a6b7db3Sskrll     ((m32r/d (unit u-cti))
9692a6b7db3Sskrll      (m32rx (unit u-cti))
9702a6b7db3Sskrll      (m32r2 (unit u-cti)))
9712a6b7db3Sskrll)
9722a6b7db3Sskrll
9732a6b7db3Sskrll(dnmi bl24r "relaxable bl24"
9742a6b7db3Sskrll     (UNCOND-CTI RELAXED (IDOC BR))
9752a6b7db3Sskrll     "bl $disp24"
9762a6b7db3Sskrll     (emit bl24 disp24)
9772a6b7db3Sskrll)
9782a6b7db3Sskrll
9792a6b7db3Sskrll(dni bcl8 "bcl with 8 bit displacement"
9802a6b7db3Sskrll     (COND-CTI FILL-SLOT (MACH m32rx,m32r2) (PIPE O) (IDOC BR))
9812a6b7db3Sskrll     "bcl.s $disp8"
9822a6b7db3Sskrll     (+ OP1_7 (f-r1 8) disp8)
9832a6b7db3Sskrll     (if condbit
9842a6b7db3Sskrll         (sequence ()
9852a6b7db3Sskrll		   (set (reg h-gr 14)
9862a6b7db3Sskrll			(add (and pc (const -4))
9872a6b7db3Sskrll			     (const 4)))
9882a6b7db3Sskrll		   (set pc disp8)))
9892a6b7db3Sskrll     ((m32rx (unit u-cti))
9902a6b7db3Sskrll      (m32r2 (unit u-cti)))
9912a6b7db3Sskrll)
9922a6b7db3Sskrll
9932a6b7db3Sskrll(dnmi bcl8r "relaxable bcl8"
9942a6b7db3Sskrll     (COND-CTI FILL-SLOT (MACH m32rx,m32r2) (PIPE O) RELAXABLE (IDOC BR))
9952a6b7db3Sskrll     "bcl $disp8"
9962a6b7db3Sskrll     (emit bcl8 disp8)
9972a6b7db3Sskrll)
9982a6b7db3Sskrll
9992a6b7db3Sskrll(dni bcl24 "bcl with 24 bit displacement"
10002a6b7db3Sskrll     (COND-CTI (MACH m32rx,m32r2) (IDOC BR))
10012a6b7db3Sskrll     "bcl.l $disp24"
10022a6b7db3Sskrll     (+ OP1_15 (f-r1 8) disp24)
10032a6b7db3Sskrll     (if condbit
10042a6b7db3Sskrll         (sequence ()
10052a6b7db3Sskrll		   (set (reg h-gr 14) (add pc (const 4)))
10062a6b7db3Sskrll		   (set pc disp24)))
10072a6b7db3Sskrll     ((m32rx (unit u-cti))
10082a6b7db3Sskrll      (m32r2 (unit u-cti)))
10092a6b7db3Sskrll)
10102a6b7db3Sskrll
10112a6b7db3Sskrll(dnmi bcl24r "relaxable bcl24"
10122a6b7db3Sskrll     (COND-CTI (MACH m32rx,m32r2) RELAXED (IDOC BR))
10132a6b7db3Sskrll     "bcl $disp24"
10142a6b7db3Sskrll     (emit bcl24 disp24)
10152a6b7db3Sskrll)
10162a6b7db3Sskrll
10172a6b7db3Sskrll(dni bnc8 "bnc with 8 bit displacement"
10182a6b7db3Sskrll     (COND-CTI (PIPE O) (IDOC BR))
10192a6b7db3Sskrll     "bnc.s $disp8"
10202a6b7db3Sskrll     (+ OP1_7 (f-r1 13) disp8)
10212a6b7db3Sskrll     (if (not condbit) (set pc disp8))
10222a6b7db3Sskrll     ((m32r/d (unit u-cti))
10232a6b7db3Sskrll      (m32rx (unit u-cti))
10242a6b7db3Sskrll      (m32r2 (unit u-cti)))
10252a6b7db3Sskrll)
10262a6b7db3Sskrll
10272a6b7db3Sskrll(dnmi bnc8r "relaxable bnc8"
10282a6b7db3Sskrll     (COND-CTI RELAXABLE (PIPE O) (IDOC BR))
10292a6b7db3Sskrll     "bnc $disp8"
10302a6b7db3Sskrll     (emit bnc8 disp8)
10312a6b7db3Sskrll)
10322a6b7db3Sskrll
10332a6b7db3Sskrll(dni bnc24 "bnc with 24 bit displacement"
10342a6b7db3Sskrll     (COND-CTI (IDOC BR))
10352a6b7db3Sskrll     "bnc.l $disp24"
10362a6b7db3Sskrll     (+ OP1_15 (f-r1 13) disp24)
10372a6b7db3Sskrll     (if (not condbit) (set pc disp24))
10382a6b7db3Sskrll     ((m32r/d (unit u-cti))
10392a6b7db3Sskrll      (m32rx (unit u-cti))
10402a6b7db3Sskrll      (m32r2 (unit u-cti)))
10412a6b7db3Sskrll)
10422a6b7db3Sskrll
10432a6b7db3Sskrll(dnmi bnc24r "relaxable bnc24"
10442a6b7db3Sskrll     (COND-CTI RELAXED (IDOC BR))
10452a6b7db3Sskrll     "bnc $disp24"
10462a6b7db3Sskrll     (emit bnc24 disp24)
10472a6b7db3Sskrll)
10482a6b7db3Sskrll
10492a6b7db3Sskrll(dni bne "bne"
10502a6b7db3Sskrll     (COND-CTI (IDOC BR))
10512a6b7db3Sskrll     "bne $src1,$src2,$disp16"
10522a6b7db3Sskrll     (+ OP1_11 OP2_1 src1 src2 disp16)
10532a6b7db3Sskrll     (if (ne src1 src2) (set pc disp16))
10542a6b7db3Sskrll     ((m32r/d (unit u-cti) (unit u-cmp (cycles 0)))
10552a6b7db3Sskrll      (m32rx (unit u-cti) (unit u-cmp (cycles 0)))
10562a6b7db3Sskrll      (m32r2 (unit u-cti) (unit u-cmp (cycles 0))))
10572a6b7db3Sskrll)
10582a6b7db3Sskrll
10592a6b7db3Sskrll(dni bra8 "bra with 8 bit displacement"
10602a6b7db3Sskrll     (UNCOND-CTI FILL-SLOT (PIPE O) (IDOC BR))
10612a6b7db3Sskrll     "bra.s $disp8"
10622a6b7db3Sskrll     (+ OP1_7 (f-r1 15) disp8)
10632a6b7db3Sskrll     (set pc disp8)
10642a6b7db3Sskrll     ((m32r/d (unit u-cti))
10652a6b7db3Sskrll      (m32rx (unit u-cti))
10662a6b7db3Sskrll      (m32r2 (unit u-cti)))
10672a6b7db3Sskrll)
10682a6b7db3Sskrll
10692a6b7db3Sskrll(dnmi bra8r "relaxable bra8"
10702a6b7db3Sskrll     (UNCOND-CTI FILL-SLOT RELAXABLE (PIPE O) (IDOC BR))
10712a6b7db3Sskrll     "bra $disp8"
10722a6b7db3Sskrll     (emit bra8 disp8)
10732a6b7db3Sskrll)
10742a6b7db3Sskrll
10752a6b7db3Sskrll(dni bra24 "bra with 24 displacement"
10762a6b7db3Sskrll     (UNCOND-CTI (IDOC BR))
10772a6b7db3Sskrll     "bra.l $disp24"
10782a6b7db3Sskrll     (+ OP1_15 (f-r1 15) disp24)
10792a6b7db3Sskrll     (set pc disp24)
10802a6b7db3Sskrll     ((m32r/d (unit u-cti))
10812a6b7db3Sskrll      (m32rx (unit u-cti))
10822a6b7db3Sskrll      (m32r2 (unit u-cti)))
10832a6b7db3Sskrll)
10842a6b7db3Sskrll
10852a6b7db3Sskrll(dnmi bra24r "relaxable bra24"
10862a6b7db3Sskrll     (UNCOND-CTI RELAXED (IDOC BR))
10872a6b7db3Sskrll     "bra $disp24"
10882a6b7db3Sskrll     (emit bra24 disp24)
10892a6b7db3Sskrll)
10902a6b7db3Sskrll
10912a6b7db3Sskrll(dni bncl8 "bncl with 8 bit displacement"
10922a6b7db3Sskrll     (COND-CTI FILL-SLOT (MACH m32rx,m32r2) (PIPE O) (IDOC BR))
10932a6b7db3Sskrll     "bncl.s $disp8"
10942a6b7db3Sskrll     (+ OP1_7 (f-r1 9) disp8)
10952a6b7db3Sskrll     (if (not condbit)
10962a6b7db3Sskrll         (sequence ()
10972a6b7db3Sskrll		   (set (reg h-gr 14)
10982a6b7db3Sskrll			(add (and pc (const -4))
10992a6b7db3Sskrll			     (const 4)))
11002a6b7db3Sskrll		   (set pc disp8)))
11012a6b7db3Sskrll     ((m32rx (unit u-cti))
11022a6b7db3Sskrll      (m32r2 (unit u-cti)))
11032a6b7db3Sskrll)
11042a6b7db3Sskrll
11052a6b7db3Sskrll(dnmi bncl8r "relaxable bncl8"
11062a6b7db3Sskrll     (COND-CTI FILL-SLOT (MACH m32rx,m32r2) (PIPE O) RELAXABLE (IDOC BR))
11072a6b7db3Sskrll     "bncl $disp8"
11082a6b7db3Sskrll     (emit bncl8 disp8)
11092a6b7db3Sskrll)
11102a6b7db3Sskrll
11112a6b7db3Sskrll(dni bncl24 "bncl with 24 bit displacement"
11122a6b7db3Sskrll     (COND-CTI (MACH m32rx,m32r2) (IDOC BR))
11132a6b7db3Sskrll     "bncl.l $disp24"
11142a6b7db3Sskrll     (+ OP1_15 (f-r1 9) disp24)
11152a6b7db3Sskrll     (if (not condbit)
11162a6b7db3Sskrll         (sequence ()
11172a6b7db3Sskrll		   (set (reg h-gr 14) (add pc (const 4)))
11182a6b7db3Sskrll		   (set pc disp24)))
11192a6b7db3Sskrll     ((m32rx (unit u-cti))
11202a6b7db3Sskrll      (m32r2 (unit u-cti)))
11212a6b7db3Sskrll)
11222a6b7db3Sskrll
11232a6b7db3Sskrll(dnmi bncl24r "relaxable bncl24"
11242a6b7db3Sskrll     (COND-CTI (MACH m32rx,m32r2) RELAXED (IDOC BR))
11252a6b7db3Sskrll     "bncl $disp24"
11262a6b7db3Sskrll     (emit bncl24 disp24)
11272a6b7db3Sskrll)
11282a6b7db3Sskrll
11292a6b7db3Sskrll(dni cmp "cmp"
11302a6b7db3Sskrll     ((PIPE OS) (IDOC ALU))
11312a6b7db3Sskrll     "cmp $src1,$src2"
11322a6b7db3Sskrll     (+ OP1_0 OP2_4 src1 src2)
11332a6b7db3Sskrll     (set condbit (lt src1 src2))
11342a6b7db3Sskrll     ((m32r/d (unit u-cmp))
11352a6b7db3Sskrll      (m32rx (unit u-cmp))
11362a6b7db3Sskrll      (m32r2 (unit u-cmp)))
11372a6b7db3Sskrll)
11382a6b7db3Sskrll
11392a6b7db3Sskrll(dni cmpi "cmpi"
11402a6b7db3Sskrll     ((IDOC ALU))
11412a6b7db3Sskrll     "cmpi $src2,$simm16"
11422a6b7db3Sskrll     (+ OP1_8 (f-r1 0) OP2_4 src2 simm16)
11432a6b7db3Sskrll     (set condbit (lt src2 simm16))
11442a6b7db3Sskrll     ((m32r/d (unit u-cmp))
11452a6b7db3Sskrll      (m32rx (unit u-cmp))
11462a6b7db3Sskrll      (m32r2 (unit u-cmp)))
11472a6b7db3Sskrll)
11482a6b7db3Sskrll
11492a6b7db3Sskrll(dni cmpu "cmpu"
11502a6b7db3Sskrll     ((PIPE OS) (IDOC ALU))
11512a6b7db3Sskrll     "cmpu $src1,$src2"
11522a6b7db3Sskrll     (+ OP1_0 OP2_5 src1 src2)
11532a6b7db3Sskrll     (set condbit (ltu src1 src2))
11542a6b7db3Sskrll     ((m32r/d (unit u-cmp))
11552a6b7db3Sskrll      (m32rx (unit u-cmp))
11562a6b7db3Sskrll      (m32r2 (unit u-cmp)))
11572a6b7db3Sskrll)
11582a6b7db3Sskrll
11592a6b7db3Sskrll(dni cmpui "cmpui"
11602a6b7db3Sskrll     ((IDOC ALU))
11612a6b7db3Sskrll     "cmpui $src2,$simm16"
11622a6b7db3Sskrll     (+ OP1_8 (f-r1 0) OP2_5 src2 simm16)
11632a6b7db3Sskrll     (set condbit (ltu src2 simm16))
11642a6b7db3Sskrll     ((m32r/d (unit u-cmp))
11652a6b7db3Sskrll      (m32rx (unit u-cmp))
11662a6b7db3Sskrll      (m32r2 (unit u-cmp)))
11672a6b7db3Sskrll)
11682a6b7db3Sskrll
11692a6b7db3Sskrll(dni cmpeq "cmpeq"
11702a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE OS) (IDOC ALU))
11712a6b7db3Sskrll     "cmpeq $src1,$src2"
11722a6b7db3Sskrll     (+ OP1_0 OP2_6 src1 src2)
11732a6b7db3Sskrll     (set condbit (eq src1 src2))
11742a6b7db3Sskrll     ((m32rx (unit u-cmp))
11752a6b7db3Sskrll      (m32r2 (unit u-cmp)))
11762a6b7db3Sskrll)
11772a6b7db3Sskrll
11782a6b7db3Sskrll(dni cmpz "cmpz"
11792a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE OS) (IDOC ALU))
11802a6b7db3Sskrll     "cmpz $src2"
11812a6b7db3Sskrll     (+ OP1_0 OP2_7 (f-r1 0) src2)
11822a6b7db3Sskrll     (set condbit (eq src2 (const 0)))
11832a6b7db3Sskrll     ((m32rx (unit u-cmp))
11842a6b7db3Sskrll      (m32r2 (unit u-cmp)))
11852a6b7db3Sskrll)
11862a6b7db3Sskrll
11872a6b7db3Sskrll(dni div "div"
11882a6b7db3Sskrll     ((IDOC ALU))
11892a6b7db3Sskrll     "div $dr,$sr"
11902a6b7db3Sskrll     (+ OP1_9 OP2_0 dr sr (f-simm16 0))
11912a6b7db3Sskrll     (if (ne sr (const 0)) (set dr (div dr sr)))
11922a6b7db3Sskrll     ((m32r/d (unit u-exec (cycles 37)))
11932a6b7db3Sskrll      (m32rx (unit u-exec (cycles 37)))
11942a6b7db3Sskrll      (m32r2 (unit u-exec (cycles 37))))
11952a6b7db3Sskrll)
11962a6b7db3Sskrll
11972a6b7db3Sskrll(dni divu "divu"
11982a6b7db3Sskrll     ((IDOC ALU))
11992a6b7db3Sskrll     "divu $dr,$sr"
12002a6b7db3Sskrll     (+ OP1_9 OP2_1 dr sr (f-simm16 0))
12012a6b7db3Sskrll     (if (ne sr (const 0)) (set dr (udiv dr sr)))
12022a6b7db3Sskrll     ((m32r/d (unit u-exec (cycles 37)))
12032a6b7db3Sskrll      (m32rx (unit u-exec (cycles 37)))
12042a6b7db3Sskrll      (m32r2 (unit u-exec (cycles 37))))
12052a6b7db3Sskrll)
12062a6b7db3Sskrll
12072a6b7db3Sskrll(dni rem "rem"
12082a6b7db3Sskrll     ((IDOC ALU))
12092a6b7db3Sskrll     "rem $dr,$sr"
12102a6b7db3Sskrll     (+ OP1_9 OP2_2 dr sr (f-simm16 0))
12112a6b7db3Sskrll     ; FIXME: Check rounding direction.
12122a6b7db3Sskrll     (if (ne sr (const 0)) (set dr (mod dr sr)))
12132a6b7db3Sskrll     ((m32r/d (unit u-exec (cycles 37)))
12142a6b7db3Sskrll      (m32rx (unit u-exec (cycles 37)))
12152a6b7db3Sskrll      (m32r2 (unit u-exec (cycles 37))))
12162a6b7db3Sskrll)
12172a6b7db3Sskrll
12182a6b7db3Sskrll(dni remu "remu"
12192a6b7db3Sskrll     ((IDOC ALU))
12202a6b7db3Sskrll     "remu $dr,$sr"
12212a6b7db3Sskrll     (+ OP1_9 OP2_3 dr sr (f-simm16 0))
12222a6b7db3Sskrll     ; FIXME: Check rounding direction.
12232a6b7db3Sskrll     (if (ne sr (const 0)) (set dr (umod dr sr)))
12242a6b7db3Sskrll     ((m32r/d (unit u-exec (cycles 37)))
12252a6b7db3Sskrll      (m32rx (unit u-exec (cycles 37)))
12262a6b7db3Sskrll      (m32r2 (unit u-exec (cycles 37))))
12272a6b7db3Sskrll)
12282a6b7db3Sskrll
12292a6b7db3Sskrll(dni remh "remh"
12302a6b7db3Sskrll     ((MACH m32r2))
12312a6b7db3Sskrll     "remh $dr,$sr"
12322a6b7db3Sskrll     (+ OP1_9 OP2_2 dr sr (f-simm16 #x10))
12332a6b7db3Sskrll     ; FIXME: Check rounding direction.
12342a6b7db3Sskrll     (if (ne sr (const 0)) (set dr (mod (ext WI (trunc HI dr)) sr)))
12352a6b7db3Sskrll     ((m32r2 (unit u-exec (cycles 21))))
12362a6b7db3Sskrll)
12372a6b7db3Sskrll
12382a6b7db3Sskrll(dni remuh "remuh"
12392a6b7db3Sskrll     ((MACH m32r2))
12402a6b7db3Sskrll     "remuh $dr,$sr"
12412a6b7db3Sskrll     (+ OP1_9 OP2_3 dr sr (f-simm16 #x10))
12422a6b7db3Sskrll     ; FIXME: Check rounding direction.
12432a6b7db3Sskrll     (if (ne sr (const 0)) (set dr (umod dr sr)))
12442a6b7db3Sskrll     ((m32r2 (unit u-exec (cycles 21))))
12452a6b7db3Sskrll)
12462a6b7db3Sskrll
12472a6b7db3Sskrll(dni remb "remb"
12482a6b7db3Sskrll     ((MACH m32r2))
12492a6b7db3Sskrll     "remb $dr,$sr"
12502a6b7db3Sskrll     (+ OP1_9 OP2_2 dr sr (f-simm16 #x18))
12512a6b7db3Sskrll     ; FIXME: Check rounding direction.
12522a6b7db3Sskrll     (if (ne sr (const 0)) (set dr (mod (ext WI (trunc BI dr)) sr)))
12532a6b7db3Sskrll     ((m32r2 (unit u-exec (cycles 21))))
12542a6b7db3Sskrll)
12552a6b7db3Sskrll
12562a6b7db3Sskrll(dni remub "remub"
12572a6b7db3Sskrll     ((MACH m32r2))
12582a6b7db3Sskrll     "remub $dr,$sr"
12592a6b7db3Sskrll     (+ OP1_9 OP2_3 dr sr (f-simm16 #x18))
12602a6b7db3Sskrll     ; FIXME: Check rounding direction.
12612a6b7db3Sskrll     (if (ne sr (const 0)) (set dr (umod dr sr)))
12622a6b7db3Sskrll     ((m32r2 (unit u-exec (cycles 21))))
12632a6b7db3Sskrll)
12642a6b7db3Sskrll
12652a6b7db3Sskrll(dni divuh "divuh"
12662a6b7db3Sskrll     ((MACH m32r2))
12672a6b7db3Sskrll     "divuh $dr,$sr"
12682a6b7db3Sskrll     (+ OP1_9 OP2_1 dr sr (f-simm16 #x10))
12692a6b7db3Sskrll     (if (ne sr (const 0)) (set dr (udiv dr sr)))
12702a6b7db3Sskrll     ((m32r2 (unit u-exec (cycles 21))))
12712a6b7db3Sskrll)
12722a6b7db3Sskrll
12732a6b7db3Sskrll(dni divb "divb"
12742a6b7db3Sskrll     ((MACH m32r2))
12752a6b7db3Sskrll     "divb $dr,$sr"
12762a6b7db3Sskrll     (+ OP1_9 OP2_0 dr sr (f-simm16 #x18))
12772a6b7db3Sskrll     (if (ne sr (const 0)) (set dr (div (ext WI (trunc BI dr)) sr)))
12782a6b7db3Sskrll     ((m32r2 (unit u-exec (cycles 21))))
12792a6b7db3Sskrll)
12802a6b7db3Sskrll
12812a6b7db3Sskrll(dni divub "divub"
12822a6b7db3Sskrll     ((MACH m32r2))
12832a6b7db3Sskrll     "divub $dr,$sr"
12842a6b7db3Sskrll     (+ OP1_9 OP2_1 dr sr (f-simm16 #x18))
12852a6b7db3Sskrll     (if (ne sr (const 0)) (set dr (udiv dr sr)))
12862a6b7db3Sskrll     ((m32r2 (unit u-exec (cycles 21))))
12872a6b7db3Sskrll)
12882a6b7db3Sskrll
12892a6b7db3Sskrll(dni divh "divh"
12902a6b7db3Sskrll     ((MACH m32rx,m32r2) (IDOC ALU))
12912a6b7db3Sskrll     "divh $dr,$sr"
12922a6b7db3Sskrll     (+ OP1_9 OP2_0 dr sr (f-simm16 #x10))
12932a6b7db3Sskrll     (if (ne sr (const 0)) (set dr (div (ext WI (trunc HI dr)) sr)))
12942a6b7db3Sskrll     ((m32rx (unit u-exec (cycles 21)))
12952a6b7db3Sskrll      (m32r2 (unit u-exec (cycles 21))))
12962a6b7db3Sskrll)
12972a6b7db3Sskrll
12982a6b7db3Sskrll(dni jc "jc"
12992a6b7db3Sskrll     (COND-CTI (MACH m32rx,m32r2) (PIPE O) SPECIAL (IDOC BR))
13002a6b7db3Sskrll     "jc $sr"
13012a6b7db3Sskrll     (+ OP1_1 (f-r1 12) OP2_12 sr)
13022a6b7db3Sskrll     (if condbit (set pc (and sr (const -4))))
13032a6b7db3Sskrll     ((m32rx (unit u-cti))
13042a6b7db3Sskrll      (m32r2 (unit u-cti)))
13052a6b7db3Sskrll)
13062a6b7db3Sskrll
13072a6b7db3Sskrll(dni jnc "jnc"
13082a6b7db3Sskrll     (COND-CTI (MACH m32rx,m32r2) (PIPE O) SPECIAL (IDOC BR))
13092a6b7db3Sskrll     "jnc $sr"
13102a6b7db3Sskrll     (+ OP1_1 (f-r1 13) OP2_12 sr)
13112a6b7db3Sskrll     (if (not condbit) (set pc (and sr (const -4))))
13122a6b7db3Sskrll     ((m32rx (unit u-cti))
13132a6b7db3Sskrll      (m32r2 (unit u-cti)))
13142a6b7db3Sskrll)
13152a6b7db3Sskrll
13162a6b7db3Sskrll(dni jl "jl"
13172a6b7db3Sskrll     (UNCOND-CTI FILL-SLOT (PIPE O) (IDOC BR))
13182a6b7db3Sskrll     "jl $sr"
13192a6b7db3Sskrll     (+ OP1_1 (f-r1 14) OP2_12 sr)
13202a6b7db3Sskrll     (parallel ()
13212a6b7db3Sskrll	       (set (reg h-gr 14)
13222a6b7db3Sskrll		    (add (and pc (const -4)) (const 4)))
13232a6b7db3Sskrll	       (set pc (and sr (const -4))))
13242a6b7db3Sskrll     ((m32r/d (unit u-cti))
13252a6b7db3Sskrll      (m32rx (unit u-cti))
13262a6b7db3Sskrll      (m32r2 (unit u-cti)))
13272a6b7db3Sskrll)
13282a6b7db3Sskrll
13292a6b7db3Sskrll(dni jmp "jmp"
13302a6b7db3Sskrll     (UNCOND-CTI (PIPE O) (IDOC BR))
13312a6b7db3Sskrll     "jmp $sr"
13322a6b7db3Sskrll     (+ OP1_1 (f-r1 15) OP2_12 sr)
13332a6b7db3Sskrll     (set pc (and sr (const -4)))
13342a6b7db3Sskrll     ; The above works now so this kludge has been commented out.
13352a6b7db3Sskrll     ; It's kept around because the f-r1 reference in the semantic part
13362a6b7db3Sskrll     ; should work.
13372a6b7db3Sskrll     ; FIXME: kludge, instruction decoding not finished.
13382a6b7db3Sskrll     ; But this should work, so that's another FIXME.
13392a6b7db3Sskrll     ;(sequence VOID (if VOID (eq SI f-r1 (const SI 14))
13402a6b7db3Sskrll     ; FIXME: abuf->insn should be a macro of some sort.
13412a6b7db3Sskrll     ;(sequence VOID
13422a6b7db3Sskrll     ;	       (if VOID (eq SI (c-code SI "((abuf->insn >> 8) & 15)")
13432a6b7db3Sskrll     ;			  (const SI 14))
13442a6b7db3Sskrll     ;		   (set WI (reg WI h-gr 14)
13452a6b7db3Sskrll     ;			(add WI (and WI pc (const WI -4)) (const WI 4))))
13462a6b7db3Sskrll     ;	       (set WI pc sr))
13472a6b7db3Sskrll     ((m32r/d (unit u-cti))
13482a6b7db3Sskrll      (m32rx (unit u-cti))
13492a6b7db3Sskrll      (m32r2 (unit u-cti)))
13502a6b7db3Sskrll)
13512a6b7db3Sskrll
13522a6b7db3Sskrll(define-pmacro (no-ext-expr mode expr) expr)
13532a6b7db3Sskrll(define-pmacro (ext-expr mode expr) (ext mode expr))
13542a6b7db3Sskrll(define-pmacro (zext-expr mode expr) (zext mode expr))
13552a6b7db3Sskrll
13562a6b7db3Sskrll(define-pmacro (load-op suffix op2-op mode ext-op)
13572a6b7db3Sskrll  (begin
13582a6b7db3Sskrll    (dni (.sym ld suffix) (.str "ld" suffix)
13592a6b7db3Sskrll	 ((PIPE O) (IDOC MEM))
13602a6b7db3Sskrll	 (.str "ld" suffix " $dr,@$sr")
13612a6b7db3Sskrll	 (+ OP1_2 op2-op dr sr)
13622a6b7db3Sskrll	 (set dr (ext-op WI (mem mode sr)))
13632a6b7db3Sskrll	 ((m32r/d (unit u-load))
13642a6b7db3Sskrll	  (m32rx (unit u-load))
13652a6b7db3Sskrll	  (m32r2 (unit u-load)))
13662a6b7db3Sskrll	 )
13672a6b7db3Sskrll    (dnmi (.sym ld suffix "-2") (.str "ld" suffix "-2")
13682a6b7db3Sskrll	  (NO-DIS (PIPE O) (IDOC MEM))
13692a6b7db3Sskrll	  (.str "ld" suffix " $dr,@($sr)")
13702a6b7db3Sskrll	  (emit (.sym ld suffix) dr sr))
13712a6b7db3Sskrll    (dni (.sym ld suffix -d) (.str "ld" suffix "-d")
13722a6b7db3Sskrll	 ((IDOC MEM))
13732a6b7db3Sskrll	 (.str "ld" suffix " $dr,@($slo16,$sr)")
13742a6b7db3Sskrll	 (+ OP1_10 op2-op dr sr slo16)
13752a6b7db3Sskrll	 (set dr (ext-op WI (mem mode (add sr slo16))))
13762a6b7db3Sskrll	 ((m32r/d (unit u-load (cycles 2)))
13772a6b7db3Sskrll	  (m32rx (unit u-load (cycles 2)))
13782a6b7db3Sskrll	  (m32r2 (unit u-load (cycles 2))))
13792a6b7db3Sskrll	 )
13802a6b7db3Sskrll    (dnmi (.sym ld suffix -d2) (.str "ld" suffix "-d2")
13812a6b7db3Sskrll	  (NO-DIS (IDOC MEM))
13822a6b7db3Sskrll	  (.str "ld" suffix " $dr,@($sr,$slo16)")
13832a6b7db3Sskrll	  (emit (.sym ld suffix -d) dr sr slo16))
13842a6b7db3Sskrll    )
13852a6b7db3Sskrll)
13862a6b7db3Sskrll(load-op "" OP2_12 WI no-ext-expr)
13872a6b7db3Sskrll(load-op b OP2_8 QI ext-expr)
13882a6b7db3Sskrll(load-op h OP2_10 HI ext-expr)
13892a6b7db3Sskrll(load-op ub OP2_9 QI zext-expr)
13902a6b7db3Sskrll(load-op uh OP2_11 HI zext-expr)
13912a6b7db3Sskrll
13922a6b7db3Sskrll(dni ld-plus "ld+"
13932a6b7db3Sskrll     ((PIPE O) (IDOC MEM))
13942a6b7db3Sskrll     "ld $dr,@$sr+"
13952a6b7db3Sskrll     (+ OP1_2 dr OP2_14 sr)
13962a6b7db3Sskrll     (parallel ()
13972a6b7db3Sskrll	       ; wip: memory addresses in profiling support
13982a6b7db3Sskrll	       ;(set dr (name ld-mem (mem WI sr)))
13992a6b7db3Sskrll	       (set dr (mem WI sr))
14002a6b7db3Sskrll	       (set sr (add sr (const 4))))
14012a6b7db3Sskrll     ; Note: `pred' is the constraint.  Also useful here is (ref name)
14022a6b7db3Sskrll     ; and returns true if operand <name> was referenced
14032a6b7db3Sskrll     ; (where "referenced" means _read_ if input operand and _written_ if
14042a6b7db3Sskrll     ; output operand).
14052a6b7db3Sskrll     ; args to unit are "unit-name (name1 value1) ..."
14062a6b7db3Sskrll     ; - cycles(done),issue,pred are also specified this way
14072a6b7db3Sskrll     ; - if unspecified, default is used
14082a6b7db3Sskrll     ; - for ins/outs, extra arg is passed that says what was specified
14092a6b7db3Sskrll     ;   - this is AND'd with `written' for outs
14102a6b7db3Sskrll     ((m32r/d (unit u-load (pred (const 1)))
14112a6b7db3Sskrll	      (unit u-exec (in sr #f) (in dr sr) (out dr sr) (cycles 0) (pred (const 1))))
14122a6b7db3Sskrll      (m32rx (unit u-load)
14132a6b7db3Sskrll	     (unit u-exec (in sr #f) (in dr sr) (out dr sr) (cycles 0) (pred (const 1))))
14142a6b7db3Sskrll      (m32r2 (unit u-load)
14152a6b7db3Sskrll	     (unit u-exec (in sr #f) (in dr sr) (out dr sr) (cycles 0) (pred (const 1))))
14162a6b7db3Sskrll      )
14172a6b7db3Sskrll)
14182a6b7db3Sskrll
14192a6b7db3Sskrll(dnmi pop "pop"
14202a6b7db3Sskrll      ((PIPE O) (IDOC MEM))
14212a6b7db3Sskrll      "pop $dr"
14222a6b7db3Sskrll      (emit ld-plus dr (sr 15)) ; "ld %0,@sp+"
14232a6b7db3Sskrll)
14242a6b7db3Sskrll
14252a6b7db3Sskrll(dni ld24 "ld24"
14262a6b7db3Sskrll     ((IDOC MEM))
14272a6b7db3Sskrll     "ld24 $dr,$uimm24"
14282a6b7db3Sskrll     (+ OP1_14 dr uimm24)
14292a6b7db3Sskrll     (set dr uimm24)
14302a6b7db3Sskrll     ()
14312a6b7db3Sskrll)
14322a6b7db3Sskrll
14332a6b7db3Sskrll; ldi8 appears before ldi16 so we try the shorter version first
14342a6b7db3Sskrll
14352a6b7db3Sskrll(dni ldi8 "ldi8"
14362a6b7db3Sskrll     ((PIPE OS) (IDOC ALU))
14372a6b7db3Sskrll     "ldi8 $dr,$simm8"
14382a6b7db3Sskrll     (+ OP1_6 dr simm8)
14392a6b7db3Sskrll     (set dr simm8)
14402a6b7db3Sskrll     ()
14412a6b7db3Sskrll)
14422a6b7db3Sskrll
14432a6b7db3Sskrll(dnmi ldi8a "ldi8 alias"
14442a6b7db3Sskrll     ((PIPE OS) (IDOC ALU))
14452a6b7db3Sskrll     "ldi $dr,$simm8"
14462a6b7db3Sskrll     (emit ldi8 dr simm8)
14472a6b7db3Sskrll)
14482a6b7db3Sskrll
14492a6b7db3Sskrll(dni ldi16 "ldi16"
14502a6b7db3Sskrll     ((IDOC ALU))
14512a6b7db3Sskrll     "ldi16 $dr,$hash$slo16"
14522a6b7db3Sskrll     (+ OP1_9 OP2_15 (f-r2 0) dr slo16)
14532a6b7db3Sskrll     (set dr slo16)
14542a6b7db3Sskrll     ()
14552a6b7db3Sskrll)
14562a6b7db3Sskrll
14572a6b7db3Sskrll(dnmi ldi16a "ldi16 alias"
14582a6b7db3Sskrll     ((IDOC ALU))
14592a6b7db3Sskrll     "ldi $dr,$hash$slo16"
14602a6b7db3Sskrll     (emit ldi16 dr slo16)
14612a6b7db3Sskrll)
14622a6b7db3Sskrll
14632a6b7db3Sskrll(dni lock "lock"
14642a6b7db3Sskrll     ((PIPE O) (IDOC MISC))
14652a6b7db3Sskrll     "lock $dr,@$sr"
14662a6b7db3Sskrll     (+ OP1_2 OP2_13 dr sr)
14672a6b7db3Sskrll     (sequence ()
14682a6b7db3Sskrll	       (set (reg h-lock) (const BI 1))
14692a6b7db3Sskrll	       (set dr (mem WI sr)))
14702a6b7db3Sskrll     ((m32r/d (unit u-load))
14712a6b7db3Sskrll      (m32rx (unit u-load))
14722a6b7db3Sskrll      (m32r2 (unit u-load)))
14732a6b7db3Sskrll)
14742a6b7db3Sskrll
14752a6b7db3Sskrll(dni machi "machi"
14762a6b7db3Sskrll     (
14772a6b7db3Sskrll      ; (MACH m32r) is a temporary hack.  This insn collides with machi-a
14782a6b7db3Sskrll      ; in the simulator so disable it for m32rx.
14792a6b7db3Sskrll      (MACH m32r) (PIPE S) (IDOC MAC)
14802a6b7db3Sskrll     )
14812a6b7db3Sskrll     "machi $src1,$src2"
14822a6b7db3Sskrll     (+ OP1_3 OP2_4 src1 src2)
14832a6b7db3Sskrll     ; FIXME: TRACE_RESULT will print the wrong thing since we
14842a6b7db3Sskrll     ; alter one of the arguments.
14852a6b7db3Sskrll     (set accum
14862a6b7db3Sskrll	  (sra DI
14872a6b7db3Sskrll	       (sll DI
14882a6b7db3Sskrll		    (add DI
14892a6b7db3Sskrll			 accum
14902a6b7db3Sskrll			 (mul DI
14912a6b7db3Sskrll			      (ext DI (and WI src1 (const #xffff0000)))
14922a6b7db3Sskrll			      (ext DI (trunc HI (sra WI src2 (const 16))))))
14932a6b7db3Sskrll		    (const 8))
14942a6b7db3Sskrll	       (const 8)))
14952a6b7db3Sskrll     ((m32r/d (unit u-mac)))
14962a6b7db3Sskrll)
14972a6b7db3Sskrll
14982a6b7db3Sskrll(dni machi-a "machi-a"
14992a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC MAC))
15002a6b7db3Sskrll     "machi $src1,$src2,$acc"
15012a6b7db3Sskrll     (+ OP1_3 src1 acc (f-op23 4) src2)
15022a6b7db3Sskrll     (set acc
15032a6b7db3Sskrll	  (sra DI
15042a6b7db3Sskrll	       (sll DI
15052a6b7db3Sskrll		    (add DI
15062a6b7db3Sskrll			 acc
15072a6b7db3Sskrll			 (mul DI
15082a6b7db3Sskrll			      (ext DI (and WI src1 (const #xffff0000)))
15092a6b7db3Sskrll			      (ext DI (trunc HI (sra WI src2 (const 16))))))
15102a6b7db3Sskrll		    (const 8))
15112a6b7db3Sskrll	       (const 8)))
15122a6b7db3Sskrll     ((m32rx (unit u-mac))
15132a6b7db3Sskrll      (m32r2 (unit u-mac)))
15142a6b7db3Sskrll)
15152a6b7db3Sskrll
15162a6b7db3Sskrll(dni maclo "maclo"
15172a6b7db3Sskrll     ((MACH m32r) (PIPE S) (IDOC MAC))
15182a6b7db3Sskrll     "maclo $src1,$src2"
15192a6b7db3Sskrll     (+ OP1_3 OP2_5 src1 src2)
15202a6b7db3Sskrll     (set accum
15212a6b7db3Sskrll	  (sra DI
15222a6b7db3Sskrll	       (sll DI
15232a6b7db3Sskrll		    (add DI
15242a6b7db3Sskrll			 accum
15252a6b7db3Sskrll			 (mul DI
15262a6b7db3Sskrll			      (ext DI (sll WI src1 (const 16)))
15272a6b7db3Sskrll			      (ext DI (trunc HI src2))))
15282a6b7db3Sskrll		    (const 8))
15292a6b7db3Sskrll	       (const 8)))
15302a6b7db3Sskrll     ((m32r/d (unit u-mac)))
15312a6b7db3Sskrll)
15322a6b7db3Sskrll
15332a6b7db3Sskrll(dni maclo-a "maclo-a"
15342a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC MAC))
15352a6b7db3Sskrll     "maclo $src1,$src2,$acc"
15362a6b7db3Sskrll     (+ OP1_3 src1 acc (f-op23 5) src2)
15372a6b7db3Sskrll     (set acc
15382a6b7db3Sskrll	  (sra DI
15392a6b7db3Sskrll	       (sll DI
15402a6b7db3Sskrll		    (add DI
15412a6b7db3Sskrll			 acc
15422a6b7db3Sskrll			 (mul DI
15432a6b7db3Sskrll			      (ext DI (sll WI src1 (const 16)))
15442a6b7db3Sskrll			      (ext DI (trunc HI src2))))
15452a6b7db3Sskrll		    (const 8))
15462a6b7db3Sskrll	       (const 8)))
15472a6b7db3Sskrll     ((m32rx (unit u-mac))
15482a6b7db3Sskrll      (m32r2 (unit u-mac)))
15492a6b7db3Sskrll)
15502a6b7db3Sskrll
15512a6b7db3Sskrll(dni macwhi "macwhi"
15522a6b7db3Sskrll     ((MACH m32r) (PIPE S) (IDOC MAC))
15532a6b7db3Sskrll     "macwhi $src1,$src2"
15542a6b7db3Sskrll     (+ OP1_3 OP2_6 src1 src2)
15552a6b7db3Sskrll     (set accum
15562a6b7db3Sskrll	  (sra DI
15572a6b7db3Sskrll	       (sll DI
15582a6b7db3Sskrll		    (add DI
15592a6b7db3Sskrll			 accum
15602a6b7db3Sskrll			 (mul DI
15612a6b7db3Sskrll			      (ext DI src1)
15622a6b7db3Sskrll			      (ext DI (trunc HI (sra WI src2 (const 16))))))
15632a6b7db3Sskrll		    (const 8))
15642a6b7db3Sskrll	       (const 8)))
15652a6b7db3Sskrll     ((m32r/d (unit u-mac)))
15662a6b7db3Sskrll)
15672a6b7db3Sskrll
15682a6b7db3Sskrll(dni macwhi-a "macwhi-a"
15692a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) SPECIAL (IDOC MAC))
15702a6b7db3Sskrll     "macwhi $src1,$src2,$acc"
15712a6b7db3Sskrll     (+ OP1_3 src1 acc (f-op23 6) src2)
15722a6b7db3Sskrll     ; Note that this doesn't do the sign extension, which is correct.
15732a6b7db3Sskrll     (set acc
15742a6b7db3Sskrll	  (add acc
15752a6b7db3Sskrll	       (mul (ext DI src1)
15762a6b7db3Sskrll		    (ext DI (trunc HI (sra src2 (const 16)))))))
15772a6b7db3Sskrll     ((m32rx (unit u-mac))
15782a6b7db3Sskrll      (m32r2 (unit u-mac)))
15792a6b7db3Sskrll)
15802a6b7db3Sskrll
15812a6b7db3Sskrll(dni macwlo "macwlo"
15822a6b7db3Sskrll     ((MACH m32r) (PIPE S) (IDOC MAC))
15832a6b7db3Sskrll     "macwlo $src1,$src2"
15842a6b7db3Sskrll     (+ OP1_3 OP2_7 src1 src2)
15852a6b7db3Sskrll     (set accum
15862a6b7db3Sskrll	  (sra DI
15872a6b7db3Sskrll	       (sll DI
15882a6b7db3Sskrll		    (add DI
15892a6b7db3Sskrll			 accum
15902a6b7db3Sskrll			 (mul DI
15912a6b7db3Sskrll			      (ext DI src1)
15922a6b7db3Sskrll			      (ext DI (trunc HI src2))))
15932a6b7db3Sskrll		    (const 8))
15942a6b7db3Sskrll	       (const 8)))
15952a6b7db3Sskrll     ((m32r/d (unit u-mac)))
15962a6b7db3Sskrll)
15972a6b7db3Sskrll
15982a6b7db3Sskrll(dni macwlo-a "macwlo-a"
15992a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) SPECIAL (IDOC MAC))
16002a6b7db3Sskrll     "macwlo $src1,$src2,$acc"
16012a6b7db3Sskrll     (+ OP1_3 src1 acc (f-op23 7) src2)
16022a6b7db3Sskrll     ; Note that this doesn't do the sign extension, which is correct.
16032a6b7db3Sskrll     (set acc
16042a6b7db3Sskrll	  (add acc
16052a6b7db3Sskrll	       (mul (ext DI src1)
16062a6b7db3Sskrll		    (ext DI (trunc HI src2)))))
16072a6b7db3Sskrll     ((m32rx (unit u-mac))
16082a6b7db3Sskrll      (m32r2 (unit u-mac)))
16092a6b7db3Sskrll)
16102a6b7db3Sskrll
16112a6b7db3Sskrll(dni mul "mul"
16122a6b7db3Sskrll     ((PIPE S) (IDOC ALU))
16132a6b7db3Sskrll     "mul $dr,$sr"
16142a6b7db3Sskrll     (+ OP1_1 OP2_6 dr sr)
16152a6b7db3Sskrll     (set dr (mul dr sr))
16162a6b7db3Sskrll     ((m32r/d (unit u-exec (cycles 4)))
16172a6b7db3Sskrll      (m32rx (unit u-exec (cycles 4)))
16182a6b7db3Sskrll      (m32r2 (unit u-exec (cycles 4))))
16192a6b7db3Sskrll)
16202a6b7db3Sskrll
16212a6b7db3Sskrll(dni mulhi "mulhi"
16222a6b7db3Sskrll     ((MACH m32r) (PIPE S) (IDOC ACCUM))
16232a6b7db3Sskrll     "mulhi $src1,$src2"
16242a6b7db3Sskrll     (+ OP1_3 OP2_0 src1 src2)
16252a6b7db3Sskrll     (set accum
16262a6b7db3Sskrll	  (sra DI
16272a6b7db3Sskrll	       (sll DI
16282a6b7db3Sskrll		    (mul DI
16292a6b7db3Sskrll			 (ext DI (and WI src1 (const #xffff0000)))
16302a6b7db3Sskrll			 (ext DI (trunc HI (sra WI src2 (const 16)))))
16312a6b7db3Sskrll		    (const 16))
16322a6b7db3Sskrll	       (const 16)))
16332a6b7db3Sskrll     ((m32r/d (unit u-mac)))
16342a6b7db3Sskrll)
16352a6b7db3Sskrll
16362a6b7db3Sskrll(dni mulhi-a "mulhi-a"
16372a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC ACCUM))
16382a6b7db3Sskrll     "mulhi $src1,$src2,$acc"
16392a6b7db3Sskrll     (+ OP1_3 (f-op23 0) src1 acc src2)
16402a6b7db3Sskrll     (set acc
16412a6b7db3Sskrll	  (sra DI
16422a6b7db3Sskrll	       (sll DI
16432a6b7db3Sskrll		    (mul DI
16442a6b7db3Sskrll			 (ext DI (and WI src1 (const #xffff0000)))
16452a6b7db3Sskrll			 (ext DI (trunc HI (sra WI src2 (const 16)))))
16462a6b7db3Sskrll		    (const 16))
16472a6b7db3Sskrll	       (const 16)))
16482a6b7db3Sskrll     ((m32rx (unit u-mac))
16492a6b7db3Sskrll      (m32r2 (unit u-mac)))
16502a6b7db3Sskrll)
16512a6b7db3Sskrll
16522a6b7db3Sskrll(dni mullo "mullo"
16532a6b7db3Sskrll     ((MACH m32r) (PIPE S) (IDOC ACCUM))
16542a6b7db3Sskrll     "mullo $src1,$src2"
16552a6b7db3Sskrll     (+ OP1_3 OP2_1 src1 src2)
16562a6b7db3Sskrll     (set accum
16572a6b7db3Sskrll	  (sra DI
16582a6b7db3Sskrll	       (sll DI
16592a6b7db3Sskrll		    (mul DI
16602a6b7db3Sskrll			 (ext DI (sll WI src1 (const 16)))
16612a6b7db3Sskrll			 (ext DI (trunc HI src2)))
16622a6b7db3Sskrll		    (const 16))
16632a6b7db3Sskrll	       (const 16)))
16642a6b7db3Sskrll     ((m32r/d (unit u-mac)))
16652a6b7db3Sskrll)
16662a6b7db3Sskrll
16672a6b7db3Sskrll(dni mullo-a "mullo-a"
16682a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC ACCUM))
16692a6b7db3Sskrll     "mullo $src1,$src2,$acc"
16702a6b7db3Sskrll     (+ OP1_3 src1 acc (f-op23 1) src2)
16712a6b7db3Sskrll     (set acc
16722a6b7db3Sskrll	  (sra DI
16732a6b7db3Sskrll	       (sll DI
16742a6b7db3Sskrll		    (mul DI
16752a6b7db3Sskrll			 (ext DI (sll WI src1 (const 16)))
16762a6b7db3Sskrll			 (ext DI (trunc HI src2)))
16772a6b7db3Sskrll		    (const 16))
16782a6b7db3Sskrll	       (const 16)))
16792a6b7db3Sskrll     ((m32rx (unit u-mac))
16802a6b7db3Sskrll      (m32r2 (unit u-mac)))
16812a6b7db3Sskrll)
16822a6b7db3Sskrll
16832a6b7db3Sskrll(dni mulwhi "mulwhi"
16842a6b7db3Sskrll     ((MACH m32r) (PIPE S) (IDOC ACCUM))
16852a6b7db3Sskrll     "mulwhi $src1,$src2"
16862a6b7db3Sskrll     (+ OP1_3 OP2_2 src1 src2)
16872a6b7db3Sskrll     (set accum
16882a6b7db3Sskrll	  (sra DI
16892a6b7db3Sskrll	       (sll DI
16902a6b7db3Sskrll		    (mul DI
16912a6b7db3Sskrll			 (ext DI src1)
16922a6b7db3Sskrll			 (ext DI (trunc HI (sra WI src2 (const 16)))))
16932a6b7db3Sskrll		    (const 8))
16942a6b7db3Sskrll	       (const 8)))
16952a6b7db3Sskrll     ((m32r/d (unit u-mac)))
16962a6b7db3Sskrll)
16972a6b7db3Sskrll
16982a6b7db3Sskrll(dni mulwhi-a "mulwhi-a"
16992a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) SPECIAL (IDOC ACCUM))
17002a6b7db3Sskrll     "mulwhi $src1,$src2,$acc"
17012a6b7db3Sskrll     (+ OP1_3 src1 acc (f-op23 2) src2)
17022a6b7db3Sskrll     ; Note that this doesn't do the sign extension, which is correct.
17032a6b7db3Sskrll     (set acc
17042a6b7db3Sskrll	  (mul (ext DI src1)
17052a6b7db3Sskrll	       (ext DI (trunc HI (sra src2 (const 16))))))
17062a6b7db3Sskrll     ((m32rx (unit u-mac))
17072a6b7db3Sskrll      (m32r2 (unit u-mac)))
17082a6b7db3Sskrll)
17092a6b7db3Sskrll
17102a6b7db3Sskrll(dni mulwlo "mulwlo"
17112a6b7db3Sskrll     ((MACH m32r) (PIPE S) (IDOC ACCUM))
17122a6b7db3Sskrll     "mulwlo $src1,$src2"
17132a6b7db3Sskrll     (+ OP1_3 OP2_3 src1 src2)
17142a6b7db3Sskrll     (set accum
17152a6b7db3Sskrll	  (sra DI
17162a6b7db3Sskrll	       (sll DI
17172a6b7db3Sskrll		    (mul DI
17182a6b7db3Sskrll			 (ext DI src1)
17192a6b7db3Sskrll			 (ext DI (trunc HI src2)))
17202a6b7db3Sskrll		    (const 8))
17212a6b7db3Sskrll	       (const 8)))
17222a6b7db3Sskrll     ((m32r/d (unit u-mac)))
17232a6b7db3Sskrll)
17242a6b7db3Sskrll
17252a6b7db3Sskrll(dni mulwlo-a "mulwlo-a"
17262a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) SPECIAL (IDOC ACCUM))
17272a6b7db3Sskrll     "mulwlo $src1,$src2,$acc"
17282a6b7db3Sskrll     (+ OP1_3 src1 acc (f-op23 3) src2)
17292a6b7db3Sskrll     ; Note that this doesn't do the sign extension, which is correct.
17302a6b7db3Sskrll     (set acc
17312a6b7db3Sskrll	  (mul (ext DI src1)
17322a6b7db3Sskrll	       (ext DI (trunc HI src2))))
17332a6b7db3Sskrll     ((m32rx (unit u-mac))
17342a6b7db3Sskrll      (m32r2 (unit u-mac)))
17352a6b7db3Sskrll)
17362a6b7db3Sskrll
17372a6b7db3Sskrll(dni mv "mv"
17382a6b7db3Sskrll     ((PIPE OS) (IDOC ALU))
17392a6b7db3Sskrll     "mv $dr,$sr"
17402a6b7db3Sskrll     (+ OP1_1 OP2_8 dr sr)
17412a6b7db3Sskrll     (set dr sr)
17422a6b7db3Sskrll     ()
17432a6b7db3Sskrll)
17442a6b7db3Sskrll
17452a6b7db3Sskrll(dni mvfachi "mvfachi"
17462a6b7db3Sskrll     ((MACH m32r) (PIPE S) (IDOC ACCUM))
17472a6b7db3Sskrll     "mvfachi $dr"
17482a6b7db3Sskrll     (+ OP1_5 OP2_15 (f-r2 0) dr)
17492a6b7db3Sskrll     (set dr (trunc WI (sra DI accum (const 32))))
17502a6b7db3Sskrll     ((m32r/d (unit u-exec (cycles 2))))
17512a6b7db3Sskrll)
17522a6b7db3Sskrll
17532a6b7db3Sskrll(dni mvfachi-a "mvfachi-a"
17542a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC ACCUM))
17552a6b7db3Sskrll     "mvfachi $dr,$accs"
17562a6b7db3Sskrll     (+ OP1_5 dr OP2_15 accs (f-op3 0))
17572a6b7db3Sskrll     (set dr (trunc WI (sra DI accs (const 32))))
17582a6b7db3Sskrll     ((m32rx (unit u-exec (cycles 2)))
17592a6b7db3Sskrll      (m32r2 (unit u-exec (cycles 2))))
17602a6b7db3Sskrll)
17612a6b7db3Sskrll
17622a6b7db3Sskrll(dni mvfaclo "mvfaclo"
17632a6b7db3Sskrll     ((MACH m32r) (PIPE S) (IDOC ACCUM))
17642a6b7db3Sskrll     "mvfaclo $dr"
17652a6b7db3Sskrll     (+ OP1_5 OP2_15 (f-r2 1) dr)
17662a6b7db3Sskrll     (set dr (trunc WI accum))
17672a6b7db3Sskrll     ((m32r/d (unit u-exec (cycles 2))))
17682a6b7db3Sskrll)
17692a6b7db3Sskrll
17702a6b7db3Sskrll(dni mvfaclo-a "mvfaclo-a"
17712a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC ACCUM))
17722a6b7db3Sskrll     "mvfaclo $dr,$accs"
17732a6b7db3Sskrll     (+ OP1_5 dr OP2_15 accs (f-op3 1))
17742a6b7db3Sskrll     (set dr (trunc WI accs))
17752a6b7db3Sskrll     ((m32rx (unit u-exec (cycles 2)))
17762a6b7db3Sskrll      (m32r2 (unit u-exec (cycles 2))))
17772a6b7db3Sskrll)
17782a6b7db3Sskrll
17792a6b7db3Sskrll(dni mvfacmi "mvfacmi"
17802a6b7db3Sskrll     ((MACH m32r) (PIPE S) (IDOC ACCUM))
17812a6b7db3Sskrll     "mvfacmi $dr"
17822a6b7db3Sskrll     (+ OP1_5 OP2_15 (f-r2 2) dr)
17832a6b7db3Sskrll     (set dr (trunc WI (sra DI accum (const 16))))
17842a6b7db3Sskrll     ((m32r/d (unit u-exec (cycles 2))))
17852a6b7db3Sskrll)
17862a6b7db3Sskrll
17872a6b7db3Sskrll(dni mvfacmi-a "mvfacmi-a"
17882a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC ACCUM))
17892a6b7db3Sskrll     "mvfacmi $dr,$accs"
17902a6b7db3Sskrll     (+ OP1_5 dr OP2_15 accs (f-op3 2))
17912a6b7db3Sskrll     (set dr (trunc WI (sra DI accs (const 16))))
17922a6b7db3Sskrll     ((m32rx (unit u-exec (cycles 2)))
17932a6b7db3Sskrll      (m32r2 (unit u-exec (cycles 2))))
17942a6b7db3Sskrll)
17952a6b7db3Sskrll
17962a6b7db3Sskrll(dni mvfc "mvfc"
17972a6b7db3Sskrll     ((PIPE O) (IDOC MISC))
17982a6b7db3Sskrll     "mvfc $dr,$scr"
17992a6b7db3Sskrll     (+ OP1_1 OP2_9 dr scr)
18002a6b7db3Sskrll     (set dr scr)
18012a6b7db3Sskrll     ()
18022a6b7db3Sskrll)
18032a6b7db3Sskrll
18042a6b7db3Sskrll(dni mvtachi "mvtachi"
18052a6b7db3Sskrll     ((MACH m32r) (PIPE S) (IDOC ACCUM))
18062a6b7db3Sskrll     "mvtachi $src1"
18072a6b7db3Sskrll     (+ OP1_5 OP2_7 (f-r2 0) src1)
18082a6b7db3Sskrll     (set accum
18092a6b7db3Sskrll	  (or DI
18102a6b7db3Sskrll	      (and DI accum (const DI #xffffffff))
18112a6b7db3Sskrll	      (sll DI (ext DI src1) (const 32))))
18122a6b7db3Sskrll     ((m32r/d (unit u-exec (in sr src1))))
18132a6b7db3Sskrll)
18142a6b7db3Sskrll
18152a6b7db3Sskrll(dni mvtachi-a "mvtachi-a"
18162a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC ACCUM))
18172a6b7db3Sskrll     "mvtachi $src1,$accs"
18182a6b7db3Sskrll     (+ OP1_5 src1 OP2_7 accs (f-op3 0))
18192a6b7db3Sskrll     (set accs
18202a6b7db3Sskrll	  (or DI
18212a6b7db3Sskrll	      (and DI accs (const DI #xffffffff))
18222a6b7db3Sskrll	      (sll DI (ext DI src1) (const 32))))
18232a6b7db3Sskrll     ((m32rx (unit u-exec (in sr src1)))
18242a6b7db3Sskrll      (m32r2 (unit u-exec (in sr src1))))
18252a6b7db3Sskrll)
18262a6b7db3Sskrll
18272a6b7db3Sskrll(dni mvtaclo "mvtaclo"
18282a6b7db3Sskrll     ((MACH m32r) (PIPE S) (IDOC ACCUM))
18292a6b7db3Sskrll     "mvtaclo $src1"
18302a6b7db3Sskrll     (+ OP1_5 OP2_7 (f-r2 1) src1)
18312a6b7db3Sskrll     (set accum
18322a6b7db3Sskrll	  (or DI
18332a6b7db3Sskrll	      (and DI accum (const DI #xffffffff00000000))
18342a6b7db3Sskrll	      (zext DI src1)))
18352a6b7db3Sskrll     ((m32r/d (unit u-exec (in sr src1))))
18362a6b7db3Sskrll)
18372a6b7db3Sskrll
18382a6b7db3Sskrll(dni mvtaclo-a "mvtaclo-a"
18392a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC ACCUM))
18402a6b7db3Sskrll     "mvtaclo $src1,$accs"
18412a6b7db3Sskrll     (+ OP1_5 src1 OP2_7 accs (f-op3 1))
18422a6b7db3Sskrll     (set accs
18432a6b7db3Sskrll	  (or DI
18442a6b7db3Sskrll	      (and DI accs (const DI #xffffffff00000000))
18452a6b7db3Sskrll	      (zext DI src1)))
18462a6b7db3Sskrll     ((m32rx (unit u-exec (in sr src1)))
18472a6b7db3Sskrll      (m32r2 (unit u-exec (in sr src1))))
18482a6b7db3Sskrll)
18492a6b7db3Sskrll
18502a6b7db3Sskrll(dni mvtc "mvtc"
18512a6b7db3Sskrll     ((PIPE O) (IDOC MISC))
18522a6b7db3Sskrll     "mvtc $sr,$dcr"
18532a6b7db3Sskrll     (+ OP1_1 OP2_10 dcr sr)
18542a6b7db3Sskrll     (set dcr sr)
18552a6b7db3Sskrll     ()
18562a6b7db3Sskrll)
18572a6b7db3Sskrll
18582a6b7db3Sskrll(dni neg "neg"
18592a6b7db3Sskrll     ((PIPE OS) (IDOC ALU))
18602a6b7db3Sskrll     "neg $dr,$sr"
18612a6b7db3Sskrll     (+ OP1_0 OP2_3 dr sr)
18622a6b7db3Sskrll     (set dr (neg sr))
18632a6b7db3Sskrll     ()
18642a6b7db3Sskrll)
18652a6b7db3Sskrll
18662a6b7db3Sskrll(dni nop "nop"
18672a6b7db3Sskrll     ((PIPE OS) (IDOC MISC))
18682a6b7db3Sskrll     "nop"
18692a6b7db3Sskrll     (+ OP1_7 OP2_0 (f-r1 0) (f-r2 0))
18702a6b7db3Sskrll     (c-code VOID "PROFILE_COUNT_FILLNOPS (current_cpu, abuf->addr);\n")
18712a6b7db3Sskrll     ; FIXME: quick hack: parallel nops don't contribute to cycle count.
18722a6b7db3Sskrll     ; Other kinds of nops do however (which we currently ignore).
18732a6b7db3Sskrll     ((m32r/d (unit u-exec (cycles 0)))
18742a6b7db3Sskrll      (m32rx (unit u-exec (cycles 0)))
18752a6b7db3Sskrll      (m32r2 (unit u-exec (cycles 0))))
18762a6b7db3Sskrll)
18772a6b7db3Sskrll
18782a6b7db3Sskrll(dni not "not"
18792a6b7db3Sskrll     ((PIPE OS) (IDOC ALU))
18802a6b7db3Sskrll     "not $dr,$sr"
18812a6b7db3Sskrll     (+ OP1_0 OP2_11 dr sr)
18822a6b7db3Sskrll     (set dr (inv sr))
18832a6b7db3Sskrll     ()
18842a6b7db3Sskrll)
18852a6b7db3Sskrll
18862a6b7db3Sskrll(dni rac "rac"
18872a6b7db3Sskrll     ((MACH m32r) (PIPE S) (IDOC MAC))
18882a6b7db3Sskrll     "rac"
18892a6b7db3Sskrll     (+ OP1_5 OP2_9 (f-r1 0) (f-r2 0))
18902a6b7db3Sskrll     (sequence ((DI tmp1))
18912a6b7db3Sskrll	       (set tmp1 (sll DI accum (const 1)))
18922a6b7db3Sskrll	       (set tmp1 (add DI tmp1 (const DI #x8000)))
18932a6b7db3Sskrll	       (set accum
18942a6b7db3Sskrll		    (cond DI
18952a6b7db3Sskrll			  ((gt tmp1 (const DI #x00007fffffff0000))
18962a6b7db3Sskrll			   (const DI #x00007fffffff0000))
18972a6b7db3Sskrll			  ((lt tmp1 (const DI #xffff800000000000))
18982a6b7db3Sskrll			   (const DI #xffff800000000000))
18992a6b7db3Sskrll			  (else (and tmp1 (const DI #xffffffffffff0000)))))
19002a6b7db3Sskrll	       )
19012a6b7db3Sskrll     ((m32r/d (unit u-mac)))
19022a6b7db3Sskrll)
19032a6b7db3Sskrll
19042a6b7db3Sskrll(dni rac-dsi "rac-dsi"
19052a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC MAC))
19062a6b7db3Sskrll     "rac $accd,$accs,$imm1"
19072a6b7db3Sskrll     (+ OP1_5 accd (f-bits67 0) OP2_9 accs (f-bit14 0) imm1)
19082a6b7db3Sskrll     (sequence ((DI tmp1))
19092a6b7db3Sskrll	       (set tmp1 (sll accs imm1))
19102a6b7db3Sskrll	       (set tmp1 (add tmp1 (const DI #x8000)))
19112a6b7db3Sskrll	       (set accd
19122a6b7db3Sskrll		    (cond DI
19132a6b7db3Sskrll			  ((gt tmp1 (const DI #x00007fffffff0000))
19142a6b7db3Sskrll			   (const DI #x00007fffffff0000))
19152a6b7db3Sskrll			  ((lt tmp1 (const DI #xffff800000000000))
19162a6b7db3Sskrll			   (const DI #xffff800000000000))
19172a6b7db3Sskrll			  (else (and tmp1 (const DI #xffffffffffff0000)))))
19182a6b7db3Sskrll	       )
19192a6b7db3Sskrll     ((m32rx (unit u-mac))
19202a6b7db3Sskrll      (m32r2 (unit u-mac)))
19212a6b7db3Sskrll)
19222a6b7db3Sskrll
19232a6b7db3Sskrll(dnmi rac-d "rac-d"
19242a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC MAC))
19252a6b7db3Sskrll     "rac $accd"
19262a6b7db3Sskrll     (emit rac-dsi accd (f-accs 0) (f-imm1 0))
19272a6b7db3Sskrll)
19282a6b7db3Sskrll
19292a6b7db3Sskrll(dnmi rac-ds "rac-ds"
19302a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC MAC))
19312a6b7db3Sskrll     "rac $accd,$accs"
19322a6b7db3Sskrll     (emit rac-dsi accd accs (f-imm1 0))
19332a6b7db3Sskrll)
19342a6b7db3Sskrll
19352a6b7db3Sskrll
19362a6b7db3Sskrll(dni rach "rach"
19372a6b7db3Sskrll     ((MACH m32r) (PIPE S) (IDOC MAC))
19382a6b7db3Sskrll     "rach"
19392a6b7db3Sskrll     (+ OP1_5 OP2_8 (f-r1 0) (f-r2 0))
19402a6b7db3Sskrll     (sequence ((DI tmp1))
19412a6b7db3Sskrll	       ; Lop off top 8 bits.
19422a6b7db3Sskrll	       ; The sign bit we want to use is bit 55 so the 64 bit value
19432a6b7db3Sskrll	       ; isn't properly signed which we deal with in the if's below.
19442a6b7db3Sskrll	       (set tmp1 (and accum (const DI #xffffffffffffff)))
19452a6b7db3Sskrll	       (if (andif (ge tmp1 (const DI #x003fff80000000))
19462a6b7db3Sskrll			  (le tmp1 (const DI #x7fffffffffffff)))
19472a6b7db3Sskrll		   (set tmp1 (const DI #x003fff80000000))
19482a6b7db3Sskrll		   ; else part
19492a6b7db3Sskrll		   (if (andif (ge tmp1 (const DI #x80000000000000))
19502a6b7db3Sskrll			      (le tmp1 (const DI #xffc00000000000)))
19512a6b7db3Sskrll		       (set tmp1 (const DI #xffc00000000000))
19522a6b7db3Sskrll		       (set tmp1 (and (add accum (const DI #x40000000))
19532a6b7db3Sskrll				      (const DI #xffffffff80000000)))))
19542a6b7db3Sskrll	       (set tmp1 (sll tmp1 (const 1)))
19552a6b7db3Sskrll	       ; Sign extend top 8 bits.
19562a6b7db3Sskrll	       (set accum
19572a6b7db3Sskrll		    ; FIXME: 7?
19582a6b7db3Sskrll		    (sra DI (sll DI tmp1 (const 7)) (const 7)))
19592a6b7db3Sskrll	       )
19602a6b7db3Sskrll     ((m32r/d (unit u-mac)))
19612a6b7db3Sskrll)
19622a6b7db3Sskrll
19632a6b7db3Sskrll(dni rach-dsi "rach-dsi"
19642a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC MAC))
19652a6b7db3Sskrll     "rach $accd,$accs,$imm1"
19662a6b7db3Sskrll     (+ OP1_5 accd (f-bits67 0) OP2_8 accs (f-bit14 0) imm1)
19672a6b7db3Sskrll     (sequence ((DI tmp1))
19682a6b7db3Sskrll	       (set tmp1 (sll accs imm1))
19692a6b7db3Sskrll	       (set tmp1 (add tmp1 (const DI #x80000000)))
19702a6b7db3Sskrll	       (set accd
19712a6b7db3Sskrll		    (cond DI
19722a6b7db3Sskrll			  ((gt tmp1 (const DI #x00007fff00000000))
19732a6b7db3Sskrll			   (const DI #x00007fff00000000))
19742a6b7db3Sskrll			  ((lt tmp1 (const DI #xffff800000000000))
19752a6b7db3Sskrll			   (const DI #xffff800000000000))
19762a6b7db3Sskrll			  (else (and tmp1 (const DI #xffffffff00000000)))))
19772a6b7db3Sskrll	       )
19782a6b7db3Sskrll     ((m32rx (unit u-mac))
19792a6b7db3Sskrll      (m32r2 (unit u-mac)))
19802a6b7db3Sskrll)
19812a6b7db3Sskrll
19822a6b7db3Sskrll(dnmi rach-d "rach-d"
19832a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC MAC))
19842a6b7db3Sskrll     "rach $accd"
19852a6b7db3Sskrll     (emit rach-dsi accd (f-accs 0) (f-imm1 0))
19862a6b7db3Sskrll)
19872a6b7db3Sskrll
19882a6b7db3Sskrll(dnmi rach-ds "rach-ds"
19892a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC MAC))
19902a6b7db3Sskrll     "rach $accd,$accs"
19912a6b7db3Sskrll     (emit rach-dsi accd accs (f-imm1 0))
19922a6b7db3Sskrll)
19932a6b7db3Sskrll
19942a6b7db3Sskrll(dni rte "rte"
19952a6b7db3Sskrll     (UNCOND-CTI (PIPE O) (IDOC BR))
19962a6b7db3Sskrll     "rte"
19972a6b7db3Sskrll     (+ OP1_1 OP2_13 (f-r1 0) (f-r2 6))
19982a6b7db3Sskrll     (sequence ()
19992a6b7db3Sskrll	       ; pc = bpc & -4
20002a6b7db3Sskrll	       (set pc (and (reg h-cr 6) (const -4)))
20012a6b7db3Sskrll	       ; bpc = bbpc
20022a6b7db3Sskrll	       (set (reg h-cr 6) (reg h-cr 14))
20032a6b7db3Sskrll	       ; psw = bpsw
20042a6b7db3Sskrll	       (set (reg h-psw) (reg h-bpsw))
20052a6b7db3Sskrll	       ; bpsw = bbpsw
20062a6b7db3Sskrll	       (set (reg h-bpsw) (reg h-bbpsw))
20072a6b7db3Sskrll     )
20082a6b7db3Sskrll     ()
20092a6b7db3Sskrll)
20102a6b7db3Sskrll
20112a6b7db3Sskrll(dni seth "seth"
20122a6b7db3Sskrll     ((IDOC ALU))
20132a6b7db3Sskrll     "seth $dr,$hash$hi16"
20142a6b7db3Sskrll     (+ OP1_13 OP2_12 dr (f-r2 0) hi16)
20152a6b7db3Sskrll     (set dr (sll WI hi16 (const 16)))
20162a6b7db3Sskrll     ()
20172a6b7db3Sskrll)
20182a6b7db3Sskrll
20192a6b7db3Sskrll(define-pmacro (shift-op sym op2-r-op op2-3-op op2-i-op sem-op)
20202a6b7db3Sskrll  (begin
20212a6b7db3Sskrll     (dni sym sym ((PIPE O_OS) (IDOC ALU))
20222a6b7db3Sskrll	  (.str sym " $dr,$sr")
20232a6b7db3Sskrll	  (+ OP1_1 op2-r-op dr sr)
20242a6b7db3Sskrll	  (set dr (sem-op dr (and sr (const 31))))
20252a6b7db3Sskrll	  ()
20262a6b7db3Sskrll     )
20272a6b7db3Sskrll     (dni (.sym sym "3") sym ((IDOC ALU))
20282a6b7db3Sskrll	  (.str sym "3 $dr,$sr,$simm16")
20292a6b7db3Sskrll	  (+ OP1_9 op2-3-op dr sr simm16)
20302a6b7db3Sskrll	  (set dr (sem-op sr (and WI simm16 (const 31))))
20312a6b7db3Sskrll	  ()
20322a6b7db3Sskrll     )
20332a6b7db3Sskrll     (dni (.sym sym "i") sym ((PIPE O_OS) (IDOC ALU))
20342a6b7db3Sskrll	  (.str sym "i $dr,$uimm5")
20352a6b7db3Sskrll	  (+ OP1_5 (f-shift-op2 op2-i-op) dr uimm5)
20362a6b7db3Sskrll	  (set dr (sem-op dr uimm5))
20372a6b7db3Sskrll	  ()
20382a6b7db3Sskrll     )
20392a6b7db3Sskrll   )
20402a6b7db3Sskrll)
20412a6b7db3Sskrll(shift-op sll OP2_4 OP2_12 2 sll)
20422a6b7db3Sskrll(shift-op sra OP2_2 OP2_10 1 sra)
20432a6b7db3Sskrll(shift-op srl OP2_0 OP2_8 0 srl)
20442a6b7db3Sskrll
20452a6b7db3Sskrll(define-pmacro (store-op suffix op2-op mode)
20462a6b7db3Sskrll  (begin
20472a6b7db3Sskrll    (dni (.sym st suffix) (.str "st" suffix)
20482a6b7db3Sskrll	 ((PIPE O) (IDOC MEM))
20492a6b7db3Sskrll	 (.str "st" suffix " $src1,@$src2")
20502a6b7db3Sskrll	 (+ OP1_2 op2-op src1 src2)
20512a6b7db3Sskrll	 (set mode (mem mode src2) src1)
20522a6b7db3Sskrll	 ((m32r/d (unit u-store (cycles 1)))
20532a6b7db3Sskrll	  (m32rx (unit u-store (cycles 1)))
20542a6b7db3Sskrll	  (m32r2 (unit u-store (cycles 1))))
20552a6b7db3Sskrll	 )
20562a6b7db3Sskrll    (dnmi (.sym st suffix "-2") (.str "st" suffix "-2")
20572a6b7db3Sskrll	  (NO-DIS (PIPE O) (IDOC MEM))
20582a6b7db3Sskrll	  (.str "st" suffix " $src1,@($src2)")
20592a6b7db3Sskrll	  (emit (.sym st suffix) src1 src2))
20602a6b7db3Sskrll    (dni (.sym st suffix -d) (.str "st" suffix "-d")
20612a6b7db3Sskrll	 ((IDOC MEM))
20622a6b7db3Sskrll	 (.str "st" suffix " $src1,@($slo16,$src2)")
20632a6b7db3Sskrll	 (+ OP1_10 op2-op src1 src2 slo16)
20642a6b7db3Sskrll	 (set mode (mem mode (add src2 slo16)) src1)
20652a6b7db3Sskrll	 ((m32r/d (unit u-store (cycles 2)))
20662a6b7db3Sskrll	  (m32rx (unit u-store (cycles 2)))
20672a6b7db3Sskrll	  (m32r2 (unit u-store (cycles 2))))
20682a6b7db3Sskrll	 )
20692a6b7db3Sskrll    (dnmi (.sym st suffix -d2) (.str "st" suffix "-d2")
20702a6b7db3Sskrll	  (NO-DIS (IDOC MEM))
20712a6b7db3Sskrll	  (.str "st" suffix " $src1,@($src2,$slo16)")
20722a6b7db3Sskrll	  (emit (.sym st suffix -d) src1 src2 slo16))
20732a6b7db3Sskrll    )
20742a6b7db3Sskrll)
20752a6b7db3Sskrll(store-op "" OP2_4 WI)
20762a6b7db3Sskrll(store-op b OP2_0 QI)
20772a6b7db3Sskrll(store-op h OP2_2 HI)
20782a6b7db3Sskrll
20792a6b7db3Sskrll(dni st-plus "st+"
20802a6b7db3Sskrll     ((PIPE O) (IDOC MEM))
20812a6b7db3Sskrll     "st $src1,@+$src2"
20822a6b7db3Sskrll     (+ OP1_2 OP2_6 src1 src2)
20832a6b7db3Sskrll     ; This has to be coded carefully to avoid an "earlyclobber" of src2.
20842a6b7db3Sskrll     (sequence ((WI new-src2))
20852a6b7db3Sskrll	       (set new-src2 (add WI src2 (const WI 4)))
20862a6b7db3Sskrll	       (set (mem WI new-src2) src1)
20872a6b7db3Sskrll	       (set src2 new-src2))
20882a6b7db3Sskrll     ((m32r/d (unit u-store)
20892a6b7db3Sskrll	      (unit u-exec (in dr src2) (out dr src2) (cycles 0)))
20902a6b7db3Sskrll      (m32rx (unit u-store)
20912a6b7db3Sskrll	     (unit u-exec (in dr src2) (out dr src2) (cycles 0)))
20922a6b7db3Sskrll      (m32r2 (unit u-store)
20932a6b7db3Sskrll	     (unit u-exec (in dr src2) (out dr src2) (cycles 0)))
20942a6b7db3Sskrll      )
20952a6b7db3Sskrll)
20962a6b7db3Sskrll
20972a6b7db3Sskrll(dni sth-plus "sth+"
20982a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE O) SPECIAL)
20992a6b7db3Sskrll     "sth $src1,@$src2+"
21002a6b7db3Sskrll     (+ OP1_2 OP2_3 src1 src2)
21012a6b7db3Sskrll     ; This has to be coded carefully to avoid an "earlyclobber" of src2.
2102be12b8bcSchristos     (sequence ((WI new-src2))
2103be12b8bcSchristos	       (set new-src2 src2)
21042a6b7db3Sskrll	       (set (mem HI new-src2) src1)
2105be12b8bcSchristos	       (set src2 (add new-src2 (const 2))))
21062a6b7db3Sskrll     ((m32rx (unit u-store)
21072a6b7db3Sskrll           (unit u-exec (in dr src2) (out dr src2) (cycles 0)))
21082a6b7db3Sskrll      (m32r2 (unit u-store)
21092a6b7db3Sskrll           (unit u-exec (in dr src2) (out dr src2) (cycles 0)))
21102a6b7db3Sskrll      )
21112a6b7db3Sskrll)
21122a6b7db3Sskrll
21132a6b7db3Sskrll(dni stb-plus "stb+"
21142a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE O) SPECIAL)
21152a6b7db3Sskrll     "stb $src1,@$src2+"
21162a6b7db3Sskrll     (+ OP1_2 OP2_1 src1 src2)
21172a6b7db3Sskrll     ; This has to be coded carefully to avoid an "earlyclobber" of src2.
2118be12b8bcSchristos     (sequence ((WI new-src2))
2119be12b8bcSchristos	       (set new-src2 src2)
21202a6b7db3Sskrll	       (set (mem QI new-src2) src1)
2121be12b8bcSchristos	       (set src2 (add new-src2 (const 1))))
21222a6b7db3Sskrll     ((m32rx (unit u-store)
21232a6b7db3Sskrll           (unit u-exec (in dr src2) (out dr src2) (cycles 0)))
21242a6b7db3Sskrll      (m32r2 (unit u-store)
21252a6b7db3Sskrll           (unit u-exec (in dr src2) (out dr src2) (cycles 0)))
21262a6b7db3Sskrll      )
21272a6b7db3Sskrll)
21282a6b7db3Sskrll
21292a6b7db3Sskrll(dni st-minus "st-"
21302a6b7db3Sskrll     ((PIPE O) (IDOC MEM))
21312a6b7db3Sskrll     "st $src1,@-$src2"
21322a6b7db3Sskrll     (+ OP1_2 OP2_7 src1 src2)
21332a6b7db3Sskrll     ; This is the original way.  It doesn't work for parallel execution
21342a6b7db3Sskrll     ; because of the earlyclobber of src2.
21352a6b7db3Sskrll     ;(sequence ()
21362a6b7db3Sskrll     ;	       (set src2 (sub src2 (const 4)))
21372a6b7db3Sskrll     ;	       (set (mem WI src2) src1))
21382a6b7db3Sskrll     (sequence ((WI new-src2))
21392a6b7db3Sskrll	       (set new-src2 (sub src2 (const 4)))
21402a6b7db3Sskrll	       (set (mem WI new-src2) src1)
21412a6b7db3Sskrll	       (set src2 new-src2))
21422a6b7db3Sskrll     ((m32r/d (unit u-store)
21432a6b7db3Sskrll	      (unit u-exec (in dr src2) (out dr src2) (cycles 0)))
21442a6b7db3Sskrll      (m32rx (unit u-store)
21452a6b7db3Sskrll	     (unit u-exec (in dr src2) (out dr src2) (cycles 0)))
21462a6b7db3Sskrll      (m32r2 (unit u-store)
21472a6b7db3Sskrll	     (unit u-exec (in dr src2) (out dr src2) (cycles 0)))
21482a6b7db3Sskrll      )
21492a6b7db3Sskrll)
21502a6b7db3Sskrll
21512a6b7db3Sskrll(dnmi push "push" ((PIPE O) (IDOC MEM))
21522a6b7db3Sskrll  "push $src1"
21532a6b7db3Sskrll  (emit st-minus src1 (src2 15)) ; "st %0,@-sp"
21542a6b7db3Sskrll)
21552a6b7db3Sskrll
21562a6b7db3Sskrll(dni sub "sub"
21572a6b7db3Sskrll     ((PIPE OS) (IDOC ALU))
21582a6b7db3Sskrll     "sub $dr,$sr"
21592a6b7db3Sskrll     (+ OP1_0 OP2_2 dr sr)
21602a6b7db3Sskrll     (set dr (sub dr sr))
21612a6b7db3Sskrll     ()
21622a6b7db3Sskrll)
21632a6b7db3Sskrll
21642a6b7db3Sskrll(dni subv "sub:rv"
21652a6b7db3Sskrll     ((PIPE OS) (IDOC ALU))
21662a6b7db3Sskrll     "subv $dr,$sr"
21672a6b7db3Sskrll     (+ OP1_0 OP2_0 dr sr)
21682a6b7db3Sskrll     (parallel ()
21692a6b7db3Sskrll	       (set dr (sub dr sr))
21702a6b7db3Sskrll	       (set condbit (sub-oflag dr sr (const 0))))
21712a6b7db3Sskrll     ()
21722a6b7db3Sskrll)
21732a6b7db3Sskrll
21742a6b7db3Sskrll(dni subx "sub:rx"
21752a6b7db3Sskrll     ((PIPE OS) (IDOC ALU))
21762a6b7db3Sskrll     "subx $dr,$sr"
21772a6b7db3Sskrll     (+ OP1_0 OP2_1 dr sr)
21782a6b7db3Sskrll     (parallel ()
21792a6b7db3Sskrll	       (set dr (subc dr sr condbit))
21802a6b7db3Sskrll	       (set condbit (sub-cflag dr sr condbit)))
21812a6b7db3Sskrll     ()
21822a6b7db3Sskrll)
21832a6b7db3Sskrll
21842a6b7db3Sskrll(dni trap "trap"
21852a6b7db3Sskrll     (UNCOND-CTI FILL-SLOT (PIPE O) (IDOC MISC))
21862a6b7db3Sskrll     "trap $uimm4"
21872a6b7db3Sskrll     (+ OP1_1 OP2_15 (f-r1 0) uimm4)
21882a6b7db3Sskrll     (sequence ()
21892a6b7db3Sskrll	       ; bbpc = bpc
21902a6b7db3Sskrll	       (set (reg h-cr 14) (reg h-cr 6))
21912a6b7db3Sskrll	       ; Set bpc to the return address.  Actually it's not quite the
21922a6b7db3Sskrll	       ; return address as RTE rounds the address down to a word
21932a6b7db3Sskrll	       ; boundary.
21942a6b7db3Sskrll	       (set (reg h-cr 6) (add pc (const 4)))
21952a6b7db3Sskrll	       ; bbpsw = bpsw
21962a6b7db3Sskrll	       (set (reg h-bbpsw) (reg h-bpsw))
21972a6b7db3Sskrll	       ; bpsw = psw
21982a6b7db3Sskrll	       (set (reg h-bpsw) (reg h-psw))
21992a6b7db3Sskrll	       ; sm is unchanged, ie,c are set to zero.
22002a6b7db3Sskrll	       (set (reg h-psw) (and (reg h-psw) (const #x80)))
22012a6b7db3Sskrll	       ; m32r_trap handles operating vs user mode
22022a6b7db3Sskrll	       (set WI pc (c-call WI "m32r_trap" pc uimm4))
22032a6b7db3Sskrll     )
22042a6b7db3Sskrll     ()
22052a6b7db3Sskrll)
22062a6b7db3Sskrll
22072a6b7db3Sskrll(dni unlock "unlock"
22082a6b7db3Sskrll     ((PIPE O) (IDOC MISC))
22092a6b7db3Sskrll     "unlock $src1,@$src2"
22102a6b7db3Sskrll     (+ OP1_2 OP2_5 src1 src2)
22112a6b7db3Sskrll     (sequence ()
22122a6b7db3Sskrll	       (if (reg h-lock)
22132a6b7db3Sskrll		   (set (mem WI src2) src1))
22142a6b7db3Sskrll	       (set (reg h-lock) (const BI 0)))
22152a6b7db3Sskrll     ((m32r/d (unit u-load))
22162a6b7db3Sskrll      (m32rx (unit u-load))
22172a6b7db3Sskrll      (m32r2 (unit u-load)))
22182a6b7db3Sskrll)
22192a6b7db3Sskrll
22202a6b7db3Sskrll; Saturate into byte.
22212a6b7db3Sskrll(dni satb "satb"
22222a6b7db3Sskrll     ((MACH m32rx,m32r2) (IDOC ALU))
22232a6b7db3Sskrll     "satb $dr,$sr"
22242a6b7db3Sskrll     (+ OP1_8 dr OP2_6 sr (f-uimm16 #x0300))
22252a6b7db3Sskrll     (set dr
22262a6b7db3Sskrll	  ; FIXME: min/max would simplify this nicely of course.
22272a6b7db3Sskrll	  (cond WI
22282a6b7db3Sskrll		((ge sr (const 127)) (const 127))
22292a6b7db3Sskrll		((le sr (const -128)) (const -128))
22302a6b7db3Sskrll		(else sr)))
22312a6b7db3Sskrll     ()
22322a6b7db3Sskrll)
22332a6b7db3Sskrll
22342a6b7db3Sskrll; Saturate into half word.
22352a6b7db3Sskrll(dni sath "sath"
22362a6b7db3Sskrll     ((MACH m32rx,m32r2) (IDOC ALU))
22372a6b7db3Sskrll     "sath $dr,$sr"
22382a6b7db3Sskrll     (+ OP1_8 dr OP2_6 sr (f-uimm16 #x0200))
22392a6b7db3Sskrll     (set dr
22402a6b7db3Sskrll	  (cond WI
22412a6b7db3Sskrll		((ge sr (const 32767)) (const 32767))
22422a6b7db3Sskrll		((le sr (const -32768)) (const -32768))
22432a6b7db3Sskrll		(else sr)))
22442a6b7db3Sskrll     ()
22452a6b7db3Sskrll)
22462a6b7db3Sskrll
22472a6b7db3Sskrll; Saturate word.
22482a6b7db3Sskrll(dni sat "sat"
22492a6b7db3Sskrll     ((MACH m32rx,m32r2) SPECIAL (IDOC ALU))
22502a6b7db3Sskrll     "sat $dr,$sr"
22512a6b7db3Sskrll     (+ OP1_8 dr OP2_6 sr (f-uimm16 0))
22522a6b7db3Sskrll     (set dr
22532a6b7db3Sskrll	  (if WI condbit
22542a6b7db3Sskrll	       (if WI (lt sr (const 0))
22552a6b7db3Sskrll		    (const #x7fffffff)
22562a6b7db3Sskrll		    (const #x80000000))
22572a6b7db3Sskrll	       sr))
22582a6b7db3Sskrll     ()
22592a6b7db3Sskrll)
22602a6b7db3Sskrll
22612a6b7db3Sskrll; Parallel compare byte zeros.
22622a6b7db3Sskrll; Set C bit in condition register if any byte in source register is zero.
22632a6b7db3Sskrll(dni pcmpbz "pcmpbz"
22642a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE OS) SPECIAL (IDOC ALU))
22652a6b7db3Sskrll     "pcmpbz $src2"
22662a6b7db3Sskrll     (+ OP1_0 (f-r1 3) OP2_7 src2)
22672a6b7db3Sskrll     (set condbit
22682a6b7db3Sskrll	  (cond BI
22692a6b7db3Sskrll		 ((eq (and src2 (const #xff)) (const 0)) (const BI 1))
22702a6b7db3Sskrll		 ((eq (and src2 (const #xff00)) (const 0)) (const BI 1))
22712a6b7db3Sskrll		 ((eq (and src2 (const #xff0000)) (const 0)) (const BI 1))
22722a6b7db3Sskrll		 ((eq (and src2 (const #xff000000)) (const 0)) (const BI 1))
22732a6b7db3Sskrll		 (else (const BI 0))))
22742a6b7db3Sskrll     ((m32rx (unit u-cmp))
22752a6b7db3Sskrll      (m32r2 (unit u-cmp)))
22762a6b7db3Sskrll)
22772a6b7db3Sskrll
22782a6b7db3Sskrll; Add accumulators
22792a6b7db3Sskrll(dni sadd "sadd"
22802a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC ACCUM))
22812a6b7db3Sskrll     "sadd"
22822a6b7db3Sskrll     (+ OP1_5 (f-r1 0) OP2_14 (f-r2 4))
22832a6b7db3Sskrll     (set (reg h-accums 0)
22842a6b7db3Sskrll	  (add (sra (reg h-accums 1) (const 16))
22852a6b7db3Sskrll	       (reg h-accums 0)))
22862a6b7db3Sskrll     ((m32rx (unit u-mac))
22872a6b7db3Sskrll      (m32r2 (unit u-mac)))
22882a6b7db3Sskrll)
22892a6b7db3Sskrll
22902a6b7db3Sskrll; Multiply and add into accumulator 1
22912a6b7db3Sskrll(dni macwu1 "macwu1"
22922a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC MAC))
22932a6b7db3Sskrll     "macwu1 $src1,$src2"
22942a6b7db3Sskrll     (+ OP1_5 src1 OP2_11 src2)
22952a6b7db3Sskrll     (set (reg h-accums 1)
22962a6b7db3Sskrll	  (sra DI
22972a6b7db3Sskrll		(sll DI
22982a6b7db3Sskrll		      (add DI
22992a6b7db3Sskrll			    (reg h-accums 1)
23002a6b7db3Sskrll			    (mul DI
23012a6b7db3Sskrll				  (ext DI src1)
23022a6b7db3Sskrll				  (ext DI (and src2 (const #xffff)))))
23032a6b7db3Sskrll		      (const 8))
23042a6b7db3Sskrll		(const 8)))
23052a6b7db3Sskrll     ((m32rx (unit u-mac))
23062a6b7db3Sskrll      (m32r2 (unit u-mac)))
23072a6b7db3Sskrll)
23082a6b7db3Sskrll
23092a6b7db3Sskrll; Multiply and subtract from accumulator 0
23102a6b7db3Sskrll(dni msblo "msblo"
23112a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC MAC))
23122a6b7db3Sskrll     "msblo $src1,$src2"
23132a6b7db3Sskrll     (+ OP1_5 src1 OP2_13 src2)
23142a6b7db3Sskrll     (set accum
23152a6b7db3Sskrll	  (sra DI
23162a6b7db3Sskrll		(sll DI
23172a6b7db3Sskrll		      (sub accum
23182a6b7db3Sskrll			   (sra DI
23192a6b7db3Sskrll				 (sll DI
23202a6b7db3Sskrll				       (mul DI
23212a6b7db3Sskrll					     (ext DI (trunc HI src1))
23222a6b7db3Sskrll					     (ext DI (trunc HI src2)))
23232a6b7db3Sskrll				       (const 32))
23242a6b7db3Sskrll				 (const 16)))
23252a6b7db3Sskrll		      (const 8))
23262a6b7db3Sskrll		(const 8)))
23272a6b7db3Sskrll     ((m32rx (unit u-mac))
23282a6b7db3Sskrll      (m32r2 (unit u-mac)))
23292a6b7db3Sskrll)
23302a6b7db3Sskrll
23312a6b7db3Sskrll; Multiply into accumulator 1
23322a6b7db3Sskrll(dni mulwu1 "mulwu1"
23332a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC MAC))
23342a6b7db3Sskrll     "mulwu1 $src1,$src2"
23352a6b7db3Sskrll     (+ OP1_5 src1 OP2_10 src2)
23362a6b7db3Sskrll     (set (reg h-accums 1)
23372a6b7db3Sskrll	  (sra DI
23382a6b7db3Sskrll		(sll DI
23392a6b7db3Sskrll		      (mul DI
23402a6b7db3Sskrll			    (ext DI src1)
23412a6b7db3Sskrll			    (ext DI (and src2 (const #xffff))))
23422a6b7db3Sskrll		      (const 16))
23432a6b7db3Sskrll		(const 16)))
23442a6b7db3Sskrll     ((m32rx (unit u-mac))
23452a6b7db3Sskrll      (m32r2 (unit u-mac)))
23462a6b7db3Sskrll)
23472a6b7db3Sskrll
23482a6b7db3Sskrll; Multiply and add into accumulator 1
23492a6b7db3Sskrll(dni maclh1 "maclh1"
23502a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE S) (IDOC MAC))
23512a6b7db3Sskrll     "maclh1 $src1,$src2"
23522a6b7db3Sskrll     (+ OP1_5 src1 OP2_12 src2)
23532a6b7db3Sskrll     (set (reg h-accums 1)
23542a6b7db3Sskrll	  (sra DI
23552a6b7db3Sskrll		(sll DI
23562a6b7db3Sskrll		    (add DI
23572a6b7db3Sskrll			  (reg h-accums 1)
23582a6b7db3Sskrll			  (sll DI
23592a6b7db3Sskrll				(ext DI
23602a6b7db3Sskrll				      (mul SI
23612a6b7db3Sskrll					    (ext SI (trunc HI src1))
23622a6b7db3Sskrll					    (sra SI src2 (const SI 16))))
23632a6b7db3Sskrll			      (const 16)))
23642a6b7db3Sskrll		    (const 8))
23652a6b7db3Sskrll	       (const 8)))
23662a6b7db3Sskrll     ((m32rx (unit u-mac))
23672a6b7db3Sskrll      (m32r2 (unit u-mac)))
23682a6b7db3Sskrll)
23692a6b7db3Sskrll
23702a6b7db3Sskrll; skip instruction if C
23712a6b7db3Sskrll(dni sc "sc"
23722a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE O) SPECIAL (IDOC BR))
23732a6b7db3Sskrll     "sc"
23742a6b7db3Sskrll     (+ OP1_7 (f-r1 4) OP2_0 (f-r2 1))
23752a6b7db3Sskrll     (skip (zext INT condbit))
23762a6b7db3Sskrll     ()
23772a6b7db3Sskrll)
23782a6b7db3Sskrll
23792a6b7db3Sskrll; skip instruction if not C
23802a6b7db3Sskrll(dni snc "snc"
23812a6b7db3Sskrll     ((MACH m32rx,m32r2) (PIPE O) SPECIAL (IDOC BR))
23822a6b7db3Sskrll     "snc"
23832a6b7db3Sskrll     (+ OP1_7 (f-r1 5) OP2_0 (f-r2 1))
23842a6b7db3Sskrll     (skip (zext INT (not condbit)))
23852a6b7db3Sskrll     ()
23862a6b7db3Sskrll)
23872a6b7db3Sskrll
2388be12b8bcSchristos; PSW &= ((~ uimm8) | 0xff00)
23892a6b7db3Sskrll(dni clrpsw "clrpsw"
23902a6b7db3Sskrll     ((PIPE O) SPECIAL_M32R)
23912a6b7db3Sskrll     "clrpsw $uimm8"
23922a6b7db3Sskrll     (+ OP1_7 (f-r1 2) uimm8)
23932a6b7db3Sskrll     (set USI (reg h-cr 0)
23942a6b7db3Sskrll              (and USI (reg h-cr 0)
2395be12b8bcSchristos		   (or USI (zext SI (inv QI uimm8)) (const #xff00))))
23962a6b7db3Sskrll     ()
23972a6b7db3Sskrll)
23982a6b7db3Sskrll
23992a6b7db3Sskrll; PSW |= (unsigned char) uimm8
24002a6b7db3Sskrll(dni setpsw "setpsw"
24012a6b7db3Sskrll     ((PIPE O) SPECIAL_M32R)
24022a6b7db3Sskrll     "setpsw $uimm8"
24032a6b7db3Sskrll     (+ OP1_7 (f-r1 1) uimm8)
24042a6b7db3Sskrll     (set USI (reg h-cr 0) uimm8)
24052a6b7db3Sskrll     ()
24062a6b7db3Sskrll)
24072a6b7db3Sskrll
24082a6b7db3Sskrll; bset
24092a6b7db3Sskrll(dni bset "bset"
24102a6b7db3Sskrll     (SPECIAL_M32R)
24112a6b7db3Sskrll     "bset $uimm3,@($slo16,$sr)"
24122a6b7db3Sskrll     (+ OP1_10 (f-bit4 0) uimm3 OP2_6 sr slo16)
24132a6b7db3Sskrll     (set QI (mem QI (add sr slo16))
24142a6b7db3Sskrll             (or QI (mem QI (add sr slo16))
2415be12b8bcSchristos		 (sll QI (const 1) (sub (const 7) uimm3))))
24162a6b7db3Sskrll     ()
24172a6b7db3Sskrll)
24182a6b7db3Sskrll
24192a6b7db3Sskrll; bclr
24202a6b7db3Sskrll(dni bclr "bclr"
24212a6b7db3Sskrll     (SPECIAL_M32R)
24222a6b7db3Sskrll     "bclr $uimm3,@($slo16,$sr)"
24232a6b7db3Sskrll     (+ OP1_10 (f-bit4 0) uimm3  OP2_7 sr slo16)
24242a6b7db3Sskrll     (set QI (mem QI (add sr slo16))
24252a6b7db3Sskrll             (and QI (mem QI (add sr slo16))
2426be12b8bcSchristos                   (inv QI (sll QI (const 1) (sub (const 7) uimm3)))))
24272a6b7db3Sskrll     ()
24282a6b7db3Sskrll)
24292a6b7db3Sskrll
24302a6b7db3Sskrll; btst
24312a6b7db3Sskrll(dni btst "btst"
24322a6b7db3Sskrll     (SPECIAL_M32R (PIPE O))
24332a6b7db3Sskrll     "btst $uimm3,$sr"
24342a6b7db3Sskrll     (+ OP1_0 (f-bit4 0) uimm3 OP2_15 sr)
2435be12b8bcSchristos     (set condbit (and QI (srl QI sr (sub (const 7) uimm3)) (const 1)))
24362a6b7db3Sskrll     ()
24372a6b7db3Sskrll)
2438